Commit 114f77df authored by yiwenshao's avatar yiwenshao

do not need to call show databases in debug/load,instead we call create_embedded_thd

parent 6cede695
...@@ -102,32 +102,25 @@ static ResType load_files(std::string db="tdb", std::string table="student"){ ...@@ -102,32 +102,25 @@ static ResType load_files(std::string db="tdb", std::string table="student"){
//to be //to be
} }
metadata_files res_meta = load_meta(db,table); metadata_files res_meta = load_meta(db,table);
// for(unsigned int i=0;i<res_meta.dec_onion_index.size();i++){
//choosen onion for each field
// res[i].choosenOnions.push_back(res_meta.get_choosen_onions()[i]);
// }
std::shared_ptr<ReturnMeta> rm = getReturnMeta(fms,res); std::shared_ptr<ReturnMeta> rm = getReturnMeta(fms,res);
//why do we need this?? //why do we need this??
std::string backq = "show databases"; create_embedded_thd(0);
executeAndGetResultRemote(globalConn,backq);
rawMySQLReturnValue resraw2; rawMySQLReturnValue resraw;
//load fields in the stored file //load fields in the stored file
vector<vector<string>> res_field = load_table_fields(res_meta); vector<vector<string>> res_field = load_table_fields(res_meta);
resraw2.rowValues = res_field; resraw.rowValues = res_field;
auto field_names = flat_vec(res_meta.selected_field_names); auto field_names = flat_vec(res_meta.selected_field_names);
auto field_types = flat_vec(res_meta.selected_field_types); auto field_types = flat_vec(res_meta.selected_field_types);
auto field_lengths = flat_vec(res_meta.selected_field_lengths); auto field_lengths = flat_vec(res_meta.selected_field_lengths);
resraw2.fieldNames = field_names; resraw.fieldNames = field_names;
// resraw2.choosen_onions = ;
for(unsigned int i=0;i<field_types.size();++i) { for(unsigned int i=0;i<field_types.size();++i) {
resraw2.fieldTypes.push_back(static_cast<enum_field_types>(field_types[i])); resraw.fieldTypes.push_back(static_cast<enum_field_types>(field_types[i]));
} }
ResType rawtorestype = MygetResTypeFromLuaTable(false, &resraw2); ResType rawtorestype = MygetResTypeFromLuaTable(false, &resraw);
auto finalresults = decryptResults(rawtorestype,*rm); auto finalresults = decryptResults(rawtorestype,*rm);
return finalresults; return finalresults;
} }
...@@ -135,6 +128,7 @@ static ResType load_files(std::string db="tdb", std::string table="student"){ ...@@ -135,6 +128,7 @@ static ResType load_files(std::string db="tdb", std::string table="student"){
int int
main(int argc, char* argv[]){ main(int argc, char* argv[]){
init(); init();
create_embedded_thd(0);
std::string db="tdb",table="student"; std::string db="tdb",table="student";
globalEsp = (char*)malloc(sizeof(char)*5000); globalEsp = (char*)malloc(sizeof(char)*5000);
if(globalEsp==NULL){ if(globalEsp==NULL){
......
...@@ -109,56 +109,7 @@ void rawMySQLReturnValue::show(){ ...@@ -109,56 +109,7 @@ void rawMySQLReturnValue::show(){
cout<<endl; cout<<endl;
} }
//must be static, or we get "no previous declaration"
//execute the query and get the rawReturnVale, this struct can be copied.
static
rawMySQLReturnValue executeAndGetResultRemote(Connect * curConn,std::string query){
std::unique_ptr<DBResult> dbres;
curConn->execute(query, &dbres);
rawMySQLReturnValue myRaw;
if(dbres==nullptr||dbres->n==NULL){
std::cout<<"no results"<<std::endl;
return myRaw;
}
int num = mysql_num_rows(dbres->n);
int numOfFields = mysql_num_fields(dbres->n);
MYSQL_FIELD *field;
MYSQL_ROW row;
if(num!=0){
while( (row = mysql_fetch_row(dbres->n)) ){
//what's the difference between fieldlen
unsigned long * fieldLen = mysql_fetch_lengths(dbres->n);
std::vector<std::string> curRow;
for(int i=0;i<numOfFields;i++){
if (i == 0) {
while( (field = mysql_fetch_field(dbres->n)) ) {
myRaw.fieldNames.push_back(std::string(field->name));
myRaw.fieldTypes.push_back(field->type);
//myRaw.lengths.push_back(field->length);
//myRaw.lengths.push_back(fieldLen[i]);
myRaw.lengths.push_back(field->max_length);
myRaw.maxlengths.push_back(field->max_length);
//cout<<field->length<<"::"<<field->max_length<<endl;
}
}
if(row[i]==NULL) curRow.push_back("NULL");
else curRow.push_back(std::string(row[i],fieldLen[i]));
}
myRaw.rowValues.push_back(curRow);
}
}
return myRaw;
}
//helper function for transforming the rawMySQLReturnValue //helper function for transforming the rawMySQLReturnValue
static Item_null * static Item_null *
make_null(const std::string &name = ""){ make_null(const std::string &name = ""){
char *const n = current_thd->strdup(name.c_str()); char *const n = current_thd->strdup(name.c_str());
......
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