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 @@
//This connection mimics the behaviour of MySQL-Proxy
Connect *globalConn;
//query for testing purposes
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 res = "SELECT ";
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>
filenames.push_back(item);
}
int len = resraw.fieldNames.size();
for(int i=0;i<len;i++){
if(IS_NUM(resraw.fieldTypes[i])){
writeColumndataNum(resraw.columnData[i],filenames[i]);
......@@ -58,11 +56,45 @@ void write_raw_data_to_files(MySQLColumnData& resraw,std::vector<FieldMetaTrans>
}
}
static void store(std::string db, std::string table){
static
std::vector<std::string>
getDbTables(std::string db) {
executeAndGetColumnData(globalConn,std::string("use ")+db);
MySQLColumnData resraw = executeAndGetColumnData(globalConn,"show tables");
return resraw.columnData[0];
}
static
void store(std::string db, std::string intable){
std::unique_ptr<SchemaInfo> schema = myLoadSchemaInfo(gembeddedDir);
//do this for each table
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);
}
for(auto table:tables) {
//get all the fields in the tables
std::vector<FieldMeta*> fms = getFieldMeta(*schema,db,table);
//transform the field so that selected onions can be used
std::vector<FieldMetaTrans> res;
for(auto i=0u;i<fms.size();i++){
......@@ -70,14 +102,17 @@ static void store(std::string db, std::string table){
res.push_back(ft);
res.back().trans(fms[i]);
}
/*this is our strategy, each field should be able to choose the selected onion*/
storeStrategies(res);
//generate the backup query and then fetch the tuples
std::string backup_query = getTestQuery(*schema,res,db,table);
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){
......@@ -96,11 +131,12 @@ static void store(std::string db, std::string table){
}
//write the tuples into files
write_raw_data_to_files(resraw,res,db,table);
}
}
int
main(int argc, char* argv[]){
std::string db="tdb",table="student";
std::string db="tdb",table="-1";
std::string ip="127.0.0.1";
int port=3306;
if(argc==4){
......@@ -108,7 +144,9 @@ main(int argc, char* argv[]){
db = std::string(argv[2]);
table = std::string(argv[3]);
}
/*Init globalConn to interact with MySQL Server. Init embedded MySQL to use the parser*/
globalConn = globalInit(ip,port);
//store data and metadata
store(db,table);
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