-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
86 lines (80 loc) · 2.57 KB
/
Copy pathmain.cpp
File metadata and controls
86 lines (80 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* File: main.cpp
* Author: Administrator
*
* Created on 2012年10月15日, 下午2:48
*/
#include <cstdlib>
#include <direct.h>
#include <iostream>
#include <fstream>
#include <string>
#include "DBMS.h"
using namespace std;
/*
* create database a
* create table test(aaa char(7) primary key, bbb int primary key, ccc int)
*/
int main(int argc, char** argv) {
// boost::regex reg(".*\\..*");
// string hi("nihao teaid nihao");
// boost::smatch matches;
// if(boost::regex_match(hi, reg))
// cout << "ok!" << endl;
DBMS idbms;
char in[256];
string command;
string::size_type i;
const string exit = "exit";
const string createTable = "create table "; //
const string createDatabase = "create database ";
const string showDatabases = "show databases";
const string use = "use ";
const string describe = "describe ";
const string dropDatabase = "drop database";
const string showTables = "show tables";
const string dropTable = "drop table ";
const string select = "select ";
const string insert = "insert ";
while(true) {
cout << "flightSQL> ";
cin.getline(in, 256, '\n');
command.clear();
command.insert(0, in);
if(i = command.find(exit, 0) != string::npos) {
return 0;
}
else if(i = command.find(createTable, 0) != string::npos) {
idbms.CreateTable(command);
}
else if(i = command.find(createDatabase, 0) != string::npos) {
idbms.CreateDatabase(command.substr(createDatabase.length()));
}
else if(i = command.find(showDatabases, 0) != string::npos) {
idbms.ShowDatabases();
}
else if(i = command.find(use, 0) != string::npos) {
idbms.Use(command.substr(use.length()));
}
else if(i = command.find(describe, 0) != string::npos) {
idbms.Describe(command.substr(describe.length()));
}
else if(i = command.find(dropDatabase, 0) != string::npos) {
idbms.DropDatabase(command.substr(dropDatabase.length()));
}
else if(i = command.find(showTables, 0) != string::npos) {
idbms.ShowTables();
}
else if(i = command.find(dropTable, 0) != string::npos) {
idbms.DropTable(command);
}
else if(i = command.find(select, 0) != string::npos) {
idbms.Select(command);
}
else if(i = command.find(insert, 0) != string::npos) {
idbms.Insert(command);
}
else
cout << "error" << endl;
}
}