Commit dcdbd150 authored by yiwenshao's avatar yiwenshao

able to use mtl/try_writeschema

parent 6dcea991
#include "main/big_proxy.hh"
#include <vector>
using std::string;
std::vector<string> create{
"create database tdb;",
"show databases;"
};
int
main(int argc,char ** argv) {
big_proxy b;
for(auto item:create){
b.go(item);
}
return 0;
}
#include <map>
#include <iostream>
#include <vector>
#include <set>
#include <functional>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <main/Connect.hh>
#include <main/Analysis.hh>
#include <main/rewrite_main.hh>
#include <main/rewrite_util.hh>
static std::string embeddedDir="/t/cryt/shadow";
static void init_embedded_db(){
std::string client="192.168.1.1:1234";
ConnectionInfo ci("localhost", "root", "letmein",3306);
const std::string master_key = "113341234";
SharedProxyState *shared_ps = new SharedProxyState(ci, embeddedDir , master_key, determineSecurityRating());
(void)shared_ps;
}
static
void get_and_show(Connect* conn,std::string query){
std::unique_ptr<DBResult> dbres;
conn->execute(query,&dbres);
dbres->showResults();
}
int
main() {
char *buffer;
if((buffer = getcwd(NULL, 0)) == NULL){
perror("getcwd error");
}
embeddedDir = std::string(buffer)+"/shadow";//init embedded db
init_embedded_db();
std::unique_ptr<Connect> e_conn(Connect::getEmbedded(embeddedDir));
std::string query;
while(true){
std::getline(std::cin,query);
if(query!=std::string("q"))
get_and_show(e_conn.get(),query);
else break;
}
return 0;
}
This diff is collapsed.
...@@ -300,3 +300,47 @@ DBResult::unpack() ...@@ -300,3 +300,47 @@ DBResult::unpack()
return ResType(this->success, this->affected_rows, this->insert_id, return ResType(this->success, this->affected_rows, this->insert_id,
std::move(names), std::move(types), std::move(rows)); std::move(names), std::move(types), std::move(rows));
} }
void
DBResult::showResults(){
if (nullptr == n) {
return ;
}
const size_t row_count = static_cast<size_t>(mysql_num_rows(n));
const int col_count = mysql_num_fields(n);
std::vector<std::string> names;
std::vector<enum_field_types> types;
for (int j = 0;; j++) {
MYSQL_FIELD *const field = mysql_fetch_field(n);
if (!field) {
assert(col_count == j);
break;
}
names.push_back(field->name);
types.push_back(field->type);
}
std::vector<std::vector<std::string> > rows;
for (size_t index = 0;; index++) {
const MYSQL_ROW row = mysql_fetch_row(n);
if (!row) {
assert(row_count == index);
break;
}
unsigned long *const lengths = mysql_fetch_lengths(n);
std::vector<std::string> resrow;
for (int j = 0; j < col_count; j++) {
std::string item(row[j],lengths[j]);
resrow.push_back(item);
}
rows.push_back(resrow);
}
for(auto item:rows){
for(auto i:item){
std::cout<<i<<"\t";
}
std::cout<<std::endl;
}
}
...@@ -29,6 +29,7 @@ class DBResult { ...@@ -29,6 +29,7 @@ class DBResult {
//returns data from this db result //returns data from this db result
ResType unpack(); ResType unpack();
void showResults();
static DBResult *store(MYSQL *const mysql); static DBResult *store(MYSQL *const mysql);
......
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