Commit cacaa34f authored by yiwenshao's avatar yiwenshao

final_store in tools able to support multiple tables

parent d8521abb
INSERT INTO `tdb`.`table_KBMACQBCDL` VALUES (7172051510492996326, 13597518156, 'ۀ#p+Ow<G:< 5Fš2\nX\Z4+ tD?#>GzZJY\0<o؇\r3E ^YC[?i_3=(:uJQ׬OB^Ma7+Ek^?2˖;UUN`iTI8?|e5am},9RL" -7D-i.%P 9>\06K\'%', 10597100466299340645, '`\0u-Ypy(>^U/Q', 4683721645241909493, '', 10055494352803353658);
...@@ -3,9 +3,8 @@ ...@@ -3,9 +3,8 @@
//This connection mimics the behaviour of MySQL-Proxy //This connection mimics the behaviour of MySQL-Proxy
Connect *globalConn; Connect *globalConn;
//query for testing purposes
static static
std::string getTestQuery(SchemaInfo &schema, std::vector<FieldMetaTrans> &tfds, std::string getBackupQuery(SchemaInfo &schema, std::vector<FieldMetaTrans> &tfds,
std::string db="tdb",std::string table="student1"){ 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));
...@@ -48,7 +47,6 @@ void write_raw_data_to_files(MySQLColumnData& resraw,std::vector<FieldMetaTrans> ...@@ -48,7 +47,6 @@ void write_raw_data_to_files(MySQLColumnData& resraw,std::vector<FieldMetaTrans>
filenames.push_back(item); filenames.push_back(item);
} }
int len = resraw.fieldNames.size(); int len = resraw.fieldNames.size();
for(int i=0;i<len;i++){ for(int i=0;i<len;i++){
if(IS_NUM(resraw.fieldTypes[i])){ if(IS_NUM(resraw.fieldTypes[i])){
writeColumndataNum(resraw.columnData[i],filenames[i]); writeColumndataNum(resraw.columnData[i],filenames[i]);
...@@ -58,49 +56,87 @@ void write_raw_data_to_files(MySQLColumnData& resraw,std::vector<FieldMetaTrans> ...@@ -58,49 +56,87 @@ void write_raw_data_to_files(MySQLColumnData& resraw,std::vector<FieldMetaTrans>
} }
} }
static void store(std::string db, std::string table){ static
std::unique_ptr<SchemaInfo> schema = myLoadSchemaInfo(gembeddedDir); std::vector<std::string>
//get all the fields in the tables getDbTables(std::string db) {
std::vector<FieldMeta*> fms = getFieldMeta(*schema,db,table); executeAndGetColumnData(globalConn,std::string("use ")+db);
MySQLColumnData resraw = executeAndGetColumnData(globalConn,"show tables");
return resraw.columnData[0];
}
//transform the field so that selected onions can be used
std::vector<FieldMetaTrans> res; static
for(auto i=0u;i<fms.size();i++){ void store(std::string db, std::string intable){
FieldMetaTrans ft; std::unique_ptr<SchemaInfo> schema = myLoadSchemaInfo(gembeddedDir);
res.push_back(ft); //do this for each table
res.back().trans(fms[i]); std::vector<std::string> tables;
if(intable==std::string("-1")){
tables = getDbTables(db);
std::map<std::string,int> annIndex;
for(unsigned int i=0u;i<tables.size();++i) {
annIndex[tables[i]]=i;
}
//then transform
const std::unique_ptr<AES_KEY> &TK = std::unique_ptr<AES_KEY>(getKey(std::string("113341234")));
Analysis analysis(db,*schema,TK,
SECURITY_RATING::SENSITIVE);
if(analysis.databaseMetaExists(db)){
const DatabaseMeta & dbm = analysis.getDatabaseMeta(db);
auto &tableMetas = dbm.getChildren();
for(auto & kvtable:tableMetas){
auto annoname = kvtable.second->getAnonTableName();
auto plainname = kvtable.first.getValue();
tables[annIndex[annoname]]=plainname;
}
}
}else {
tables.push_back(intable);
} }
/*this is our strategy, each field should be able to choose the selected onion*/ for(auto table:tables) {
storeStrategies(res); //get all the fields in the tables
//generate the backup query and then fetch the tuples std::vector<FieldMeta*> fms = getFieldMeta(*schema,db,table);
std::string backup_query = getTestQuery(*schema,res,db,table); //transform the field so that selected onions can be used
MySQLColumnData resraw = executeAndGetColumnData(globalConn,backup_query); std::vector<FieldMetaTrans> res;
//then we should set the type and length of FieldMetaTrans for(auto i=0u;i<fms.size();i++){
auto types = resraw.fieldTypes; FieldMetaTrans ft;
auto lengths = resraw.maxLengths; res.push_back(ft);
int base_types = 0; res.back().trans(fms[i]);
int base_lengths = 0;
for(auto &item:res){
vector<int> tempTypes;
vector<int> tempLengths;
for(unsigned int i=0u;i<item.getChoosenOnionName().size();i++){
tempTypes.push_back(types[base_types++]);
tempLengths.push_back(lengths[base_lengths++]);
} }
item.setChoosenFieldTypes(tempTypes);
item.setChoosenFieldLengths(tempLengths); /*this is our strategy, each field should be able to choose the selected onion*/
if(item.getHasSalt()){//also this should be changed. storeStrategies(res);
item.setSaltType(types[base_types++]); //generate the backup query and then fetch the tuples
item.setSaltLength(lengths[base_lengths++]); std::string backup_query = getBackupQuery(*schema,res,db,table);
MySQLColumnData resraw = executeAndGetColumnData(globalConn,backup_query);
//then we should set the type and length of FieldMetaTrans
auto types = resraw.fieldTypes;
auto lengths = resraw.maxLengths;
int base_types = 0;
int base_lengths = 0;
for(auto &item:res){
vector<int> tempTypes;
vector<int> tempLengths;
for(unsigned int i=0u;i<item.getChoosenOnionName().size();i++){
tempTypes.push_back(types[base_types++]);
tempLengths.push_back(lengths[base_lengths++]);
}
item.setChoosenFieldTypes(tempTypes);
item.setChoosenFieldLengths(tempLengths);
if(item.getHasSalt()){//also this should be changed.
item.setSaltType(types[base_types++]);
item.setSaltLength(lengths[base_lengths++]);
}
} }
//write the tuples into files
write_raw_data_to_files(resraw,res,db,table);
} }
//write the tuples into files
write_raw_data_to_files(resraw,res,db,table);
} }
int int
main(int argc, char* argv[]){ main(int argc, char* argv[]){
std::string db="tdb",table="student"; std::string db="tdb",table="-1";
std::string ip="127.0.0.1"; std::string ip="127.0.0.1";
int port=3306; int port=3306;
if(argc==4){ if(argc==4){
...@@ -108,7 +144,9 @@ main(int argc, char* argv[]){ ...@@ -108,7 +144,9 @@ main(int argc, char* argv[]){
db = std::string(argv[2]); db = std::string(argv[2]);
table = std::string(argv[3]); table = std::string(argv[3]);
} }
/*Init globalConn to interact with MySQL Server. Init embedded MySQL to use the parser*/
globalConn = globalInit(ip,port); globalConn = globalInit(ip,port);
//store data and metadata
store(db,table); store(db,table);
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