Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DBMS/DBMS/dbManage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ bool DBManager::updateRecord(string tableName,BYTE **Value,string *colName,BYTE
return true;
}

void DBManager::combine(const vector<RecordEntry*> &A, const vector<RecordEntry*> &B, string tableAName, string tableBName,
void DBManager::combine(const vector<RecordEntry*> &A, const vector<RecordEntry*> &B, string tableAName, string tableBName,
vector<tableJoinRequire> joinReq, string *showAColName, int showANum, string *showBColName, int showBNum) {
cout << "***************select join data show**********************" << endl;
for(int i = 0; i < A.size(); i++) {
Expand Down Expand Up @@ -239,7 +239,7 @@ int DBManager::getColumeIndex(string tableName, string columnName) {
}
return -1;
}
void DBManager::printJoinRes(RecordEntry* A, RecordEntry* B, string tableAName, string tableBName,
void DBManager::printJoinRes(RecordEntry* A, RecordEntry* B, string tableAName, string tableBName,
string *showAColName, int showANum, string *showBColName, int showBNum){
int colIndex = -1;

Expand Down
Binary file removed DBMS/DBMS/orderDB/_sysFile
Binary file not shown.
Binary file removed DBMS/DBMS/orderDB/publisher
Binary file not shown.
2 changes: 1 addition & 1 deletion DBMS/DBMS/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class table{
int getDbid() { return dbid; }
int getColumnNum(){ return columnNum; }
cName getColumnName() { return colName; }
void setName(char *c) { strcpy(name,c); }
void setName(char *c) { strcpy_s(name,c); }
void setid(int i){ table_id = i; }
void setdbid(int i = -1){dbid = i; }
void setColumnNum(int i){ columnNum = i; }
Expand Down
11 changes: 11 additions & 0 deletions DBMS/DBMS/test1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
INSERT INTO publisher VALUES
(100008,'Test2','USA');
INSERT INTO publisher VALUES
(100008,'Test3','USA');
update publisher set nation = 'CNA' where name = 'Test2';
select * from publisher where name = 'Test2';

join ==== result size
exe file
input choose

55 changes: 46 additions & 9 deletions DBMS/DBMS/wq_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,53 @@ parser::~parser() {
delete currentDb;
}
void parser::testParse(){
char filename[100];
char executeInst[1000];
vector<string> res;
printf("please input the following instruction to get into the different mode. \n");
printf("input command, get into the execute mode, one sql command.\n");
printf("input file, get into the the execute mode, many commands in file.\n");
printf("input quit, get into the quit mode.\n");
printf("input other string, start to execute in your choose mode, default one sql command.\n");
bool fileFlag = false;
while(true) {
printf("please input the command filename. If you want to quit, please input quit.\n");
scanf("%s", filename);
if (strcmp(filename, "quit") == 0)
printf(">>\n");
scanf("%s",executeInst);
if (strcmp(executeInst, "quit") == 0)
break;
else
BatchSqlInFile(filename);
else if (strcmp(executeInst, "command") == 0) {
fileFlag = false;
}
else if (strcmp(executeInst, "file") == 0) {
fileFlag = true;
}
else {
if (fileFlag == true)
BatchSqlInFile(executeInst);
else {
res.clear();
while (strcmp(executeInst, ";") != 0 && (strlen(executeInst)>0 && executeInst[strlen(executeInst)-1] !=';')) {
if (strlen(executeInst) > 0)
res.push_back(executeInst);
scanf("%s", executeInst);
}
if (strlen(executeInst)>0 && executeInst[strlen(executeInst)-1] ==';')
{
string temp(executeInst);
temp.erase(temp.length()-1);
if (temp.length() > 0)
res.push_back(temp);
}
if (!parserOneCommand(res))
cout << "*************This command is wrong.*************************" << endl;
else
cout << "*************This command is executed rightly***************" << endl;
}
}
}
}

void parser::BatchSqlInFile(char* filename) {

void parser::BatchSqlInFile(const char* filename) {
FILE* fin = fopen(filename, "r");
if (fin == NULL)
{
Expand All @@ -40,7 +75,9 @@ void parser::BatchSqlInFile(char* filename) {
//This is one command;
res[res.size()-1].erase(res[res.size()-1].length()-1);
if (!parserOneCommand(res))
cout << "This command is wrong." << endl;
cout << "*************This command is wrong.*************************" << endl;
else
cout << "*************This command is executed rightly***************" << endl;
res.clear();
}
if (feof(fin))
Expand Down Expand Up @@ -115,7 +152,7 @@ bool parser::parserOneCommand(vector<string> commands) {
else if (checkKeyWord(commands[0], SELECT)) {
return parserSelect(commands);
}
return true;
return false;
}
bool parser::parserSelect(vector<string> commands){
vector<string> tables;
Expand Down
2 changes: 1 addition & 1 deletion DBMS/DBMS/wq_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class parser{
parser(string dbname);
~parser();
void testParse();
void BatchSqlInFile(char* filename);
void BatchSqlInFile(const char* filename);
void splitStr(char* str, vector<string>* res);
bool parserOneCommand(vector<string> commands);
bool parserCreate(vector<string> commands);
Expand Down