Skip to content
/ myDBMS Public
forked from zerofang/myDBMS

SQL解释器,内存键值对数据库,SQL interpreter,LEX&YACC,FLEX&BISON

Notifications You must be signed in to change notification settings

AkaCMD/myDBMS

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

myDBMS

声明 :

fork自学长的代码,改成在windows上编译运行

for run :

RE:
windows

command:
flex sql.l
bison -d sql.y
gcc sql.c lex.yy.c sql.tab.c -o mysql
./mysql

for test :

//测试CREATE DATABASE SHOW DATABASES DROP DATABASE USE DATABASE
CREATE DATABASE XJGL;
CREATE DATABASE JUST_FOR_TEST;
CREATE DATABASE JUST_FOR_TEST;
SHOW DATABASES;
DROP DATABASE JUST_FOR_TEST;
SHOW DATABASES;
USE XJGL;

//测试CREATE TABLE SHOW TABLES DROP TABLE
CREATE TABLE STUDENT(SNAME CHAR(20),SAGE INT,SSEX INT);
CREATE TABLE COURSE(CNAME CHAR(20),CID INT);
CREATE TABLE CS(SNAME CHAR(20),CID INT);
CREATE TABLE TESTTABLE(COL1 CHAR(22),COL2 INT,COL3 CHAR(22));
CREATE TABLE TEST_TABLE(COL1 CHAR(22),COL2 INT,COL3 CHAR(22));
SHOW TABLES;
DROP TABLE TEST_TABLE;
SHOW TABLES;

//测试INSERT INTO VALUES
INSERT INTO STUDENT(SNAME,SAGE,SSEX) VALUES ('ZHANGSAN',22,1);
INSERT INTO STUDENT VALUES ('LISI',23,0);
INSERT INTO STUDENT(SNAME,SAGE) VALUES ('WANGWU',21);
INSERT INTO STUDENT VALUES ('ZHAOLIU',22,1);
INSERT INTO STUDENT VALUES ('XIAOBAI',23,0);
INSERT INTO STUDENT VALUES ('XIAOHEI',19,0);
INSERT INTO COURSE (CNAME,CID) VALUES ('DB',1);
INSERT INTO COURSE (CNAME,CID) VALUES('COMPILER',2);
insert into course (CNAME,CID) VALUES('C',3);
insert into COURSE (CNAME,CID) VALUES('C',3);

//测试单表查询
SELECT * FROM COURSE;
SELECT * FROM STUDENT;
SELECT SNAME,SAGE,SSEX FROM STUDENT;
SELECT SNAME,SAGE FROM STUDENT;
SELECT SNAME,SAGE FROM STUDENT WHERE SAGE=22;
SELECT SNAME,SAGE FROM STUDENT WHERE (((SAGE=21)));
SELECT SNAME,SAGE FROM STUDENT WHERE SAGE>21 AND SSEX=0;
SELECT SNAME,SAGE FROM STUDENT WHERE SAGE>21 OR SSEX=0;
SELECT SNAME,SAGE FROM STUDENT WHERE SAGE>21 OR SSEX=0 AND SNAME = 'LISI';
SELECT SNAME,SAGE FROM STUDENT WHERE (SAGE>21 OR SSEX=0) AND SNAME = 'LISI';
SELECT * FROM STUDENT WHERE SSEX!=1;

// 测试多表查询
SELECT * FROM STUDENT;
SELECT * FROM COURSE;
select * from student,course;
SELECT * FROM STUDENT,COURSE WHERE (SSEX=0) AND (CID=1);

//测试DELETE语句
SELECT * FROM STUDENT;
DELETE FROM STUDENT WHERE (SAGE>21) AND (SSEX=0);
SELECT * FROM STUDENT;

//测试UPDATE
SELECT * FROM STUDENT;
UPDATE STUDENT SET SAGE=21 WHERE SSEX=1;
SELECT * FROM STUDENT;
UPDATE STUDENT SET SAGE=27,SSEX=1 WHERE SNAME='ZHANGSAN';
SELECT * FROM STUDENT;

//再次测试DROP
SHOW TABLES;
DROP TABLE STUDENT;
SHOW TABLES;
DROP TABLE CS;
SHOW TABLES;
DROP TABLE TESTTABLE;
SHOW TABLES;
SHOW DATABASES;
DROP DATABASE XJGL;
SHOW DATABASES;

//正常退出
EXIT;

About

SQL解释器,内存键值对数据库,SQL interpreter,LEX&YACC,FLEX&BISON

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 79.4%
  • Yacc 17.5%
  • Lex 3.1%