Commit 06de26b6 authored by yiwenshao's avatar yiwenshao

add test_main/dml_handler_select.cc

parent 8a676116
...@@ -403,29 +403,28 @@ class MultiDeleteHandler : public DMLHandler { ...@@ -403,29 +403,28 @@ class MultiDeleteHandler : public DMLHandler {
} }
}; };
class SelectHandler : public DMLHandler { void
virtual void gather(Analysis &a, LEX *const lex) SelectHandler::gather(Analysis &a, LEX *const lex)
const{ const{
/*process the select field, that is the xxx in select xxx. also setup rewriteplain for fileds /*process the select field, that is the xxx in select xxx. also setup rewriteplain for fileds
like having. the rewriteplain are encset, which is used in decryption*/ like having. the rewriteplain are encset, which is used in decryption*/
process_select_lex(lex->select_lex, a); process_select_lex(lex->select_lex, a);
} }
virtual AbstractQueryExecutor * AbstractQueryExecutor *
rewrite(Analysis &a, LEX *lex) SelectHandler::rewrite(Analysis &a, LEX *lex)
const{ const{
LEX *const new_lex = copyWithTHD(lex); LEX *const new_lex = copyWithTHD(lex);
//table list rewrite //table list rewrite
new_lex->select_lex.top_join_list = new_lex->select_lex.top_join_list =
rewrite_table_list(lex->select_lex.top_join_list, a); rewrite_table_list(lex->select_lex.top_join_list, a);
SELECT_LEX *const select_lex_res = rewrite_select_lex(new_lex->select_lex, a); SELECT_LEX *const select_lex_res = rewrite_select_lex(new_lex->select_lex, a);
set_select_lex(new_lex,select_lex_res); set_select_lex(new_lex,select_lex_res);
return new DMLQueryExecutor(*new_lex, a.rmeta); return new DMLQueryExecutor(*new_lex, a.rmeta);
} }
};
AbstractQueryExecutor *DMLHandler:: AbstractQueryExecutor *DMLHandler::
transformLex(Analysis &analysis, LEX *lex) const { transformLex(Analysis &analysis, LEX *lex) const {
......
...@@ -142,6 +142,10 @@ class InsertHandler : public DMLHandler { ...@@ -142,6 +142,10 @@ class InsertHandler : public DMLHandler {
}; };
class SelectHandler : public DMLHandler {
virtual void gather(Analysis &a, LEX *const lex)const;
virtual AbstractQueryExecutor *rewrite(Analysis &a, LEX *const lex)const;
};
SQLDispatcher *buildDMLDispatcher(); SQLDispatcher *buildDMLDispatcher();
......
#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 testSelectHandler(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 SelectHandler();
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 = "SELECT * FROM student";
std::vector<std::string> querys{query1};
for(auto item:querys){
std::cout<<item<<std::endl;
testSelectHandler(item);
std::cout<<std::endl;
}
return 0;
}
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