Commit e1a77857 authored by Casualet's avatar Casualet

add more options to mbk.cc

parent a9b370a2
......@@ -545,11 +545,61 @@ std::string getBackupQueryWithoutSalt(SchemaInfo &schema, std::vector<transField
fieldIndex++;
}
}
res = res.substr(0,res.size()-2);
res += "FROM `"+db+std::string("`.`")+annotablename+"`";
return res;
}
static
std::string getBackupQueryWithoutSaltHex(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();
int numOfChoosenField=0;
//then a list of onion names
for(auto item:tfds){
for(auto index:item.choosenOnions){
res += item.fields[index];
res += " , ";
numOfChoosenField++;
}
}
res = res.substr(0,res.size()-2);
res = res + "FROM `"+db+std::string("`.`")+annotablename+"` limit 1;";
rawReturnValue resraw = executeAndGetResultRemote(globalConn,res);
assert(numOfChoosenField==(int)resraw.fieldTypes.size());
vector<bool> whetherToQuote;
for(auto i=0u;i<resraw.fieldTypes.size();i++){
if(IS_NUM(resraw.fieldTypes[i])) whetherToQuote.push_back(false);
else whetherToQuote.push_back(true);
}
int fieldIndex=0;
res = "SELECT ";
for(auto item:tfds){
for(auto index:item.choosenOnions){
if(whetherToQuote[fieldIndex]){
res +=string("HEX(")+item.fields[index]+")";
res += " , ";
}else{
res += item.fields[index];
res += " , ";
}
fieldIndex++;
}
}
res = res.substr(0,res.size()-2);
res += "FROM `"+db+std::string("`.`")+annotablename+"`";
return res;
}
......@@ -633,11 +683,14 @@ main(int argc, char* argv[]) {
for(int i=0;i<argc;i++){
printf("%s\n",argv[i]);
}
cout<<"./mbk dbname tablename option"
"0. back up and decrypt"
"1. back up all"
"2. back up the first onion with out dealing with quote "
"3. back up the first onion while dealing with quote "<<endl;
cout<<"./mbk dbname tablename option \n"
"0. back up and decrypt\n"
"1. back up all With Salt\n"
"2. back up the first onion with out dealing with quote With salt \n"
"3. back up the first onion while dealing with quote Without Salt \n"
"4. back up the first onion while dealing with hex Without salt\n"
"5. to be implemented\n"
<<endl;
return 0;
}
gmp[SECLEVEL::INVALID]="INVALID";
......@@ -760,8 +813,25 @@ main(int argc, char* argv[]) {
cout<<backq<<endl;
//rawReturnValue resraw = executeAndGetResultRemote(globalConn,backq);
//getInsertQuery(*schema,res,db,table,resraw);
}else if(string(argv[3])=="4"){
std::string db(argv[1]),table(argv[2]);
std::cout<<db<<":"<<table<<std::endl;
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);
item.choosenOnions.push_back(0);
}
std::string backq = getBackupQueryWithoutSaltHex(*schema,res,db,table);
cout<<backq<<endl;
//rawReturnValue resraw = executeAndGetResultRemote(globalConn,backq);
//getInsertQuery(*schema,res,db,table,resraw);
}
return 0;
return 0;
}
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