Commit 80b82eb3 authored by Casualet's avatar Casualet

able to reload fresh data

parent 55f4d7d8
...@@ -168,10 +168,8 @@ rawReturnValue executeAndGetResultRemote(Connect * curConn,std::string query){ ...@@ -168,10 +168,8 @@ rawReturnValue executeAndGetResultRemote(Connect * curConn,std::string query){
} }
int num = mysql_num_rows(dbres->n); int num = mysql_num_rows(dbres->n);
std::cout<<"num of rows: "<<num<<std::endl;
int numOfFields = mysql_num_fields(dbres->n); int numOfFields = mysql_num_fields(dbres->n);
std::cout<<"num of fields: "<<numOfFields<<std::endl;
MYSQL_FIELD *field; MYSQL_FIELD *field;
MYSQL_ROW row; MYSQL_ROW row;
...@@ -936,7 +934,6 @@ void write_raw_data_to_files(rawReturnValue& resraw,string db,string table){ ...@@ -936,7 +934,6 @@ void write_raw_data_to_files(rawReturnValue& resraw,string db,string table){
static void load_num(string filename,vector<string> &res){ static void load_num(string filename,vector<string> &res){
cout<<"load num"<<endl;
std::ifstream infile(filename); std::ifstream infile(filename);
string line; string line;
while(std::getline(infile,line)){ while(std::getline(infile,line)){
...@@ -955,7 +952,6 @@ static void load_string(string filename, vector<string> &res,unsigned long lengt ...@@ -955,7 +952,6 @@ static void load_string(string filename, vector<string> &res,unsigned long lengt
} }
static vector<vector<string>> load_table_fields(meta_file & input) { static vector<vector<string>> load_table_fields(meta_file & input) {
cout<<"load_table_fields"<<endl;
string db = input.db; string db = input.db;
string table = input.table; string table = input.table;
vector<vector<string>> res; vector<vector<string>> res;
...@@ -973,7 +969,6 @@ static vector<vector<string>> load_table_fields(meta_file & input) { ...@@ -973,7 +969,6 @@ static vector<vector<string>> load_table_fields(meta_file & input) {
}else{ }else{
load_string(datafiles[i],column,input.field_lengths[i]); load_string(datafiles[i],column,input.field_lengths[i]);
} }
cout<<"column_size: "<<column.size()<<endl;
for(unsigned int j=0u; j<column.size(); j++){ for(unsigned int j=0u; j<column.size(); j++){
if(j>=res.size()){ if(j>=res.size()){
res.push_back(vector<string>()); res.push_back(vector<string>());
...@@ -1032,6 +1027,7 @@ static bool cmp(rawReturnValue &resraw){ ...@@ -1032,6 +1027,7 @@ static bool cmp(rawReturnValue &resraw){
} }
return true; return true;
} }
/* /*
void static cmp2(rawReturnValue & res1,rawReturnValue & res2){ void static cmp2(rawReturnValue & res1,rawReturnValue & res2){
if(res1.fieldNames == res2.fieldNames){ if(res1.fieldNames == res2.fieldNames){
...@@ -1060,6 +1056,34 @@ void static cmp2(rawReturnValue & res1,rawReturnValue & res2){ ...@@ -1060,6 +1056,34 @@ void static cmp2(rawReturnValue & res1,rawReturnValue & res2){
} }
*/ */
static rawReturnValue with_remote(){
std::string db="tdb",table="student";
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);
meta_file res_meta = load_meta();
for(unsigned int i=0;i<res_meta.choosen_onions.size();i++){
res[i].choosenOnions.push_back(res_meta.choosen_onions[i]);
}
std::shared_ptr<ReturnMeta> rm = getReturnMeta(fms,res);
std::string backq = "show databases";
executeAndGetResultRemote(globalConn,backq);
rawReturnValue resraw2;
vector<vector<string>> res_field = load_table_fields(res_meta);
resraw2.rowValues = res_field;
resraw2.fieldNames = res_meta.field_names;
resraw2.choosen_onions = res_meta.choosen_onions;
for(unsigned int i=0;i<res_meta.field_types.size();++i){
resraw2.fieldTypes.push_back(static_cast<enum_field_types>(std::stoi(res_meta.field_types[i])));
}
ResType rawtorestype = MygetResTypeFromLuaTable(false, &resraw2);
auto finalresults = decryptResults(rawtorestype,*rm);
parseResType(finalresults);
return resraw2;
}
int int
main(int argc, char* argv[]) { main(int argc, char* argv[]) {
...@@ -1278,30 +1302,7 @@ main(int argc, char* argv[]) { ...@@ -1278,30 +1302,7 @@ main(int argc, char* argv[]) {
auto finalresults = decryptResults(rawtorestype,*rm); auto finalresults = decryptResults(rawtorestype,*rm);
parseResType(finalresults); parseResType(finalresults);
}else{ }else{
std::string db="tdb",table="student"; with_remote();
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);
meta_file res_meta = load_meta();
for(unsigned int i=0;i<res_meta.choosen_onions.size();i++){
res[i].choosenOnions.push_back(res_meta.choosen_onions[i]);
}
std::shared_ptr<ReturnMeta> rm = getReturnMeta(fms,res);
std::string backq = getTestQuery(*schema,res,db,table);
executeAndGetResultRemote(globalConn,backq);
rawReturnValue resraw2;
vector<vector<string>> res_field = load_table_fields(res_meta);
resraw2.rowValues = res_field;
resraw2.fieldNames = res_meta.field_names;
resraw2.choosen_onions = res_meta.choosen_onions;
for(unsigned int i=0;i<res_meta.field_types.size();++i){
resraw2.fieldTypes.push_back(static_cast<enum_field_types>(std::stoi(res_meta.field_types[i])));
}
ResType rawtorestype = MygetResTypeFromLuaTable(false, &resraw2);
auto finalresults = decryptResults(rawtorestype,*rm);
parseResType(finalresults);
} }
fclose(stream); fclose(stream);
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