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
743d7942
Commit
743d7942
authored
Jan 07, 2018
by
yiwenshao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add debug/try_insert.cc
parent
374225c6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
10 deletions
+89
-10
test_insertHandlerv1.cc
debug/test_insertHandlerv1.cc
+62
-0
try_insert.cc
debug/try_insert.cc
+27
-10
No files found.
debug/test_insertHandlerv1.cc
0 → 100644
View file @
743d7942
#include <iostream>
#include <vector>
#include <functional>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <main/Connect.hh>
#include <main/rewrite_util.hh>
#include <main/sql_handler.hh>
#include <main/dml_handler.hh>
#include <main/ddl_handler.hh>
#include <main/CryptoHandlers.hh>
static
std
::
string
embeddedDir
=
"/t/cryt/shadow"
;
static
void
testInsertHandler
(
std
::
string
query
){
std
::
unique_ptr
<
Connect
>
e_conn
(
Connect
::
getEmbedded
(
embeddedDir
));
std
::
unique_ptr
<
SchemaInfo
>
schema
(
new
SchemaInfo
());
std
::
function
<
DBMeta
*
(
DBMeta
*
const
)
>
loadChildren
=
[
&
loadChildren
,
&
e_conn
](
DBMeta
*
const
parent
)
{
auto
kids
=
parent
->
fetchChildren
(
e_conn
);
for
(
auto
it
:
kids
)
{
loadChildren
(
it
);
}
return
parent
;
};
//load all metadata and then store it in schema
loadChildren
(
schema
.
get
());
const
std
::
unique_ptr
<
AES_KEY
>
&
TK
=
std
::
unique_ptr
<
AES_KEY
>
(
getKey
(
std
::
string
(
"113341234"
)));
//just like what we do in Rewrite::rewrite,dispatchOnLex
Analysis
analysis
(
std
::
string
(
"tdb"
),
*
schema
,
TK
,
SECURITY_RATING
::
SENSITIVE
);
DMLHandler
*
h
=
new
InsertHandler
();
std
::
unique_ptr
<
query_parse
>
p
;
p
=
std
::
unique_ptr
<
query_parse
>
(
new
query_parse
(
"tdb"
,
query
));
LEX
*
const
lex
=
p
->
lex
();
auto
executor
=
h
->
transformLex
(
analysis
,
lex
);
std
::
cout
<<
((
DMLQueryExecutor
*
)
executor
)
->
getQuery
()
<<
std
::
endl
;
}
int
main
()
{
char
*
buffer
;
if
((
buffer
=
getcwd
(
NULL
,
0
))
==
NULL
){
perror
(
"getcwd error"
);
}
embeddedDir
=
std
::
string
(
buffer
)
+
"/shadow"
;
const
std
::
string
master_key
=
"113341234"
;
ConnectionInfo
ci
(
"localhost"
,
"root"
,
"letmein"
,
3306
);
SharedProxyState
*
shared_ps
=
new
SharedProxyState
(
ci
,
embeddedDir
,
master_key
,
determineSecurityRating
());
assert
(
shared_ps
!=
NULL
);
std
::
string
query1
=
"insert into student values(1,
\"
zhangfei
\"
)"
;
std
::
vector
<
std
::
string
>
querys
{
query1
};
for
(
auto
item
:
querys
){
std
::
cout
<<
item
<<
std
::
endl
;
testInsertHandler
(
item
);
std
::
cout
<<
std
::
endl
;
}
return
0
;
}
debug/t
est_insertHandler
.cc
→
debug/t
ry_insert
.cc
View file @
743d7942
...
@@ -10,9 +10,25 @@
...
@@ -10,9 +10,25 @@
#include <main/dml_handler.hh>
#include <main/dml_handler.hh>
#include <main/ddl_handler.hh>
#include <main/ddl_handler.hh>
#include <main/CryptoHandlers.hh>
#include <main/CryptoHandlers.hh>
#include <main/rewrite_main.hh>
extern
CItemTypesDir
itemTypes
;
template
<
typename
ContainerType
>
void
myRewriteInsertHelper
(
const
Item
&
i
,
const
FieldMeta
&
fm
,
Analysis
&
a
,
ContainerType
*
const
append_list
)
{
std
::
vector
<
Item
*>
l
;
//这里先做lookup, 找到类以后调用内部的结果, 试试
//对于普通的student操作, 最后调用的是ANON的typical_rewrite_insert_type来进行重写.
itemTypes
.
do_rewrite_insert
(
i
,
fm
,
a
,
&
l
);
for
(
auto
it
:
l
)
{
append_list
->
push_back
(
it
);
}
}
static
std
::
string
embeddedDir
=
"/t/cryt/shadow"
;
static
std
::
string
embeddedDir
=
"/t/cryt/shadow"
;
/*
static
std
::
string
getInsertResults
(
Analysis
a
,
LEX
*
lex
){
static
std
::
string
getInsertResults
(
Analysis
a
,
LEX
*
lex
){
LEX
*
const
new_lex
=
copyWithTHD
(
lex
);
LEX
*
const
new_lex
=
copyWithTHD
(
lex
);
const
std
::
string
&
table
=
const
std
::
string
&
table
=
...
@@ -55,7 +71,7 @@ static std::string getInsertResults(Analysis a,LEX* lex){
...
@@ -55,7 +71,7 @@ static std::string getInsertResults(Analysis a,LEX* lex){
a
.
getFieldMeta
(
db_name
,
ifd
->
table_name
,
a
.
getFieldMeta
(
db_name
,
ifd
->
table_name
,
ifd
->
field_name
);
ifd
->
field_name
);
fmVec
.
push_back
(
&
fm
);
fmVec
.
push_back
(
&
fm
);
r
ewriteInsertHelper(*i, fm, a, &newList);
myR
ewriteInsertHelper
(
*
i
,
fm
,
a
,
&
newList
);
}
}
// Collect the implicit defaults.
// Collect the implicit defaults.
...
@@ -70,12 +86,12 @@ static std::string getInsertResults(Analysis a,LEX* lex){
...
@@ -70,12 +86,12 @@ static std::string getInsertResults(Analysis a,LEX* lex){
const
Item_field
*
const
item_field
=
const
Item_field
*
const
item_field
=
make_item_field
(
*
seed_item_field
,
table
,
make_item_field
(
*
seed_item_field
,
table
,
implicit_it
->
getFieldName
());
implicit_it
->
getFieldName
());
r
ewriteInsertHelper(*item_field, *implicit_it, a,
myR
ewriteInsertHelper
(
*
item_field
,
*
implicit_it
,
a
,
&
newList
);
&
newList
);
// Get default values.
// Get default values.
const
std
::
string
def_value
=
implicit_it
->
defaultValue
();
const
std
::
string
def_value
=
implicit_it
->
defaultValue
();
r
ewriteInsertHelper(*make_item_string(def_value),
myR
ewriteInsertHelper
(
*
make_item_string
(
def_value
),
*
implicit_it
,
a
,
&
implicit_defaults
);
*
implicit_it
,
a
,
&
implicit_defaults
);
}
}
...
@@ -121,7 +137,7 @@ static std::string getInsertResults(Analysis a,LEX* lex){
...
@@ -121,7 +137,7 @@ static std::string getInsertResults(Analysis a,LEX* lex){
}
}
//fetch values, and use fieldMeta to facilitate rewrite
//fetch values, and use fieldMeta to facilitate rewrite
//every filed should be encrypted with onions of encryption
//every filed should be encrypted with onions of encryption
r
ewriteInsertHelper(*i, **fmVecIt, a, newList0);
myR
ewriteInsertHelper
(
*
i
,
**
fmVecIt
,
a
,
newList0
);
++
fmVecIt
;
++
fmVecIt
;
}
}
for
(
auto
def_it
:
implicit_defaults
)
{
for
(
auto
def_it
:
implicit_defaults
)
{
...
@@ -144,8 +160,8 @@ static std::string getInsertResults(Analysis a,LEX* lex){
...
@@ -144,8 +160,8 @@ static std::string getInsertResults(Analysis a,LEX* lex){
new_lex
->
update_list
=
res_fields
;
new_lex
->
update_list
=
res_fields
;
new_lex
->
value_list
=
res_values
;
new_lex
->
value_list
=
res_values
;
}
}
return lexToQuery(*lex);
return
lexToQuery
(
*
new_
lex
);
}
*/
}
static
void
testInsertHandler
(
std
::
string
query
){
static
void
testInsertHandler
(
std
::
string
query
){
...
@@ -165,13 +181,14 @@ static void testInsertHandler(std::string query){
...
@@ -165,13 +181,14 @@ static void testInsertHandler(std::string query){
//just like what we do in Rewrite::rewrite,dispatchOnLex
//just like what we do in Rewrite::rewrite,dispatchOnLex
Analysis
analysis
(
std
::
string
(
"tdb"
),
*
schema
,
TK
,
Analysis
analysis
(
std
::
string
(
"tdb"
),
*
schema
,
TK
,
SECURITY_RATING
::
SENSITIVE
);
SECURITY_RATING
::
SENSITIVE
);
DMLHandler
*
h
=
new
InsertHandler
();
//
DMLHandler *h = new InsertHandler();
std
::
unique_ptr
<
query_parse
>
p
;
std
::
unique_ptr
<
query_parse
>
p
;
p
=
std
::
unique_ptr
<
query_parse
>
(
p
=
std
::
unique_ptr
<
query_parse
>
(
new
query_parse
(
"tdb"
,
query
));
new
query_parse
(
"tdb"
,
query
));
LEX
*
const
lex
=
p
->
lex
();
LEX
*
const
lex
=
p
->
lex
();
auto
executor
=
h
->
transformLex
(
analysis
,
lex
);
std
::
cout
<<
getInsertResults
(
analysis
,
lex
)
<<
std
::
endl
;
std
::
cout
<<
((
DMLQueryExecutor
*
)
executor
)
->
getQuery
()
<<
std
::
endl
;
//auto executor = h->transformLex(analysis,lex);
//std::cout<<((DMLQueryExecutor*)executor)->getQuery()<<std::endl;
}
}
int
int
...
...
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