Commit aff376c7 authored by casualet's avatar casualet

able to analyse both plaintex and encrypted columns

parent 88be7384
...@@ -17,3 +17,5 @@ writeFile ...@@ -17,3 +17,5 @@ writeFile
*CMakeFiles* *CMakeFiles*
*all* *all*
*back1.sql *back1.sql
*back.sql
*load.sql
...@@ -5,29 +5,10 @@ ...@@ -5,29 +5,10 @@
#include <string> #include <string>
using namespace std; using namespace std;
extern Connect *con; extern Connect *con;
void createSelect(string database,string table){
auto dbresult = con->execute(string("SELECT * FROM `")+database+"`.`"+string(table)+"` LIMIT 1;");
DBResult * result = dbresult.get();
vector<vector<string>> rows = result->getRows();
vector<enum_field_types> types = result->getTypes();
vector<string> fields = result->getFields();
string head = "SELECT ";
for(int i=0;i<types.size();i++){
if(IS_NUM(types[i])){
head += fields[i]+",";
}
else{
head+=string("QUOTE(")+fields[i]+"),";
}
}
head[head.size()-1]=' ';
head += "FROM `"+database+"`.`"+table+"`";
cout<<head<<endl;
}
int main(int argc,char**argv){ int main(int argc,char**argv){
if(argc==3)return 0; if(argc==3)return 0;
createSelect(string(argv[1]),string(argv[2]));
return 0; return 0;
} }
...@@ -6,19 +6,48 @@ ...@@ -6,19 +6,48 @@
using namespace std; using namespace std;
extern Connect *con; extern Connect *con;
string createSelect(string database,string table){
auto dbresult = con->execute(string("SELECT * FROM `")+database+"`.`"+string(table)+"` LIMIT 1;");
DBResult * result = dbresult.get();
vector<vector<string>> rows = result->getRows();
vector<enum_field_types> types = result->getTypes();
vector<string> fields = result->getFields();
string head = "SELECT ";
for(int i=0;i<types.size();i++){
if(IS_NUM(types[i])){
head += fields[i]+",";
}
else{
head+=string("QUOTE(")+fields[i]+"),";
}
}
head[head.size()-1]=' ';
head += "FROM `"+database+"`.`"+table+"`";
cout<<head<<endl;
return head;
}
//http://php.net/manual/zh/function.mysql-escape-string.php //http://php.net/manual/zh/function.mysql-escape-string.php
//https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_quote //https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_quote
//backup in configurable extended version //backup in configurable extended version
static int numOfPipe = 3; static int numOfPipe = 3;
void backupselect(){ void backupselect(string query,string table){
string query,table;
getline(cin,query);
cin>>table;
auto dbresult = con->execute(query); auto dbresult = con->execute(query);
DBResult * result = dbresult.get(); DBResult * result = dbresult.get();
vector<vector<string>> rows = result->getRows(); vector<vector<string>> rows = result->getRows();
vector<enum_field_types> types = result->getTypes(); vector<enum_field_types> types = result->getTypes();
vector<string> fieldNames = result->getFields();
string head = string("INSERT INTO ")+"`"+table+"`"+string(" VALUES ("); string head = string("INSERT INTO ")+"`"+table+"`"+string(" VALUES (");
system("rm -rf allColumns");
system("mkdir allColumns");
vector<FILE *> files;
for(auto i=0u;i<types.size();i++){
FILE * cur = fopen((string("allColumns/")+fieldNames[i]).c_str(),"w");
if(cur==NULL) exit(1);
files.push_back(cur);
}
for(auto i=0;i<rows.size();i++){ for(auto i=0;i<rows.size();i++){
string cur=head; string cur=head;
for(int j=0;j<rows[i].size();j++){ for(int j=0;j<rows[i].size();j++){
...@@ -46,13 +75,27 @@ void backupselect(){ ...@@ -46,13 +75,27 @@ void backupselect(){
cur+=";"; cur+=";";
cout<<cur<<endl; cout<<cur<<endl;
} }
for(auto i=0u;i<files.size();i++ ){
for(auto item:rows){
fwrite(item[i].c_str(),1,item[i].size(),files[i]);
fprintf(files[i],"\n");
}
}
for(auto i=0u;i<files.size();i++)
fclose(files[i]);
} }
int main(int argc,char**argv){ int main(int argc,char**argv){
if(argc!=2) return 0; if(argc!=4){
cout<<"numOfpipe, db, table"<<endl;
return 0;
}
string num = string(argv[1]); string num = string(argv[1]);
numOfPipe = stoi(num); numOfPipe = stoi(num);
backupselect(); string query = createSelect(string(argv[2]),string(argv[3]));
backupselect(query,string(argv[3]));
return 0; return 0;
} }
...@@ -7,7 +7,7 @@ function inittable { ...@@ -7,7 +7,7 @@ function inittable {
mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "drop database if exists tpcc1000" mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "drop database if exists tpcc1000"
mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "create database tpcc1000" mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "create database tpcc1000"
mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "use tpcc1000; drop table if exists student" mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "use tpcc1000; drop table if exists student"
len=$[$1+16] len=$[$1+0]
#not supported #not supported
#mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "create table if not exists tpcc1000.student(name varchar(${len}))" #mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "create table if not exists tpcc1000.student(name varchar(${len}))"
mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "use tpcc1000; create table if not exists student(name varchar(${len}))" mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "use tpcc1000; create table if not exists student(name varchar(${len}))"
......
if [ $# = 0 ];then
echo "arg1: len of field, arg2 num in pipe, arg3 num of pipe"
exit
fi
function inittable {
mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tpcc1000"
mysql -uroot -pletmein -h127.0.0.1 -e "create database tpcc1000"
mysql -uroot -pletmein -h127.0.0.1 -e "use tpcc1000; drop table if exists student"
len=$[$1+0]
#not supported
#mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "create table if not exists tpcc1000.student(name varchar(${len}))"
mysql -uroot -pletmein -h127.0.0.1 -e "use tpcc1000; create table if not exists student(name varchar(${len}))"
echo "create table if not exists tpcc1000.student(name varchar(${len}))"
}
#generate load.sql
head='INSERT INTO student VALUES '
cur=""
function getField {
num=$1
for((i=0;i<$num;i++))do
cur=${cur}a
done
cur=\'$cur\'
}
getField $1
multi=""
function getMultipleFields {
num=$1
multi=\($cur\)
for((i=1;i<$num;i++))do
multi=${multi}\,\($cur\)
done
}
getMultipleFields $2
rm -rf load.sql
echo "start to get multiple inserts!!!!"
for((i=0;i<$3;i++))do
echo $head$multi\; >> load.sql
done
inittable $1
mysql -uroot -pletmein -h127.0.0.1 tpcc1000 < load.sql
mysqldump --skip-extended-insert -uroot -pletmein -h127.0.0.1 --hex-blob --compact tpcc1000 > back.sql
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