Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
Practical-Cryptdb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Zhaozhen
Practical-Cryptdb
Commits
5fb9030d
Commit
5fb9030d
authored
Jan 04, 2018
by
yiwenshao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug
parent
2b651e0f
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
24 additions
and
163 deletions
+24
-163
backup_fields.sh
packages/operation/backup_fields.sh
+1
-0
Makefile
packages/tls/mysql_wrapper/Makefile
+1
-1
analysis
packages/tls/mysql_wrapper/analysis
+0
-0
analysis.cc
packages/tls/mysql_wrapper/analysis.cc
+0
-29
backFieldsToFiles
packages/tls/mysql_wrapper/backFieldsToFiles
+0
-0
createInsert
packages/tls/mysql_wrapper/createInsert
+0
-0
createInsert.cc
packages/tls/mysql_wrapper/createInsert.cc
+0
-114
createSelect
packages/tls/mysql_wrapper/createSelect
+0
-0
main
packages/tls/mysql_wrapper/main
+0
-0
main.cc
packages/tls/mysql_wrapper/main.cc
+22
-19
No files found.
packages/operation/backup_fields.sh
0 → 100755
View file @
5fb9030d
../tls/mysql_wrapper/backFieldsToFiles tdb 1
packages/tls/mysql_wrapper/Makefile
View file @
5fb9030d
...
@@ -8,7 +8,7 @@ CXX=g++
...
@@ -8,7 +8,7 @@ CXX=g++
.PHONY
:
all
.PHONY
:
all
executables
:=
main
createInsert backFieldsToFiles analysi
s
executables
:=
main
backFieldsToFile
s
all
:
$(executables)
all
:
$(executables)
...
...
packages/tls/mysql_wrapper/analysis
deleted
100755 → 0
View file @
2b651e0f
File deleted
packages/tls/mysql_wrapper/analysis.cc
deleted
100644 → 0
View file @
2b651e0f
#include <iostream>
#include <stdlib.h>
#include "mysqllib/utilities.h"
#include "mysqllib/MyConnect.h"
#include <vector>
#include <string>
using
namespace
std
;
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
();
}
int
main
(
int
argc
,
char
**
argv
){
system
(
"rm -rf allTables"
);
system
(
"mkdir allTables"
);
if
(
argc
!=
3
){
cout
<<
"db, table"
<<
endl
;
return
0
;
}
string
db
(
argv
[
1
]),
table
(
argv
[
2
]);
createSelect
(
db
,
table
);
return
0
;
}
packages/tls/mysql_wrapper/backFieldsToFiles
View file @
5fb9030d
No preview for this file type
packages/tls/mysql_wrapper/createInsert
deleted
100755 → 0
View file @
2b651e0f
File deleted
packages/tls/mysql_wrapper/createInsert.cc
deleted
100644 → 0
View file @
2b651e0f
#include <iostream>
#include "mysqllib/utilities.h"
#include "mysqllib/MyConnect.h"
#include <vector>
#include <string>
using
namespace
std
;
extern
Connect
*
con
;
string
createSelect
(
string
database
,
string
table
,
bool
isQuote
=
true
){
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
{
if
(
isQuote
)
head
+=
string
(
"QUOTE("
)
+
fields
[
i
]
+
"),"
;
else
head
+=
string
(
"HEX("
)
+
fields
[
i
]
+
"),"
;
}
}
head
[
head
.
size
()
-
1
]
=
' '
;
head
+=
"FROM `"
+
database
+
"`.`"
+
table
+
"`"
;
return
head
;
}
//http://php.net/manual/zh/function.mysql-escape-string.php
//https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_quote
//backup in configurable extended version
static
int
numOfPipe
=
3
;
void
backupselect
(
string
query
,
string
table
){
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
();
string
head
=
string
(
"INSERT INTO "
)
+
"`"
+
table
+
"`"
+
string
(
" VALUES ("
);
for
(
auto
i
=
0
;
i
<
rows
.
size
();
i
++
){
string
cur
=
head
;
for
(
int
j
=
0
;
j
<
rows
[
i
].
size
();
j
++
){
if
(
IS_NUM
(
types
[
j
]))
cur
+=
rows
[
i
][
j
]
+
","
;
else
{
cur
+=
rows
[
i
][
j
]
+
","
;
}
}
cur
[
cur
.
size
()
-
1
]
=
')'
;
for
(
int
k
=
1
;
k
<
numOfPipe
;
k
++
){
//for each pipe
i
++
;
if
(
i
>=
rows
.
size
())
break
;
cur
+=
",("
;
for
(
int
j
=
0
;
j
<
rows
[
i
].
size
();
j
++
){
if
(
IS_NUM
(
types
[
j
]))
cur
+=
rows
[
i
][
j
]
+
","
;
else
{
cur
+=
rows
[
i
][
j
]
+
","
;
}
}
cur
[
cur
.
size
()
-
1
]
=
')'
;
}
cur
+=
";"
;
cout
<<
cur
<<
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
]);
}
return
res
;
}
int
main
(
int
argc
,
char
**
argv
){
if
(
argc
!=
4
){
cout
<<
"numOfpipe, db, isQuote"
<<
endl
;
return
0
;
}
string
num
=
string
(
argv
[
1
]);
numOfPipe
=
stoi
(
num
);
vector
<
string
>
tables
=
getTables
(
string
(
argv
[
2
]));
bool
isQuote
;
if
(
string
(
argv
[
3
])
==
"true"
){
isQuote
=
true
;
}
else
if
(
string
(
argv
[
3
])
==
"false"
){
isQuote
=
false
;
}
else
{
printf
(
"error
\n
"
);
return
0
;
}
for
(
auto
item
:
tables
){
string
query
=
createSelect
(
string
(
argv
[
2
]),
item
,
isQuote
);
backupselect
(
query
,
item
);
}
return
0
;
}
packages/tls/mysql_wrapper/createSelect
deleted
100755 → 0
View file @
2b651e0f
File deleted
packages/tls/mysql_wrapper/main
View file @
5fb9030d
No preview for this file type
packages/tls/mysql_wrapper/main.cc
View file @
5fb9030d
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
using
namespace
std
;
using
namespace
std
;
extern
Connect
*
con
;
extern
Connect
*
con
;
string
createSelect
(
string
database
,
string
table
){
string
createSelect
(
string
database
,
string
table
,
bool
isQuote
=
true
){
auto
dbresult
=
con
->
execute
(
string
(
"SELECT * FROM `"
)
+
database
+
"`.`"
+
string
(
table
)
+
"` LIMIT 1;"
);
auto
dbresult
=
con
->
execute
(
string
(
"SELECT * FROM `"
)
+
database
+
"`.`"
+
string
(
table
)
+
"` LIMIT 1;"
);
DBResult
*
result
=
dbresult
.
get
();
DBResult
*
result
=
dbresult
.
get
();
vector
<
vector
<
string
>>
rows
=
result
->
getRows
();
vector
<
vector
<
string
>>
rows
=
result
->
getRows
();
...
@@ -18,7 +18,9 @@ string createSelect(string database,string table){
...
@@ -18,7 +18,9 @@ string createSelect(string database,string table){
head
+=
fields
[
i
]
+
","
;
head
+=
fields
[
i
]
+
","
;
}
}
else
{
else
{
head
+=
string
(
"QUOTE("
)
+
fields
[
i
]
+
"),"
;
if
(
isQuote
)
head
+=
string
(
"QUOTE("
)
+
fields
[
i
]
+
"),"
;
else
head
+=
string
(
"HEX("
)
+
fields
[
i
]
+
"),"
;
}
}
}
}
head
[
head
.
size
()
-
1
]
=
' '
;
head
[
head
.
size
()
-
1
]
=
' '
;
...
@@ -38,16 +40,6 @@ void backupselect(string query,string table){
...
@@ -38,16 +40,6 @@ void backupselect(string query,string table){
vector
<
enum_field_types
>
types
=
result
->
getTypes
();
vector
<
enum_field_types
>
types
=
result
->
getTypes
();
vector
<
string
>
fieldNames
=
result
->
getFields
();
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
++
){
...
@@ -75,17 +67,28 @@ void backupselect(string query,string table){
...
@@ -75,17 +67,28 @@ void backupselect(string query,string table){
cur
+=
";"
;
cur
+=
";"
;
cout
<<
cur
<<
endl
;
cout
<<
cur
<<
endl
;
}
}
}
for
(
auto
i
=
0u
;
i
<
files
.
size
();
i
++
){
for
(
auto
item
:
rows
){
vector
<
string
>
getTables
(
string
db
){
fwrite
(
item
[
i
].
c_str
(),
1
,
item
[
i
].
size
(),
files
[
i
]);
string
query
=
string
(
"SHOW TABLES IN "
)
+
db
;
fprintf
(
files
[
i
],
"
\n
"
);
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
]);
}
}
for
(
auto
i
=
0u
;
i
<
files
.
size
();
i
++
)
return
res
;
fclose
(
files
[
i
]);
}
}
int
main
(
int
argc
,
char
**
argv
){
int
main
(
int
argc
,
char
**
argv
){
if
(
argc
!=
4
){
if
(
argc
!=
4
){
cout
<<
"numOfpipe, db, table"
<<
endl
;
cout
<<
"numOfpipe, db, table"
<<
endl
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment