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
15c0202c
Commit
15c0202c
authored
Oct 30, 2017
by
Casualet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rewrite rewrite_main
parent
3d8f9cbe
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
75 deletions
+40
-75
test_load_schema.cc
debug/test_load_schema.cc
+0
-16
rewrite_main.cc
main/rewrite_main.cc
+40
-59
No files found.
debug/test_load_schema.cc
View file @
15c0202c
...
@@ -95,23 +95,7 @@ static DBMeta* loadChildren(DBMeta *const parent,std::unique_ptr<Connect> &e_con
...
@@ -95,23 +95,7 @@ static DBMeta* loadChildren(DBMeta *const parent,std::unique_ptr<Connect> &e_con
static
std
::
unique_ptr
<
SchemaInfo
>
myLoadSchemaInfo
(){
static
std
::
unique_ptr
<
SchemaInfo
>
myLoadSchemaInfo
(){
std
::
unique_ptr
<
Connect
>
e_conn
(
Connect
::
getEmbedded
(
embeddedDir
));
std
::
unique_ptr
<
Connect
>
e_conn
(
Connect
::
getEmbedded
(
embeddedDir
));
std
::
unique_ptr
<
SchemaInfo
>
schema
(
new
SchemaInfo
());
std
::
unique_ptr
<
SchemaInfo
>
schema
(
new
SchemaInfo
());
loadChildren
(
schema
.
get
(),
e_conn
);
loadChildren
(
schema
.
get
(),
e_conn
);
// auto load = std::bind(loadChildren,std::placeholders::_1,e_conn);
/* 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());
// load(schema.get());
//Analysis analysis(std::string("student"),*schema,std::unique_ptr<AES_KEY>(getKey(std::string("113341234"))),
// SECURITY_RATING::SENSITIVE);
return
schema
;
return
schema
;
}
}
...
...
main/rewrite_main.cc
View file @
15c0202c
...
@@ -591,74 +591,70 @@ metaSanityCheck(const std::unique_ptr<Connect> &e_conn)
...
@@ -591,74 +591,70 @@ metaSanityCheck(const std::unique_ptr<Connect> &e_conn)
return
true
;
return
true
;
}
}
// This function will not build all of our tables when it is run
// This function will not build all of our tables when it is run
// on an empty database. If you don't have a parent, your table won't be
// on an empty database. If you don't have a parent, your table won't be
// built. We probably want to seperate our database logic into 3 parts.
// built. We probably want to seperate our database logic into 3 parts.
// 1> Schema buildling (CREATE TABLE IF NOT EXISTS...)
// 1> Schema buildling (CREATE TABLE IF NOT EXISTS...)
// 2> INSERTing
// 2> INSERTing
// 3> SELECTing
// 3> SELECTing
/*
*Now I want to separate the original loadSchemaInfo into two parts.
*/
static
DBMeta
*
loadChildren
(
DBMeta
*
const
parent
,
const
std
::
unique_ptr
<
Connect
>
&
e_conn
){
auto
kids
=
parent
->
fetchChildren
(
e_conn
);
for
(
auto
it
:
kids
)
{
loadChildren
(
it
,
e_conn
);
}
return
parent
;
}
std
::
unique_ptr
<
SchemaInfo
>
std
::
unique_ptr
<
SchemaInfo
>
loadSchemaInfo
(
const
std
::
unique_ptr
<
Connect
>
&
conn
,
loadSchemaInfo
(
const
std
::
unique_ptr
<
Connect
>
&
conn
,
const
std
::
unique_ptr
<
Connect
>
&
e_conn
)
const
std
::
unique_ptr
<
Connect
>
&
e_conn
){
{
// Must be done before loading the children.
// Must be done before loading the children.
assert
(
deltaSanityCheck
(
conn
,
e_conn
));
assert
(
deltaSanityCheck
(
conn
,
e_conn
));
std
::
unique_ptr
<
SchemaInfo
>
schema
(
new
SchemaInfo
());
std
::
unique_ptr
<
SchemaInfo
>
schema
(
new
SchemaInfo
());
// Recursively rebuild the AbstractMeta<Whatever> and it's children.
// Recursively rebuild the AbstractMeta<Whatever> and it's children.
std
::
function
<
DBMeta
*
(
DBMeta
*
const
)
>
loadChildren
=
loadChildren
(
schema
.
get
(),
e_conn
);
[
&
loadChildren
,
&
e_conn
](
DBMeta
*
const
parent
)
{
auto
kids
=
parent
->
fetchChildren
(
e_conn
);
for
(
auto
it
:
kids
)
{
loadChildren
(
it
);
}
return
parent
;
/* lambda */
};
loadChildren
(
schema
.
get
());
//check from the upmost to the lowest
//check from the upmost to the lowest
assert
(
sanityCheck
(
*
schema
.
get
()));
assert
(
sanityCheck
(
*
schema
.
get
()));
//check metaobject and bleeding table are identical
//check metaobject and bleeding table are identical
assert
(
metaSanityCheck
(
e_conn
));
assert
(
metaSanityCheck
(
e_conn
));
// compares SHOW TABLES on embedded and remote with the SchemaInfo
// compares SHOW TABLES on embedded and remote with the SchemaInfo
assert
(
tablesSanityCheck
(
*
schema
.
get
(),
e_conn
,
conn
));
assert
(
tablesSanityCheck
(
*
schema
.
get
(),
e_conn
,
conn
));
return
std
::
move
(
schema
);
return
std
::
move
(
schema
);
}
}
template
<
typename
Type
>
static
void
template
<
typename
Type
>
static
void
translatorHelper
(
std
::
vector
<
std
::
string
>
texts
,
translatorHelper
(
std
::
vector
<
std
::
string
>
texts
,
std
::
vector
<
Type
>
enums
)
std
::
vector
<
Type
>
enums
){
{
TypeText
<
Type
>::
addSet
(
enums
,
texts
);
TypeText
<
Type
>::
addSet
(
enums
,
texts
);
}
}
static
bool
static
bool
buildTypeTextTranslator
()
buildTypeTextTranslator
(){
{
// Onions.
// Onions.
const
std
::
vector
<
std
::
string
>
onion_strings
const
std
::
vector
<
std
::
string
>
onion_strings
{
{
"oINVALID"
,
"oPLAIN"
,
"oEq"
,
"oOrder"
,
"oADD"
,
"oSWP"
"oINVALID"
,
"oPLAIN"
,
"oEq"
,
"oOrder"
,
"oADD"
,
"oSWP"
};
};
const
std
::
vector
<
onion
>
onions
const
std
::
vector
<
onion
>
onions
{
{
oINVALID
,
oPLAIN
,
oDET
,
oOPE
,
oAGG
,
oSWP
oINVALID
,
oPLAIN
,
oDET
,
oOPE
,
oAGG
,
oSWP
};
};
RETURN_FALSE_IF_FALSE
(
onion_strings
.
size
()
==
onions
.
size
());
RETURN_FALSE_IF_FALSE
(
onion_strings
.
size
()
==
onions
.
size
());
translatorHelper
<
onion
>
(
onion_strings
,
onions
);
translatorHelper
<
onion
>
(
onion_strings
,
onions
);
// SecLevels.
// SecLevels.
const
std
::
vector
<
std
::
string
>
seclevel_strings
const
std
::
vector
<
std
::
string
>
seclevel_strings
{
{
"RND"
,
"DET"
,
"DETJOIN"
,
"OPEFOREIGN"
,
"OPE"
,
"HOM"
,
"SEARCH"
,
"PLAINVAL"
,
"RND"
,
"DET"
,
"DETJOIN"
,
"OPEFOREIGN"
,
"OPE"
,
"HOM"
,
"SEARCH"
,
"PLAINVAL"
,
"INVALID"
"INVALID"
};
};
const
std
::
vector
<
SECLEVEL
>
seclevels
const
std
::
vector
<
SECLEVEL
>
seclevels
{
{
SECLEVEL
::
RND
,
SECLEVEL
::
DET
,
SECLEVEL
::
DETJOIN
,
SECLEVEL
::
OPEFOREIGN
,
SECLEVEL
::
OPE
,
SECLEVEL
::
RND
,
SECLEVEL
::
DET
,
SECLEVEL
::
DETJOIN
,
SECLEVEL
::
OPEFOREIGN
,
SECLEVEL
::
OPE
,
SECLEVEL
::
HOM
,
SECLEVEL
::
SEARCH
,
SECLEVEL
::
PLAINVAL
,
SECLEVEL
::
HOM
,
SECLEVEL
::
SEARCH
,
SECLEVEL
::
PLAINVAL
,
SECLEVEL
::
INVALID
SECLEVEL
::
INVALID
...
@@ -667,8 +663,7 @@ buildTypeTextTranslator()
...
@@ -667,8 +663,7 @@ buildTypeTextTranslator()
translatorHelper
(
seclevel_strings
,
seclevels
);
translatorHelper
(
seclevel_strings
,
seclevels
);
// MYSQL types.
// MYSQL types.
const
std
::
vector
<
std
::
string
>
mysql_type_strings
const
std
::
vector
<
std
::
string
>
mysql_type_strings
{
{
"MYSQL_TYPE_DECIMAL"
,
"MYSQL_TYPE_TINY"
,
"MYSQL_TYPE_SHORT"
,
"MYSQL_TYPE_DECIMAL"
,
"MYSQL_TYPE_TINY"
,
"MYSQL_TYPE_SHORT"
,
"MYSQL_TYPE_LONG"
,
"MYSQL_TYPE_FLOAT"
,
"MYSQL_TYPE_DOUBLE"
,
"MYSQL_TYPE_LONG"
,
"MYSQL_TYPE_FLOAT"
,
"MYSQL_TYPE_DOUBLE"
,
"MYSQL_TYPE_NULL"
,
"MYSQL_TYPE_TIMESTAMP"
,
"MYSQL_TYPE_LONGLONG"
,
"MYSQL_TYPE_NULL"
,
"MYSQL_TYPE_TIMESTAMP"
,
"MYSQL_TYPE_LONGLONG"
,
...
@@ -681,8 +676,7 @@ buildTypeTextTranslator()
...
@@ -681,8 +676,7 @@ buildTypeTextTranslator()
"MYSQL_TYPE_VAR_STRING"
,
"MYSQL_TYPE_STRING"
,
"MYSQL_TYPE_VAR_STRING"
,
"MYSQL_TYPE_STRING"
,
"MYSQL_TYPE_GEOMETRY"
"MYSQL_TYPE_GEOMETRY"
};
};
const
std
::
vector
<
enum
enum_field_types
>
mysql_types
const
std
::
vector
<
enum
enum_field_types
>
mysql_types
{
{
MYSQL_TYPE_DECIMAL
,
MYSQL_TYPE_TINY
,
MYSQL_TYPE_SHORT
,
MYSQL_TYPE_DECIMAL
,
MYSQL_TYPE_TINY
,
MYSQL_TYPE_SHORT
,
MYSQL_TYPE_LONG
,
MYSQL_TYPE_FLOAT
,
MYSQL_TYPE_DOUBLE
,
MYSQL_TYPE_LONG
,
MYSQL_TYPE_FLOAT
,
MYSQL_TYPE_DOUBLE
,
MYSQL_TYPE_NULL
,
MYSQL_TYPE_TIMESTAMP
,
MYSQL_TYPE_LONGLONG
,
MYSQL_TYPE_NULL
,
MYSQL_TYPE_TIMESTAMP
,
MYSQL_TYPE_LONGLONG
,
...
@@ -701,8 +695,7 @@ buildTypeTextTranslator()
...
@@ -701,8 +695,7 @@ buildTypeTextTranslator()
translatorHelper
(
mysql_type_strings
,
mysql_types
);
translatorHelper
(
mysql_type_strings
,
mysql_types
);
// MYSQL item types.
// MYSQL item types.
const
std
::
vector
<
std
::
string
>
mysql_item_strings
const
std
::
vector
<
std
::
string
>
mysql_item_strings
{
{
"FIELD_ITEM"
,
"FUNC_ITEM"
,
"SUM_FUNC_ITEM"
,
"STRING_ITEM"
,
"FIELD_ITEM"
,
"FUNC_ITEM"
,
"SUM_FUNC_ITEM"
,
"STRING_ITEM"
,
"INT_ITEM"
,
"REAL_ITEM"
,
"NULL_ITEM"
,
"VARBIN_ITEM"
,
"INT_ITEM"
,
"REAL_ITEM"
,
"NULL_ITEM"
,
"VARBIN_ITEM"
,
"COPY_STR_ITEM"
,
"FIELD_AVG_ITEM"
,
"DEFAULT_VALUE_ITEM"
,
"COPY_STR_ITEM"
,
"FIELD_AVG_ITEM"
,
"DEFAULT_VALUE_ITEM"
,
...
@@ -712,8 +705,7 @@ buildTypeTextTranslator()
...
@@ -712,8 +705,7 @@ buildTypeTextTranslator()
"PARAM_ITEM"
,
"TRIGGER_FIELD_ITEM"
,
"DECIMAL_ITEM"
,
"PARAM_ITEM"
,
"TRIGGER_FIELD_ITEM"
,
"DECIMAL_ITEM"
,
"XPATH_NODESET"
,
"XPATH_NODESET_CMP"
,
"VIEW_FIXER_ITEM"
"XPATH_NODESET"
,
"XPATH_NODESET_CMP"
,
"VIEW_FIXER_ITEM"
};
};
const
std
::
vector
<
enum
Item
::
Type
>
mysql_item_types
const
std
::
vector
<
enum
Item
::
Type
>
mysql_item_types
{
{
Item
::
Type
::
FIELD_ITEM
,
Item
::
Type
::
FUNC_ITEM
,
Item
::
Type
::
FIELD_ITEM
,
Item
::
Type
::
FUNC_ITEM
,
Item
::
Type
::
SUM_FUNC_ITEM
,
Item
::
Type
::
STRING_ITEM
,
Item
::
Type
::
SUM_FUNC_ITEM
,
Item
::
Type
::
STRING_ITEM
,
Item
::
Type
::
INT_ITEM
,
Item
::
Type
::
REAL_ITEM
,
Item
::
Type
::
INT_ITEM
,
Item
::
Type
::
REAL_ITEM
,
...
@@ -734,13 +726,11 @@ buildTypeTextTranslator()
...
@@ -734,13 +726,11 @@ buildTypeTextTranslator()
translatorHelper
(
mysql_item_strings
,
mysql_item_types
);
translatorHelper
(
mysql_item_strings
,
mysql_item_types
);
// ALTER TABLE [table] DISABLE/ENABLE KEYS
// ALTER TABLE [table] DISABLE/ENABLE KEYS
const
std
::
vector
<
std
::
string
>
disable_enable_keys_strings
const
std
::
vector
<
std
::
string
>
disable_enable_keys_strings
{
{
"DISABLE"
,
"ENABLE"
,
"LEAVE_AS_IS"
"DISABLE"
,
"ENABLE"
,
"LEAVE_AS_IS"
};
};
const
std
::
vector
<
enum
enum_enable_or_disable
>
const
std
::
vector
<
enum
enum_enable_or_disable
>
disable_enable_keys_types
disable_enable_keys_types
{
{
DISABLE
,
ENABLE
,
LEAVE_AS_IS
DISABLE
,
ENABLE
,
LEAVE_AS_IS
};
};
RETURN_FALSE_IF_FALSE
(
disable_enable_keys_strings
.
size
()
==
RETURN_FALSE_IF_FALSE
(
disable_enable_keys_strings
.
size
()
==
...
@@ -749,15 +739,12 @@ buildTypeTextTranslator()
...
@@ -749,15 +739,12 @@ buildTypeTextTranslator()
disable_enable_keys_types
);
disable_enable_keys_types
);
// Onion Layouts.
// Onion Layouts.
const
std
::
vector
<
std
::
string
>
onion_layout_strings
const
std
::
vector
<
std
::
string
>
onion_layout_strings
{
{
"PLAIN_ONION_LAYOUT"
,
"NUM_ONION_LAYOUT"
,
"PLAIN_ONION_LAYOUT"
,
"NUM_ONION_LAYOUT"
,
"BEST_EFFORT_NUM_ONION_LAYOUT"
,
"STR_ONION_LAYOUT"
,
"BEST_EFFORT_NUM_ONION_LAYOUT"
,
"STR_ONION_LAYOUT"
,
"BEST_EFFORT_STR_ONION_LAYOUT"
"BEST_EFFORT_STR_ONION_LAYOUT"
};
};
const
std
::
vector
<
onionlayout
>
onion_layouts
const
std
::
vector
<
onionlayout
>
onion_layouts
{
{
PLAIN_ONION_LAYOUT
,
NUM_ONION_LAYOUT
,
PLAIN_ONION_LAYOUT
,
NUM_ONION_LAYOUT
,
BEST_EFFORT_NUM_ONION_LAYOUT
,
STR_ONION_LAYOUT
,
BEST_EFFORT_NUM_ONION_LAYOUT
,
STR_ONION_LAYOUT
,
BEST_EFFORT_STR_ONION_LAYOUT
BEST_EFFORT_STR_ONION_LAYOUT
...
@@ -767,14 +754,12 @@ buildTypeTextTranslator()
...
@@ -767,14 +754,12 @@ buildTypeTextTranslator()
translatorHelper
(
onion_layout_strings
,
onion_layouts
);
translatorHelper
(
onion_layout_strings
,
onion_layouts
);
// Geometry type.
// Geometry type.
const
std
::
vector
<
std
::
string
>
geometry_type_strings
const
std
::
vector
<
std
::
string
>
geometry_type_strings
{
{
"GEOM_GEOMETRY"
,
"GEOM_POINT"
,
"GEOM_LINESTRING"
,
"GEOM_POLYGON"
,
"GEOM_GEOMETRY"
,
"GEOM_POINT"
,
"GEOM_LINESTRING"
,
"GEOM_POLYGON"
,
"GEOM_MULTIPOINT"
,
"GEOM_MULTILINESTRING"
,
"GEOM_MULTIPOLYGON"
,
"GEOM_MULTIPOINT"
,
"GEOM_MULTILINESTRING"
,
"GEOM_MULTIPOLYGON"
,
"GEOM_GEOMETRYCOLLECTION"
"GEOM_GEOMETRYCOLLECTION"
};
};
std
::
vector
<
Field
::
geometry_type
>
geometry_types
std
::
vector
<
Field
::
geometry_type
>
geometry_types
{
{
Field
::
GEOM_GEOMETRY
,
Field
::
GEOM_POINT
,
Field
::
GEOM_LINESTRING
,
Field
::
GEOM_GEOMETRY
,
Field
::
GEOM_POINT
,
Field
::
GEOM_LINESTRING
,
Field
::
GEOM_POLYGON
,
Field
::
GEOM_MULTIPOINT
,
Field
::
GEOM_POLYGON
,
Field
::
GEOM_MULTIPOINT
,
Field
::
GEOM_MULTILINESTRING
,
Field
::
GEOM_MULTIPOLYGON
,
Field
::
GEOM_MULTILINESTRING
,
Field
::
GEOM_MULTIPOLYGON
,
...
@@ -785,12 +770,10 @@ buildTypeTextTranslator()
...
@@ -785,12 +770,10 @@ buildTypeTextTranslator()
translatorHelper
(
geometry_type_strings
,
geometry_types
);
translatorHelper
(
geometry_type_strings
,
geometry_types
);
// Security Rating.
// Security Rating.
const
std
::
vector
<
std
::
string
>
security_rating_strings
const
std
::
vector
<
std
::
string
>
security_rating_strings
{
{
"SENSITIVE"
,
"BEST_EFFORT"
,
"PLAIN"
"SENSITIVE"
,
"BEST_EFFORT"
,
"PLAIN"
};
};
const
std
::
vector
<
SECURITY_RATING
>
security_rating_types
const
std
::
vector
<
SECURITY_RATING
>
security_rating_types
{
{
SECURITY_RATING
::
SENSITIVE
,
SECURITY_RATING
::
BEST_EFFORT
,
SECURITY_RATING
::
SENSITIVE
,
SECURITY_RATING
::
BEST_EFFORT
,
SECURITY_RATING
::
PLAIN
SECURITY_RATING
::
PLAIN
};
};
...
@@ -818,10 +801,8 @@ buildTypeTextTranslator()
...
@@ -818,10 +801,8 @@ buildTypeTextTranslator()
// buildTypeTextTranslator, handle it as a static constant in
// buildTypeTextTranslator, handle it as a static constant in
// Rewriter and panic when it fails.
// Rewriter and panic when it fails.
static
bool
static
bool
buildTypeTextTranslatorHack
()
buildTypeTextTranslatorHack
(){
{
assert
(
buildTypeTextTranslator
());
assert
(
buildTypeTextTranslator
());
return
true
;
return
true
;
}
}
...
...
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