Commit 7021b816 authored by yiwenshao's avatar yiwenshao

able to backup schema

parent ecec3dba
...@@ -9,7 +9,7 @@ CXX=g++ ...@@ -9,7 +9,7 @@ CXX=g++
.PHONY: all .PHONY: all
executables:=main backFieldsToFiles client escape executables:=main backFieldsToFiles client escape backupSchema
all: $(executables) all: $(executables)
...@@ -25,6 +25,9 @@ client:obj/client.o $(OBJFILES) ...@@ -25,6 +25,9 @@ client:obj/client.o $(OBJFILES)
escape:obj/escape.o $(OBJFILES) escape:obj/escape.o $(OBJFILES)
$(CXX) -o $@ $^ $(LDFLAGS) $(CXX) -o $@ $^ $(LDFLAGS)
backupSchema:obj/backupSchema.o $(OBJFILES)
$(CXX) -o $@ $^ $(LDFLAGS)
.PHONY:clean .PHONY:clean
......
/* table_BARVVQXXXG */
CREATE TABLE `table_BARVVQXXXG` (
`HNSEGFOWDWoEq` bigint(20) unsigned DEFAULT NULL,
`PEWGZUYZRWoOrder` varbinary(32) DEFAULT NULL,
`FETULHJOAZoADD` varbinary(256) DEFAULT NULL,
`cdb_saltLVMFMPASNF` bigint(8) unsigned DEFAULT NULL,
`XFAWMBQMAJoEq` varbinary(48) DEFAULT NULL,
`IIPECDLNRLoOrder` varbinary(32) DEFAULT NULL,
`MKSYYFSQHJoSWP` blob,
`cdb_saltTHMLLSSBQV` bigint(8) unsigned DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
#include <iostream>
#include <stdlib.h>
#include "mysqllib/utilities.h"
#include "mysqllib/MyConnect.h"
#include <vector>
#include <string>
using namespace std;
extern Connect *con;
void backupSchema(string query){
auto dbresult = con->execute(query);
DBResult * result = dbresult.get();
vector<vector<string>> rows = result->getRows();
cout<<"/* "<<rows[0][0]<<" */"<<endl;
cout<<rows[0][1]<<endl;
// for(auto row:rows){
// for(int i=0;i<row.size();i++){
// cout<<row[i]<<endl;
// }
// }
}
vector<string> getTables(string db){
string query = string("SHOW TABLES IN ")+db;
auto dbresult = con->execute(query);
DBResult * result = dbresult.get();
vector<vector<string>> rows = result->getRows();
vector<enum_field_types> types = result->getTypes();
vector<string> fieldNames = result->getFields();
vector<string> res;
for(auto item:rows){
assert(item.size()==1);
res.push_back(item[0]);
}
string q = string("use ") + db;
con->execute(q);
return res;
}
int main(int argc,char**argv){
if(argc!=2){
cout<<"db"<<endl;
return 0;
}
string db(argv[1]);
vector<string> tablesprefix = getTables(db);
for(auto item:tablesprefix){
string query = string("show create table ")+item+";";
backupSchema(query);
}
return 0;
}
...@@ -83,7 +83,7 @@ Connect::execute(const std::string &query){ ...@@ -83,7 +83,7 @@ Connect::execute(const std::string &query){
MYSQL_RES *result = mysql_store_result(conn); MYSQL_RES *result = mysql_store_result(conn);
if (result == NULL) { if (result == NULL) {
std::cout<<"no results for this query"<<std::endl; //std::cout<<"no results for this query"<<std::endl;
return std::shared_ptr<DBResult>(NULL); return std::shared_ptr<DBResult>(NULL);
} }
......
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