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