mid;//作为一个中间的储存
+
+ for (int i = 0; i < num; i++)
+ {
+ char *p = &column_and_data[i][0];//将第一个字符给p进行赋值
+ //std::cout< which_to_update;//用这个变量和这之后的操作来进行找出哪几个属性需要替换
+ for (int i = 0; i < column.size(); i++)
+ {
+ for (int j = 0; j < p->head_num; j++)
+ {
+ if (p->table_head[j] == column[i])
+ {
+ which_to_update.push_back(j);
+ break;
+ }
+ }
+ }
+
+ if (flag)//如果是指定位置的update
+ {
+ order2 = OrderDivide(order1, ' ', 1);
+ judge = order1;
+ judge = Upper(judge);
+ //std::cout< which_get = ListDivide(order2, ' ');
+
+ if (which_get.size() != 3)
+ {
+ std::cout<<"参数不足"<head_num; which_int++)
+ {
+ if (p->table_head[which_int] == which_head)
+ {
+ which_if = which_int;
+ break;//一定要跳出
+ }
+ }
+ if (which_int == p->head_num)
+ {
+ std::cout<<"WHERE所指条件不存在"<all_data.size(); i++)
+ {
+ if (p->all_data[i][which_if] == which_data)//如果是符合WHERE的条件的数据条
+ {
+ for (int j = 0; j < which_to_update.size(); j++)
+ {
+ //std::cout<<"?";
+ p->all_data[i][which_to_update[j]] = data[j];
+ }
+ }
+ }
+ //以上所期许的应该是将符合的数据都进行了更新
+ }
+
+ else
+ {
+ for (int i = 0; i < p->all_data.size(); i++)
+ {
+ for (int j = 0; j < which_to_update.size(); j++)
+ {
+ p->all_data[i][which_to_update[j]] = data[j];
+ }
+ }
+ }
+
+ this->save(p);
+
+ this->print_data(p->table_head, p->all_data);
+
+ std::cout<<" UPDATE成功"< a, std::vector b, int which)
+{
+ //bool flag;
+ return (strcmp(a[which].c_str(), b[which].c_str()) > 0);
+}
+
+void Data_Table::swap(std::vector &a, std::vector &b)
+{
+ std::vector mid = a;
+ a = b;
+ b = mid;
+ return;
+}
+
+
+void Data_Table::select(char *input)
+{
+ char *order1, *order2;
+ std::string name, judge;
+ order1 = OrderDivide(input, ' ', 1);
+ judge = input;
+ judge = Upper(judge);
+ Table *p = HEAD;
+ bool flag = false;
+ std::vector > data;
+ std::vector data_head;
+ char *to_file;
+ std::vector > mid_data;
+
+ if (judge == "*")//这就是全部输出的模式
+ {
+ order2 = OrderDivide(order1, ' ', 1);
+ judge = order1;
+ judge = Upper(judge);
+ if (judge != "FROM")
+ {
+ std::cout<<"语法错误,缺少关键词“FROM”"<next)
+ {
+ if (p->table_name == name)
+ break;
+ }
+ if (!p)
+ {
+ std::cout<<"表“"< column = ListDivide(order1, ' ');
+ //std::cout<head_num; i++)
+ {
+ if (column[0] == p->table_head[i])
+ {
+ which = i;
+ break;
+ }
+ }
+ if (which == -1)
+ {
+ std::cout<<"属性值有偏差"<all_data.size(); i++)
+ {
+ if (p->all_data[i][which] == column[2])
+ {
+ data.push_back(p->all_data[i]);
+ //std::cout<table_head;
+
+ //已经转站完毕
+ if (*order2 == 'T')
+ {
+ flag = true;
+ to_file = order2;
+ }
+ }
+
+ //*************************************************************
+
+ else//(*order1 == '\0' || *order1 == 'T')//如果名字之后是空,或者是tofile
+ {
+ data = p->all_data;
+ data_head = p->table_head;
+ if (*order1 == 'T')
+ {
+ to_file = order1;
+ flag = true;
+ }
+ }
+
+ this->print_data(data_head, data);
+ }
+
+ else//这时候是排序的操作!!!!!!!!!!!!!!!!!!!!!!!!!!
+ {
+ order2 = OrderDivide(order1, ' ', 2);
+ judge = order1;
+ judge = Upper(judge);
+ if (judge != "ORDER BY")
+ {
+ std::cout<<"语法错误,缺少关键词ORDER BY"< column_get = ListDivide(order2, ',');
+ order2 = OrderDivide(order1, ' ', 1);
+ std::vector mode_get = ListDivide(order1, '|');
+ data_head = p->table_head;
+ std::vector > mid_data;
+
+ //*****************************************************
+ if (*order2 == 'W')
+ {
+ //这里就是简单的部分展示
+ order1 = OrderDivide(order2, ' ', 1);
+ judge = order2;
+ judge = Upper(judge);
+ if (judge != "WHERE")
+ {
+ std::cout<<"语法错误,缺少关键词“WHERE”"< column = ListDivide(order1, ' ');
+ if (column.size() != 3)
+ {
+ std::cout<<"参数不足"<head_num; i++)
+ {
+ if (column[0] == p->table_head[i])
+ {
+ which = i;
+ break;
+ }
+ }
+ if (which == -1)
+ {
+ std::cout<<"属性值有偏差"<all_data.size(); i++)
+ {
+ if (p->all_data[i][which] == column[2])
+ data.push_back(p->all_data[i]);
+ }
+
+ //已经转站完毕
+
+ if (*order2 == 'T')
+ {
+ flag = true;
+ to_file = order2;
+ }
+ }
+
+ //**********************************************************
+ else
+ {
+ if (*order2 == 'T')
+ {
+ flag = true;
+ to_file = order2;
+ }
+ data = p->all_data;
+ }
+
+
+ std::vector which;
+ std::vector mode;
+ //分别作为哪一列和哪一种模式的标志
+
+ for (int i = 0; i < column_get.size(); i++)
+ {
+ for (int j = 0; j < p->head_num; j++)
+ {
+ if (p->table_head[j] == column_get[i])
+ {
+ which.push_back(j);
+ break;
+ }
+ }
+ }
+ if (which.size() != column_get.size())
+ {
+ std::cout<<"存在未知属性"< 0; i--)//这时候需要的是第i和第i-1
+ {
+ int check = 0;
+ for (; check < t; check++)
+ {
+ //std::cout<<"?";
+ if (this->compare(data[i], data[i-1], which[check]) != 0)
+ {
+ //std::cout<<"?";
+ break;
+ }
+ }
+ if (check == t)//前面的属性都一样,进行后一个属性的排序
+ {
+ if (mode[t] == 1)//升序
+ {
+ if (this->compare(data[i], data[i-1], which[t]) > 0)
+ this->swap(data[i], data[i-1]);
+ }
+ else
+ {
+ if (this->compare(data[i], data[i-1], which[t]) < 0)
+ this->swap(data[i], data[i-1]);
+ }
+ }
+ }
+ }
+ }
+
+ this->print_data(data_head, data);
+
+ }
+
+ }
+ //这之中有return;
+
+ else if (Upper(judge) == "DISTINCT")
+ {
+ order2 = OrderDivide(order1, ' ', 1);
+ std::vector head_get = ListDivide(order1, ',');//将所有的属性读入
+ order1 = OrderDivide(order2, ' ', 1);
+ judge = order2;
+ judge = Upper(judge);
+ if (judge != "FROM")
+ {
+ std::cout<<"语法错误,缺少关键词“FROM”"<next)
+ {
+ if (p->table_name == name)
+ break;
+ }
+ if (!p)
+ {
+ std::cout<<"表“"< head;
+ for (int i = 0; i < head_get.size(); i++)
+ {
+ for (int j = 0; j < p->head_num; j++)
+ {
+ if (p->table_head[j] == head_get[i])
+ {
+ head.push_back(j);//将位置进行记录
+ break;
+ }
+ }
+ }
+ if (head.size() != head_get.size())
+ {
+ std::cout<<"属性不对等"<all_data.size(); i++)
+ {
+ bool x = true;
+ for (int j = 0; j < data.size(); j++)//对于已有的data进行遍历
+ {
+ int which = 0;
+ for (; which < head.size(); which++)
+ {
+ if (data[j][which] != p->all_data[i][head[which]])
+ break;
+ }
+ if (which == head.size())
+ {
+ x = false;
+ break;
+ }
+ }
+
+ if (x)
+ {
+ std::vector mid;
+ for (int which = 0; which < head.size(); which++)
+ {
+ mid.push_back(p->all_data[i][head[which]]);
+ }
+ data.push_back(mid);
+ mid.clear();
+ }
+ }
+
+ this->print_data(data_head,data);
+
+ }
+
+ else//这时候是input就是属性的开始,order1已经越过了所有的属性
+ {
+ std::vector head_get = ListDivide(input, ',');
+ //将属性领入其中
+ order2 = OrderDivide(order1, ' ', 1);
+ judge = order1;
+ judge = Upper(judge);
+ if (judge != "FROM")
+ {
+ std::cout<<"语法错误,缺少关键词“FROM”"<next)
+ {
+ if (p->table_name == name)
+ break;
+ }
+ if (!p)
+ {
+ std::cout<<"表“"< head;
+
+ for (int i = 0; i < head_get.size(); i++)
+ {
+ for (int j = 0; j < p->table_head.size(); j++)
+ {
+ if (p->table_head[j] == head_get[i])
+ {
+ head.push_back(j);
+ break;
+ }
+ }
+ }
+ if (head.size() != head_get.size())
+ {
+ std::cout<<"属性不对等"< column = ListDivide(order2, ' ');
+ if (column.size() != 3)
+ {
+ std::cout<<"参数不足"<head_num; i++)
+ {
+ if (column[0] == p->table_head[i])
+ {
+ which = i;
+ break;
+ }
+ }
+ if (which == -1)
+ {
+ std::cout<<"属性值有偏差"<all_data.size(); i++)
+ {
+ if (p->all_data[i][which] == column[2])
+ mid_data.push_back(p->all_data[i]);
+ }
+
+ //已经转站完毕
+
+ if (*order1 == 'T')
+ {
+ flag = true;
+ to_file = order1;
+ }
+ }
+
+ else
+ {
+ mid_data = p->all_data;
+
+ if (*order1 == 'T')
+ {
+ flag = true;
+ to_file = order1;
+ }
+ }
+
+ for (int i = 0; i < mid_data.size(); i++)
+ {
+ std::vector mid;
+ for (int j = 0; j < head.size(); j++)
+ {
+ mid.push_back(mid_data[i][head[j]]);
+ }
+ data.push_back(mid);
+ mid.clear();
+ }
+ //将所有的东西进行压入
+
+ this->print_data(data_head, data);
+ }
+
+ //下面有一个文件的写入这个小操作
+
+
+
+ if (flag)
+ {
+ order1 = OrderDivide(to_file, ' ', 1);
+ judge = to_file;
+ judge = Upper(judge);
+ if (judge != "TO")
+ {
+ std::cout<<"语法错误,缺少关键词“TO“"<save_pro(data_head, data, filename);
+ std::cout<<"文件写入成功"< head, const std::vector > data,const std::string filename) const
+{
+ FILE *file;//作为文件的指针操作
+
+
+ file = fopen((filename_head + filename).c_str(), "w");
+ if (!file)
+ {
+ std::cout<<"文件打开失败!"<
+#include
+#include
+#include
+#include
+#include
+#include//作为setw设定对齐的头文件
+#include
+
+
+#define MAXLEN 1000
+#define STANDARD 18
+
+
+char* OrderDivide(char *p, char key, int num);
+
+std::vector ListDivide(char *p, char key);
+
+std::vector ListDividePro(char *p, char key);
+
+std::string Upper(std::string input);
+
+void MyCorrect(std::string input);
+
+struct Table
+{
+ std::string table_file_name;
+ std::string table_name;
+ std::vector table_head;
+ int head_num;//作为属性的数目
+ std::vector > all_data;
+ Table *next;
+
+};
+
+class Data_Table
+{
+private:
+ std::vector > condition;
+ std::string condition_filename;
+ //前两个是对于数据库的维护文件的相关操作
+ std::string filename_head;//用于文件名的头
+ Table *HEAD;
+public:
+ Data_Table();
+ void ini();
+ void condition_save();
+ void save(const Table *p) const;
+ void save_pro(const std::vector head, const std::vector > data,const std::string filename) const;
+ void print_head(const Table *p) const;
+ void create(char *input);
+ void drop(char *input);
+ void table_list(char *input);
+ void insert(char *input);
+ void my_delete(char *input);
+ void print_data(const std::vector head, const std::vector > data) const;
+ void update(char *input);
+ void select(char *input);
+ int compare(std::vector a, std::vector b, int which);
+ void swap(std::vector &a, std::vector &b);
+ void compute(char *inupt);
+ void search(char *input);
+};
\ No newline at end of file
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..b2a6a6d
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,82 @@
+#include
+#include
+
+#include
+#include
+#include"head.h"
+
+
+using namespace std;
+
+
+int main()
+{
+ char input[MAXLEN];
+ char *secondinput;//作为二级输入的指针进行储存
+ string judge;//作为判断第一个关键词的词储存
+
+ char first[MAXLEN];
+ string firstjudge;//决定是否进去
+
+ cout<<"~$ ";
+ cin>>first;//这是作为进入的判定
+
+ firstjudge = first;
+
+ firstjudge = Upper(firstjudge);
+
+ if (firstjudge != "MYSQL")
+ {
+ cout<<"无法进入"< 初始化"<";
+ cin.getline(input, MAXLEN, '\n');//默许的输入语句长度为1000;
+ //cout< ListDivide(char *p, char key)
+{
+ std::vector list;
+ std::string mid;//作为中间的转换
+ char *order = p;
+
+ /*
+ for (; *(pp+1) != '\0'; pp++);
+ if (*pp == '\n')
+ {
+ *pp = '\0';
+ std::cout<<"?";
+ }
+ */
+
+
+ while(*order != '\0')
+ {
+ order = OrderDivide(order, key, 1);
+ mid = p;
+ for (int i = 0; i < mid.length(); i++)
+ {
+ if (mid[i] == '\n')
+ mid[i] = ' ';
+ }
+
+ list.push_back(mid);//将这个属性压进容器
+ p = order;
+ }
+
+ if (list[list.size()-1] == " ")
+ list.pop_back();
+
+ //if (list[list.size()-1][list[(list.size()-1)].length()-1] == '\n')
+ //list[list.size()-1][list[(list.size()-1)].length()-1] = ' ';
+
+
+ return list;
+}
+
+std::vector ListDividePro(char *p, char key)
+{
+ std::vector list;
+ std::string mid;//作为中间的转换
+ char *order = p;
+
+ /*
+ for (; *(pp+1) != '\0'; pp++);
+ if (*pp == '\n')
+ {
+ *pp = '\0';
+ std::cout<<"?";
+ }
+ */
+
+ bool flag = true;
+
+ while(*order != '\0')
+ {
+ order = OrderDivide(order, key, 1);
+ p = p + 1;
+ if (flag)
+ {
+ flag = false;
+ p = p - 1;
+ }
+ mid = p;
+
+ list.push_back(mid);//将这个属性压进容器
+ p = order;
+ }
+
+
+ return list;
+}
\ No newline at end of file