rowdata.push_back(p);
rowdata.push_back(p);
p=strtok(NULL,d);
}
//cout<
rowdata.clear();
}
if(strcmp(s.c_str(),line) == 0)
{
number = 1;
}
}
fin.close();
///--------------------------------------------------------------------------------///
cin>>command;
transform(command.begin(),command.end(),command.begin(),towupper);
if(command == ";")
{
for(int i = 0 ; i < data.size(); ++i)
{
for(int j = 0 ; j < data[i].size(); ++j)
{
cout<
cout<
}
else if(command == "ORDER")
{
cin>>command;
int commandposition = -1;
transform(command.begin(),command.end(),command.begin(),towupper);
if(command == "BY")
{
cin>>command;///属性
OrderBy(command, data);
}
}
else if(command == "WHERE")
{
cin>>command;
int positionOfColumn2;
int LineOfCommand = 0;///
int temp = 0;
///----------------判断是否存在command---------------//
for(int j = 0 ; j < data[0].size(); ++j)
{
if(data[0][j] == command)
{
positionOfColumn2 = j;
temp = 1;
break;
}
}
if(temp == 0)
return;
cin>>command;///输入命令
string value1;
string value2;
transform(command.begin(),command.end(),command.begin(),towupper);
if(command == "=")
{
cin>>value1;
cin>>command;
transform(command.begin(),command.end(),command.begin(),towupper);
if(command == ";")///select * form table where column = values ;
{
for(int i = 0 ; i < data[0].size(); ++i)
cout<
{
for(int j = 0 ; j < data[i].size(); ++j)
{
if(j == positionOfColumn2)
{
if(data[i][j] == value1)
{
for(int k = 0; k < data[i].size(); ++k)
{
cout<
cout<
}
}
}
}
}
else if(command == "AND")///SELECT * FROM Persons WHERE FirstName='Thomas' AND LastName='Carter
{
cin>>command;
int positionOfColumn3;///command的位置
int LineOfCommand = 0;///
int temp = 0;
///----------------判断是否存在command---------------//
for(int j = 0 ; j < data[0].size(); ++j)
{
if(data[0][j] == command)
{
positionOfColumn3 = j;
temp = 1;
break;
}
}
if(temp == 0)
return;
cin>>command;
if(command == "=")
{
cin>>value2;
for(int i = 0 ; i < data[0].size(); ++i)
cout<
{
for(int j = 0 ; j < data[i].size(); ++j)
{
if(j == positionOfColumn2)
{
if(data[i][j] == value1)
{
///cout<
{
if(j1 == positionOfColumn3)
{
if(data[i][j1] == value2)
{
for(int k = 0; k < data[i].size(); ++k)
{
cout<
cout<
}
}
}
}
}
}
}
}
else if(command == "OR")///SELECT * FROM Persons WHERE FirstName='Thomas' AND LastName='Carter
{
cin>>command;
int positionOfColumn3;///command的位置
int LineOfCommand = 0;///
int temp = 0;
///----------------判断是否存在command---------------//
for(int j = 0 ; j < data[0].size(); ++j)
{
if(data[0][j] == command)
{
positionOfColumn3 = j;
temp = 1;
break;
}
}
if(temp == 0)
return;
cin>>command;
if(command == "=")
{
cin>>value2;
for(int i = 0 ; i < data[0].size(); ++i)
cout<
{
for(int j = 0 ; j < data[i].size(); ++j)
{
if(positionOfColumn2 == positionOfColumn3)
{
if(j == positionOfColumn2)
{
if(data[i][j] == value1 || data[i][j] == value2)
{
for(int k = 0; k < data[i].size(); ++k)
{
cout<
cout<
}
}
}
else
{
if(j == positionOfColumn2 || j == positionOfColumn3)
{
if(j == positionOfColumn2)
{
if(data[i][j] == value1)
{
for(int k = 0; k < data[i].size(); ++k)
{
cout<
cout<
}
}
else if(j == positionOfColumn3)
{
if(data[i][j] == value2)
{
for(int k = 0; k < data[i].size(); ++k)
{
cout<
cout<
}
}
}
}
}
}
}
}
else if(command == ">")
{
cin>>command;
for(int i = 0 ; i < data[0].size(); ++i)
cout<
{
for(int j = 0 ; j < data[i].size(); ++j)
{
if(j == positionOfColumn2)
{
int integer=atoi(data[i][j].c_str());///string转为int
int integer1 = atoi(command.c_str());
if(integer > integer1)
{
for(int k = 0; k < data[i].size(); ++k)
{
cout<
cout<
}
}
}
}
}
else if(command == "<")
{
cin>>command;
for(int i = 0 ; i < data[0].size(); ++i)
cout<
{
for(int j = 0 ; j < data[i].size(); ++j)
{
if(j == positionOfColumn2)
{
int integer=atoi(data[i][j].c_str());///string转为int
int integer1 = atoi(command.c_str());
if(integer < integer1)
{
for(int k = 0; k < data[i].size(); ++k)
{
cout<
cout<
}
}
}
}
}
else if(command == "<>")
{
cin>>command;
for(int i = 0 ; i < data[0].size(); ++i)
cout<
{
for(int j = 0 ; j < data[i].size(); ++j)
{
if(j == positionOfColumn2)
{
int integer=atoi(data[i][j].c_str());///string转为int
int integer1 = atoi(command.c_str());
if(integer != integer1)
{
for(int k = 0; k < data[i].size(); ++k)
{
cout<
cout<
}
}
}
}
}
else if(command == ">=")
{
cin>>command;
for(int i = 0 ; i < data[0].size(); ++i)
cout<
{
for(int j = 0 ; j < data[i].size(); ++j)
{
if(j == positionOfColumn2)
{
int integer=atoi(data[i][j].c_str());///string转为int
int integer1 = atoi(command.c_str());
if(integer >= integer1)
{
for(int k = 0; k < data[i].size(); ++k)
{
cout<
cout<
}
}
}
}
}
else if(command == "<=")
{
cin>>command;
for(int i = 0 ; i < data[0].size(); ++i)
cout<
{
for(int j = 0 ; j < data[i].size(); ++j)
{
if(j == positionOfColumn2)
{
int integer=atoi(data[i][j].c_str());///string转为int
int integer1 = atoi(command.c_str());
if(integer <= integer1)
{
for(int k = 0; k < data[i].size(); ++k)
{
cout<
cout<
}
}
}
}
}
else if(command == "BETWEEN")
{
int number1;
int number2;
cin>>number1;
cin>>command;
transform(command.begin(),command.end(),command.begin(),towupper);
if(command == "AND")
{
cin>>number2;
int maxn = number1;
if(maxn > number2)
{
maxn = number2;
number2 = number1;
number1 = maxn;
}
for(int i = 0 ; i < data[0].size(); ++i)
cout<
{
for(int j = 0 ; j < data[i].size(); ++j)
{
if(j == positionOfColumn2)
{
int integer=atoi(data[i][j].c_str());///string转为int
if(integer > number1 && integer < number2)
{
for(int k = 0; k < data[i].size(); ++k)
{
cout<
cout<
}
}
}
}
}
}
else if(command == "IN")
{
cin>>command;
if(command == "(")
{
vector
cin>>command;
while(command != ")")
{
int commandint = atoi(command.c_str());
values.push_back(commandint);
cin>>command;
}
for(int i = 0 ; i < data[0].size(); ++i)
cout<
{
for(int j = 0 ; j < data[i].size(); ++j)
{
if(j == positionOfColumn2)
{
int integer=atoi(data[i][j].c_str());///string转为int
vector
for(val = values.begin(); val <= values.end(); ++val)
{
if(integer == *val)
{
for(int k = 0; k < data[i].size(); ++k)
{
cout<
cout<
}
}
}
}
}
}
}
}
}
else
{
cout<<"The user does not have the authority"<
}
}
void Database::AppointSelect(string column,string name,User user,Database database)///选择语句 select column from TABLE WHERE 属性 = values
///select column from TABLE ;--*****************************************问题
{
int key = 0;///是否拥有权限
vector
for(it=user.User_select.begin(); it!=user.User_select.end();)
{
if(*it == name)
{
key = 1;
break;
}
else
++it; //指向下一个位置
}
if(key == 1)
{
int number;
char line[100];
FILE *fp;
string path;
string command;///命令
path = database.getAllpath() + name+".txt";
number=0;
ofstream ofile;///向文件中写入数据
while((fp = fopen(path.c_str(),"r+")) == NULL) ///判断按读方式打 file_name 文件是否失败,如果不存在
{
cout<<"Table name input error: ";
cin>>name;
if(name == "ENDINPUT")
return;
path = database.getAllpath() + name +".txt";
}
fclose(fp);
///----------------------读出INDEX存入data2中---------------------------------///
vector
vector
string t_file = "F:\\database\\INDEX.txt";
ifstream fin1(t_file.c_str());
while(fin1.getline(line,100))
{
char *p;
const char *d = "_";
p = strtok(line,d);
while(p)
{
///printf("%s\n",p);
rowdata.push_back(p);
p=strtok(NULL,d);
}
data2.push_back(rowdata);
rowdata.clear();
}
fin1.close();
///-------------------------------------------------------///
///---------------------判断表是否拥有索引----------------------------------///
int exist = 0;
for(int i = 0 ; i < data2.size(); ++i)
{
if(name == data2[i][0])///存在
{
exist = 1;
}
}
///--------------------------------将数据保存在data里--------------------///////////
vector
// vector
int hang = 0;///data行
//cout<<"DDDDDDD"<
string s = "- - - - - - - - - - - - - - - - - - - - - - - - ---";
while(fin.getline(line,100))///从s开始读出存入data中。
{
if(number == 1)
{
char *p;
const char *d = " ";
p = strtok(line,d);
while(p)
{
//cout<