Commit 8cd33505 authored by Casualet's avatar Casualet

able to write metadata into file and reload it

parent 3ea9d967
...@@ -44,12 +44,15 @@ ...@@ -44,12 +44,15 @@
#include <sstream> #include <sstream>
#include <unistd.h> #include <unistd.h>
#include <map> #include <map>
#include <fstream>
using std::cout; using std::cout;
using std::cin; using std::cin;
using std::endl; using std::endl;
using std::vector; using std::vector;
using std::string; using std::string;
using std::to_string;
std::map<SECLEVEL,std::string> gmp; std::map<SECLEVEL,std::string> gmp;
std::map<onion,std::string> gmp2; std::map<onion,std::string> gmp2;
...@@ -104,9 +107,40 @@ Connect *globalConn; ...@@ -104,9 +107,40 @@ Connect *globalConn;
struct rawReturnValue{ struct rawReturnValue{
std::vector<std::vector<std::string> > rowValues; std::vector<std::vector<std::string> > rowValues;
std::vector<std::string> fieldNames; std::vector<std::string> fieldNames;
std::vector<int> fieldTypes; std::vector<enum_field_types> fieldTypes;
std::vector<int> lengths; std::vector<int> lengths;
std::vector<int> maxlengths; std::vector<int> maxlengths;
void show(){
cout<<"rowvalues:"<<endl;
for(auto item_vec:rowValues){
for(auto item:item_vec){
cout<<item.size()<<"\t";
}
cout<<endl;
}
cout<<"types:"<<endl;
for(auto item:fieldTypes){
cout<<IS_NUM(item)<<"\t";
}
cout<<endl;
cout<<"fieldNames:"<<endl;
for(auto item:fieldNames){
cout<<item<<"\t";
}
cout<<endl;
cout<<"lengths:"<<endl;
for(auto item:lengths){
cout<<item<<"\t";
}
cout<<endl;
cout<<"maxlengths:"<<endl;
for(auto item:maxlengths){
cout<<item<<"\t";
}
cout<<endl;
}
}; };
...@@ -184,7 +218,9 @@ void printrawReturnValue(rawReturnValue & cur) { ...@@ -184,7 +218,9 @@ void printrawReturnValue(rawReturnValue & cur) {
} }
*/ */
//helper function for transforming the rawReturnValue //helper function for transforming the rawReturnValue
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());
...@@ -685,6 +721,149 @@ void writeResultsColumns(rawReturnValue & raw){ ...@@ -685,6 +721,149 @@ void writeResultsColumns(rawReturnValue & raw){
} }
static void write_meta(rawReturnValue& resraw,string db,string table){
//write metadata
FILE * localmeta = NULL;
localmeta = fopen("metadata.data","a");
string s = string("database:")+db;
s+="\n";
fwrite(s.c_str(),1,s.size(),localmeta);
s = string("table:")+table;
s+="\n";
fwrite(s.c_str(),1,s.size(),localmeta);
s = string("num_of_fields:")+to_string(resraw.fieldNames.size())+"\n";
fwrite(s.c_str(),1,s.size(),localmeta);
s = string("field_types:");
for(auto item:resraw.fieldTypes){
if(IS_NUM(item)){
s+=string("N ");
}else s+=string("S ");
}
s.back()='\n';
fwrite(s.c_str(),1,s.size(),localmeta);
s = string("field_lengths:");
for(auto item : resraw.lengths){
s+=to_string(item)+=" ";
}
s.back()='\n';
fwrite(s.c_str(),1,s.size(),localmeta);
s = string("field_names:");
for(auto item : resraw.fieldNames){
s+=item+=" ";
}
s.back()='\n';
fwrite(s.c_str(),1,s.size(),localmeta);
fclose(localmeta);
}
struct meta_file{
string db,table;
int num_of_fields;
vector<string> field_types;
vector<int> field_lengths;
vector<string> field_names;
void show(){
cout<<db<<endl;
cout<<table<<endl;
cout<<num_of_fields<<endl;
for(auto item:field_types){
cout<<item<<"\t";
}
cout<<endl;
for(auto item:field_lengths){
cout<<item<<"\t";
}
cout<<endl;
for(auto item:field_names){
cout<<item<<"\t";
}
cout<<endl;
}
};
#include <sstream>
static meta_file load_meta(string filename){
//FILE * meta = NULL;
//localmeta = fopen(filename.c_str(),"r");
std::ifstream infile(filename);
string line;
meta_file res;
while(std::getline(infile,line)){
int index = line.find(":");
string head = line.substr(0,index);
if(head=="database"){
res.db = line.substr(index+1);
}else if(head=="table"){
res.table = line.substr(index+1);
}else if(head=="num_of_fields"){
res.num_of_fields = std::stoi(line.substr(index+1));
}else if(head=="field_types"){
string types = line.substr(index+1);
int start=0,next=0;
while((next=types.find(' ',start))!=-1){
string item = types.substr(start,next-start);
res.field_types.push_back(item);
start = next+1;
}
string item = types.substr(start);
res.field_types.push_back(item);
}else if(head=="field_lengths"){
string lengths = line.substr(index+1);
int start=0,next=0;
while((next=lengths.find(' ',start))!=-1){
string item = lengths.substr(start,next-start);
res.field_lengths.push_back(std::stoi(item));
start = next+1;
}
string item = lengths.substr(start);
res.field_lengths.push_back(std::stoi(item));
}else if(head=="field_names"){
string names = line.substr(index+1);
int start=0,next=0;
while((next=names.find(' ',start))!=-1){
string item = names.substr(start,next-start);
res.field_names.push_back(item);
start = next+1;
}
string item = names.substr(start);
res.field_names.push_back(item);
}
}
return res;
}
static
void write_raw_data_to_files(rawReturnValue& resraw,string db,string table){
//write metafiles
write_meta(resraw,db,table);
//write datafiles
}
/*
rawReturnValue load_raw_data_from_files(){
}*/
int int
main(int argc, char* argv[]) { main(int argc, char* argv[]) {
if(argc!=5){ if(argc!=5){
...@@ -701,7 +880,7 @@ main(int argc, char* argv[]) { ...@@ -701,7 +880,7 @@ main(int argc, char* argv[]) {
"6. tobe implemented" "6. tobe implemented"
<<endl; <<endl;
return 0; return 0;
} }
string hexstring(argv[4]); string hexstring(argv[4]);
bool useHex=false; bool useHex=false;
if(hexstring=="hex"){ if(hexstring=="hex"){
...@@ -772,6 +951,12 @@ main(int argc, char* argv[]) { ...@@ -772,6 +951,12 @@ main(int argc, char* argv[]) {
std::shared_ptr<ReturnMeta> rm = getReturnMeta(fms,res); std::shared_ptr<ReturnMeta> rm = getReturnMeta(fms,res);
std::string backq = getTestQuery(*schema,res,db,table); std::string backq = getTestQuery(*schema,res,db,table);
rawReturnValue resraw = executeAndGetResultRemote(globalConn,backq); rawReturnValue resraw = executeAndGetResultRemote(globalConn,backq);
if(1==2)
write_raw_data_to_files(resraw,db,table);
else{
load_meta("metadata.data");
}
resraw.show();
ResType rawtorestype = MygetResTypeFromLuaTable(false, &resraw); ResType rawtorestype = MygetResTypeFromLuaTable(false, &resraw);
auto finalresults = decryptResults(rawtorestype,*rm); auto finalresults = decryptResults(rawtorestype,*rm);
parseResType(finalresults); parseResType(finalresults);
...@@ -878,7 +1063,8 @@ main(int argc, char* argv[]) { ...@@ -878,7 +1063,8 @@ main(int argc, char* argv[]) {
} }
analyseCost(*schema,res,db,table); analyseCost(*schema,res,db,table);
}else{ }else{
meta_file res = load_meta("metadata.data");
res.show();
} }
fclose(stream); fclose(stream);
return 0; return 0;
......
This diff is collapsed.
database:tdb
table:student
num_of_fields:4
field_types:N N S N
field_lengths:20 8 64 8
field_names:PFMDHKUBAToEq cdb_saltXZMEYJFFMA GEKBROFQEOoEq cdb_saltTNTIQAULBW
...@@ -84,6 +84,5 @@ int main(int argc,char**argv){ ...@@ -84,6 +84,5 @@ int main(int argc,char**argv){
string query = createSelect(string(argv[1]),item,stoi(option)); string query = createSelect(string(argv[1]),item,stoi(option));
backupselect(query,string("allTables/")+item+"/"); backupselect(query,string("allTables/")+item+"/");
} }
return 0; return 0;
} }
This diff is collapsed.
mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tpcc1000" mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tpcc1000"
mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tdb" mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tdb"
mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tdb2" mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tdb2"
mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tdb3"
rm -rf ./shadow/* rm -rf ./shadow/*
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
END IF; END IF;
END END
CREATE PROCEDURE remote_db.generic_prefix_adjustOnion CREATE PROCEDURE remote_db.generic_prefix_adjustOnion
(IN completion_id INTEGER, (IN completion_id INTEGER,
IN adjust_query0 VARBINARY(500), IN adjust_query0 VARBINARY(500),
......
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