Commit b1fde292 authored by yiwenshao's avatar yiwenshao

update test_load_schema

parent c38e16a8
...@@ -28,7 +28,6 @@ static std::map<std::string, WrapperState*> clients; ...@@ -28,7 +28,6 @@ static std::map<std::string, WrapperState*> clients;
//This connection mimics the behaviour of MySQL-Proxy //This connection mimics the behaviour of MySQL-Proxy
Connect *globalConn; Connect *globalConn;
/*for each field, convert the format to FieldMeta_Wrapper*/ /*for each field, convert the format to FieldMeta_Wrapper*/
static void init(){ static void init(){
std::string client="192.168.1.1:1234"; std::string client="192.168.1.1:1234";
//one Wrapper per user. //one Wrapper per user.
......
...@@ -6,12 +6,12 @@ static std::map<std::string, WrapperState*> clients; ...@@ -6,12 +6,12 @@ static std::map<std::string, WrapperState*> clients;
//This connection mimics the behaviour of MySQL-Proxy //This connection mimics the behaviour of MySQL-Proxy
Connect *globalConn; Connect *globalConn;
static void init(){ static void init(std::string ip,int port){
std::string client="192.168.1.1:1234"; std::string client="192.168.1.1:1234";
//one Wrapper per user. //one Wrapper per user.
clients[client] = new WrapperState(); clients[client] = new WrapperState();
//Connect phase //Connect phase
ConnectionInfo ci("localhost", "root", "letmein",3306); ConnectionInfo ci("localhost", "root", "letmein",port);
const std::string master_key = "113341234"; const std::string master_key = "113341234";
char *buffer; char *buffer;
if((buffer = getcwd(NULL, 0)) == NULL){ if((buffer = getcwd(NULL, 0)) == NULL){
...@@ -26,7 +26,7 @@ static void init(){ ...@@ -26,7 +26,7 @@ static void init(){
clients[client]->ps = std::unique_ptr<ProxyState>(new ProxyState(*shared_ps)); clients[client]->ps = std::unique_ptr<ProxyState>(new ProxyState(*shared_ps));
clients[client]->ps->safeCreateEmbeddedTHD(); clients[client]->ps->safeCreateEmbeddedTHD();
//Connect end!! //Connect end!!
globalConn = new Connect(ci.server, ci.user, ci.passwd, ci.port); globalConn = new Connect(ip, ci.user, ci.passwd, port);
} }
...@@ -118,12 +118,16 @@ static void store(std::string db, std::string table){ ...@@ -118,12 +118,16 @@ static void store(std::string db, std::string table){
int int
main(int argc, char* argv[]){ main(int argc, char* argv[]){
init();
std::string db="tdb",table="student"; std::string db="tdb",table="student";
if(argc==3){ std::string ip="127.0.0.1";
db = std::string(argv[1]); int port=3306;
table = std::string(argv[2]); if(argc==5){
ip = std::string(argv[1]);
port = std::stoi(std::string(argv[2]));
db = std::string(argv[3]);
table = std::string(argv[4]);
} }
init(ip,port);
store(db,table); store(db,table);
return 0; return 0;
} }
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
#include <main/rewrite_util.hh> #include <main/rewrite_util.hh>
static std::string embeddedDir="/t/cryt/shadow"; static std::string embeddedDir="/t/cryt/shadow";
using std::cout;
using std::endl;
//My WrapperState. //My WrapperState.
class WrapperState { class WrapperState {
...@@ -46,10 +49,20 @@ private: ...@@ -46,10 +49,20 @@ private:
//global map, for each client, we have one WrapperState which contains ProxyState. //global map, for each client, we have one WrapperState which contains ProxyState.
static std::map<std::string, WrapperState*> clients; static std::map<std::string, WrapperState*> clients;
static void processOnionMeta(const OnionMeta &om){
for(auto &item:om.getLayers()){
cout<<" "<<TypeText<SECLEVEL>::toText(item->level())<<" ";
}
cout<<endl;
}
static void processFieldMeta(const FieldMeta &field){ static void processFieldMeta(const FieldMeta &field){
std::cout<<GREEN_BEGIN<<"PRINT FieldMeta"<<COLOR_END<<std::endl; std::cout<<GREEN_BEGIN<<"PRINT FieldMeta"<<COLOR_END<<std::endl;
for(const auto & onion: field.getChildren()){ for(const auto & onionnow: field.getChildren()){
std::cout<<onion.second->getDatabaseID()<<":"<<onion.first.getValue()<<std::endl; std::cout<<"onionmetaid: "<<onionnow.second->getDatabaseID()
<<" ### onion name: "<<TypeText<onion>::toText(onionnow.first.getValue())<<std::endl;
processOnionMeta(*(onionnow.second));
} }
std::cout<<GREEN_BEGIN<<"end FieldMeta"<<COLOR_END<<std::endl; std::cout<<GREEN_BEGIN<<"end FieldMeta"<<COLOR_END<<std::endl;
} }
...@@ -57,7 +70,8 @@ static void processFieldMeta(const FieldMeta &field){ ...@@ -57,7 +70,8 @@ static void processFieldMeta(const FieldMeta &field){
static void processTableMeta(const TableMeta &table){ static void processTableMeta(const TableMeta &table){
std::cout<<GREEN_BEGIN<<"PRINT TableMeta"<<COLOR_END<<std::endl; std::cout<<GREEN_BEGIN<<"PRINT TableMeta"<<COLOR_END<<std::endl;
for(const auto & field: table.getChildren()){ for(const auto & field: table.getChildren()){
std::cout<<field.second->getDatabaseID()<<":"<<field.first.getValue()<<std::endl; std::cout<<"fieldmetaid: "<<field.second->getDatabaseID()
<<" ### fieldmeta name: "<<field.first.getValue()<<std::endl;
processFieldMeta(*(field.second)); processFieldMeta(*(field.second));
} }
} }
...@@ -65,6 +79,7 @@ static void processTableMeta(const TableMeta &table){ ...@@ -65,6 +79,7 @@ static void processTableMeta(const TableMeta &table){
static void processDatabaseMeta(const DatabaseMeta & db) { static void processDatabaseMeta(const DatabaseMeta & db) {
std::cout<<GREEN_BEGIN<<"PRINT DatabaseMeta"<<COLOR_END<<std::endl; std::cout<<GREEN_BEGIN<<"PRINT DatabaseMeta"<<COLOR_END<<std::endl;
for(const auto & table: db.getChildren()){ for(const auto & table: db.getChildren()){
cout<<"tablemetaid: "<<table.second->getDatabaseID()<<" ### dbmeta name: "<<table.first.getValue()<<std::endl;
processTableMeta(*(table.second)); processTableMeta(*(table.second));
} }
} }
...@@ -74,12 +89,13 @@ static void processSchemaInfo(SchemaInfo &schema){ ...@@ -74,12 +89,13 @@ static void processSchemaInfo(SchemaInfo &schema){
std::cout<<GREEN_BEGIN<<"PRINT SchemaInfo"<<COLOR_END<<std::endl; std::cout<<GREEN_BEGIN<<"PRINT SchemaInfo"<<COLOR_END<<std::endl;
//only const auto & is allowed, now copying. or we meet use of deleted function. //only const auto & is allowed, now copying. or we meet use of deleted function.
for(const auto & child : schema.getChildren()) { for(const auto & child : schema.getChildren()) {
std::cout<<child.second->getDatabaseID()<<":"<<child.first.getValue()<<std::endl; std::cout<<"dbmetaid: "<<child.second->getDatabaseID()<<" ### dbmeta name:"<<child.first.getValue()<<std::endl;
processDatabaseMeta(*(child.second)); processDatabaseMeta(*(child.second));
} }
} }
static DBMeta* loadChildren(DBMeta *const parent,std::unique_ptr<Connect> &e_conn){ static DBMeta* loadChildren(DBMeta *const parent,std::unique_ptr<Connect> &e_conn){
auto kids = parent->fetchChildren(e_conn); auto kids = parent->fetchChildren(e_conn);
for (auto it : kids) { for (auto it : kids) {
loadChildren(it,e_conn); loadChildren(it,e_conn);
...@@ -87,7 +103,8 @@ static DBMeta* loadChildren(DBMeta *const parent,std::unique_ptr<Connect> &e_con ...@@ -87,7 +103,8 @@ static DBMeta* loadChildren(DBMeta *const parent,std::unique_ptr<Connect> &e_con
return parent; return parent;
} }
static std::unique_ptr<SchemaInfo> myLoadSchemaInfo(){ static
std::unique_ptr<SchemaInfo> myLoadSchemaInfo(){
std::unique_ptr<Connect> e_conn(Connect::getEmbedded(embeddedDir)); std::unique_ptr<Connect> e_conn(Connect::getEmbedded(embeddedDir));
std::unique_ptr<SchemaInfo> schema(new SchemaInfo()); std::unique_ptr<SchemaInfo> schema(new SchemaInfo());
loadChildren(schema.get(),e_conn); loadChildren(schema.get(),e_conn);
......
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