Commit 30a7d726 authored by casualet's avatar casualet

update

parent 019674ff
OBJDIRS += showHelper
##note that xx=*.cc will not expand. wildcard *.cc will include files from other directories.
SHOWHELPER_OBJS := $(patsubst %.cc,$(OBJDIR)/%.o,$(wildcard showHelper/*.cc))
all: $(SHOWHELPER_OBJS) $(OBJDIR)/libshowhelper.so
$(OBJDIR)/libshowhelper.so: $(SHOWHELPER_OBJS) \
$(OBJDIR)/libedbparser.so
$(CXX) -shared -g -o $@ $(SHOWHELPER_OBJS) $(LDFLAGS) $(LDRPATH) -L/$(MYBUILD)/libmysqld -lmysqld -laio -lz -ldl -lm -lcrypt -lpthread -ledbcrypto -ledbutil -ledbparser
# vim: set noexpandtab:
#include"showHelper/show_AltersubHandler.hh"
#include"showHelper/show_Dispatcher.hh"
#include"showHelper/show_utilities.hh"
void showAlterSubHandler::showAll(const LEX *lex){
stepOne(lex);
}
void showAddIndexSubHandler::stepOne(const LEX *lex){
std::cout<<"add index show"<<std::endl;
show::showKeyList(lex);
}
void showForeignKeySubHandler::stepOne(const LEX *lex){
std::cout<<"add foreign key"<<std::endl;
show::showKeyList(lex);
}
#pragma once
#include"showHelper/show_SQLHandler.hh"
class showAddIndexSubHandler:public showAlterSubHandler{
public:
showAddIndexSubHandler(){}
virtual ~showAddIndexSubHandler(){}
private:
virtual void stepOne(const LEX *lex);
};
class showForeignKeySubHandler:public showAlterSubHandler{
public:
showForeignKeySubHandler(){}
virtual ~showForeignKeySubHandler(){}
private:
virtual void stepOne(const LEX *lex);
};
#include<iostream>
#include"showHelper/show_DDLHandler.hh"
#include"showHelper/show_Dispatcher.hh"
#include"showHelper/show_utilities.hh"
using std::cout;
using std::endl;
// #### DDLHandler
void showDDLHandler::showAll(const LEX *lex){
stepOne(lex);
}
// #### CreateTableHandler
// show essential things of create table.
void showCreateTableHandler::stepOne(const LEX *lex){
std::cout<<"TYPE CREATE_TABLE:"<<std::endl;
assert(lex!=NULL);
assert(lex->select_lex.table_list.first);
if(lex->select_lex.table_list.first){
show::showTableList(const_cast<LEX*>(lex));
show::showKeyList(const_cast<LEX*>(lex));
show::showCreateFiled(const_cast<LEX*>(lex));
}
}
//## showAlterTableHandler
void showAlterTableHandler::stepOne(const LEX *lex){
if(alterdis->canDo(lex)){
const std::vector<showAlterSubHandler*> handlers = alterdis->dispatch(lex);
assert(handlers.size()>0);
for(auto it:handlers){
it->showAll(lex);
}
}else{
std::cout<<"unable to recognize the query"<<endl;
}
}
#pragma once
#include"showHelper/show_SQLHandler.hh"
#include"showHelper/show_Dispatcher.hh"
class showDDLHandler:public showSQLHandler{
public:
showDDLHandler(){}
virtual void showAll(const LEX *lex);
virtual ~showDDLHandler(){}
private:
virtual void stepOne(const LEX *lex)=0;
};
class showCreateTableHandler:public showDDLHandler{
public:
showCreateTableHandler(){}
virtual ~showCreateTableHandler(){}
private:
virtual void stepOne(const LEX *lex);
};
class showAlterTableHandler:public showDDLHandler{
public:
showAlterTableHandler(){}
virtual ~showAlterTableHandler(){}
private:
virtual void stepOne(const LEX *lex);
};
#include"showHelper/show_Dispatcher.hh"
bool showSQLDispatcher::canDo(LEX *const lex)const{
auto command = extract(lex);
return handlers.find(command)!=handlers.end();
}
long long showSQLDispatcher::extract(LEX *const lex)const{
return lex->sql_command;
}
const std::shared_ptr<showSQLHandler> showSQLDispatcher::dispatch(LEX *const lex) const{
auto it = handlers.find(extract(lex));
assert(it!=handlers.end());
assert(it->second);
return it->second;
}
///showAlterDispatcher
bool showAlterDispatcher::canDo(LEX *const lex)const{
if (0 == lex->alter_info.flags) {
return false;
}
long long flags = lex->alter_info.flags;
for (const auto &it : handlers) {
flags -= lex->alter_info.flags & it.first;
}
return 0 == flags;
}
//get handlers from lex->alter_info.flags
std::vector<showAlterSubHandler *> showAlterDispatcher::dispatch(LEX *const lex) const{
std::vector<showAlterSubHandler*> out;
for (const auto &it : handlers) {
const long long extract = lex->alter_info.flags & it.first;
if (extract) {
auto it_handler = handlers.find(extract);
assert(handlers.end() != it_handler && it_handler->second);
out.push_back(it_handler->second.get());
}
}
return out;
}
/*
able to support
SQLCOM_CREATE_TABLE,
*/
showSQLDispatcher* buildShowDDLDispatcher(){
showDDLHandler *h;
showSQLDispatcher * dispatcher = new showSQLDispatcher;
h = new showCreateTableHandler;
dispatcher->addHandler(SQLCOM_CREATE_TABLE, h);
h = new showAlterTableHandler;
dispatcher->addHandler(SQLCOM_ALTER_TABLE,h);
return dispatcher;
}
showAlterDispatcher* buildShowAlterDispatcher(){
showAlterSubHandler *h;
showAlterDispatcher *dispatcher = new showAlterDispatcher;
h = new showAddIndexSubHandler;
dispatcher->addHandler(ALTER_ADD_INDEX,h);
h = new showForeignKeySubHandler;
dispatcher->addHandler(ALTER_FOREIGN_KEY,h);
return dispatcher;
}
extern const showSQLDispatcher* const ddldis = buildShowDDLDispatcher();
extern const showAlterDispatcher* const alterdis = buildShowAlterDispatcher();
#pragma once
#include"showHelper/show_SQLHandler.hh"
#include"showHelper/show_DDLHandler.hh"
#include"showHelper/show_AltersubHandler.hh"
template <typename FetchMe>
class showDispatcher {
public:
virtual ~showDispatcher() {}
bool addHandler(long long cmd, FetchMe *const h) {
if (NULL == h) {
return false;
}
auto it = handlers.find(cmd);
if (handlers.end() != it) {
return false;
}
handlers[cmd] = std::unique_ptr<FetchMe>(h);
return true;
}
virtual bool canDo(LEX *const lex) const = 0;
protected:
std::map<long long, std::shared_ptr<FetchMe>> handlers;
};
class showSQLDispatcher : public showDispatcher<showSQLHandler> {
public:
showSQLDispatcher(){}
bool canDo(LEX *const lex) const;
const std::shared_ptr<showSQLHandler> dispatch(LEX *const lex) const;
private:
virtual long long extract(LEX *const lex) const;
};
class showAlterDispatcher : public showDispatcher<showAlterSubHandler> {
public:
std::vector<showAlterSubHandler *> dispatch(LEX *const lex) const;
bool canDo(LEX *const lex) const;
};
showSQLDispatcher* buildShowDDLDispatcher();
showAlterDispatcher* buildShowAlterDispatcher();
extern const showSQLDispatcher* const ddldis;
extern const showAlterDispatcher* const alterdis;
#pragma once
#include <util/util.hh>
#include <string>
#include <sql_parse.h>
#include <parser/mysql_type_metadata.hh>
#include <parser/sql_utils.hh>
#include <crypto/BasicCrypto.hh>
#include <assert.h>
#include <sstream>
#include <sys/stat.h>
#include <sys/types.h>
#include <parser/embedmysql.hh>
#include <sql_base.h>
#include <sql_select.h>
#include <sql_delete.h>
#include <sql_insert.h>
#include <sql_update.h>
#include <sql_parse.h>
#include <handler.h>
#include <parser/stringify.hh>
#include <util/errstream.hh>
#include <util/rob.hh>
#include <iostream>
class showSQLHandler{
public:
showSQLHandler(){}
virtual void showAll(const LEX *lex)=0;
virtual ~showSQLHandler(){}
};
class showAlterSubHandler{
public:
showAlterSubHandler(){}
virtual void showAll(const LEX *lex);
virtual ~showAlterSubHandler(){}
private:
virtual void stepOne(const LEX *lex)=0;
};
#include"showHelper/show_entry.hh"
#include"showHelper/show_utilities.hh"
void parseSQL(std::string query){
show::draw(query,show::RED);
std::unique_ptr<query_parse> p = show::getLex(query);
LEX *const lex = p->lex();
if(ddldis->canDo(lex)){
std::cout<<"ddl can do"<<std::endl;
const std::shared_ptr<showSQLHandler> h = ddldis->dispatch(lex);
h->showAll(lex);
}else{
}
}
#pragma once
#include "showHelper/show_DDLHandler.hh"
#include "showHelper/show_AltersubHandler.hh"
#include "showHelper/show_utilities.hh"
#include <string>
void parseSQL(std::string query);
This diff is collapsed.
#pragma once
#include <util/util.hh>
#include <string>
#include <sql_parse.h>
#include <parser/mysql_type_metadata.hh>
#include <parser/sql_utils.hh>
#include <crypto/BasicCrypto.hh>
#include <assert.h>
#include <sstream>
#include <sys/stat.h>
#include <sys/types.h>
#include <parser/embedmysql.hh>
#include <sql_base.h>
#include <sql_select.h>
#include <sql_delete.h>
#include <sql_insert.h>
#include <sql_update.h>
#include <sql_parse.h>
#include <handler.h>
#include <parser/stringify.hh>
#include <util/errstream.hh>
#include <util/rob.hh>
#include <iostream>
using std::string;
namespace show{
const std::string BOLD_BEGIN = "\033[1m";
const std::string RED_BEGIN = "\033[1;31m";
const std::string GREEN_BEGIN = "\033[1;92m";
const std::string COLOR_END = "\033[0m";
enum color{
BLANK,
RED,
GREEN,
BOLD
};
//output char*
void output(char *content, color c = BLANK);
template<class T,class ...arg>
void output(T t,arg... rest){
if(t==NULL) {
std::cout<<"NULL"<<"\t";
}else{
std::cout<<std::string(t)<<"\t";
}
output(rest...);
}
//output std::string
void draw(std::string,color c = BLANK);
template<class T,class ...arg>
void draw(T t,arg... rest){
if(t.size()==0){
std::cout<<"0string\t";
}else{
std::cout<<t<<"\t";
}
draw(rest...);
}
namespace keytrans{
extern std::map<int,std::string> trans;
}
namespace commandtrans{
extern std::map<int,std::string> trans;
}
namespace altertrans{
extern std::map<long long,std::string> trans;
}
namespace itemtypetrans{
extern std::map<int,std::string> trans;
}
namespace datatypetrans{
extern std::map<int,string> trans;
}
namespace fieldflagtrans{
extern std::map<int,string> trans;
}
}
namespace show{
std::string
empty_if_null(const char *const p);
std::unique_ptr<query_parse> getLex(std::string origQuery);
//const LEX* const lex will not pass,that's why she used RiboldMYSQL::constList_iterator in parser/lex_util.hh
void showKeyList(LEX *lex);
void showCreateFiled(LEX* lex);
void showTableList(LEX *lex);
}
namespace rewrite{
string
lexToQuery(const LEX &lex);
}
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