Commit f74196e9 authored by casualet's avatar casualet

able to choose all the onions

parent dfb8ad27
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
using std::cout; using std::cout;
using std::cin; using std::cin;
using std::endl; using std::endl;
using std::vector;
std::map<SECLEVEL,std::string> gmp; std::map<SECLEVEL,std::string> gmp;
std::map<onion,std::string> gmp2; std::map<onion,std::string> gmp2;
...@@ -258,6 +259,7 @@ static std::vector<FieldMeta *> getFieldMeta(SchemaInfo &schema,std::string db = ...@@ -258,6 +259,7 @@ static std::vector<FieldMeta *> getFieldMeta(SchemaInfo &schema,std::string db =
struct transField{ struct transField{
bool hasSalt; bool hasSalt;
FieldMeta *originalFm; FieldMeta *originalFm;
vector<int> choosenOnions;
int onionIndex=0; int onionIndex=0;
int numOfOnions=0; int numOfOnions=0;
//onions //onions
...@@ -464,7 +466,35 @@ std::shared_ptr<ReturnMeta> getReturnMeta(std::vector<FieldMeta*> fms, std::vect ...@@ -464,7 +466,35 @@ std::shared_ptr<ReturnMeta> getReturnMeta(std::vector<FieldMeta*> fms, std::vect
} }
static static
std::string getBackupQuery(SchemaInfo &schema, std::vector<transField> &tfds,std::string db="tdb",std::string table="student1"){ std::string getBackupQuery(SchemaInfo &schema, std::vector<transField> &tfds,
std::string db="tdb",std::string table="student1"){
std::string res = "SELECT ";
const std::unique_ptr<IdentityMetaKey> dbmeta_key(new IdentityMetaKey(db));
//get databaseMeta, search in the map
DatabaseMeta * dbm = schema.getChild(*dbmeta_key);
const TableMeta & tbm = *((*dbm).getChild(IdentityMetaKey(table)));
std::string annotablename = tbm.getAnonTableName();
//then a list of onion names
for(auto item:tfds){
for(auto index:item.choosenOnions){
res += item.fields[index];
res += " , ";
}
if(item.hasSalt){
res += item.originalFm->getSaltName()+" , ";
}
}
res = res.substr(0,res.size()-2);
res = res + "FROM `"+db+std::string("`.`")+annotablename+"`";
return res;
}
/*
static
std::string getBackupQueryAll(SchemaInfo &schema, std::vector<transField> &tfds,
std::string db="tdb",std::string table="student1"){
std::string res = "SELECT "; std::string res = "SELECT ";
const std::unique_ptr<IdentityMetaKey> dbmeta_key(new IdentityMetaKey(db)); const std::unique_ptr<IdentityMetaKey> dbmeta_key(new IdentityMetaKey(db));
//get databaseMeta, search in the map //get databaseMeta, search in the map
...@@ -484,6 +514,9 @@ std::string getBackupQuery(SchemaInfo &schema, std::vector<transField> &tfds,std ...@@ -484,6 +514,9 @@ std::string getBackupQuery(SchemaInfo &schema, std::vector<transField> &tfds,std
res = res + "FROM `"+db+std::string("`.`")+annotablename+"`"; res = res + "FROM `"+db+std::string("`.`")+annotablename+"`";
return res; return res;
} }
*/
int int
...@@ -512,14 +545,11 @@ main() { ...@@ -512,14 +545,11 @@ main() {
ConnectionInfo ci("localhost", "root", "letmein",3306); ConnectionInfo ci("localhost", "root", "letmein",3306);
//const std::string master_key = "113341234"; //const std::string master_key = "113341234";
const std::string master_key = "113341234HEHE"; const std::string master_key = "113341234HEHE";
char *buffer; char *buffer;
if((buffer = getcwd(NULL, 0)) == NULL){ if((buffer = getcwd(NULL, 0)) == NULL){
perror("getcwd error"); perror("getcwd error");
} }
embeddedDir = std::string(buffer)+"/shadow"; embeddedDir = std::string(buffer)+"/shadow";
SharedProxyState *shared_ps = SharedProxyState *shared_ps =
new SharedProxyState(ci, embeddedDir , master_key, determineSecurityRating()); new SharedProxyState(ci, embeddedDir , master_key, determineSecurityRating());
assert(0 == mysql_thread_init()); assert(0 == mysql_thread_init());
...@@ -545,6 +575,7 @@ main() { ...@@ -545,6 +575,7 @@ main() {
std::cout<<"please input table name "<<std::endl; std::cout<<"please input table name "<<std::endl;
cin>>table; cin>>table;
std::unique_ptr<SchemaInfo> schema = myLoadSchemaInfo(); std::unique_ptr<SchemaInfo> schema = myLoadSchemaInfo();
//get all the fields in the tables.
std::vector<FieldMeta*> fms = getFieldMeta(*schema,db,table); std::vector<FieldMeta*> fms = getFieldMeta(*schema,db,table);
auto res = getTransField(fms); auto res = getTransField(fms);
for(auto &item:res){ for(auto &item:res){
...@@ -558,7 +589,28 @@ main() { ...@@ -558,7 +589,28 @@ main() {
ResType rawtorestype = MygetResTypeFromLuaTable(false, &resraw); ResType rawtorestype = MygetResTypeFromLuaTable(false, &resraw);
auto finalresults = decryptResults(rawtorestype,*rm); auto finalresults = decryptResults(rawtorestype,*rm);
parseResType(finalresults); parseResType(finalresults);
}else if(curQuery=="backall"){
std::string db,table;
std::cout<<"please input dbname "<<std::endl;
cin>>db;
std::cout<<"please input table name "<<std::endl;
cin>>table;
std::unique_ptr<SchemaInfo> schema = myLoadSchemaInfo();
//get all the fields in the tables.
std::vector<FieldMeta*> fms = getFieldMeta(*schema,db,table);
auto res = getTransField(fms);
//for each filed, we choose all the onions and salts.
for(auto &item:res){
assert(item.choosenOnions.size()==0u);
assert(item.onions.size()==item.originalOm.size());
assert(item.fields.size()==item.originalOm.size() || item.fields.size()==item.originalOm.size()+1);
for(unsigned int i=0u;i<item.onions.size();i++){
item.choosenOnions.push_back(i);
}
}
std::string backq = getBackupQuery(*schema,res,db,table);
cout<<backq<<endl;
} }
std::cout<<GREEN_BEGIN<<"\nplease input a new query:#######"<<COLOR_END<<std::endl; std::cout<<GREEN_BEGIN<<"\nplease input a new query:#######"<<COLOR_END<<std::endl;
std::getline(std::cin,curQuery); std::getline(std::cin,curQuery);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment