├── screenshot ├── druidpp-2014-1.jpg ├── druidpp-2014-2.jpg └── druidpp-2014-3.jpg ├── deps ├── smhasher │ ├── DifferentialTest.cpp │ ├── Random.cpp │ ├── SpeedTest.h │ ├── CityTest.cpp │ ├── SpookyTest.cpp │ ├── sha1.h │ ├── CMakeLists.txt │ ├── Platform.cpp │ ├── MurmurHash1.h │ ├── MurmurHash3.h │ ├── AvalancheTest.cpp │ ├── MurmurHash2.h │ ├── lookup3.cpp │ ├── SuperFastHash.cpp │ ├── PMurHash.h │ ├── Stats.cpp │ └── Platform.h └── xxhash │ └── Makefile ├── ast ├── Object.cpp ├── SQLSetQuantifier.cpp ├── SQLPartitioningClause.h ├── SQLHint.h ├── expr │ ├── SQLLiteralExpr.h │ ├── SQLAllColumnExpr.cpp │ ├── SQLNullExpr.cpp │ ├── SQLDefaultExpr.cpp │ ├── SQLCharExpr.h │ ├── SQLAllColumnExpr.h │ ├── SQLNCharExpr.h │ ├── SQLListExpr.h │ ├── SQLDefaultExpr.h │ ├── SQLTextLiteralExpr.h │ ├── SQLNullExpr.h │ ├── SQLUnaryOperator.h │ ├── SQLUnaryOperator.cpp │ ├── SQLNCharExpr.cpp │ ├── SQLNumericLiteralExpr.h │ ├── SQLAnyExpr.h │ ├── SQLCharExpr.cpp │ ├── SQLAllExpr.h │ ├── SQLNotExpr.h │ ├── SQLIntegerExpr.h │ ├── SQLNumberExpr.h │ ├── SQLSomeExpr.h │ ├── SQLCastExpr.h │ ├── SQLHexExpr.h │ ├── SQLQueryExpr.h │ ├── SQLCurrentOfCursorExpr.h │ ├── SQLUnaryExpr.h │ ├── SQLExistsExpr.h │ ├── SQLIdentifierExpr.h │ ├── SQLPropertyExpr.h │ ├── SQLCaseExpr_Item.h │ ├── SQLInListExpr.h │ ├── SQLVariantRefExpr.h │ ├── SQLTextLiteralExpr.cpp │ ├── SQLInSubQueryExpr.h │ ├── SQLListExpr.cpp │ ├── SQLBinaryOpExpr.h │ ├── SQLBetweenExpr.h │ ├── SQLMethodInvokeExpr.h │ ├── SQLCaseExpr.h │ ├── SQLNotExpr.cpp │ ├── SQLCaseExpr_Item.cpp │ ├── SQLAggregateExpr.h │ ├── SQLSomeExpr.cpp │ ├── SQLAllExpr.cpp │ ├── SQLAnyExpr.cpp │ ├── SQLQueryExpr.cpp │ ├── SQLNumberExpr.cpp │ ├── SQLHexExpr.cpp │ ├── SQLCurrentOfCursorExpr.cpp │ ├── SQLIntegerExpr.cpp │ ├── SQLCastExpr.cpp │ ├── SQLUnaryExpr.cpp │ ├── SQLExistsExpr.cpp │ ├── SQLVariantRefExpr.cpp │ ├── SQLPropertyExpr.cpp │ ├── SQLIdentifierExpr.cpp │ ├── SQLAggregateExpr.cpp │ ├── SQLCaseExpr.cpp │ └── SQLInSubQueryExpr.cpp ├── SQLStatement.h ├── SQLExpr.h ├── SQLName.h ├── SQLSetQuantifier.h ├── SQLOrderingSpecification.cpp ├── SQLASTVisitor.h ├── SQLDataType.h ├── SQLExprImpl.h ├── SQLCommentHint.cpp ├── SQLOrderingSpecification.h ├── SQLStatementImpl.cpp ├── Object.h ├── SQLStatementImpl.h ├── SQLOver.h ├── SQLCommentHint.h ├── SQLDataTypeImpl.h ├── complex.cpp ├── SQLObjectImpl.h ├── SQLObject.h ├── SQLOver.cpp └── SQLOrderBy.h ├── parser ├── SQLParser_test.cpp ├── SQLParserUtils.h ├── LayoutCharacters.cpp ├── test.cpp ├── Token_test.cpp ├── EOFParserException.cpp ├── IllegalStateException.cpp ├── NumberFormatException.cpp ├── IllegalArgumentException.cpp ├── NotAllowCommentException.cpp ├── ParserException.cpp ├── ParserException.h ├── UnsupportedOperationException.cpp ├── CharTypes_test.cpp ├── EOFParserException.h ├── IllegalStateException.h ├── NumberFormatException.h ├── IllegalArgumentException.h ├── NotAllowCommentException.h ├── SQLDDLParser.h ├── UnsupportedOperationException.h ├── OdpsSelectParser.h ├── OdpsUDTFSQLSelectItem.h ├── SQLDDLParser.cpp ├── LayoutCharacters.h ├── SQLCreateTableParser.h ├── CharTypes.h ├── SQLParser.h ├── OdpsUDTFSQLSelectItem.cpp ├── Keywords_test.cpp ├── CommentTest.cpp ├── OdpsSelectParser.cpp ├── SQLExprParser_test.cpp ├── SQLParserUtils.cpp └── SQLSelectParser.h ├── visitor ├── functions │ ├── Nil.cpp │ ├── Now.cpp │ ├── Function.h │ ├── Concat.h │ ├── Elt.h │ ├── Bin.h │ ├── BitLength.h │ ├── Char.h │ ├── Hex.h │ ├── If.h │ ├── Nil.h │ ├── Greatest.h │ ├── Left.h │ ├── Lpad.h │ ├── Now.h │ ├── Lcase.h │ ├── Least.h │ ├── Ltrim.h │ ├── Trim.h │ ├── Instr.h │ ├── Length.h │ ├── Locate.h │ ├── Ucase.h │ ├── Right.h │ ├── Insert.h │ ├── Reverse.h │ ├── Isnull.h │ ├── Substring.h │ ├── Unhex.h │ ├── Concat.cpp │ ├── Least.cpp │ ├── Ascii.h │ ├── Greatest.cpp │ ├── Trim.cpp │ ├── Isnull.cpp │ ├── Length.cpp │ ├── Ucase.cpp │ ├── Lcase.cpp │ ├── BitLength.cpp │ ├── Bin.cpp │ ├── Reverse.cpp │ ├── If.cpp │ ├── OneParamFunctions.h │ ├── Instr.cpp │ ├── Elt.cpp │ ├── Ltrim.cpp │ ├── Char.cpp │ ├── Hex.cpp │ ├── Left.cpp │ ├── Right.cpp │ ├── Ascii.cpp │ ├── Lpad.cpp │ ├── Locate.cpp │ ├── Unhex.cpp │ ├── Substring.cpp │ └── Insert.cpp ├── ParameterizedVisitor.h ├── ExportParameterVisitor.h ├── PrintableVisitor.h ├── SQLEvalVisitor.cpp ├── SQLASTOutputVisitorUtils.h ├── SQLASTOutputVisitorUtils.cpp ├── SQLEvalVisitor.h ├── ExportParameterVisitorUtils_2014_05_05.h ├── ParameterizedOutputVisitor.h ├── ExportParameterVisitorUtils.h ├── Makefile ├── x.cpp ├── ParameterizedOutputVisitor.cpp └── SQLEvalVisitorImpl.h └── issues.txt /screenshot/druidpp-2014-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tzws/druidpp/HEAD/screenshot/druidpp-2014-1.jpg -------------------------------------------------------------------------------- /screenshot/druidpp-2014-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tzws/druidpp/HEAD/screenshot/druidpp-2014-2.jpg -------------------------------------------------------------------------------- /screenshot/druidpp-2014-3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tzws/druidpp/HEAD/screenshot/druidpp-2014-3.jpg -------------------------------------------------------------------------------- /deps/smhasher/DifferentialTest.cpp: -------------------------------------------------------------------------------- 1 | #include "DifferentialTest.h" 2 | 3 | //---------------------------------------------------------------------------- 4 | -------------------------------------------------------------------------------- /ast/Object.cpp: -------------------------------------------------------------------------------- 1 | 2 | //std::string Object::x = "in Object class"; 3 | 4 | std::string toString() 5 | { 6 | std::string x = "in Object class"; 7 | return x; 8 | } 9 | 10 | 11 | -------------------------------------------------------------------------------- /parser/SQLParser_test.cpp: -------------------------------------------------------------------------------- 1 | // g++ x.cpp -std=c++11 2 | #include 3 | #include 4 | #include "Lexer.h" 5 | #include "SQLParser.h" 6 | 7 | 8 | int main () 9 | { 10 | return 0; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /deps/smhasher/Random.cpp: -------------------------------------------------------------------------------- 1 | #include "Random.h" 2 | 3 | Rand g_rand1(1); 4 | Rand g_rand2(2); 5 | Rand g_rand3(3); 6 | Rand g_rand4(4); 7 | 8 | //----------------------------------------------------------------------------- 9 | -------------------------------------------------------------------------------- /visitor/functions/Nil.cpp: -------------------------------------------------------------------------------- 1 | #include "Nil.h" 2 | Nil::~Nil() 3 | { 4 | 5 | } 6 | 7 | Nil * Nil::instance() 8 | { 9 | static Nil x; 10 | return &x; 11 | } 12 | 13 | Object *Nil::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 14 | return NULL; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /visitor/functions/Now.cpp: -------------------------------------------------------------------------------- 1 | #include "Now.h" 2 | Now::~Now() 3 | { 4 | 5 | } 6 | 7 | Now * Now::instance() 8 | { 9 | static Now x; 10 | return &x; 11 | } 12 | 13 | Object *Now::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 14 | return new Date(); 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /ast/SQLSetQuantifier.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLSetQuantifier.h" 2 | 3 | // SQL 92 4 | int SQLSetQuantifier::ALL = 1; 5 | int SQLSetQuantifier::DISTINCT = 2; 6 | 7 | int SQLSetQuantifier::UNIQUE = 3; 8 | int SQLSetQuantifier::DISTINCTROW = 4; 9 | 10 | // 11 | 12 | -------------------------------------------------------------------------------- /parser/SQLParserUtils.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | public class SQLParserUtils { 4 | 5 | public: 6 | static SQLStatementParser createSQLStatementParser(std::string sql, std::string dbType); 7 | 8 | static SQLExprParser createExprParser(std::string sql, std::string dbType); 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /visitor/functions/Function.h: -------------------------------------------------------------------------------- 1 | #ifndef Function_HEADER_H 2 | #define Function_HEADER_H 3 | #include "SQLMethodInvokeExpr.h" 4 | #include "SQLEvalVisitor.h" 5 | 6 | 7 | class Function { 8 | public: 9 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) = 0; 10 | }; 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /parser/LayoutCharacters.cpp: -------------------------------------------------------------------------------- 1 | #include "LayoutCharacters.h" 2 | int LayoutCharacters::TabInc = 8; 3 | char LayoutCharacters::TAB = 0x8; 4 | char LayoutCharacters::LF = 0xA; 5 | char LayoutCharacters::FF = 0xC; 6 | char LayoutCharacters::CR = 0xD; 7 | char LayoutCharacters::EOI = 0x1A; 8 | 9 | 10 | -------------------------------------------------------------------------------- /ast/SQLPartitioningClause.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLPartitioningClause_HEADER_H 2 | #define SQLPartitioningClause_HEADER_H 3 | 4 | #include 5 | 6 | class SQLPartitioningClause : virtual public SQLObject { 7 | 8 | virtual ~SQLPartitioningClause() { 9 | 10 | }; 11 | }; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /ast/SQLHint.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SQLHint_HEADER_H 3 | #define SQLHint_HEADER_H 4 | #include 5 | #include "SQLObject.h" 6 | class SQLHint : virtual public SQLObject { 7 | public: 8 | virtual ~SQLHint() { 9 | 10 | } 11 | 12 | }; 13 | typedef boost::shared_ptr SQLHint_ptr; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /deps/smhasher/SpeedTest.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | void BulkSpeedTest ( pfHash hash, uint32_t seed ); 6 | void TinySpeedTest ( pfHash hash, int hashsize, int keysize, uint32_t seed, bool verbose, double & outCycles ); 7 | 8 | //----------------------------------------------------------------------------- 9 | -------------------------------------------------------------------------------- /visitor/functions/Concat.h: -------------------------------------------------------------------------------- 1 | #ifndef Concat_HEADER_H 2 | #define Concat_HEADER_H 3 | 4 | class Concat : virtual public Function { 5 | 6 | 7 | public: 8 | 9 | static Concat *instance(); 10 | virtual ~Concat(); 11 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 12 | }; 13 | #endif 14 | 15 | -------------------------------------------------------------------------------- /visitor/ParameterizedVisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef ParameterizedVisitor_HEADER_H 2 | #define ParameterizedVisitor_HEADER_H 3 | 4 | class ParameterizedVisitor : virtual public PrintableVisitor { 5 | 6 | public: 7 | 8 | virtual int getReplaceCount() = 0; 9 | 10 | virtual void incrementReplaceCunt() = 0; 11 | 12 | }; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /ast/expr/SQLLiteralExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLLiteralExpr_HEADER_H 2 | #define SQLLiteralExpr_HEADER_H 3 | 4 | #include 5 | #include "../SQLExpr.h" 6 | 7 | class SQLLiteralExpr : virtual public SQLExpr { 8 | 9 | public: 10 | virtual ~SQLLiteralExpr() { 11 | 12 | } 13 | 14 | 15 | }; 16 | #endif 17 | 18 | -------------------------------------------------------------------------------- /ast/SQLStatement.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLStatement_HEADER_H 2 | #define SQLStatement_HEADER_H 3 | 4 | #include 5 | class SQLStatement : virtual public SQLObject { 6 | public: 7 | 8 | virtual ~SQLStatement() { 9 | 10 | }; 11 | }; 12 | typedef boost::shared_ptr SQLStatement_ptr; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /visitor/ExportParameterVisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef ExportParameterVisitor_HEADER_H 2 | #define ExportParameterVisitor_HEADER_H 3 | 4 | #include 5 | 6 | class ExportParameterVisitor : virtual public SQLASTVisitor { 7 | public: 8 | virtual std::list getParameters() = 0; 9 | virtual ~ExportParameterVisitor() { 10 | 11 | } 12 | }; 13 | 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /visitor/PrintableVisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef PrintableVisitor_HEADER_H 2 | #define PrintableVisitor_HEADER_H 3 | 4 | #include 5 | class PrintableVisitor : virtual public SQLASTVisitor { 6 | public: 7 | virtual void print(char value) = 0; 8 | 9 | virtual void print(std::string &text) = 0; 10 | 11 | virtual ~PrintableVisitor() { 12 | 13 | } 14 | }; 15 | #endif 16 | 17 | -------------------------------------------------------------------------------- /ast/SQLExpr.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SQLExpr_HEADER_H 3 | #define SQLExpr_HEADER_H 4 | #include 5 | #include "SQLObject.h" 6 | class SQLExpr : virtual public SQLObject { 7 | public: 8 | //virtual void doNothing () = 0; 9 | 10 | virtual ~SQLExpr() { 11 | 12 | } 13 | }; 14 | typedef boost::shared_ptr SQLExpr_ptr; 15 | 16 | #endif 17 | 18 | -------------------------------------------------------------------------------- /ast/SQLName.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SQLName_HEADER_H 3 | #define SQLName_HEADER_H 4 | #include 5 | #include "SQLExpr.h" 6 | class SQLName : virtual public SQLExpr { 7 | public: 8 | virtual std::string &getSimleName() = 0; 9 | 10 | virtual ~SQLName() { 11 | 12 | } 13 | }; 14 | typedef boost::shared_ptr SQLName_ptr; 15 | 16 | #endif 17 | 18 | -------------------------------------------------------------------------------- /ast/SQLSetQuantifier.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLSetQuantifier_HEADER_H 2 | #define SQLSetQuantifier_HEADER_H 3 | 4 | #include 5 | class SQLSetQuantifier { 6 | 7 | public: 8 | // SQL 92 9 | static int ALL; 10 | static int DISTINCT; 11 | 12 | static int UNIQUE; 13 | static int DISTINCTROW; 14 | 15 | // 16 | }; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /visitor/functions/Elt.h: -------------------------------------------------------------------------------- 1 | #ifndef Elt_HEADER_H 2 | #define Elt_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLExpr.h" 7 | #include "SQLMethodInvokeExpr.h" 8 | 9 | class Elt : virtual Function { 10 | 11 | 12 | public: 13 | static Elt *instance(); 14 | virtual ~Elt(); 15 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 16 | }; 17 | #endif 18 | 19 | -------------------------------------------------------------------------------- /parser/test.cpp: -------------------------------------------------------------------------------- 1 | // g++ x.cpp -std=c++11 2 | #include 3 | #include 4 | #include "Lexer.h" 5 | #include "SQLParser.h" 6 | #include "SQLExprParser.h" 7 | #include "SQLSelectParser.h" 8 | #include "SQLStatementParser.h" 9 | #include "SQLDDLParser.h" 10 | #include "SQLCreateTableParser.h" 11 | #include "OdpsSelectParser.h" 12 | 13 | 14 | int main () 15 | { 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /visitor/SQLEvalVisitor.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLEvalVisitor.h" 2 | std::string SQLEvalVisitor::EVAL_VALUE = "eval.value"; 3 | std::string SQLEvalVisitor::EVAL_EXPR = "eval.expr"; 4 | Object * SQLEvalVisitor::EVAL_ERROR = new Object(); 5 | Object * SQLEvalVisitor::EVAL_VALUE_COUNT = new Object(); 6 | Object * SQLEvalVisitor::EVAL_VALUE_NULL = new Object(); 7 | 8 | SQLEvalVisitor::~SQLEvalVisitor() { 9 | 10 | } 11 | 12 | -------------------------------------------------------------------------------- /visitor/functions/Bin.h: -------------------------------------------------------------------------------- 1 | #ifndef Bin_HEADER_H 2 | #define Bin_HEADER_H 3 | 4 | #include "SQLEvalVisitor.h" 5 | #include "SQLExpr.h" 6 | #include "SQLMethodInvokeExpr.h" 7 | 8 | class Bin : virtual public Function { 9 | 10 | public: 11 | //static Bin instance = new Bin(); 12 | 13 | static Bin *instance(); 14 | virtual ~Bin(); 15 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 16 | }; 17 | #endif 18 | -------------------------------------------------------------------------------- /ast/expr/SQLAllColumnExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLAllColumnExpr.h" 2 | 3 | SQLAllColumnExpr::SQLAllColumnExpr(){ 4 | 5 | } 6 | 7 | SQLAllColumnExpr::~SQLAllColumnExpr(){ 8 | 9 | } 10 | void SQLAllColumnExpr::output(std::string & buf) { 11 | //buf.append("*"); 12 | buf += "*"; 13 | } 14 | 15 | void SQLAllColumnExpr::accept0(SQLASTVisitor *visitor) { 16 | visitor->visit(this); 17 | visitor->endVisit(this); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /deps/smhasher/CityTest.cpp: -------------------------------------------------------------------------------- 1 | #include "City.h" 2 | 3 | void CityHash64_test ( const void * key, int len, uint32_t seed, void * out ) 4 | { 5 | *(uint64*)out = CityHash64WithSeed((const char *)key,len,seed); 6 | } 7 | 8 | void CityHash128_test ( const void * key, int len, uint32_t seed, void * out ) 9 | { 10 | uint128 s(0,0); 11 | 12 | s.first = seed; 13 | 14 | *(uint128*)out = CityHash128WithSeed((const char*)key,len,s); 15 | } 16 | -------------------------------------------------------------------------------- /visitor/functions/BitLength.h: -------------------------------------------------------------------------------- 1 | #ifndef BitLength_HEADER_H 2 | #define BitLength_HEADER_H 3 | 4 | #include "SQLEvalVisitor.h" 5 | #include "SQLExpr.h" 6 | #include "SQLMethodInvokeExpr.h" 7 | 8 | 9 | class BitLength : virtual public Function { 10 | 11 | public: 12 | static BitLength *instance(); 13 | virtual ~BitLength(); 14 | 15 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 16 | }; 17 | #endif 18 | 19 | -------------------------------------------------------------------------------- /visitor/functions/Char.h: -------------------------------------------------------------------------------- 1 | #ifndef Char_HEADER_H 2 | #define Char_HEADER_H 3 | 4 | //import java.math.BigDecimal; 5 | 6 | #include "SQLEvalVisitor.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | 10 | class Char : virtual public Function { 11 | 12 | public: 13 | static Char *instance(); 14 | virtual ~Char(); 15 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 16 | }; 17 | #endif 18 | 19 | -------------------------------------------------------------------------------- /parser/Token_test.cpp: -------------------------------------------------------------------------------- 1 | //http://codereview.stackexchange.com/questions/14309/conversion-between-enum-and-string-in-c-class-header 2 | //http://stackoverflow.com/questions/207976/how-to-easily-map-c-enums-to-strings 3 | #include 4 | #include "Token.h" 5 | 6 | int main() 7 | { 8 | std::cout << " enum SELECT = " << tokenStringList.at(TOKEN_SELECT) << std::endl; 9 | std::string all = "ALL"; 10 | 11 | return 0; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /visitor/functions/Hex.h: -------------------------------------------------------------------------------- 1 | #ifndef Hex_HEADER_H 2 | #define Hex_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLExpr.h" 7 | #include "SQLMethodInvokeExpr.h" 8 | #include "ParserException.h" 9 | #include "HexBin.h" 10 | 11 | 12 | class Hex : virtual public Function { 13 | 14 | 15 | public: 16 | static Hex *instance(); 17 | virtual ~Hex(); 18 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 19 | }; 20 | #endif 21 | 22 | -------------------------------------------------------------------------------- /visitor/functions/If.h: -------------------------------------------------------------------------------- 1 | #ifndef If_HEADER_H 2 | #define If_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | class If : virtual public Function { 12 | 13 | public: 14 | static If *instance(); 15 | virtual ~If(); 16 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 17 | 18 | }; 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /visitor/functions/Nil.h: -------------------------------------------------------------------------------- 1 | #ifndef Nil_HEADER_H 2 | #define Nil_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | class Nil : virtual public Function { 12 | public: 13 | static Nil *instance(); 14 | virtual ~Nil(); 15 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 16 | 17 | }; 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /parser/EOFParserException.cpp: -------------------------------------------------------------------------------- 1 | #include "EOFParserException.h" 2 | EOFParserException::EOFParserException() 3 | throw(): std::exception() 4 | { 5 | } 6 | 7 | EOFParserException::EOFParserException(const std::string& msg) 8 | throw(): std::exception(), m_msg(msg) 9 | { 10 | } 11 | 12 | const char* EOFParserException::what() const throw() 13 | { 14 | return m_msg.c_str(); 15 | } 16 | 17 | EOFParserException::~EOFParserException() throw() 18 | { 19 | } 20 | -------------------------------------------------------------------------------- /visitor/functions/Greatest.h: -------------------------------------------------------------------------------- 1 | #ifndef Greatest_HEADER_H 2 | #define Greatest_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLExpr.h" 7 | #include "SQLMethodInvokeExpr.h" 8 | #include "SQLEvalVisitorUtils.h" 9 | 10 | 11 | class Greatest : virtual public Function { 12 | 13 | 14 | public: 15 | static Greatest *instance(); 16 | virtual ~Greatest(); 17 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 18 | }; 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /visitor/functions/Left.h: -------------------------------------------------------------------------------- 1 | #ifndef Left_HEADER_H 2 | #define Left_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | class Left : virtual public Function { 12 | public: 13 | static Left *instance(); 14 | virtual ~Left(); 15 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 16 | 17 | }; 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /visitor/functions/Lpad.h: -------------------------------------------------------------------------------- 1 | #ifndef Lpad_HEADER_H 2 | #define Lpad_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | class Lpad : virtual public Function { 12 | public: 13 | static Lpad *instance(); 14 | virtual ~Lpad(); 15 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 16 | 17 | }; 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /visitor/functions/Now.h: -------------------------------------------------------------------------------- 1 | #ifndef Now_HEADER_H 2 | #define Now_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | class Now : virtual public Function { 12 | public: 13 | static Now *instance(); 14 | virtual ~Now(); 15 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 16 | 17 | }; 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /visitor/functions/Lcase.h: -------------------------------------------------------------------------------- 1 | #ifndef Lcase_HEADER_H 2 | #define Lcase_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | class Lcase : virtual public Function { 12 | public: 13 | static Lcase *instance(); 14 | virtual ~Lcase(); 15 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 16 | 17 | }; 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /visitor/functions/Least.h: -------------------------------------------------------------------------------- 1 | #ifndef Least_HEADER_H 2 | #define Least_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | class Least : virtual public Function { 12 | public: 13 | static Least *instance(); 14 | virtual ~Least(); 15 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 16 | 17 | }; 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /visitor/functions/Ltrim.h: -------------------------------------------------------------------------------- 1 | #ifndef Ltrim_HEADER_H 2 | #define Ltrim_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | class Ltrim : virtual public Function { 12 | public: 13 | static Ltrim *instance(); 14 | virtual ~Ltrim(); 15 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 16 | 17 | }; 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /visitor/functions/Trim.h: -------------------------------------------------------------------------------- 1 | #ifndef Trim_HEADER_H 2 | #define Trim_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | class Trim : virtual public Function { 12 | public: 13 | static Trim *instance(); 14 | virtual ~Trim(); 15 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 16 | 17 | 18 | }; 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /visitor/functions/Instr.h: -------------------------------------------------------------------------------- 1 | #ifndef Instr_HEADER_H 2 | #define Instr_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | class Instr : virtual public Function { 12 | 13 | public: 14 | static Instr *instance(); 15 | virtual ~Instr(); 16 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 17 | }; 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /visitor/functions/Length.h: -------------------------------------------------------------------------------- 1 | #ifndef Length_HEADER_H 2 | #define Length_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | class Length : virtual public Function { 12 | public: 13 | static Length *instance(); 14 | virtual ~Length(); 15 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 16 | 17 | }; 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /visitor/functions/Locate.h: -------------------------------------------------------------------------------- 1 | #ifndef Locate_HEADER_H 2 | #define Locate_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | class Locate : virtual public Function { 12 | public: 13 | static Locate *instance(); 14 | virtual ~Locate(); 15 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 16 | 17 | }; 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /visitor/functions/Ucase.h: -------------------------------------------------------------------------------- 1 | #ifndef Ucase_HEADER_H 2 | #define Ucase_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | class Ucase : virtual public Function { 12 | public: 13 | static Ucase *instance(); 14 | virtual ~Ucase(); 15 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 16 | 17 | 18 | }; 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /ast/SQLOrderingSpecification.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "SQLOrderingSpecification.h" 3 | 4 | SQLOrderingSpecification SQLOrderingSpecification::ASC = SQLOrderingSpecification(1); 5 | SQLOrderingSpecification SQLOrderingSpecification::DESC = SQLOrderingSpecification(2); 6 | 7 | SQLOrderingSpecification::SQLOrderingSpecification(int x) 8 | { 9 | this->num = x; 10 | } 11 | 12 | 13 | SQLOrderingSpecification::~SQLOrderingSpecification() 14 | { 15 | 16 | } 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /visitor/functions/Right.h: -------------------------------------------------------------------------------- 1 | #ifndef Right_HEADER_H 2 | #define Right_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | class Right : virtual public Function { 12 | public: 13 | static Right *instance(); 14 | virtual ~Right(); 15 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 16 | 17 | 18 | }; 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /visitor/functions/Insert.h: -------------------------------------------------------------------------------- 1 | #ifndef Insert_HEADER_H 2 | #define Insert_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | class Insert : virtual public Function { 12 | 13 | public: 14 | static Insert *instance(); 15 | virtual ~Insert(); 16 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 17 | 18 | }; 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /visitor/functions/Reverse.h: -------------------------------------------------------------------------------- 1 | #ifndef Reverse_HEADER_H 2 | #define Reverse_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | class Reverse : virtual public Function { 12 | public: 13 | static Reverse *instance(); 14 | virtual ~Reverse(); 15 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 16 | 17 | }; 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /visitor/functions/Isnull.h: -------------------------------------------------------------------------------- 1 | #ifndef Isnull_HEADER_H 2 | #define Isnull_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | public class Isnull : virtual public Function { 12 | 13 | public: 14 | static Isnull *instance(); 15 | virtual ~Isnull(); 16 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 17 | 18 | }; 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /parser/IllegalStateException.cpp: -------------------------------------------------------------------------------- 1 | #include "IllegalStateException.h" 2 | IllegalStateException::IllegalStateException() 3 | throw(): std::exception() 4 | { 5 | } 6 | 7 | IllegalStateException::IllegalStateException(const std::string& msg) 8 | throw(): std::exception(), m_msg(msg) 9 | { 10 | } 11 | 12 | const char* IllegalStateException::what() const throw() 13 | { 14 | return m_msg.c_str(); 15 | } 16 | 17 | IllegalStateException::~IllegalStateException() throw() 18 | { 19 | } 20 | -------------------------------------------------------------------------------- /parser/NumberFormatException.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberFormatException.h" 2 | NumberFormatException::NumberFormatException() 3 | throw(): std::exception() 4 | { 5 | } 6 | 7 | NumberFormatException::NumberFormatException(const std::string& msg) 8 | throw(): std::exception(), m_msg(msg) 9 | { 10 | } 11 | 12 | const char* NumberFormatException::what() const throw() 13 | { 14 | return m_msg.c_str(); 15 | } 16 | 17 | NumberFormatException::~NumberFormatException() throw() 18 | { 19 | } 20 | -------------------------------------------------------------------------------- /visitor/functions/Substring.h: -------------------------------------------------------------------------------- 1 | #ifndef Substring_HEADER_H 2 | #define Substring_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | class Substring : virtual public Function { 12 | public: 13 | static Substring *instance(); 14 | virtual ~Substring(); 15 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 16 | 17 | 18 | }; 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /parser/IllegalArgumentException.cpp: -------------------------------------------------------------------------------- 1 | #include "IllegalArgumentException.h" 2 | IllegalArgumentException::IllegalArgumentException() 3 | throw(): std::exception() 4 | { 5 | } 6 | 7 | IllegalArgumentException::IllegalArgumentException(const std::string& msg) 8 | throw(): std::exception(), m_msg(msg) 9 | { 10 | } 11 | 12 | const char* IllegalArgumentException::what() const throw() 13 | { 14 | return m_msg.c_str(); 15 | } 16 | 17 | IllegalArgumentException::~IllegalArgumentException() throw() 18 | { 19 | } 20 | -------------------------------------------------------------------------------- /parser/NotAllowCommentException.cpp: -------------------------------------------------------------------------------- 1 | #include "NotAllowCommentException.h" 2 | NotAllowCommentException::NotAllowCommentException() 3 | throw(): std::exception() 4 | { 5 | } 6 | 7 | NotAllowCommentException::NotAllowCommentException(const std::string& msg) 8 | throw(): std::exception(), m_msg(msg) 9 | { 10 | } 11 | 12 | const char* NotAllowCommentException::what() const throw() 13 | { 14 | return m_msg.c_str(); 15 | } 16 | 17 | NotAllowCommentException::~NotAllowCommentException() throw() 18 | { 19 | } 20 | -------------------------------------------------------------------------------- /parser/ParserException.cpp: -------------------------------------------------------------------------------- 1 | #include "ParserException.h" 2 | #include 3 | #include 4 | ParserException::ParserException() 5 | throw(): std::exception() 6 | { 7 | } 8 | 9 | ParserException::ParserException(const std::string& msg) 10 | throw(): std::exception(), m_msg(msg) 11 | { 12 | } 13 | 14 | const char* ParserException::what() const throw() 15 | { 16 | return m_msg.c_str(); 17 | } 18 | 19 | ParserException::~ParserException() throw() 20 | { 21 | fprintf(stderr, "%s\n", m_msg.c_str()); 22 | } 23 | -------------------------------------------------------------------------------- /ast/expr/SQLNullExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLNullExpr.h" 2 | SQLNullExpr::SQLNullExpr(){ 3 | 4 | } 5 | SQLNullExpr::~SQLNullExpr(){ 6 | 7 | } 8 | 9 | void SQLNullExpr::output(std::string & buf) { 10 | buf += "NULL"; 11 | } 12 | 13 | void SQLNullExpr::accept0(SQLASTVisitor *visitor) { 14 | visitor->visit(this); 15 | 16 | visitor->endVisit(this); 17 | } 18 | 19 | //int SQLNullExpr::hashCode() { 20 | //return 0; 21 | //} 22 | 23 | //bool SQLNullExpr::equals(Object o) { 24 | //return o instanceof SQLNullExpr; 25 | //} 26 | 27 | -------------------------------------------------------------------------------- /parser/ParserException.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #if !defined(PARSER_HEADER_H) 4 | #define PARSER_HEADER_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class ParserException : public std::exception 12 | { 13 | public: 14 | ParserException() throw(); 15 | ParserException(const std::string& msg) throw(); 16 | virtual const char* what() const throw(); 17 | virtual ~ParserException() throw(); 18 | 19 | protected: 20 | 21 | std::string m_msg; 22 | }; 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /parser/UnsupportedOperationException.cpp: -------------------------------------------------------------------------------- 1 | #include "UnsupportedOperationException.h" 2 | UnsupportedOperationException::UnsupportedOperationException() 3 | throw(): std::exception() 4 | { 5 | } 6 | 7 | UnsupportedOperationException::UnsupportedOperationException(const std::string& msg) 8 | throw(): std::exception(), m_msg(msg) 9 | { 10 | } 11 | 12 | const char* UnsupportedOperationException::what() const throw() 13 | { 14 | return m_msg.c_str(); 15 | } 16 | 17 | UnsupportedOperationException::~UnsupportedOperationException() throw() 18 | { 19 | } 20 | -------------------------------------------------------------------------------- /parser/CharTypes_test.cpp: -------------------------------------------------------------------------------- 1 | // g++ x.cpp -std=c++11 2 | #include 3 | #include 4 | #include "CharTypes.h" 5 | 6 | int main () 7 | { 8 | CharTypes c; 9 | std::cout << c.isDigit('9') << std::endl; 10 | std::cout << c.isWhitespace(' ') << std::endl; 11 | std::cout << c.isWhitespace(" ") << std::endl; 12 | std::cout << c.isFirstIdentifierChar(',') << std::endl; 13 | std::cout << c.isIdentifierChar('$') << std::endl; 14 | std::cout << c.isIdentifierChar('z') << std::endl; 15 | std::cout << c.isIdentifierChar(' ') << std::endl; 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /visitor/functions/Unhex.h: -------------------------------------------------------------------------------- 1 | #ifndef Unhex_HEADER_H 2 | #define Unhex_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | //import java.io.UnsupportedEncodingException; 12 | 13 | //import com.alibaba.druid.util.HexBin; 14 | 15 | class Unhex : virtual public Function { 16 | 17 | public: 18 | static Unhex *instance(); 19 | virtual ~Unhex(); 20 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 21 | 22 | }; 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /ast/SQLASTVisitor.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SQLASTVisitor_HEADER_H 3 | #define SQLASTVisitor_HEADER_H 4 | //#include "SQLObject.h" 5 | 6 | #include 7 | class SQLObject; 8 | class SQLASTVisitor { 9 | public: 10 | 11 | bool visit(SQLObject * x) { 12 | 13 | return true; 14 | } 15 | bool endVisit(SQLObject * x) { 16 | 17 | return true; 18 | } 19 | 20 | bool preVisit(SQLObject * x) { 21 | 22 | return true; 23 | } 24 | 25 | 26 | bool postVisit(SQLObject * x) { 27 | 28 | return true; 29 | } 30 | }; 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /deps/smhasher/SpookyTest.cpp: -------------------------------------------------------------------------------- 1 | #include "Spooky.h" 2 | 3 | void SpookyHash32_test(const void *key, int len, uint32_t seed, void *out) { 4 | *(uint32_t*)out = SpookyHash::Hash32(key, len, seed); 5 | } 6 | 7 | void SpookyHash64_test(const void *key, int len, uint32_t seed, void *out) { 8 | *(uint64_t*)out = SpookyHash::Hash64(key, len, seed); 9 | } 10 | 11 | void SpookyHash128_test(const void *key, int len, uint32_t seed, void *out) { 12 | uint64_t h1 = seed, h2 = seed; 13 | SpookyHash::Hash128(key, len, &h1, &h2); 14 | ((uint64_t*)out)[0] = h1; 15 | ((uint64_t*)out)[1] = h2; 16 | } 17 | -------------------------------------------------------------------------------- /ast/SQLDataType.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SQLDataType_HEADER_H 3 | #define SQLDataType_HEADER_H 4 | #include 5 | #include 6 | #include "SQLObject.h" 7 | #include "SQLExpr.h" 8 | 9 | class SQLDataType : virtual public SQLObject { 10 | 11 | public: 12 | 13 | virtual std::string & getName() = 0; 14 | 15 | virtual void setName(std::string &name) = 0; 16 | 17 | virtual std::list &getArguments() = 0; 18 | 19 | virtual ~SQLDataType() { 20 | 21 | } 22 | }; 23 | typedef boost::shared_ptr SQLDataType_ptr; 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /parser/EOFParserException.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #if !defined(EOFParserException_HEADER_H) 4 | #define EOFParserException_HEADER_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class EOFParserException : public std::exception 12 | { 13 | public: 14 | EOFParserException() throw(); 15 | EOFParserException(const std::string& msg) throw(); 16 | virtual const char* what() const throw(); 17 | virtual ~EOFParserException() throw(); 18 | 19 | protected: 20 | 21 | std::string m_msg; 22 | }; 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /visitor/SQLASTOutputVisitorUtils.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLASTOutputVisitorUtils_HEADER_H 2 | #define SQLASTOutputVisitorUtils_HEADER_H 3 | 4 | //import com.alibaba.druid.sql.ast.expr.SQLCharExpr; 5 | //import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr; 6 | //import com.alibaba.druid.sql.ast.expr.SQLNumberExpr; 7 | 8 | class SQLASTOutputVisitorUtils { 9 | 10 | public: 11 | static bool visit(PrintableVisitor visitor, SQLIntegerExpr x); 12 | 13 | static bool visit(PrintableVisitor visitor, SQLNumberExpr x); 14 | 15 | static bool visit(PrintableVisitor visitor, SQLCharExpr x); 16 | }; 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /visitor/functions/Concat.cpp: -------------------------------------------------------------------------------- 1 | #include "Concat.h" 2 | 3 | Concat::~Concat() 4 | { 5 | 6 | } 7 | 8 | Concat * Concat::instance() 9 | { 10 | static Concat x; 11 | return &x; 12 | } 13 | 14 | Object *Concat::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 15 | StringBuilder buf = new StringBuilder(); 16 | 17 | for (SQLExpr item : x.getParameters()) { 18 | item.accept(visitor); 19 | 20 | Object itemValue = item.getAttributes().get(EVAL_VALUE); 21 | if (itemValue == null) { 22 | return null; 23 | } 24 | buf.append(itemValue.toString()); 25 | } 26 | 27 | return buf.toString(); 28 | } 29 | -------------------------------------------------------------------------------- /ast/SQLExprImpl.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SQLExprImpl_HEADER_H 3 | #define SQLExprImpl_HEADER_H 4 | 5 | #include 6 | #include "Object.h" 7 | #include "SQLObject.h" 8 | #include "SQLObjectImpl.h" 9 | #include "SQLExpr.h" 10 | 11 | class SQLExprImpl : virtual public SQLObjectImpl, virtual public SQLExpr { 12 | 13 | public: 14 | SQLExprImpl(){ 15 | 16 | }; 17 | ~SQLExprImpl(){ 18 | 19 | }; 20 | //virtual bool equals(Object *o) = 0; 21 | 22 | //virtual int hashCode() = 0; 23 | }; 24 | typedef boost::shared_ptr SQLExprImpl_ptr; 25 | 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /deps/smhasher/sha1.h: -------------------------------------------------------------------------------- 1 | /* public api for steve reid's public domain SHA-1 implementation */ 2 | /* this file is in the public domain */ 3 | 4 | #pragma once 5 | 6 | #include "Platform.h" 7 | 8 | struct SHA1_CTX 9 | { 10 | uint32_t state[5]; 11 | uint32_t count[2]; 12 | uint8_t buffer[64]; 13 | }; 14 | 15 | #define SHA1_DIGEST_SIZE 20 16 | 17 | void SHA1_Init(SHA1_CTX* context); 18 | void SHA1_Update(SHA1_CTX* context, const uint8_t* data, const size_t len); 19 | void SHA1_Final(SHA1_CTX* context, uint8_t digest[SHA1_DIGEST_SIZE]); 20 | 21 | void sha1_32a ( const void * key, int len, uint32_t seed, void * out ); -------------------------------------------------------------------------------- /ast/SQLCommentHint.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "SQLHint.h" 3 | #include "SQLCommentHint.h" 4 | SQLCommentHint::SQLCommentHint(){ 5 | 6 | } 7 | 8 | SQLCommentHint::~SQLCommentHint(){ 9 | 10 | } 11 | SQLCommentHint::SQLCommentHint(std::string &theText){ 12 | 13 | text = theText; 14 | } 15 | 16 | std::string &SQLCommentHint::getText() { 17 | return text; 18 | } 19 | 20 | void SQLCommentHint::setText(std::string &theText) { 21 | text = theText; 22 | } 23 | 24 | void SQLCommentHint::accept0(SQLASTVisitor *visitor) { 25 | 26 | visitor->visit(this); 27 | visitor->endVisit(this); 28 | 29 | } 30 | 31 | -------------------------------------------------------------------------------- /parser/IllegalStateException.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #if !defined(ILLEGALSTATEXCEPTION_HEADER_H) 4 | #define ILLEGALSTATEXCEPTION_HEADER_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class IllegalStateException : public std::exception 12 | { 13 | public: 14 | IllegalStateException() throw(); 15 | IllegalStateException(const std::string& msg) throw(); 16 | virtual const char* what() const throw(); 17 | virtual ~IllegalStateException() throw(); 18 | 19 | protected: 20 | 21 | std::string m_msg; 22 | }; 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /parser/NumberFormatException.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #if !defined(NumberFormatException_HEADER_H) 4 | #define NumberFormatException_HEADER_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class NumberFormatException : public std::exception 12 | { 13 | public: 14 | NumberFormatException() throw(); 15 | NumberFormatException(const std::string& msg) throw(); 16 | virtual const char* what() const throw(); 17 | virtual ~NumberFormatException() throw(); 18 | 19 | protected: 20 | 21 | std::string m_msg; 22 | }; 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /ast/SQLOrderingSpecification.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLOrderingSpecification_HEADER_H 2 | #define SQLOrderingSpecification_HEADER_H 3 | 4 | #include 5 | class SQLOrderingSpecification { 6 | public: 7 | 8 | static SQLOrderingSpecification ASC; 9 | static SQLOrderingSpecification DESC; 10 | 11 | private: 12 | int num; 13 | SQLOrderingSpecification(int x); 14 | ~SQLOrderingSpecification(); 15 | 16 | }; 17 | typedef boost::shared_ptr SQLOrderingSpecification_ptr; 18 | 19 | 20 | //enum SQLOrderingSpecification { 21 | //ASC, 22 | //DESC 23 | //}; 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /ast/expr/SQLDefaultExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLDefaultExpr.h" 2 | 3 | SQLDefaultExpr::SQLDefaultExpr() { 4 | 5 | } 6 | 7 | SQLDefaultExpr::~SQLDefaultExpr() { 8 | 9 | } 10 | //bool SQLDefaultExpr::equals(Object o) { 11 | //return o instanceof SQLDefaultExpr; 12 | //} 13 | 14 | //int SQLDefaultExpr::hashCode() { 15 | //return 0; 16 | //} 17 | 18 | void SQLDefaultExpr::accept0(SQLASTVisitor *visitor) { 19 | visitor->visit(this); 20 | visitor->endVisit(this); 21 | } 22 | 23 | //std::string &SQLDefaultExpr::toString() { 24 | //std::string *defalt = new std::string( "DEFAULT"); 25 | //return *defalt; 26 | //} 27 | 28 | -------------------------------------------------------------------------------- /visitor/functions/Least.cpp: -------------------------------------------------------------------------------- 1 | #include "Least.h" 2 | Least::~Least() 3 | { 4 | 5 | } 6 | 7 | Least * Least::instance() 8 | { 9 | static Least x; 10 | return &x; 11 | } 12 | 13 | Object *Least::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 14 | Object result = null; 15 | for (SQLExpr item : x.getParameters()) { 16 | item.accept(visitor); 17 | 18 | Object itemValue = item.getAttributes().get(EVAL_VALUE); 19 | if (result == null) { 20 | result = itemValue; 21 | } else { 22 | if (SQLEvalVisitorUtils.lt(itemValue, result)) { 23 | result = itemValue; 24 | } 25 | } 26 | } 27 | 28 | return result; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /ast/SQLStatementImpl.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLStatementImpl.h" 2 | #include 3 | #include 4 | 5 | SQLStatementImpl::SQLStatementImpl(){ 6 | 7 | } 8 | 9 | SQLStatementImpl::~SQLStatementImpl(){ 10 | 11 | } 12 | std::string &SQLStatementImpl::toString() { 13 | 14 | 15 | #if WIN32 16 | std::string x = ""; 17 | return x; 18 | #else 19 | 20 | #endif 21 | } 22 | 23 | void SQLStatementImpl::accept0(SQLASTVisitor *visitor) { 24 | 25 | fprintf(stderr, "UnsupportedOperationException in SQLStatementImpl::accept0\n"); 26 | assert(false); 27 | //throw new UnsupportedOperationException(this.getClass().getName()); 28 | 29 | } 30 | 31 | -------------------------------------------------------------------------------- /parser/IllegalArgumentException.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #if !defined(IllegalArgumentException_HEADER_H) 4 | #define IllegalArgumentException_HEADER_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class IllegalArgumentException : public std::exception 12 | { 13 | public: 14 | IllegalArgumentException() throw(); 15 | IllegalArgumentException(const std::string& msg) throw(); 16 | virtual const char* what() const throw(); 17 | virtual ~IllegalArgumentException() throw(); 18 | 19 | protected: 20 | 21 | std::string m_msg; 22 | }; 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /parser/NotAllowCommentException.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #if !defined(NOTALLOWCOMMENTEXCEPTION_HEADER_H) 4 | #define NOTALLOWCOMMENTEXCEPTION_HEADER_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class NotAllowCommentException : public std::exception 12 | { 13 | public: 14 | NotAllowCommentException() throw(); 15 | NotAllowCommentException(const std::string& msg) throw(); 16 | virtual const char* what() const throw(); 17 | virtual ~NotAllowCommentException() throw(); 18 | 19 | protected: 20 | 21 | 22 | 23 | std::string m_msg; 24 | }; 25 | 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /visitor/SQLASTOutputVisitorUtils.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLASTOutputVisitorUtils.h" 2 | 3 | 4 | bool visit(PrintableVisitor visitor, SQLIntegerExpr x) { 5 | visitor.print(x.getNumber().toString()); 6 | return false; 7 | } 8 | 9 | bool visit(PrintableVisitor visitor, SQLNumberExpr x) { 10 | visitor.print(x.getNumber().toString()); 11 | return false; 12 | } 13 | 14 | bool visit(PrintableVisitor visitor, SQLCharExpr x) { 15 | visitor.print('\''); 16 | 17 | String text = x.getText(); 18 | text = text.replaceAll("'", "''"); 19 | text = text.replaceAll("\\\\", "\\\\"); 20 | 21 | visitor.print(text); 22 | 23 | visitor.print('\''); 24 | return false; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /visitor/functions/Ascii.h: -------------------------------------------------------------------------------- 1 | #ifndef Ascii_HEADER_H 2 | #define Ascii_HEADER_H 3 | 4 | #include "SQLEvalVisitor.h" 5 | #include "SQLExpr.h" 6 | #include "SQLMethodInvokeExpr.h" 7 | 8 | class Ascii : virtual public Function { 9 | 10 | private: 11 | //static bool _init; 12 | //static bool init(); 13 | Ascii(); 14 | Ascii(Ascii const&); // Don't Implement 15 | void operator=(Ascii const&); // Don't implement 16 | public: 17 | 18 | //static Ascii &instance(); 19 | static Ascii *instance(); 20 | //static Ascii *ins; 21 | virtual ~Ascii(); 22 | 23 | Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 24 | }; 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /visitor/functions/Greatest.cpp: -------------------------------------------------------------------------------- 1 | #$include "Greatest.h" 2 | 3 | Greatest::~Greatest() 4 | { 5 | 6 | } 7 | 8 | Greatest * Greatest::instance() 9 | { 10 | static Greatest x; 11 | return &x; 12 | } 13 | 14 | Object *Greatest::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 15 | Object result = null; 16 | for (SQLExpr item : x.getParameters()) { 17 | item.accept(visitor); 18 | 19 | Object itemValue = item.getAttributes().get(EVAL_VALUE); 20 | if (result == null) { 21 | result = itemValue; 22 | } else { 23 | if (SQLEvalVisitorUtils.gt(itemValue, result)) { 24 | result = itemValue; 25 | } 26 | } 27 | } 28 | 29 | return result; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /parser/SQLDDLParser.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLDDLParser_HEADER_H 2 | #define SQLDDLParser_HEADER_H 3 | 4 | #include 5 | #include 6 | #include "../ast/statement/SQLTableConstaint.h" 7 | 8 | #include "SQLParser.h" 9 | #include "SQLExprParser.h" 10 | #include "SQLStatementParser.h" 11 | 12 | class SQLDDLParser : public SQLStatementParser { 13 | 14 | public: 15 | SQLDDLParser(std::string &sql); 16 | ~SQLDDLParser(); 17 | 18 | SQLDDLParser(SQLExprParser *exprParser); 19 | 20 | protected: 21 | SQLTableConstaint *parseConstraint(); 22 | }; 23 | typedef boost::shared_ptr SQLDDLParser_ptr; 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /parser/UnsupportedOperationException.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #if !defined(UnsupportedOperationException_HEADER_H) 4 | #define UnsupportedOperationException_HEADER_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class UnsupportedOperationException : public std::exception 12 | { 13 | public: 14 | UnsupportedOperationException() throw(); 15 | UnsupportedOperationException(const std::string& msg) throw(); 16 | virtual const char* what() const throw(); 17 | virtual ~UnsupportedOperationException() throw(); 18 | 19 | protected: 20 | 21 | std::string m_msg; 22 | }; 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /ast/expr/SQLCharExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLCharExpr_HEADER_H 2 | #define SQLCharExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | #include "../../visitor/SQLASTVisitor.h" 7 | #include "SQLLiteralExpr.h" 8 | #include "SQLTextLiteralExpr.h" 9 | 10 | class SQLCharExpr : virtual public SQLTextLiteralExpr { 11 | typedef SQLTextLiteralExpr super; 12 | public: 13 | SQLCharExpr(); 14 | virtual ~SQLCharExpr(); 15 | 16 | SQLCharExpr(std::string &text); 17 | 18 | void output(std::string &buf); 19 | 20 | protected: 21 | void accept0(SQLASTVisitor *visitor); 22 | }; 23 | typedef boost::shared_ptr SQLCharExpr_ptr; 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /ast/expr/SQLAllColumnExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLAllColumnExpr_HEADER_H 2 | #define SQLAllColumnExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | #include "../SQLExprImpl.h" 7 | #include "../../visitor/SQLASTVisitor.h" 8 | 9 | 10 | 11 | class SQLAllColumnExpr : virtual public SQLExprImpl { 12 | 13 | public: 14 | SQLAllColumnExpr(); 15 | virtual ~SQLAllColumnExpr(); 16 | 17 | void output(std::string & buf); 18 | 19 | //int hashCode(); 20 | //bool equals(Object o); 21 | protected: 22 | void accept0(SQLASTVisitor *visitor); 23 | 24 | }; 25 | typedef boost::shared_ptr SQLAllColumnExpr_ptr; 26 | 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /visitor/functions/Trim.cpp: -------------------------------------------------------------------------------- 1 | #include "Trim.h" 2 | Trim::~Trim() 3 | { 4 | 5 | } 6 | 7 | Trim * Trim::instance() 8 | { 9 | static Trim x; 10 | return &x; 11 | } 12 | 13 | Object *Trim::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 14 | if (x.getParameters().size() != 1) { 15 | return SQLEvalVisitor.EVAL_ERROR; 16 | } 17 | 18 | SQLExpr param0 = x.getParameters().get(0); 19 | param0.accept(visitor); 20 | 21 | Object param0Value = param0.getAttributes().get(EVAL_VALUE); 22 | if (param0Value == null) { 23 | return SQLEvalVisitor.EVAL_ERROR; 24 | } 25 | 26 | std::string strValue = param0Value.toString(); 27 | std::string result = strValue.trim(); 28 | return result; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /ast/Object.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef OBJECT_HEADER_H 3 | #define OBJECT_HEADER_H 4 | #include 5 | #include 6 | class Object { 7 | private: 8 | //static std::string x; 9 | //static std::string x; 10 | public: 11 | 12 | //virtual std::string toString(); 13 | 14 | virtual std::string &toString() 15 | { 16 | #if WIN32 17 | std::string x = ""; 18 | return x; 19 | #else 20 | 21 | #endif 22 | //return x; 23 | } 24 | 25 | virtual std::string & getClass() 26 | { 27 | static std::string className = "Object"; 28 | return className; 29 | } 30 | 31 | //virtual ~Object() = 0; 32 | }; 33 | typedef boost::shared_ptr Object_ptr; 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /ast/expr/SQLNCharExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLNCharExpr_HEADER_H 2 | #define SQLNCharExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | 7 | 8 | #include "../../visitor/SQLASTVisitor.h" 9 | #include "SQLTextLiteralExpr.h" 10 | 11 | 12 | 13 | class SQLNCharExpr : virtual public SQLTextLiteralExpr { 14 | 15 | typedef SQLTextLiteralExpr super; 16 | 17 | public: 18 | SQLNCharExpr(); 19 | virtual ~SQLNCharExpr(); 20 | 21 | SQLNCharExpr(std::string &text); 22 | 23 | void output(std::string & buf); 24 | 25 | protected: 26 | void accept0(SQLASTVisitor *visitor); 27 | }; 28 | typedef boost::shared_ptr SQLNCharExpr_ptr; 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /parser/OdpsSelectParser.h: -------------------------------------------------------------------------------- 1 | #ifndef OdpsSelectParser_HEADER_H 2 | #define OdpsSelectParser_HEADER_H 3 | 4 | #include 5 | #include "../ast/SQLExpr.h" 6 | #include "../ast/expr/SQLIdentifierExpr.h" 7 | #include "../ast/statement/SQLSelectItem.h" 8 | #include "OdpsUDTFSQLSelectItem.h" 9 | #include "SQLExprParser.h" 10 | #include "SQLSelectParser.h" 11 | #include "Token.h" 12 | 13 | class OdpsSelectParser : public SQLSelectParser { 14 | public: 15 | OdpsSelectParser(SQLExprParser *exprParser); 16 | ~OdpsSelectParser(); 17 | 18 | protected: 19 | SQLSelectItem *parseSelectItem(); 20 | }; 21 | typedef boost::shared_ptr OdpsSelectParser_ptr; 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /ast/expr/SQLListExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLListExpr_HEADER_H 2 | #define SQLListExpr_HEADER_H 3 | #include 4 | #include "../SQLExpr.h" 5 | #include "../SQLExprImpl.h" 6 | #include "../../visitor/SQLASTVisitor.h" 7 | 8 | 9 | 10 | class SQLListExpr : virtual public SQLExprImpl { 11 | 12 | private: 13 | std::list items; 14 | 15 | public: 16 | SQLListExpr(); 17 | virtual ~SQLListExpr(); 18 | std::list & getItems(); 19 | 20 | //int hashCode(); 21 | //bool equals(Object obj); 22 | protected: 23 | void accept0(SQLASTVisitor *visitor); 24 | 25 | 26 | }; 27 | typedef boost::shared_ptr SQLListExpr_ptr; 28 | 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /ast/expr/SQLDefaultExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLDefaultExpr_HEADER_H 2 | #define SQLDefaultExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "../SQLExprImpl.h" 8 | #include "../../visitor/SQLASTVisitor.h" 9 | 10 | #include "SQLLiteralExpr.h" 11 | 12 | class SQLDefaultExpr : virtual public SQLExprImpl, virtual public SQLLiteralExpr { 13 | 14 | public: 15 | SQLDefaultExpr(); 16 | virtual ~SQLDefaultExpr(); 17 | //bool equals(Object o); 18 | //int hashCode(); 19 | 20 | //std::string &toString(); 21 | protected: 22 | void accept0(SQLASTVisitor *visitor); 23 | 24 | }; 25 | typedef boost::shared_ptr SQLDefaultExpr_ptr; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /ast/expr/SQLTextLiteralExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLTextLiteralExpr_HEADER_H 2 | #define SQLTextLiteralExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | #include "../SQLExprImpl.h" 7 | #include "SQLLiteralExpr.h" 8 | 9 | 10 | class SQLTextLiteralExpr : virtual public SQLExprImpl, virtual public SQLLiteralExpr { 11 | 12 | protected: 13 | std::string text; 14 | 15 | public: 16 | SQLTextLiteralExpr(); 17 | 18 | SQLTextLiteralExpr(std::string &text); 19 | 20 | std::string &getText(); 21 | 22 | void setText(std::string &text); 23 | 24 | virtual ~SQLTextLiteralExpr(); 25 | 26 | //int hashCode(); 27 | //bool equals(Object obj); 28 | }; 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /visitor/functions/Isnull.cpp: -------------------------------------------------------------------------------- 1 | #include "Isnull.h" 2 | Isnull::~Isnull() 3 | { 4 | 5 | } 6 | 7 | Isnull * Isnull::instance() 8 | { 9 | static Isnull x; 10 | return &x; 11 | } 12 | 13 | Object *Isnull::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 14 | final List parameters = x.getParameters(); 15 | if (parameters.size() == 0) { 16 | return EVAL_ERROR; 17 | } 18 | 19 | SQLExpr condition = parameters.get(0); 20 | condition.accept(visitor); 21 | Object itemValue = condition.getAttributes().get(EVAL_VALUE); 22 | if (itemValue == EVAL_VALUE_NULL) { 23 | return Boolean.TRUE; 24 | } else if (itemValue == null) { 25 | return null; 26 | } else { 27 | return Boolean.FALSE; 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /visitor/functions/Length.cpp: -------------------------------------------------------------------------------- 1 | #include "Length.h" 2 | Length::~Length() 3 | { 4 | 5 | } 6 | 7 | Length * Length::instance() 8 | { 9 | static Length x; 10 | return &x; 11 | } 12 | 13 | Object *Length::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 14 | if (x.getParameters().size() != 1) { 15 | return SQLEvalVisitor.EVAL_ERROR; 16 | } 17 | 18 | SQLExpr param0 = x.getParameters().get(0); 19 | param0.accept(visitor); 20 | 21 | Object param0Value = param0.getAttributes().get(EVAL_VALUE); 22 | if (param0Value == null) { 23 | return SQLEvalVisitor.EVAL_ERROR; 24 | } 25 | 26 | std::string strValue = param0Value.toString(); 27 | 28 | int result = strValue.length(); 29 | return result; 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /visitor/functions/Ucase.cpp: -------------------------------------------------------------------------------- 1 | #include "Ucase.h" 2 | Ucase::~Ucase() 3 | { 4 | 5 | } 6 | 7 | Ucase * Ucase::instance() 8 | { 9 | static Ucase x; 10 | return &x; 11 | } 12 | 13 | Object *Ucase::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 14 | if (x.getParameters().size() != 1) { 15 | return SQLEvalVisitor.EVAL_ERROR; 16 | } 17 | 18 | SQLExpr param0 = x.getParameters().get(0); 19 | param0.accept(visitor); 20 | 21 | Object param0Value = param0.getAttributes().get(EVAL_VALUE); 22 | if (param0Value == null) { 23 | return SQLEvalVisitor.EVAL_ERROR; 24 | } 25 | 26 | std::string strValue = param0Value.toString(); 27 | 28 | std::string result = strValue.toUpperCase(); 29 | return result; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /ast/expr/SQLNullExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLNullExpr_HEADER_H 2 | #define SQLNullExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | #include "../SQLExpr.h" 7 | #include "../SQLExprImpl.h" 8 | #include "../../visitor/SQLASTVisitor.h" 9 | 10 | #include "SQLLiteralExpr.h" 11 | 12 | class SQLNullExpr : virtual public SQLExprImpl, virtual public SQLLiteralExpr { 13 | 14 | public: 15 | SQLNullExpr(); 16 | virtual ~SQLNullExpr(); 17 | 18 | void output(std::string & buf); 19 | 20 | //int hashCode(); 21 | //bool equals(Object o); 22 | protected: 23 | void accept0(SQLASTVisitor *visitor); 24 | 25 | }; 26 | typedef boost::shared_ptr SQLNullExpr_ptr; 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /visitor/functions/Lcase.cpp: -------------------------------------------------------------------------------- 1 | #include "Lcase.h" 2 | Lcase::~Lcase() 3 | { 4 | 5 | } 6 | 7 | Lcase * Lcase::instance() 8 | { 9 | static Lcase x; 10 | return &x; 11 | } 12 | 13 | Object *Lcase::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 14 | if (x.getParameters().size() != 1) { 15 | return SQLEvalVisitor.EVAL_ERROR; 16 | } 17 | 18 | SQLExpr param0 = x.getParameters().get(0); 19 | param0.accept(visitor); 20 | 21 | Object param0Value = param0.getAttributes().get(EVAL_VALUE); 22 | if (param0Value == null) { 23 | return SQLEvalVisitor.EVAL_ERROR; 24 | } 25 | 26 | std::string strValue = param0Value.toString(); 27 | 28 | std::string result = strValue.toLowerCase(); 29 | 30 | return result; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /ast/expr/SQLUnaryOperator.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLUnaryOperator_HEADER_H 2 | #define SQLUnaryOperator_HEADER_H 3 | #include 4 | #include 5 | class SQLUnaryOperator { 6 | 7 | public: 8 | static SQLUnaryOperator Plus; 9 | static SQLUnaryOperator Negative; 10 | static SQLUnaryOperator Not; 11 | static SQLUnaryOperator Compl; 12 | static SQLUnaryOperator Prior; 13 | static SQLUnaryOperator ConnectByRoot; 14 | static SQLUnaryOperator BINARY; 15 | static SQLUnaryOperator RAW; 16 | static SQLUnaryOperator NOT; 17 | 18 | std::string name; 19 | 20 | SQLUnaryOperator(std::string theName); 21 | }; 22 | typedef boost::shared_ptr SQLUnaryOperator_ptr; 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /parser/OdpsUDTFSQLSelectItem.h: -------------------------------------------------------------------------------- 1 | #ifndef OdpsUDTFSQLSelectItem_HEADER_H 2 | #define OdpsUDTFSQLSelectItem_HEADER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "../ast/statement/SQLSelectItem.h" 9 | #include "UnsupportedOperationException.h" 10 | 11 | class OdpsUDTFSQLSelectItem : virtual public SQLSelectItem { 12 | 13 | private: 14 | std::list aliasList; 15 | 16 | public: 17 | OdpsUDTFSQLSelectItem(); 18 | ~OdpsUDTFSQLSelectItem(); 19 | std::string &getAlias(); 20 | 21 | void setAlias(std::string &alias); 22 | 23 | std::list & getAliasList(); 24 | 25 | }; 26 | typedef boost::shared_ptr OdpsUDTFSQLSelectItem_ptr; 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /ast/expr/SQLUnaryOperator.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLUnaryOperator.h" 2 | 3 | SQLUnaryOperator SQLUnaryOperator::Plus(std::string("+")); 4 | SQLUnaryOperator SQLUnaryOperator::Negative(std::string("-")); 5 | SQLUnaryOperator SQLUnaryOperator::Not(std::string("!")); 6 | SQLUnaryOperator SQLUnaryOperator::Compl(std::string("~")); 7 | SQLUnaryOperator SQLUnaryOperator::Prior(std::string("PRIOR")); 8 | SQLUnaryOperator SQLUnaryOperator::ConnectByRoot(std::string("CONNECT BY")); 9 | SQLUnaryOperator SQLUnaryOperator::BINARY(std::string("BINARY")); 10 | SQLUnaryOperator SQLUnaryOperator::RAW(std::string("RAW")); 11 | SQLUnaryOperator SQLUnaryOperator::NOT(std::string("NOT")); 12 | 13 | SQLUnaryOperator::SQLUnaryOperator(std::string theName){ 14 | name = theName; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /deps/smhasher/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(SMHasher) 2 | 3 | cmake_minimum_required(VERSION 2.4) 4 | 5 | set(CMAKE_BUILD_TYPE Release) 6 | 7 | add_library( 8 | SMHasherSupport 9 | AvalancheTest.cpp 10 | Bitslice.cpp 11 | Bitvec.cpp 12 | CityTest.cpp 13 | City.cpp 14 | crc.cpp 15 | DifferentialTest.cpp 16 | Hashes.cpp 17 | KeysetTest.cpp 18 | lookup3.cpp 19 | md5.cpp 20 | MurmurHash1.cpp 21 | MurmurHash2.cpp 22 | MurmurHash3.cpp 23 | Platform.cpp 24 | Random.cpp 25 | sha1.cpp 26 | SpeedTest.cpp 27 | Spooky.cpp 28 | SpookyTest.cpp 29 | Stats.cpp 30 | SuperFastHash.cpp 31 | Types.cpp 32 | PMurHash.c 33 | ) 34 | 35 | add_executable( 36 | SMHasher 37 | main.cpp 38 | ) 39 | 40 | target_link_libraries( 41 | SMHasher 42 | SMHasherSupport 43 | ) 44 | -------------------------------------------------------------------------------- /ast/expr/SQLNCharExpr.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SQLNCharExpr.h" 3 | SQLNCharExpr::SQLNCharExpr(){ 4 | 5 | } 6 | 7 | SQLNCharExpr::~SQLNCharExpr(){ 8 | 9 | } 10 | SQLNCharExpr::SQLNCharExpr(std::string &theText) : super(theText){ 11 | //super(theText); 12 | } 13 | 14 | void SQLNCharExpr::output(std::string & buf) { 15 | if ((text == "") || (text.length() == 0)) { 16 | buf += "NULL"; 17 | return; 18 | } 19 | 20 | buf += "N'"; 21 | //buf.append(this.text.replaceAll("'", "''")); 22 | boost::replace_all(text,"'", "''"); 23 | buf += text; 24 | buf += "'"; 25 | 26 | //buf.append("'"); 27 | 28 | } 29 | 30 | void SQLNCharExpr::accept0(SQLASTVisitor * visitor) { 31 | visitor->visit(this); 32 | visitor->endVisit(this); 33 | } 34 | -------------------------------------------------------------------------------- /ast/SQLStatementImpl.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLStatementImpl_HEADER_H 2 | #define SQLStatementImpl_HEADER_H 3 | 4 | #include 5 | #include "Object.h" 6 | #include "SQLObject.h" 7 | #include "SQLObjectImpl.h" 8 | #include "SQLExpr.h" 9 | #include "SQLOrderBy.h" 10 | #include "../visitor/SQLASTVisitor.h" 11 | #include "SQLStatement.h" 12 | 13 | 14 | //import com.alibaba.druid.sql.SQLUtils; 15 | //import com.alibaba.druid.sql.visitor.SQLASTVisitor; 16 | 17 | class SQLStatementImpl : virtual public SQLObjectImpl, virtual public SQLStatement { 18 | 19 | public: 20 | SQLStatementImpl(); 21 | virtual ~SQLStatementImpl(); 22 | 23 | std::string &toString(); 24 | 25 | protected: 26 | void accept0(SQLASTVisitor *visitor); 27 | }; 28 | typedef boost::shared_ptr SQLStatementImpl_ptr; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /visitor/functions/BitLength.cpp: -------------------------------------------------------------------------------- 1 | #include "BitLength.h" 2 | 3 | BitLength::~BitLength() 4 | { 5 | 6 | } 7 | 8 | BitLength * BitLength::instance() 9 | { 10 | static BitLength x; // Guaranteed to be destroyed. 11 | // Instantiated on first use. 12 | return &x; 13 | } 14 | 15 | Object *BitLength::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 16 | if (x.getParameters().size() != 1) { 17 | return SQLEvalVisitor.EVAL_ERROR; 18 | } 19 | 20 | SQLExpr param0 = x.getParameters().get(0); 21 | param0.accept(visitor); 22 | 23 | Object param0Value = param0.getAttributes().get(EVAL_VALUE); 24 | if (param0Value == null) { 25 | return SQLEvalVisitor.EVAL_ERROR; 26 | } 27 | 28 | if (param0Value instanceof String) { 29 | return ((String) param0Value).getBytes().length * 8; 30 | } 31 | return SQLEvalVisitor.EVAL_ERROR; 32 | } 33 | -------------------------------------------------------------------------------- /ast/expr/SQLNumericLiteralExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLNumericLiteralExpr_HEADER_H 2 | #define SQLNumericLiteralExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "../SQLExprImpl.h" 8 | //#include "../../visitor/SQLASTVisitor.h" 9 | 10 | #include "SQLLiteralExpr.h" 11 | using boost::rational; 12 | typedef rational RNumber; 13 | 14 | class SQLNumericLiteralExpr : virtual public SQLExprImpl, virtual public SQLLiteralExpr { 15 | 16 | public: 17 | SQLNumericLiteralExpr(){ 18 | 19 | } 20 | 21 | virtual ~SQLNumericLiteralExpr(){ 22 | 23 | } 24 | 25 | 26 | virtual RNumber *getNumber() = 0; 27 | 28 | virtual void setNumber(RNumber *number) = 0; 29 | }; 30 | typedef boost::shared_ptr SQLNumericLiteralExpr_ptr; 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /deps/smhasher/Platform.cpp: -------------------------------------------------------------------------------- 1 | #include "Platform.h" 2 | 3 | #include 4 | 5 | void testRDTSC ( void ) 6 | { 7 | int64_t temp = rdtsc(); 8 | 9 | printf("%d",(int)temp); 10 | } 11 | 12 | #if defined(_MSC_VER) 13 | 14 | #include 15 | 16 | void SetAffinity ( int cpu ) 17 | { 18 | SetProcessAffinityMask(GetCurrentProcess(),cpu); 19 | SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); 20 | } 21 | 22 | #else 23 | 24 | #include 25 | 26 | void SetAffinity ( int /*cpu*/ ) 27 | { 28 | #if !defined(__CYGWIN__) && !defined(__APPLE__) 29 | cpu_set_t mask; 30 | 31 | CPU_ZERO(&mask); 32 | 33 | CPU_SET(2,&mask); 34 | 35 | if( sched_setaffinity(0,sizeof(mask),&mask) == -1) 36 | { 37 | printf("WARNING: Could not set CPU affinity\n"); 38 | } 39 | #endif 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /ast/expr/SQLAnyExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLAnyExpr_HEADER_H 2 | #define SQLAnyExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | #include "../SQLExprImpl.h" 7 | #include "../../visitor/SQLASTVisitor.h" 8 | #include "../statement/SQLSelect.h" 9 | 10 | 11 | class SQLAnyExpr : virtual public SQLExprImpl { 12 | 13 | public: 14 | SQLSelect *subQuery; 15 | 16 | SQLAnyExpr(); 17 | virtual ~SQLAnyExpr(); 18 | 19 | SQLAnyExpr(SQLSelect *select); 20 | 21 | SQLSelect *getSubQuery(); 22 | 23 | void setSubQuery(SQLSelect *subQuery); 24 | 25 | void output(std::string & buf); 26 | //int hashCode(); 27 | //bool equals(Object obj); 28 | 29 | protected: 30 | void accept0(SQLASTVisitor *visitor); 31 | 32 | }; 33 | typedef boost::shared_ptr SQLAnyExpr_ptr; 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /ast/expr/SQLCharExpr.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SQLCharExpr.h" 3 | SQLCharExpr::SQLCharExpr(){ 4 | 5 | } 6 | 7 | SQLCharExpr::~SQLCharExpr(){ 8 | 9 | } 10 | SQLCharExpr::SQLCharExpr(std::string & thetext): super(thetext){ 11 | //super(thetext); 12 | } 13 | 14 | void SQLCharExpr::output(std::string &buf) { 15 | if ((text == "") || (text.length() == 0)) { 16 | //buf.append("NULL"); 17 | buf += "NULL"; 18 | } else { 19 | //buf.append("'"); 20 | //buf.append(this.text.replaceAll("'", "''")); 21 | //buf.append("'"); 22 | 23 | 24 | buf += "'"; 25 | boost::replace_all(text,"'", "''"); 26 | buf += text; 27 | buf += "'"; 28 | } 29 | } 30 | 31 | void SQLCharExpr::accept0(SQLASTVisitor *visitor) { 32 | visitor->visit(this); 33 | visitor->endVisit(this); 34 | } 35 | -------------------------------------------------------------------------------- /parser/SQLDDLParser.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLDDLParser.h" 2 | SQLDDLParser::SQLDDLParser(std::string &theSql) : SQLStatementParser(theSql){ 3 | //super(sql); 4 | } 5 | 6 | SQLDDLParser::SQLDDLParser(SQLExprParser *theExprParser) : SQLStatementParser(theExprParser){ 7 | //super(exprParser); 8 | } 9 | 10 | SQLDDLParser::~SQLDDLParser(){ 11 | 12 | } 13 | SQLTableConstaint *SQLDDLParser::parseConstraint() { 14 | if (lexer->getToken() == CONSTRAINT) { 15 | lexer->nextToken(); 16 | } 17 | 18 | if (lexer->getToken() == IDENTIFIER) { 19 | this->exprParser->getName(); 20 | throw new ParserException("TODO"); 21 | } 22 | 23 | if (lexer->getToken() == PRIMARY) { 24 | lexer->nextToken(); 25 | accept(KEY); 26 | 27 | throw new ParserException("TODO"); 28 | } 29 | 30 | throw new ParserException("TODO"); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /visitor/functions/Bin.cpp: -------------------------------------------------------------------------------- 1 | #include "Bin.h" 2 | 3 | Bin::~Bin() 4 | { 5 | 6 | } 7 | 8 | Bin * Bin::instance() 9 | { 10 | static Bin x; // Guaranteed to be destroyed. 11 | // Instantiated on first use. 12 | return &x; 13 | } 14 | 15 | Object *Bin::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 16 | if (x.getParameters().size() != 1) { 17 | return SQLEvalVisitor.EVAL_ERROR; 18 | } 19 | 20 | SQLExpr param0 = x.getParameters().get(0); 21 | param0.accept(visitor); 22 | 23 | Object param0Value = param0.getAttributes().get(EVAL_VALUE); 24 | if (param0Value == null) { 25 | return SQLEvalVisitor.EVAL_ERROR; 26 | } 27 | 28 | if (param0Value instanceof Number) { 29 | long longValue = ((Number) param0Value).longValue(); 30 | String result = Long.toString(longValue, 2); 31 | return result; 32 | } 33 | return SQLEvalVisitor.EVAL_ERROR; 34 | } 35 | -------------------------------------------------------------------------------- /ast/expr/SQLAllExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLAllExpr_HEADER_H 2 | #define SQLAllExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "../SQLExprImpl.h" 8 | #include "../../visitor/SQLASTVisitor.h" 9 | #include "../statement/SQLSelect.h" 10 | 11 | class SQLAllExpr : virtual public SQLExprImpl { 12 | 13 | public: 14 | SQLSelect *subQuery; 15 | 16 | public: 17 | SQLAllExpr(); 18 | virtual ~SQLAllExpr(); 19 | 20 | SQLAllExpr(SQLSelect *select); 21 | 22 | SQLSelect *getSubQuery(); 23 | 24 | void setSubQuery(SQLSelect *subQuery); 25 | 26 | void output(std::string & buf); 27 | 28 | //int hashCode(); 29 | //bool equals(Object obj); 30 | protected: 31 | void accept0(SQLASTVisitor *visitor); 32 | 33 | 34 | }; 35 | typedef boost::shared_ptr SQLAllExpr_ptr; 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /ast/expr/SQLNotExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLNotExpr_HEADER_H 2 | #define SQLNotExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | #include "../SQLExpr.h" 7 | #include "../SQLExprImpl.h" 8 | #include "../../visitor/SQLASTVisitor.h" 9 | 10 | 11 | class SQLNotExpr : virtual public SQLExprImpl { 12 | 13 | private: 14 | //static long serialVersionUID = 1L; 15 | public: 16 | SQLExpr *expr; 17 | 18 | SQLNotExpr(); 19 | virtual ~SQLNotExpr(); 20 | 21 | SQLNotExpr(SQLExpr *expr); 22 | 23 | SQLExpr *getExpr(); 24 | 25 | void setExpr(SQLExpr *expr); 26 | 27 | void output(std::string & buf); 28 | 29 | //int hashCode(); 30 | //bool equals(Object obj); 31 | protected: 32 | void accept0(SQLASTVisitor *visitor); 33 | 34 | }; 35 | typedef boost::shared_ptr SQLNotExpr_ptr; 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /visitor/functions/Reverse.cpp: -------------------------------------------------------------------------------- 1 | #include "Reverse.h" 2 | Reverse::~Reverse() 3 | { 4 | 5 | } 6 | 7 | Reverse * Reverse::instance() 8 | { 9 | static Reverse x; 10 | return &x; 11 | } 12 | 13 | Object *Reverse::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 14 | if (x.getParameters().size() != 1) { 15 | return SQLEvalVisitor.EVAL_ERROR; 16 | } 17 | 18 | SQLExpr param0 = x.getParameters().get(0); 19 | param0.accept(visitor); 20 | 21 | Object param0Value = param0.getAttributes().get(EVAL_VALUE); 22 | if (param0Value == null) { 23 | return SQLEvalVisitor.EVAL_ERROR; 24 | } 25 | 26 | std::string strValue = param0Value.toString(); 27 | 28 | StringBuilder buf = new StringBuilder(); 29 | for (int i = strValue.length() - 1; i >= 0; --i) { 30 | buf.append(strValue.charAt(i)); 31 | } 32 | std::string result = buf.toString(); 33 | return result; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /visitor/functions/If.cpp: -------------------------------------------------------------------------------- 1 | #include "If.h" 2 | 3 | If::~If() 4 | { 5 | 6 | } 7 | 8 | If * If::instance() 9 | { 10 | static If x; 11 | return &x; 12 | } 13 | 14 | 15 | Object *If::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 16 | final List parameters = x.getParameters(); 17 | if (parameters.size() == 0) { 18 | return EVAL_ERROR; 19 | } 20 | 21 | SQLExpr condition = parameters.get(0); 22 | condition.accept(visitor); 23 | Object itemValue = condition.getAttributes().get(EVAL_VALUE); 24 | if (Boolean.TRUE == itemValue || !SQLEvalVisitorUtils.eq(itemValue, 0)) { 25 | SQLExpr trueExpr = parameters.get(1); 26 | trueExpr.accept(visitor); 27 | return trueExpr.getAttributes().get(EVAL_VALUE); 28 | } else { 29 | SQLExpr falseExpr = parameters.get(2); 30 | falseExpr.accept(visitor); 31 | return falseExpr.getAttributes().get(EVAL_VALUE); 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /ast/expr/SQLIntegerExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLIntegerExpr_HEADER_H 2 | #define SQLIntegerExpr_HEADER_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include "../../visitor/SQLASTVisitor.h" 9 | #include "SQLNumericLiteralExpr.h" 10 | 11 | 12 | class SQLIntegerExpr : virtual public SQLNumericLiteralExpr { 13 | 14 | private: 15 | RNumber *number; 16 | 17 | public: 18 | SQLIntegerExpr(RNumber *number); 19 | 20 | SQLIntegerExpr(); 21 | virtual ~SQLIntegerExpr(); 22 | 23 | RNumber *getNumber(); 24 | int intValue(); 25 | 26 | void setNumber(RNumber *number); 27 | 28 | void output(std::string & buf); 29 | 30 | //int hashCode(); 31 | //bool equals(Object obj); 32 | protected: 33 | void accept0(SQLASTVisitor *visitor); 34 | 35 | }; 36 | typedef boost::shared_ptr SQLIntegerExpr_ptr; 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /ast/expr/SQLNumberExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLNumberExpr_HEADER_H 2 | #define SQLNumberExpr_HEADER_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include "../SQLExprImpl.h" 9 | #include "../../visitor/SQLASTVisitor.h" 10 | #include "SQLNumericLiteralExpr.h" 11 | 12 | 13 | class SQLNumberExpr : virtual public SQLNumericLiteralExpr { 14 | 15 | private: 16 | RNumber *number; 17 | 18 | public: 19 | SQLNumberExpr(); 20 | virtual ~SQLNumberExpr(); 21 | 22 | SQLNumberExpr(RNumber *number); 23 | 24 | RNumber *getNumber(); 25 | 26 | void setNumber(RNumber *number); 27 | 28 | void output(std::string & buf); 29 | 30 | //int hashCode(); 31 | //bool equals(Object obj); 32 | protected: 33 | void accept0(SQLASTVisitor *visitor); 34 | 35 | }; 36 | typedef boost::shared_ptr SQLNumberExpr_ptr; 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /parser/LayoutCharacters.h: -------------------------------------------------------------------------------- 1 | #ifndef LAYOUTCHARACTER_HEADER_H 2 | #define LAYOUTCHARACTER_HEADER_H 3 | #include 4 | class LayoutCharacters { 5 | 6 | public: 7 | 8 | /** 9 | * Tabulator column increment. 10 | */ 11 | static int TabInc; 12 | 13 | /** 14 | * Tabulator character. 15 | */ 16 | static char TAB; 17 | 18 | /** 19 | * Line feed character. 20 | */ 21 | static char LF; 22 | 23 | /** 24 | * Form feed character. 25 | */ 26 | static char FF; 27 | 28 | /** 29 | * Carriage return character. 30 | */ 31 | static char CR; 32 | 33 | /** 34 | * QS_TODO 为什么不是0x0?
35 | * End of input character. Used as a sentinel to denote the character one beyond the last defined character in a 36 | * source file. 37 | */ 38 | static char EOI; 39 | }; 40 | 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /parser/SQLCreateTableParser.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLCreateTableParser_HEADER_H 2 | #define SQLCreateTableParser_HEADER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "SQLDDLParser.h" 8 | #include "SQLParser.h" 9 | #include "SQLExprParser.h" 10 | #include "SQLStatementParser.h" 11 | #include "../ast/statement/SQLCreateTableStatement.h" 12 | 13 | class SQLCreateTableParser : public SQLDDLParser { 14 | 15 | public: 16 | SQLCreateTableParser(std::string &sql); 17 | SQLCreateTableParser(SQLExprParser *exprParser); 18 | ~SQLCreateTableParser(); 19 | 20 | SQLCreateTableStatement *parseCrateTable(); 21 | 22 | SQLCreateTableStatement *parseCrateTable(bool acceptCreate); 23 | 24 | protected: 25 | SQLCreateTableStatement *newCreateStatement(); 26 | }; 27 | typedef boost::shared_ptr SQLCreateTableParser_ptr; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /ast/expr/SQLSomeExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLSomeExpr_HEADER_H 2 | #define SQLSomeExpr_HEADER_H 3 | 4 | 5 | #include 6 | #include 7 | #include "../SQLExprImpl.h" 8 | #include "../statement/SQLSelect.h" 9 | #include "../../visitor/SQLASTVisitor.h" 10 | 11 | 12 | #include "../statement/SQLSelect.h" 13 | 14 | class SQLSomeExpr : virtual public SQLExprImpl { 15 | 16 | public: 17 | SQLSelect *subQuery; 18 | 19 | SQLSomeExpr(); 20 | virtual ~SQLSomeExpr(); 21 | 22 | SQLSomeExpr(SQLSelect *select); 23 | 24 | SQLSelect *getSubQuery(); 25 | 26 | void setSubQuery(SQLSelect *subQuery); 27 | 28 | void output(std::string & buf); 29 | 30 | //int hashCode(); 31 | //bool equals(Object obj); 32 | protected: 33 | void accept0(SQLASTVisitor *visitor); 34 | 35 | }; 36 | typedef boost::shared_ptr SQLSomeExpr_ptr; 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /ast/expr/SQLCastExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLCastExpr_HEADER_H 2 | #define SQLCastExpr_HEADER_H 3 | 4 | #include 5 | #include "../SQLExpr.h" 6 | #include "../SQLExprImpl.h" 7 | #include "../../visitor/SQLASTVisitor.h" 8 | #include "../SQLDataType.h" 9 | 10 | 11 | class SQLCastExpr : virtual public SQLExprImpl { 12 | 13 | private: 14 | SQLExpr *expr; 15 | SQLDataType *dataType; 16 | 17 | public: 18 | SQLCastExpr(); 19 | virtual ~SQLCastExpr(); 20 | 21 | SQLExpr *getExpr(); 22 | 23 | void setExpr(SQLExpr *expr); 24 | 25 | SQLDataType *getDataType(); 26 | 27 | void setDataType(SQLDataType *dataType); 28 | 29 | protected: 30 | void accept0(SQLASTVisitor *visitor); 31 | 32 | public: 33 | //int hashCode(); 34 | //public bool equals(Object obj); 35 | 36 | }; 37 | typedef boost::shared_ptr SQLCastExpr_ptr; 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /visitor/functions/OneParamFunctions.h: -------------------------------------------------------------------------------- 1 | #ifndef OneParamFunctions_HEADER_H 2 | #define OneParamFunctions_HEADER_H 3 | 4 | 5 | #include "SQLEvalVisitor.h" 6 | #include "SQLEvalVisitorUtils.h" 7 | #include "SQLExpr.h" 8 | #include "SQLMethodInvokeExpr.h" 9 | #include "ParserException.h" 10 | 11 | //import java.math.BigDecimal; 12 | //import java.math.BigInteger; 13 | 14 | 15 | //import com.alibaba.druid.util.Utils; 16 | 17 | class OneParamFunctions : virtual public Function { 18 | public: 19 | static OneParamFunctions *instance(); 20 | virtual ~OneParamFunctions(); 21 | virtual Object *eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x); 22 | 23 | static std::string soundex(std::string str); 24 | 25 | static std::string clean(std::string str); 26 | 27 | private: 28 | static char getMappingCode(std::string str, int index); 29 | 30 | static char map(char ch); 31 | 32 | 33 | }; 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /ast/expr/SQLHexExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLHexExpr_HEADER_H 2 | #define SQLHexExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "../Object.h" 8 | #include "../SQLExprImpl.h" 9 | #include "../statement/SQLSelect.h" 10 | //#include "../HexBin.h" 11 | #include "SQLLiteralExpr.h" 12 | 13 | //import com.alibaba.druid.util.HexBin; 14 | 15 | class SQLHexExpr : virtual public SQLExprImpl, virtual public SQLLiteralExpr { 16 | 17 | private: 18 | std::string hex; 19 | 20 | public: 21 | SQLHexExpr(std::string &hex); 22 | virtual ~SQLHexExpr(); 23 | 24 | std::string &getHex(); 25 | 26 | void output(std::string & buf); 27 | 28 | //int hashCode(); 29 | //bool equals(Object obj); 30 | //char[] toBytes(); 31 | protected: 32 | void accept0(SQLASTVisitor *visitor); 33 | 34 | }; 35 | typedef boost::shared_ptr SQLHexExpr_ptr; 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /issues.txt: -------------------------------------------------------------------------------- 1 | 1. it does not differentiate long and int type. the differentiate is made in SQLExprParser.cpp. 2 | 2. change std::list to std::vector 3 | 3. add a char* based identifierEquals("SAVEPOINT" 4 | 4. In SQLExprParser, the std::list returned, is newed. Should use auto_ptr, or 5 | make it memeber of class. 6 | 5. anything newed, Should be removed; 7 | 6. the list/vector/set of pointers, should be released. 8 | 9 | 7. change list to vector 10 | 11 | 8. how about the delete in SQLExprParser?? what's the effect? 12 | 13 | 14 | 15 | 16 | 17 | 18 | ------------------------------------------------------ 19 | 20 | SQLStatementParser: 21 | => SQLParer 22 | => Lexer 23 | construct SQLParser done 24 | => Lexer getNextToken() 25 | => SQLExprParser with SQLParser's lexer 26 | => SQLParser with SQLParser's lexer 27 | construct SQLExprParser done 28 | => SQLStatementParser construct done 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /visitor/functions/Instr.cpp: -------------------------------------------------------------------------------- 1 | #include "Instr.h" 2 | Instr::~Instr() 3 | { 4 | 5 | } 6 | 7 | Instr * Instr::instance() 8 | { 9 | static Instr x; 10 | return &x; 11 | } 12 | 13 | Object *Instr::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 14 | if (x.getParameters().size() != 2) { 15 | return SQLEvalVisitor.EVAL_ERROR; 16 | } 17 | 18 | SQLExpr param0 = x.getParameters().get(0); 19 | SQLExpr param1 = x.getParameters().get(1); 20 | param0.accept(visitor); 21 | param1.accept(visitor); 22 | 23 | Object param0Value = param0.getAttributes().get(EVAL_VALUE); 24 | Object param1Value = param1.getAttributes().get(EVAL_VALUE); 25 | if (param0Value == null || param1Value == null) { 26 | return SQLEvalVisitor.EVAL_ERROR; 27 | } 28 | 29 | String strValue0 = param0Value.toString(); 30 | String strValue1 = param1Value.toString(); 31 | 32 | int result = strValue0.indexOf(strValue1) + 1; 33 | return result; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /visitor/functions/Elt.cpp: -------------------------------------------------------------------------------- 1 | #include "Elt.h" 2 | Elt::~Elt() 3 | { 4 | 5 | } 6 | 7 | Elt * Elt::instance() 8 | { 9 | static Elt x; 10 | return &x; 11 | } 12 | 13 | Object *Elt::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 14 | if (x.getParameters().size() <= 1) { 15 | return SQLEvalVisitor.EVAL_ERROR; 16 | } 17 | 18 | SQLExpr param0 = x.getParameters().get(0); 19 | param0.accept(visitor); 20 | 21 | Object param0Value = param0.getAttributes().get(EVAL_VALUE); 22 | int param0IntValue; 23 | if (!(param0Value instanceof Number)) { 24 | return SQLEvalVisitor.EVAL_ERROR; 25 | } 26 | param0IntValue = ((Number) param0Value).intValue(); 27 | 28 | if (param0IntValue >= x.getParameters().size()) { 29 | return null; 30 | } 31 | 32 | SQLExpr item = x.getParameters().get(param0IntValue); 33 | item.accept(visitor); 34 | 35 | Object itemValue = item.getAttributes().get(EVAL_VALUE); 36 | return itemValue; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /ast/expr/SQLQueryExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLQueryExpr_HEADER_H 2 | #define SQLQueryExpr_HEADER_H 3 | #include 4 | #include 5 | #include "../SQLExprImpl.h" 6 | #include "../statement/SQLSelect.h" 7 | #include "../../visitor/SQLASTVisitor.h" 8 | 9 | 10 | class SQLQueryExpr : virtual public SQLExprImpl { 11 | 12 | private: 13 | //static final long serialVersionUID = 1L; 14 | public: 15 | SQLSelect *subQuery; 16 | 17 | SQLQueryExpr(); 18 | virtual ~SQLQueryExpr(); 19 | 20 | SQLQueryExpr(SQLSelect *select); 21 | 22 | SQLSelect *getSubQuery(); 23 | 24 | void setSubQuery(SQLSelect *subQuery); 25 | 26 | void output(std::string &buf); 27 | 28 | //int hashCode(); 29 | //bool equals(Object obj); 30 | protected: 31 | void accept0(SQLASTVisitor *visitor); 32 | 33 | }; 34 | typedef boost::shared_ptr SQLQueryExpr_ptr; 35 | 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /visitor/functions/Ltrim.cpp: -------------------------------------------------------------------------------- 1 | #include "Ltrim.h" 2 | Ltrim::~Ltrim() 3 | { 4 | 5 | } 6 | 7 | Ltrim * Ltrim::instance() 8 | { 9 | static Ltrim x; 10 | return &x; 11 | } 12 | 13 | Object *Ltrim::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 14 | if (x.getParameters().size() != 1) { 15 | return SQLEvalVisitor.EVAL_ERROR; 16 | } 17 | 18 | SQLExpr param0 = x.getParameters().get(0); 19 | param0.accept(visitor); 20 | 21 | Object param0Value = param0.getAttributes().get(EVAL_VALUE); 22 | if (param0Value == null) { 23 | return SQLEvalVisitor.EVAL_ERROR; 24 | } 25 | 26 | std::string strValue = param0Value.toString(); 27 | 28 | int index = -1; 29 | for (int i = 0; i < strValue.length(); ++i) { 30 | if (!Character.isWhitespace(strValue.charAt(i))) { 31 | index = i; 32 | break; 33 | } 34 | } 35 | 36 | if (index <= 0) { 37 | return strValue; 38 | } else { 39 | return strValue.substring(index); 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /visitor/SQLEvalVisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLEvalVisitor_HEADER_H 2 | #define SQLEvalVisitor_HEADER_H 3 | 4 | class SQLEvalVisitor : virtual public SQLASTVisitor { 5 | 6 | public: 7 | static std::string EVAL_VALUE; 8 | static std::string EVAL_EXPR; 9 | static Object * EVAL_ERROR; 10 | static Object * EVAL_VALUE_COUNT; 11 | static Object * EVAL_VALUE_NULL; 12 | 13 | virtual ~SQLEvalVisitor(); 14 | virtual Function getFunction(std::string funcName) = 0; 15 | 16 | virtual void registerFunction(std::string funcName, Function function) = 0; 17 | 18 | virtual void unregisterFunction(std::string funcName) = 0; 19 | 20 | virtual List getParameters() = 0; 21 | 22 | virtual void setParameters(List parameters) = 0; 23 | 24 | virtual int incrementAndGetVariantIndex() = 0; 25 | 26 | virtual bool isMarkVariantIndex() = 0; 27 | 28 | virtual void setMarkVariantIndex(bool markVariantIndex) = 0; 29 | }; 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /visitor/functions/Char.cpp: -------------------------------------------------------------------------------- 1 | #include "Char.h" 2 | 3 | Char::~Char() 4 | { 5 | 6 | } 7 | 8 | Char * Char::instance() 9 | { 10 | static Char x; 11 | return &x; 12 | } 13 | 14 | Object *Char::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 15 | if (x.getParameters().size() == 0) { 16 | return SQLEvalVisitor.EVAL_ERROR; 17 | } 18 | 19 | StringBuffer buf = new StringBuffer(x.getParameters().size()); 20 | for (SQLExpr param : x.getParameters()) { 21 | param.accept(visitor); 22 | 23 | Object paramValue = param.getAttributes().get(EVAL_VALUE); 24 | 25 | if (paramValue instanceof Number) { 26 | int charCode = ((Number) paramValue).intValue(); 27 | buf.append((char) charCode); 28 | } else if (paramValue instanceof String) { 29 | int charCode = new BigDecimal((String)paramValue).intValue(); 30 | buf.append((char) charCode); 31 | } else { 32 | return SQLEvalVisitor.EVAL_ERROR; 33 | } 34 | } 35 | 36 | return buf.toString(); 37 | } 38 | -------------------------------------------------------------------------------- /ast/SQLOver.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLOver_HEADER_H 2 | #define SQLOver_HEADER_H 3 | 4 | #include 5 | #include "Object.h" 6 | #include "SQLObject.h" 7 | #include "SQLObjectImpl.h" 8 | #include "SQLExpr.h" 9 | #include "SQLOrderBy.h" 10 | #include "../visitor/SQLASTVisitor.h" 11 | 12 | 13 | 14 | class SQLOver : virtual public SQLObjectImpl { 15 | 16 | protected: 17 | std::list partitionBy; 18 | SQLOrderBy *orderBy; 19 | void accept0(SQLASTVisitor *visitor); 20 | 21 | public: 22 | SQLOver(); 23 | virtual ~SQLOver(); 24 | 25 | SQLOver(SQLOrderBy *orderBy); 26 | SQLOrderBy *getOrderBy(); 27 | 28 | void setOrderBy(SQLOrderBy *orderBy); 29 | std::list &getPartitionBy(); 30 | //void acceptChild(SQLASTVisitor *visitor, std::list &children); 31 | 32 | //int hashCode(); 33 | 34 | //bool equals(Object obj); 35 | }; 36 | typedef boost::shared_ptr SQLOver_ptr; 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /parser/CharTypes.h: -------------------------------------------------------------------------------- 1 | // g++ x.cpp -std=c++11 2 | #include 3 | #include 4 | 5 | #ifndef CHARTYPES_HEADER_H 6 | #define CHARTYPES_HEADER_H 7 | #include 8 | #define HEXFLAGSLENGTH 256 9 | 10 | class CharTypes { 11 | public: 12 | CharTypes (); 13 | ~CharTypes (); 14 | 15 | static bool isHex(char c); 16 | static bool isDigit(char c); 17 | static bool isFirstIdentifierChar(char c); 18 | 19 | /** 20 | * @return false if {@link LayoutCharacters#EOI} 21 | */ 22 | static bool isWhitespace(char c); 23 | static bool isWhitespace(std::string c); 24 | 25 | static bool isIdentifierChar(char c); 26 | 27 | private: 28 | static bool hexFlags[256]; 29 | static bool firstIdentifierFlags[256]; 30 | static bool identifierFlags[256]; 31 | static bool whitespaceFlags[256]; 32 | static bool __init; 33 | static bool init(); 34 | 35 | }; 36 | typedef boost::shared_ptr CharTypes_ptr; 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /ast/expr/SQLCurrentOfCursorExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLCurrentOfCursorExpr_HEADER_H 2 | #define SQLCurrentOfCursorExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | #include "../SQLName.h" 7 | #include "../SQLExprImpl.h" 8 | #include "../../visitor/SQLASTVisitor.h" 9 | 10 | 11 | 12 | class SQLCurrentOfCursorExpr : virtual public SQLExprImpl { 13 | 14 | private: 15 | SQLName *cursorName; 16 | 17 | public: 18 | SQLCurrentOfCursorExpr(); 19 | virtual ~SQLCurrentOfCursorExpr(); 20 | 21 | SQLCurrentOfCursorExpr(SQLName *cursorName); 22 | 23 | SQLName *getCursorName(); 24 | 25 | void setCursorName(SQLName *cursorName); 26 | 27 | void output(std::string & buf); 28 | 29 | //int hashCode(); 30 | //bool equals(Object obj); 31 | protected: 32 | void accept0(SQLASTVisitor *visitor); 33 | 34 | 35 | }; 36 | typedef boost::shared_ptr SQLCurrentOfCursorExpr_ptr; 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /parser/SQLParser.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SQLParser_HEADER_H 3 | #define SQLParser_HEADER_H 4 | 5 | #include 6 | #include 7 | #include "Lexer.h" 8 | #include "ParserException.h" 9 | #include "Token.h" 10 | 11 | 12 | 13 | class SQLParser { 14 | 15 | private: 16 | bool lexerHere; 17 | protected: 18 | Lexer *lexer; 19 | 20 | bool identifierEquals(std::string &text); 21 | bool identifierEquals(const char *); 22 | void acceptIdentifier(std::string &text); 23 | void acceptIdentifier(const char *text); 24 | 25 | std::string &as(); 26 | 27 | void setErrorEndPos(int errPos); 28 | 29 | public: 30 | SQLParser(std::string& sql); 31 | 32 | SQLParser(Lexer* lexer); 33 | ~SQLParser(); 34 | 35 | Lexer *getLexer(); 36 | 37 | void accept(Token token); 38 | 39 | void match(Token token); 40 | 41 | private: 42 | int errorEndPos; 43 | std::string alias; 44 | 45 | }; 46 | typedef boost::shared_ptr SQLParser_ptr; 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /visitor/functions/Hex.cpp: -------------------------------------------------------------------------------- 1 | #include "Hex.h" 2 | 3 | Hex::~Hex() 4 | { 5 | 6 | } 7 | 8 | Hex * Hex::instance() 9 | { 10 | static Hex x; 11 | return &x; 12 | } 13 | 14 | Object *Hex::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 15 | if (x.getParameters().size() != 1) { 16 | throw new ParserException("argument's != 1, " + x.getParameters().size()); 17 | } 18 | 19 | SQLExpr param0 = x.getParameters().get(0); 20 | param0.accept(visitor); 21 | 22 | Object param0Value = param0.getAttributes().get(EVAL_VALUE); 23 | if (param0Value == null) { 24 | return SQLEvalVisitor.EVAL_ERROR; 25 | } 26 | 27 | if (param0Value instanceof String) { 28 | byte[] bytes = ((String) param0Value).getBytes(); 29 | String result = HexBin.encode(bytes); 30 | return result; 31 | } 32 | 33 | if (param0Value instanceof Number) { 34 | long value = ((Number) param0Value).longValue(); 35 | String result = Long.toHexString(value).toUpperCase(); 36 | return result; 37 | } 38 | 39 | return SQLEvalVisitor.EVAL_ERROR; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /ast/expr/SQLUnaryExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLUnaryExpr_HEADER_H 2 | #define SQLUnaryExpr_HEADER_H 3 | 4 | #include 5 | #include "../SQLExpr.h" 6 | #include "../SQLExprImpl.h" 7 | #include "../../visitor/SQLASTVisitor.h" 8 | 9 | 10 | #include "SQLUnaryOperator.h" 11 | 12 | 13 | class SQLUnaryExpr : virtual public SQLExprImpl { 14 | 15 | private: 16 | //static long serialVersionUID = 1L; 17 | SQLExpr *expr; 18 | SQLUnaryOperator *xoperator; 19 | 20 | public: 21 | SQLUnaryExpr(); 22 | virtual ~SQLUnaryExpr(); 23 | 24 | SQLUnaryExpr(SQLUnaryOperator *xoperator, SQLExpr *expr); 25 | 26 | SQLUnaryOperator *getOperator(); 27 | 28 | void setOperator(SQLUnaryOperator *xoperator); 29 | 30 | SQLExpr *getExpr(); 31 | 32 | void setExpr(SQLExpr *expr); 33 | 34 | //int hashCode(); 35 | //bool equals(Object obj); 36 | protected: 37 | void accept0(SQLASTVisitor *visitor); 38 | 39 | }; 40 | typedef boost::shared_ptr SQLUnaryExpr_ptr; 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /visitor/functions/Left.cpp: -------------------------------------------------------------------------------- 1 | #include "Left.h" 2 | Left::~Left() 3 | { 4 | 5 | } 6 | 7 | Left * Left::instance() 8 | { 9 | static Left x; 10 | return &x; 11 | } 12 | 13 | Object * Left::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 14 | if (x.getParameters().size() != 2) { 15 | return SQLEvalVisitor.EVAL_ERROR; 16 | } 17 | 18 | SQLExpr param0 = x.getParameters().get(0); 19 | SQLExpr param1 = x.getParameters().get(1); 20 | param0.accept(visitor); 21 | param1.accept(visitor); 22 | 23 | Object param0Value = param0.getAttributes().get(EVAL_VALUE); 24 | Object param1Value = param1.getAttributes().get(EVAL_VALUE); 25 | if (param0Value == null || param1Value == null) { 26 | return SQLEvalVisitor.EVAL_ERROR; 27 | } 28 | 29 | std::string strValue = param0Value.toString(); 30 | int intValue = SQLEvalVisitorUtils.castToInteger(param1Value); 31 | 32 | if (intValue > strValue.length()) { 33 | return SQLEvalVisitor.EVAL_ERROR; 34 | } 35 | 36 | std::string result = strValue.substring(0, intValue); 37 | 38 | return result; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /parser/OdpsUDTFSQLSelectItem.cpp: -------------------------------------------------------------------------------- 1 | #include "OdpsUDTFSQLSelectItem.h" 2 | OdpsUDTFSQLSelectItem::OdpsUDTFSQLSelectItem() { 3 | 4 | } 5 | 6 | OdpsUDTFSQLSelectItem::~OdpsUDTFSQLSelectItem() { 7 | 8 | //for(std::list::iterator it = aliasList.begin(); it != aliasList.end(); ++it) 9 | //{ 10 | //std::cout << __FILE__ << ": " << __LINE__ << ", in SQLExprParser::~SQLExprParser, destructor step 1.1" << std::endl; 11 | //delete *it; 12 | //} 13 | //aliasList.clear(); 14 | 15 | 16 | } 17 | std::string & OdpsUDTFSQLSelectItem::getAlias() { 18 | //fprintf(stderr, "UnsupportedOperationException in SQLStatementImpl::getAlias\n"); 19 | //assert(false); 20 | throw new UnsupportedOperationException(); 21 | } 22 | 23 | void OdpsUDTFSQLSelectItem::setAlias(std::string &alias) { 24 | throw new UnsupportedOperationException(); 25 | //fprintf(stderr, "UnsupportedOperationException in SQLStatementImpl::setAlias\n"); 26 | //assert(false); 27 | } 28 | 29 | std::list & OdpsUDTFSQLSelectItem::getAliasList() { 30 | return aliasList; 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /parser/Keywords_test.cpp: -------------------------------------------------------------------------------- 1 | //http://codereview.stackexchange.com/questions/14309/conversion-between-enum-and-string-in-c-class-header 2 | //http://stackoverflow.com/questions/207976/how-to-easily-map-c-enums-to-strings 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include "Keywords.h" 9 | 10 | int main() 11 | { 12 | 13 | Keywords * keywods = Keywords::getInstance(); 14 | std::cout << " enum SELECT = " << tokenStringList.at(TOKEN_SELECT) << std::endl; 15 | std::string all = "ALL"; 16 | std::cout << " getKeywods " << keywods->getKeyword(all) << std::endl; 17 | std::string xxx = "xxx"; 18 | std::cout << " getKeywods " << keywods->getKeyword(xxx) << std::endl; 19 | 20 | TokenMap &tkmap = keywods->getKeywords(); 21 | 22 | TokenMap::iterator it = tkmap.begin(); 23 | 24 | for( ; it != tkmap.end(); ++it) 25 | { 26 | std::cout<<"key:"<first <<"value:"<second< 5 | #include "../SQLExprImpl.h" 6 | #include "../statement/SQLSelect.h" 7 | #include "../../visitor/SQLASTVisitor.h" 8 | #include "../../visitor/SQLASTVisitor.h" 9 | 10 | 11 | 12 | class SQLExistsExpr : virtual public SQLExprImpl { 13 | 14 | private: 15 | //static long serialVersionUID = 1L; 16 | public: 17 | bool xnot; 18 | SQLSelect *subQuery; 19 | 20 | SQLExistsExpr(); 21 | virtual ~SQLExistsExpr(); 22 | 23 | SQLExistsExpr(SQLSelect *subQuery); 24 | 25 | SQLExistsExpr(SQLSelect *subQuery, bool xnot); 26 | 27 | bool isNot(); 28 | 29 | void setNot(bool xnot); 30 | 31 | SQLSelect *getSubQuery(); 32 | 33 | void setSubQuery(SQLSelect *subQuery); 34 | 35 | //int hashCode(); 36 | //bool equals(Object obj); 37 | protected: 38 | void accept0(SQLASTVisitor *visitor); 39 | 40 | }; 41 | typedef boost::shared_ptr SQLExistsExpr_ptr; 42 | #endif 43 | 44 | -------------------------------------------------------------------------------- /ast/expr/SQLIdentifierExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLIdentifierExpr_HEADER_H 2 | #define SQLIdentifierExpr_HEADER_H 3 | #include 4 | #include "../SQLExprImpl.h" 5 | #include "../../visitor/SQLASTVisitor.h" 6 | #include "../SQLName.h" 7 | 8 | class SQLIdentifierExpr : virtual public SQLExprImpl, virtual public SQLName { 9 | 10 | private: 11 | std::string name; 12 | 13 | std::string lowerName; 14 | 15 | public: 16 | SQLIdentifierExpr(); 17 | virtual ~SQLIdentifierExpr(); 18 | 19 | SQLIdentifierExpr(std::string &name); 20 | 21 | std::string &getSimleName(); 22 | 23 | std::string &getName(); 24 | 25 | void setName(std::string &name); 26 | 27 | std::string &getLowerName(); 28 | 29 | void setLowerName(std::string &lowerName); 30 | 31 | void output(std::string &buf); 32 | //int hashCode(); 33 | //bool equals(Object obj); 34 | 35 | protected: 36 | void accept0(SQLASTVisitor *visitor); 37 | 38 | 39 | }; 40 | typedef boost::shared_ptr SQLIdentifierExpr_ptr; 41 | 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /ast/expr/SQLPropertyExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLPropertyExpr_HEADER_H 2 | #define SQLPropertyExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "../SQLExpr.h" 8 | #include "../SQLExprImpl.h" 9 | #include "../SQLName.h" 10 | #include "../../visitor/SQLASTVisitor.h" 11 | 12 | 13 | class SQLPropertyExpr : virtual public SQLExprImpl, virtual public SQLName { 14 | 15 | private: 16 | SQLExpr *owner; 17 | std::string name; 18 | 19 | public: 20 | SQLPropertyExpr(SQLExpr *owner, std::string &name); 21 | 22 | SQLPropertyExpr(); 23 | virtual ~SQLPropertyExpr(); 24 | 25 | std::string &getSimleName(); 26 | 27 | SQLExpr *getOwner(); 28 | 29 | void setOwner(SQLExpr *owner); 30 | 31 | std::string &getName(); 32 | 33 | void setName(std::string &name); 34 | 35 | void output(std::string & buf); 36 | //int hashCode(); 37 | //bool equals(Object obj); 38 | 39 | protected: 40 | void accept0(SQLASTVisitor *visitor); 41 | 42 | 43 | }; 44 | typedef boost::shared_ptr SQLPropertyExpr_ptr; 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /visitor/ExportParameterVisitorUtils_2014_05_05.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef ExportParameterVisitorUtils_HEADER_H 3 | #define ExportParameterVisitorUtils_HEADER_H 4 | 5 | #include 6 | 7 | #include "../ast/SQLExpr.h" 8 | #include "../ast/expr/SQLBetweenExpr.h" 9 | #include "../ast/expr/SQLBinaryOpExpr.h" 10 | #include "../ast/expr/SQLCharExpr.h" 11 | #include "../ast/expr/SQLLiteralExpr.h" 12 | #include "../ast/expr/SQLNumericLiteralExpr.h" 13 | #include "../ast/expr/SQLVariantRefExpr.h" 14 | 15 | //#include "../dialect/mysql/ast/expr/MySqlBooleanExpr.h" 16 | 17 | 18 | 19 | class ExportParameterVisitorUtils { 20 | 21 | private: 22 | //SQLVariantRefExpr *theRef; 23 | 24 | public: 25 | static bool exportParamterAndAccept(std::list ¶meters, std::list &list); 26 | 27 | static SQLExpr *exportParameter(std::list ¶meters, SQLExpr *param); 28 | 29 | static void exportParameter(std::list ¶meters, SQLBinaryOpExpr *x); 30 | 31 | static void exportParameter(std::list ¶meters, SQLBetweenExpr *x); 32 | }; 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /ast/expr/SQLCaseExpr_Item.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLCaseExpr_Item_HEADER_H 2 | #define SQLCaseExpr_Item_HEADER_H 3 | 4 | #include 5 | #include 6 | #include "../SQLExpr.h" 7 | #include "../SQLExprImpl.h" 8 | #include "../../visitor/SQLASTVisitor.h" 9 | #include "../SQLObjectImpl.h" 10 | 11 | class SQLCaseExpr_Item : virtual public SQLObjectImpl { 12 | 13 | private: 14 | //static long serialVersionUID = 1L; 15 | SQLExpr *conditionExpr; 16 | SQLExpr *valueExpr; 17 | 18 | public: 19 | SQLCaseExpr_Item(); 20 | virtual ~SQLCaseExpr_Item(); 21 | 22 | SQLCaseExpr_Item(SQLExpr *conditionExpr, SQLExpr *valueExpr); 23 | 24 | SQLExpr *getConditionExpr(); 25 | 26 | void setConditionExpr(SQLExpr *conditionExpr); 27 | 28 | SQLExpr *getValueExpr(); 29 | 30 | void setValueExpr(SQLExpr *valueExpr); 31 | 32 | protected: 33 | void accept0(SQLASTVisitor *visitor); 34 | 35 | public: 36 | //int hashCode(); 37 | //bool equals(Object obj); 38 | 39 | }; 40 | 41 | typedef boost::shared_ptr SQLCaseExpr_Item_ptr; 42 | #endif 43 | 44 | -------------------------------------------------------------------------------- /deps/smhasher/MurmurHash1.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // MurmurHash1 was written by Austin Appleby, and is placed in the public 3 | // domain. The author hereby disclaims copyright to this source code. 4 | 5 | #ifndef _MURMURHASH1_H_ 6 | #define _MURMURHASH1_H_ 7 | 8 | //----------------------------------------------------------------------------- 9 | // Platform-specific functions and macros 10 | 11 | // Microsoft Visual Studio 12 | 13 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 14 | 15 | typedef unsigned char uint8_t; 16 | typedef unsigned int uint32_t; 17 | typedef unsigned __int64 uint64_t; 18 | 19 | // Other compilers 20 | 21 | #else // defined(_MSC_VER) 22 | 23 | #include 24 | 25 | #endif // !defined(_MSC_VER) 26 | 27 | //----------------------------------------------------------------------------- 28 | 29 | uint32_t MurmurHash1 ( const void * key, int len, uint32_t seed ); 30 | uint32_t MurmurHash1Aligned ( const void * key, int len, uint32_t seed ); 31 | 32 | //----------------------------------------------------------------------------- 33 | 34 | #endif // _MURMURHASH1_H_ 35 | -------------------------------------------------------------------------------- /ast/SQLCommentHint.h: -------------------------------------------------------------------------------- 1 | 2 | //import com.alibaba.druid.sql.visitor.SQLASTVisitor; 3 | 4 | #ifndef SQLCommentHint_HEADER_H 5 | #define SQLCommentHint_HEADER_H 6 | #include 7 | #include "SQLObject.h" 8 | #include "SQLObjectImpl.h" 9 | #include "SQLHint.h" 10 | #include "SQLCommentHint.h" 11 | #include "../visitor/SQLASTVisitor.h" 12 | 13 | //http://stackoverflow.com/questions/137282/how-can-you-avoid-the-diamond-of-death-in-c-when-using-multiple-inheritance 14 | class SQLCommentHint : virtual public SQLObjectImpl, virtual public SQLHint { 15 | 16 | private: 17 | std::string text; 18 | 19 | public: 20 | SQLCommentHint(); 21 | virtual ~SQLCommentHint(); 22 | 23 | SQLCommentHint(std::string &text); 24 | 25 | std::string& getText(); 26 | 27 | void setText(std::string &text); 28 | 29 | virtual std::string & getClass() 30 | { 31 | static std::string className = "SQLCommentHint"; 32 | return className; 33 | } 34 | 35 | 36 | protected: 37 | virtual void accept0(SQLASTVisitor *visitor); 38 | }; 39 | typedef boost::shared_ptr SQLCommentHint_ptr; 40 | 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /ast/expr/SQLInListExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLInListExpr_HEADER_H 2 | #define SQLInListExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | #include "../SQLExpr.h" 7 | #include "../SQLExprImpl.h" 8 | #include "../../visitor/SQLASTVisitor.h" 9 | 10 | 11 | class SQLInListExpr : virtual public SQLExprImpl{ 12 | 13 | private: 14 | //static long serialVersionUID = 1L; 15 | bool xnot; 16 | SQLExpr *expr; 17 | std::list targetList; 18 | 19 | public: 20 | SQLInListExpr(); 21 | virtual ~SQLInListExpr(); 22 | 23 | SQLInListExpr(SQLExpr *expr); 24 | 25 | SQLInListExpr(SQLExpr *expr, bool xnot); 26 | 27 | bool isNot(); 28 | 29 | void setNot(bool xnot); 30 | 31 | SQLExpr *getExpr(); 32 | 33 | void setExpr(SQLExpr *expr); 34 | 35 | std::list & getTargetList(); 36 | 37 | void setTargetList(std::list & targetList); 38 | 39 | //int hashCode(); 40 | //bool equals(Object obj); 41 | protected: 42 | void accept0(SQLASTVisitor *visitor); 43 | 44 | }; 45 | typedef boost::shared_ptr SQLInListExpr_ptr; 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /parser/CommentTest.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | public class CommentTest extends TestCase { 5 | 6 | public void test_0() throws Exception { 7 | String sql = "SELECT /*mark for picman*/ * FROM WP_ALBUM WHERE MEMBER_ID = ? AND ID IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; 8 | 9 | Lexer lexer = new Lexer(sql); 10 | for (;;) { 11 | lexer.nextToken(); 12 | Token tok = lexer.token(); 13 | 14 | if (tok == Token.IDENTIFIER) { 15 | System.out.println(tok.name() + "\t\t" + lexer.stringVal()); 16 | } else if (tok == Token.MULTI_LINE_COMMENT) { 17 | System.out.println(tok.name() + "\t\t" + lexer.stringVal()); 18 | } else { 19 | System.out.println(tok.name() + "\t\t\t" + tok.name); 20 | } 21 | 22 | if (tok == Token.EOF) { 23 | break; 24 | } 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /visitor/functions/Ascii.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Ascii.h" 3 | 4 | //Ascii *Ascii::ins = new Ascii(); 5 | //bool Ascii::_init = Ascii::init(); 6 | //Ascii::Ascii() : instance (nullptr) 7 | Ascii::Ascii() 8 | { 9 | 10 | } 11 | 12 | Ascii::~Ascii() 13 | { 14 | 15 | } 16 | 17 | Ascii * Ascii::instance() 18 | { 19 | static Ascii x; // Guaranteed to be destroyed. 20 | // Instantiated on first use. 21 | return &x; 22 | } 23 | 24 | //bool Ascii::init() 25 | //{ 26 | //if (ins == NULL) 27 | //{ 28 | //ins = new Ascii(); 29 | //} 30 | //return true; 31 | //} 32 | 33 | Object *Ascii::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 34 | if (x.getParameters().size() == 0) { 35 | return SQLEvalVisitor.EVAL_ERROR; 36 | } 37 | SQLExpr param = x.getParameters().get(0); 38 | param.accept(visitor); 39 | 40 | Object paramValue = param.getAttributes().get(EVAL_VALUE); 41 | if (paramValue == null) { 42 | return SQLEvalVisitor.EVAL_ERROR; 43 | } 44 | 45 | if (paramValue == EVAL_VALUE_NULL) { 46 | return EVAL_VALUE_NULL; 47 | } 48 | 49 | String strValue = paramValue.toString(); 50 | if (strValue.length() == 0) { 51 | return 0; 52 | } 53 | 54 | int ascii = strValue.charAt(0); 55 | return ascii; 56 | } 57 | -------------------------------------------------------------------------------- /ast/expr/SQLVariantRefExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLVariantRefExpr_HEADER_H 2 | #define SQLVariantRefExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "../SQLExpr.h" 8 | #include "../SQLExprImpl.h" 9 | #include "../../visitor/SQLASTVisitor.h" 10 | 11 | 12 | 13 | class SQLVariantRefExpr : virtual public SQLExprImpl { 14 | 15 | private: 16 | std::string name; 17 | 18 | bool global; 19 | 20 | int index; 21 | 22 | public: 23 | SQLVariantRefExpr(std::string &name); 24 | SQLVariantRefExpr(const char * x); 25 | virtual ~SQLVariantRefExpr(); 26 | 27 | SQLVariantRefExpr(std::string &name, bool global); 28 | 29 | SQLVariantRefExpr(); 30 | 31 | int getIndex(); 32 | 33 | void setIndex(int index); 34 | 35 | std::string &getName(); 36 | 37 | void setName(std::string &name); 38 | 39 | void output(std::string &buf); 40 | 41 | //int hashCode(); 42 | //bool equals(Object obj); 43 | bool isGlobal(); 44 | void setGlobal(bool global); 45 | protected: 46 | void accept0(SQLASTVisitor *visitor); 47 | 48 | 49 | }; 50 | typedef boost::shared_ptr SQLVariantRefExpr_ptr; 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /ast/expr/SQLTextLiteralExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLTextLiteralExpr.h" 2 | SQLTextLiteralExpr::SQLTextLiteralExpr(){ 3 | 4 | } 5 | SQLTextLiteralExpr::~SQLTextLiteralExpr(){ 6 | 7 | } 8 | 9 | 10 | SQLTextLiteralExpr::SQLTextLiteralExpr(std::string &theText){ 11 | 12 | text = theText; 13 | } 14 | 15 | std::string &SQLTextLiteralExpr::getText() { 16 | return text; 17 | } 18 | 19 | void SQLTextLiteralExpr::setText(std::string &theText) { 20 | text = theText; 21 | } 22 | 23 | //int SQLTextLiteralExpr::hashCode() { 24 | //final int prime = 31; 25 | //int result = 1; 26 | //result = prime * result + ((text == null) ? 0 : text.hashCode()); 27 | //return result; 28 | //} 29 | 30 | //bool SQLTextLiteralExpr::equals(Object obj) { 31 | //if (this == obj) { 32 | //return true; 33 | //} 34 | //if (obj == null) { 35 | //return false; 36 | //} 37 | //if (getClass() != obj.getClass()) { 38 | //return false; 39 | //} 40 | //SQLTextLiteralExpr other = (SQLTextLiteralExpr) obj; 41 | //if (text == null) { 42 | //if (other.text != null) { 43 | //return false; 44 | //} 45 | //} else if (!text.equals(other.text)) { 46 | //return false; 47 | //} 48 | //return true; 49 | //} 50 | 51 | -------------------------------------------------------------------------------- /ast/expr/SQLInSubQueryExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLInSubQueryExpr_HEADER_H 2 | #define SQLInSubQueryExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "../SQLExpr.h" 8 | #include "../SQLExprImpl.h" 9 | #include "../statement/SQLSelect.h" 10 | #include "../../visitor/SQLASTVisitor.h" 11 | 12 | 13 | 14 | class SQLInSubQueryExpr : virtual public SQLExprImpl { 15 | 16 | private: 17 | //static long serialVersionUID = 1L; 18 | bool xnot; 19 | SQLExpr *expr; 20 | 21 | public: 22 | SQLSelect *subQuery; 23 | 24 | SQLInSubQueryExpr(); 25 | virtual ~SQLInSubQueryExpr(); 26 | 27 | bool isNot(); 28 | 29 | void setNot(bool xnot); 30 | 31 | SQLExpr *getExpr(); 32 | 33 | void setExpr(SQLExpr *expr); 34 | 35 | SQLInSubQueryExpr(SQLSelect *select); 36 | 37 | SQLSelect *getSubQuery(); 38 | 39 | void setSubQuery(SQLSelect *subQuery); 40 | 41 | void output(std::string & buf); 42 | 43 | //int hashCode(); 44 | //bool equals(Object obj); 45 | protected: 46 | void accept0(SQLASTVisitor *visitor); 47 | 48 | 49 | }; 50 | typedef boost::shared_ptr SQLInSubQueryExpr_ptr; 51 | #endif 52 | 53 | -------------------------------------------------------------------------------- /ast/expr/SQLListExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLListExpr.h" 2 | SQLListExpr::SQLListExpr() { 3 | } 4 | 5 | SQLListExpr::~SQLListExpr() { 6 | 7 | for(std::list::iterator it = items.begin(); it != items.end(); ++it) 8 | { 9 | delete *it; 10 | } 11 | items.clear(); 12 | 13 | 14 | } 15 | std::list & SQLListExpr::getItems() { 16 | return items; 17 | } 18 | 19 | void SQLListExpr::accept0(SQLASTVisitor *visitor) { 20 | if (visitor->visit(this)) { 21 | acceptChild(visitor, items); 22 | } 23 | visitor->endVisit(this); 24 | } 25 | 26 | //int SQLListExpr::hashCode() { 27 | //final int prime = 31; 28 | //int result = 1; 29 | //result = prime * result + ((items == NULL) ? 0 : items.hashCode()); 30 | //return result; 31 | //} 32 | 33 | //bool SQLListExpr::equals(Object obj) { 34 | //if (this == obj) { 35 | //return true; 36 | //} 37 | //if (obj == NULL) { 38 | //return false; 39 | //} 40 | //if (getClass() != obj.getClass()) { 41 | //return false; 42 | //} 43 | //SQLListExpr other = (SQLListExpr) obj; 44 | //if (items == NULL) { 45 | //if (other.items != NULL) { 46 | //return false; 47 | //} 48 | //} else if (!items.equals(other.items)) { 49 | //return false; 50 | //} 51 | //return true; 52 | //} 53 | 54 | -------------------------------------------------------------------------------- /deps/smhasher/MurmurHash3.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // MurmurHash3 was written by Austin Appleby, and is placed in the public 3 | // domain. The author hereby disclaims copyright to this source code. 4 | 5 | #ifndef _MURMURHASH3_H_ 6 | #define _MURMURHASH3_H_ 7 | 8 | //----------------------------------------------------------------------------- 9 | // Platform-specific functions and macros 10 | 11 | // Microsoft Visual Studio 12 | 13 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 14 | 15 | typedef unsigned char uint8_t; 16 | typedef unsigned int uint32_t; 17 | typedef unsigned __int64 uint64_t; 18 | 19 | // Other compilers 20 | 21 | #else // defined(_MSC_VER) 22 | 23 | #include 24 | 25 | #endif // !defined(_MSC_VER) 26 | 27 | //----------------------------------------------------------------------------- 28 | 29 | void MurmurHash3_x86_32 ( const void * key, int len, uint32_t seed, void * out ); 30 | 31 | void MurmurHash3_x86_128 ( const void * key, int len, uint32_t seed, void * out ); 32 | 33 | void MurmurHash3_x64_128 ( const void * key, int len, uint32_t seed, void * out ); 34 | 35 | //----------------------------------------------------------------------------- 36 | 37 | #endif // _MURMURHASH3_H_ 38 | -------------------------------------------------------------------------------- /visitor/ParameterizedOutputVisitor.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef ParameterizedOutputVisitor_HEADER_H 3 | #define ParameterizedOutputVisitor_HEADER_H 4 | 5 | #include 6 | 7 | //import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; 8 | //import com.alibaba.druid.sql.ast.expr.SQLCharExpr; 9 | //import com.alibaba.druid.sql.ast.expr.SQLInListExpr; 10 | //import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr; 11 | //import com.alibaba.druid.sql.ast.expr.SQLNCharExpr; 12 | //import com.alibaba.druid.sql.ast.expr.SQLNullExpr; 13 | //import com.alibaba.druid.sql.ast.expr.SQLNumberExpr; 14 | 15 | class ParameterizedOutputVisitor : virtual public SQLASTOutputVisitor, virtual public ParameterizedVisitor { 16 | 17 | private: 18 | int replaceCount; 19 | 20 | public: 21 | ParameterizedOutputVisitor(); 22 | virtual ~ParameterizedOutputVisitor(); 23 | 24 | //ParameterizedOutputVisitor(Appendable *appender); 25 | 26 | int getReplaceCount(); 27 | 28 | void incrementReplaceCunt(); 29 | 30 | bool visit(SQLInListExpr *x); 31 | 32 | bool visit(SQLBinaryOpExpr *x); 33 | 34 | bool visit(SQLIntegerExpr *x); 35 | 36 | bool visit(SQLNumberExpr *x); 37 | 38 | bool visit(SQLCharExpr *x); 39 | 40 | bool visit(SQLNCharExpr *x); 41 | 42 | bool visit(SQLNullExpr *x); 43 | 44 | }; 45 | #endif 46 | -------------------------------------------------------------------------------- /ast/expr/SQLBinaryOpExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLBinaryOpExpr_HEADER_H 2 | #define SQLBinaryOpExpr_HEADER_H 3 | 4 | #include 5 | #include "../SQLExpr.h" 6 | #include "../SQLExprImpl.h" 7 | #include "../../visitor/SQLASTVisitor.h" 8 | 9 | #include "SQLBinaryOperator.h" 10 | 11 | class SQLBinaryOpExpr : virtual public SQLExprImpl { 12 | 13 | private: 14 | //static long serialVersionUID = 1L; 15 | SQLExpr *left; 16 | SQLExpr *right; 17 | SQLBinaryOperator *xoperator; 18 | 19 | public: 20 | SQLBinaryOpExpr(); 21 | virtual ~SQLBinaryOpExpr(); 22 | 23 | SQLBinaryOpExpr(SQLExpr *left, SQLBinaryOperator *xoperator, SQLExpr *right); 24 | 25 | SQLBinaryOpExpr(SQLExpr *left, SQLExpr *right, SQLBinaryOperator *xoperator); 26 | 27 | SQLExpr *getLeft(); 28 | 29 | void setLeft(SQLExpr *left); 30 | 31 | SQLExpr *getRight(); 32 | 33 | void setRight(SQLExpr *right); 34 | 35 | SQLBinaryOperator *getOperator(); 36 | 37 | void setOperator(SQLBinaryOperator *xoperator); 38 | 39 | //int hashCode(); 40 | //bool equals(Object obj); 41 | 42 | protected: 43 | void accept0(SQLASTVisitor *visitor); 44 | 45 | 46 | }; 47 | typedef boost::shared_ptr SQLBinaryOpExpr_ptr; 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /ast/SQLDataTypeImpl.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SQLDataTypeImpl_HEADER_H 3 | #define SQLDataTypeImpl_HEADER_H 4 | //import com.alibaba.druid.sql.visitor.SQLASTVisitor; 5 | #include 6 | #include 7 | #include 8 | #include "Object.h" 9 | #include "SQLObjectImpl.h" 10 | #include "SQLDataType.h" 11 | #include "SQLExpr.h" 12 | #include "../visitor/SQLASTVisitor.h" 13 | 14 | class SQLDataTypeImpl : virtual public SQLObjectImpl, virtual public SQLDataType { 15 | 16 | protected: 17 | std::string name; 18 | std::list arguments; 19 | 20 | void accept0(SQLASTVisitor *visitor); 21 | int listHashcode(); 22 | int stringHashcode(std::string & x); 23 | 24 | public: 25 | SQLDataTypeImpl(); 26 | virtual ~SQLDataTypeImpl(); 27 | SQLDataTypeImpl(std::string &name); 28 | std::string &getName(); 29 | 30 | void setName(std::string &name); 31 | 32 | std::list& getArguments(); 33 | 34 | int hashCode(); 35 | 36 | bool equals(Object *obj); 37 | 38 | 39 | virtual std::string & getClass() 40 | { 41 | static std::string className = "SQLDataTypeImpl"; 42 | return className; 43 | } 44 | 45 | 46 | }; 47 | typedef boost::shared_ptr SQLDataTypeImpl_ptr; 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /deps/smhasher/AvalancheTest.cpp: -------------------------------------------------------------------------------- 1 | #include "AvalancheTest.h" 2 | 3 | //----------------------------------------------------------------------------- 4 | 5 | void PrintAvalancheDiagram ( int x, int y, int reps, double scale, int * bins ) 6 | { 7 | const char * symbols = ".123456789X"; 8 | 9 | for(int i = 0; i < y; i++) 10 | { 11 | printf("["); 12 | for(int j = 0; j < x; j++) 13 | { 14 | int k = (y - i) -1; 15 | 16 | int bin = bins[k + (j*y)]; 17 | 18 | double b = double(bin) / double(reps); 19 | b = fabs(b*2 - 1); 20 | 21 | b *= scale; 22 | 23 | int s = (int)floor(b*10); 24 | 25 | if(s > 10) s = 10; 26 | if(s < 0) s = 0; 27 | 28 | printf("%c",symbols[s]); 29 | } 30 | 31 | printf("]\n"); 32 | } 33 | } 34 | 35 | //---------------------------------------------------------------------------- 36 | 37 | double maxBias ( std::vector & counts, int reps ) 38 | { 39 | double worst = 0; 40 | 41 | for(int i = 0; i < (int)counts.size(); i++) 42 | { 43 | double c = double(counts[i]) / double(reps); 44 | 45 | double d = fabs(c * 2 - 1); 46 | 47 | if(d > worst) 48 | { 49 | worst = d; 50 | } 51 | } 52 | 53 | return worst; 54 | } 55 | 56 | //----------------------------------------------------------------------------- 57 | -------------------------------------------------------------------------------- /ast/expr/SQLBetweenExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLBetweenExpr_HEADER_H 2 | #define SQLBetweenExpr_HEADER_H 3 | 4 | #include 5 | #include "../SQLExpr.h" 6 | #include "../SQLExprImpl.h" 7 | #include "../../visitor/SQLASTVisitor.h" 8 | 9 | class SQLBetweenExpr : virtual public SQLExprImpl { 10 | 11 | private: 12 | //static long serialVersionUID = 1L; 13 | bool xnot; 14 | public: 15 | SQLExpr *testExpr; 16 | SQLExpr *beginExpr; 17 | SQLExpr *endExpr; 18 | 19 | SQLBetweenExpr(); 20 | virtual ~SQLBetweenExpr(); 21 | 22 | SQLBetweenExpr(SQLExpr *testExpr, SQLExpr *beginExpr, SQLExpr *endExpr); 23 | 24 | SQLBetweenExpr(SQLExpr *testExpr, bool xnot, SQLExpr *beginExpr, SQLExpr *endExpr); 25 | 26 | 27 | SQLExpr *getTestExpr(); 28 | 29 | void setTestExpr(SQLExpr *testExpr); 30 | 31 | bool isNot(); 32 | 33 | void setNot(bool xnot); 34 | 35 | SQLExpr *getBeginExpr(); 36 | 37 | void setBeginExpr(SQLExpr *beginExpr); 38 | 39 | SQLExpr *getEndExpr(); 40 | 41 | void setEndExpr(SQLExpr *endExpr); 42 | 43 | //int hashCode(); 44 | //bool equals(Object obj); 45 | protected: 46 | void accept0(SQLASTVisitor *visitor); 47 | }; 48 | typedef boost::shared_ptr SQLBetweenExpr_ptr; 49 | #endif 50 | 51 | -------------------------------------------------------------------------------- /visitor/functions/Lpad.cpp: -------------------------------------------------------------------------------- 1 | #include "Lpad.h" 2 | Lpad::~Lpad() 3 | { 4 | 5 | } 6 | 7 | Lpad * Lpad::instance() 8 | { 9 | static Lpad x; 10 | return &x; 11 | } 12 | 13 | Object *Lpad::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 14 | List params = x.getParameters(); 15 | int paramSize = params.size(); 16 | if (paramSize != 3) { 17 | return SQLEvalVisitor.EVAL_ERROR; 18 | } 19 | 20 | SQLExpr param0 = params.get(0); 21 | SQLExpr param1 = params.get(1); 22 | SQLExpr param2 = params.get(2); 23 | 24 | param0.accept(visitor); 25 | param1.accept(visitor); 26 | param2.accept(visitor); 27 | 28 | Object param0Value = param0.getAttributes().get(EVAL_VALUE); 29 | Object param1Value = param1.getAttributes().get(EVAL_VALUE); 30 | Object param2Value = param2.getAttributes().get(EVAL_VALUE); 31 | if (param0Value == null || param1Value == null || param2Value == null) { 32 | return SQLEvalVisitor.EVAL_ERROR; 33 | } 34 | 35 | std::string strValue0 = param0Value.toString(); 36 | int len = ((Number) param1Value).intValue(); 37 | std::string strValue1 = param2Value.toString(); 38 | 39 | std::string result = strValue0; 40 | if (result.length() > len) { 41 | return result.substring(0, len); 42 | } 43 | 44 | while (result.length() < len) { 45 | result = strValue1 + result; 46 | } 47 | 48 | return result; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /ast/expr/SQLMethodInvokeExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLMethodInvokeExpr_HEADER_H 2 | #define SQLMethodInvokeExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | #include "../SQLExpr.h" 7 | #include "../SQLExprImpl.h" 8 | #include "../../visitor/SQLASTVisitor.h" 9 | 10 | 11 | class SQLMethodInvokeExpr : virtual public SQLExprImpl { 12 | 13 | private: 14 | //static long serialVersionUID = 1L; 15 | std::string methodName; 16 | SQLExpr *owner; 17 | std::list parameters; 18 | 19 | public: 20 | SQLMethodInvokeExpr(); 21 | virtual ~SQLMethodInvokeExpr(); 22 | 23 | SQLMethodInvokeExpr(std::string &methodName); 24 | 25 | SQLMethodInvokeExpr(std::string &methodName, SQLExpr *owner); 26 | 27 | std::string &getMethodName(); 28 | 29 | void setMethodName(std::string &methodName); 30 | 31 | SQLExpr *getOwner(); 32 | 33 | void setOwner(SQLExpr *owner); 34 | 35 | std::list & getParameters(); 36 | 37 | void addParameter(SQLExpr *param); 38 | 39 | void output(std::string & buf); 40 | 41 | //int hashCode(); 42 | //bool equals(Object obj); 43 | protected: 44 | void accept0(SQLASTVisitor *visitor); 45 | 46 | //void accept0(OracleASTVisitor *visitor); 47 | 48 | }; 49 | typedef boost::shared_ptr SQLMethodInvokeExpr_ptr; 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /visitor/functions/Locate.cpp: -------------------------------------------------------------------------------- 1 | #include "Locate.h" 2 | Locate::~Locate() 3 | { 4 | 5 | } 6 | 7 | Locate * Locate::instance() 8 | { 9 | static Locate x; 10 | return &x; 11 | } 12 | 13 | Object *Locate::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 14 | List params = x.getParameters(); 15 | int paramSize = params.size(); 16 | if (paramSize != 2 && paramSize != 3) { 17 | return SQLEvalVisitor.EVAL_ERROR; 18 | } 19 | 20 | SQLExpr param0 = params.get(0); 21 | SQLExpr param1 = params.get(1); 22 | SQLExpr param2 = null; 23 | 24 | param0.accept(visitor); 25 | param1.accept(visitor); 26 | if (paramSize == 3) { 27 | param2 = params.get(2); 28 | param2.accept(visitor); 29 | } 30 | 31 | Object param0Value = param0.getAttributes().get(EVAL_VALUE); 32 | Object param1Value = param1.getAttributes().get(EVAL_VALUE); 33 | if (param0Value == null || param1Value == null) { 34 | return SQLEvalVisitor.EVAL_ERROR; 35 | } 36 | 37 | std::string strValue0 = param0Value.toString(); 38 | std::string strValue1 = param1Value.toString(); 39 | 40 | if (paramSize == 2) { 41 | int result = strValue1.indexOf(strValue0) + 1; 42 | return result; 43 | } 44 | 45 | Object param2Value = param2.getAttributes().get(EVAL_VALUE); 46 | int start = ((Number) param2Value).intValue(); 47 | 48 | int result = strValue1.indexOf(strValue0, start + 1) + 1; 49 | return result; 50 | } 51 | 52 | 53 | -------------------------------------------------------------------------------- /ast/expr/SQLCaseExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLCaseExpr_HEADER_H 2 | #define SQLCaseExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | #include "../SQLExpr.h" 7 | #include "../SQLExprImpl.h" 8 | #include "../../visitor/SQLASTVisitor.h" 9 | #include "../SQLObjectImpl.h" 10 | 11 | #include "SQLCaseExpr_Item.h" 12 | 13 | class SQLCaseExpr : virtual public SQLExprImpl { 14 | 15 | 16 | private: 17 | //static long serialVersionUID = 1L; 18 | std::list items; 19 | SQLExpr *valueExpr; 20 | SQLExpr *elseExpr; 21 | 22 | public: 23 | SQLCaseExpr(); 24 | virtual ~SQLCaseExpr(); 25 | 26 | SQLExpr *getValueExpr(); 27 | 28 | void setValueExpr(SQLExpr *valueExpr); 29 | 30 | SQLExpr *getElseExpr(); 31 | 32 | void setElseExpr(SQLExpr *elseExpr); 33 | 34 | std::list & getItems(); 35 | 36 | void addItem(SQLCaseExpr_Item *item); 37 | 38 | protected: 39 | void accept0(SQLASTVisitor *visitor); 40 | void acceptChild(SQLASTVisitor *visitor, std::list &children); 41 | void acceptChild(SQLASTVisitor *visitor, SQLExpr * children); 42 | public: 43 | //int hashCode(); 44 | //bool equals(Object obj); 45 | 46 | }; 47 | typedef boost::shared_ptr SQLCaseExpr_ptr; 48 | typedef boost::shared_ptr SQLCaseExpr_Item_ptr; 49 | #endif 50 | 51 | -------------------------------------------------------------------------------- /visitor/ExportParameterVisitorUtils.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef ExportParameterVisitorUtils_HEADER_H 3 | #define ExportParameterVisitorUtils_HEADER_H 4 | 5 | #include 6 | 7 | #include "../ast/SQLExpr.h" 8 | #include "../ast/expr/SQLBetweenExpr.h" 9 | #include "../ast/expr/SQLBinaryOpExpr.h" 10 | #include "../ast/expr/SQLCharExpr.h" 11 | #include "../ast/expr/SQLLiteralExpr.h" 12 | #include "../ast/expr/SQLNumericLiteralExpr.h" 13 | #include "../ast/expr/SQLVariantRefExpr.h" 14 | 15 | //#include "../dialect/mysql/ast/expr/MySqlBooleanExpr.h" 16 | 17 | 18 | 19 | class ExportParameterVisitorUtils { 20 | 21 | private: 22 | //SQLVariantRefExpr *theRef; 23 | 24 | public: 25 | //static bool exportParamterAndAccept(std::list ¶meters, std::list &list); 26 | 27 | //static SQLExpr *exportParameter(std::list ¶meters, SQLExpr *param); 28 | 29 | //static void exportParameter(std::list ¶meters, SQLBinaryOpExpr *x); 30 | 31 | //static void exportParameter(std::list ¶meters, SQLBetweenExpr *x); 32 | 33 | 34 | static bool exportParamterAndAccept(int &size, std::list &list); 35 | 36 | static SQLExpr *exportParameter(int &size, SQLExpr *param); 37 | 38 | static void exportParameter(int &size, SQLBinaryOpExpr *x); 39 | 40 | static void exportParameter(int &size, SQLBetweenExpr *x); 41 | 42 | 43 | 44 | }; 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /ast/expr/SQLNotExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLNotExpr.h" 2 | SQLNotExpr::SQLNotExpr(){ 3 | 4 | } 5 | SQLNotExpr::~SQLNotExpr(){ 6 | if (expr != NULL) 7 | { 8 | delete expr; 9 | expr = NULL; 10 | } 11 | 12 | } 13 | SQLNotExpr::SQLNotExpr(SQLExpr * theExpr){ 14 | 15 | expr = theExpr; 16 | } 17 | 18 | SQLExpr *SQLNotExpr::getExpr() { 19 | return expr; 20 | } 21 | 22 | void SQLNotExpr::setExpr(SQLExpr *theExpr) { 23 | expr = theExpr; 24 | } 25 | 26 | void SQLNotExpr::output(std::string & buf) { 27 | buf += " NOT "; 28 | expr->output(buf); 29 | } 30 | 31 | void SQLNotExpr::accept0(SQLASTVisitor *visitor) { 32 | if (visitor->visit(this)) { 33 | acceptChild(visitor, expr); 34 | } 35 | 36 | visitor->endVisit(this); 37 | } 38 | 39 | //int hashCode() { 40 | //final int prime = 31; 41 | //int result = 1; 42 | //result = prime * result + ((expr == NULL) ? 0 : expr.hashCode()); 43 | //return result; 44 | //} 45 | 46 | //bool equals(Object obj) { 47 | //if (this == obj) { 48 | //return true; 49 | //} 50 | //if (obj == NULL) { 51 | //return false; 52 | //} 53 | //if (getClass() != obj.getClass()) { 54 | //return false; 55 | //} 56 | //SQLNotExpr other = (SQLNotExpr) obj; 57 | //if (expr == NULL) { 58 | //if (other.expr != NULL) { 59 | //return false; 60 | //} 61 | //} else if (!expr.equals(other.expr)) { 62 | //return false; 63 | //} 64 | //return true; 65 | //} 66 | 67 | -------------------------------------------------------------------------------- /ast/expr/SQLCaseExpr_Item.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLCaseExpr_Item.h" 2 | 3 | SQLCaseExpr_Item::SQLCaseExpr_Item(){ 4 | 5 | } 6 | 7 | SQLCaseExpr_Item::~SQLCaseExpr_Item(){ 8 | 9 | 10 | if (conditionExpr != NULL) 11 | { 12 | 13 | delete conditionExpr; 14 | conditionExpr = NULL; 15 | } 16 | 17 | if (valueExpr != NULL) 18 | { 19 | 20 | delete valueExpr; 21 | valueExpr = NULL; 22 | } 23 | 24 | } 25 | SQLCaseExpr_Item::SQLCaseExpr_Item(SQLExpr *theConditionExpr, SQLExpr * theValueExpr){ 26 | 27 | setConditionExpr(theConditionExpr); 28 | setValueExpr(theValueExpr); 29 | 30 | 31 | } 32 | 33 | SQLExpr *SQLCaseExpr_Item::getConditionExpr() { 34 | return conditionExpr; 35 | } 36 | 37 | void SQLCaseExpr_Item::setConditionExpr(SQLExpr *theConditionExpr) { 38 | if (theConditionExpr != NULL) { 39 | theConditionExpr->setParent(this); 40 | } 41 | conditionExpr = theConditionExpr; 42 | } 43 | 44 | SQLExpr *SQLCaseExpr_Item::getValueExpr() { 45 | return valueExpr; 46 | } 47 | 48 | void SQLCaseExpr_Item::setValueExpr(SQLExpr *theValueExpr) { 49 | if (theValueExpr != NULL) { 50 | theValueExpr->setParent(this); 51 | } 52 | valueExpr = theValueExpr; 53 | } 54 | 55 | void SQLCaseExpr_Item::accept0(SQLASTVisitor *visitor) { 56 | if (visitor->visit(this)) { 57 | acceptChild(visitor, conditionExpr); 58 | acceptChild(visitor, valueExpr); 59 | } 60 | visitor->endVisit(this); 61 | } 62 | 63 | -------------------------------------------------------------------------------- /deps/smhasher/MurmurHash2.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // MurmurHash2 was written by Austin Appleby, and is placed in the public 3 | // domain. The author hereby disclaims copyright to this source code. 4 | 5 | #ifndef _MURMURHASH2_H_ 6 | #define _MURMURHASH2_H_ 7 | 8 | //----------------------------------------------------------------------------- 9 | // Platform-specific functions and macros 10 | 11 | // Microsoft Visual Studio 12 | 13 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 14 | 15 | typedef unsigned char uint8_t; 16 | typedef unsigned int uint32_t; 17 | typedef unsigned __int64 uint64_t; 18 | 19 | // Other compilers 20 | 21 | #else // defined(_MSC_VER) 22 | 23 | #include 24 | 25 | #endif // !defined(_MSC_VER) 26 | 27 | //----------------------------------------------------------------------------- 28 | 29 | uint32_t MurmurHash2 ( const void * key, int len, uint32_t seed ); 30 | uint64_t MurmurHash64A ( const void * key, int len, uint64_t seed ); 31 | uint64_t MurmurHash64B ( const void * key, int len, uint64_t seed ); 32 | uint32_t MurmurHash2A ( const void * key, int len, uint32_t seed ); 33 | uint32_t MurmurHashNeutral2 ( const void * key, int len, uint32_t seed ); 34 | uint32_t MurmurHashAligned2 ( const void * key, int len, uint32_t seed ); 35 | 36 | //----------------------------------------------------------------------------- 37 | 38 | #endif // _MURMURHASH2_H_ 39 | 40 | -------------------------------------------------------------------------------- /ast/complex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * C++ Program to Implement Complex Numbers using Classes 3 | */ 4 | #include 5 | using namespace std; 6 | 7 | class Complex 8 | { 9 | private: 10 | int real; 11 | int imag; 12 | 13 | public: 14 | 15 | Complex(int r = 0, int i = 0): real(r), imag(i) {}; 16 | void setComplex(void) 17 | { 18 | cout << "Enter the real and imaginary parts : "; 19 | cin >> this->real; 20 | cin >> this->imag; 21 | } 22 | 23 | Complex add(const Complex& c) 24 | { 25 | Complex comp; 26 | comp.real = this->real + c.real; 27 | comp.imag = this->imag + c.imag; 28 | return comp; 29 | } 30 | 31 | Complex subtract(const Complex& c) 32 | { 33 | Complex comp; 34 | comp.real = this->real - c.real; 35 | comp.imag = this->imag - c.imag; 36 | return comp; 37 | } 38 | 39 | void printComplex(void) 40 | { 41 | cout << "Real : " << this->real << endl 42 | << "Imaginary : " << this->imag << endl; 43 | } 44 | }; 45 | 46 | 47 | int main() 48 | { 49 | Complex a, b, c, d; 50 | cout << "Setting first complex number " << endl; 51 | a.setComplex(); 52 | cout << "Setting second complex number " << endl; 53 | b.setComplex(); 54 | 55 | /* Adding two complex numbers */ 56 | cout << "Addition of a and b : " << endl; 57 | c = a.add(b); 58 | c.printComplex(); 59 | 60 | /* Subtracting two complex numbers */ 61 | 62 | cout << "Subtraction of a and b : " << endl; 63 | d = a.subtract(b); 64 | d.printComplex(); 65 | 66 | } 67 | 68 | -------------------------------------------------------------------------------- /parser/OdpsSelectParser.cpp: -------------------------------------------------------------------------------- 1 | #include "OdpsSelectParser.h" 2 | OdpsSelectParser::~OdpsSelectParser() 3 | { 4 | 5 | } 6 | OdpsSelectParser::OdpsSelectParser(SQLExprParser *theExprParser) 7 | : 8 | SQLSelectParser(theExprParser) 9 | //, exprParser(theExprParser) 10 | { 11 | //super(exprParser->getLexer()); 12 | //exprParser = exprParser; 13 | } 14 | 15 | SQLSelectItem *OdpsSelectParser::parseSelectItem() { 16 | SQLExpr *theExpr; 17 | if (lexer->getToken() == IDENTIFIER) { 18 | theExpr = new SQLIdentifierExpr(lexer->getStringVal()); 19 | lexer->nextTokenComma(); 20 | 21 | if (lexer->getToken() != COMMA) { 22 | theExpr = this->exprParser->primaryRest(theExpr); 23 | theExpr = this->exprParser->exprRest(theExpr); 24 | } 25 | } else { 26 | theExpr = expr(); 27 | } 28 | 29 | if (lexer->getToken() == AS) { 30 | lexer->nextToken(); 31 | 32 | if (lexer->getToken() == LEFTPAREN) { 33 | lexer->nextToken(); 34 | 35 | OdpsUDTFSQLSelectItem *selectItem = new OdpsUDTFSQLSelectItem(); 36 | 37 | selectItem->setExpr(theExpr); 38 | 39 | for (;;) { 40 | std::string alias = lexer->getStringVal(); 41 | lexer->nextToken(); 42 | 43 | selectItem->getAliasList().push_back(alias); 44 | 45 | if (lexer->getToken() == COMMA) { 46 | lexer->nextToken(); 47 | continue; 48 | } 49 | break; 50 | } 51 | 52 | accept(RPAREN); 53 | 54 | return selectItem; 55 | } 56 | } 57 | 58 | std::string alias = as(); 59 | 60 | return new SQLSelectItem(theExpr, alias); 61 | } 62 | -------------------------------------------------------------------------------- /ast/expr/SQLAggregateExpr.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLAggregateExpr_HEADER_H 2 | #define SQLAggregateExpr_HEADER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "../SQLExpr.h" 8 | #include "../SQLExprImpl.h" 9 | #include "../SQLOver.h" 10 | #include "../../visitor/SQLASTVisitor.h" 11 | 12 | class SQLAggregateExpr : virtual public SQLExprImpl { 13 | 14 | public: 15 | 16 | enum Option { 17 | DISTINCT, ALL, UNIQUE 18 | }; 19 | 20 | protected: 21 | std::string methodName; 22 | Option option; 23 | std::list arguments; 24 | SQLOver *over; 25 | void acceptChild(SQLASTVisitor *visitor, SQLOver * children); 26 | void acceptChild(SQLASTVisitor *visitor, std::list &children); 27 | 28 | public: 29 | SQLAggregateExpr(std::string &methodName); 30 | virtual ~SQLAggregateExpr(); 31 | 32 | SQLAggregateExpr(std::string &methodName, Option option); 33 | 34 | std::string &getMethodName(); 35 | 36 | void setMethodName(std::string &methodName); 37 | 38 | Option getOption(); 39 | 40 | void setOption(Option option); 41 | 42 | std::list & getArguments(); 43 | 44 | SQLOver *getOver(); 45 | 46 | void setOver(SQLOver *over); 47 | 48 | protected: 49 | void accept0(SQLASTVisitor *visitor); 50 | 51 | public: 52 | //int hashCode(); 53 | 54 | //bool equals(Object obj); 55 | }; 56 | typedef boost::shared_ptr SQLAggregateExpr_ptr; 57 | 58 | #endif 59 | 60 | -------------------------------------------------------------------------------- /ast/expr/SQLSomeExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLSomeExpr.h" 2 | SQLSomeExpr::SQLSomeExpr(){ 3 | 4 | } 5 | 6 | SQLSomeExpr::~SQLSomeExpr(){ 7 | if (subQuery != NULL) 8 | { 9 | delete subQuery; 10 | subQuery = NULL; 11 | 12 | } 13 | } 14 | SQLSomeExpr::SQLSomeExpr(SQLSelect * theSelect){ 15 | 16 | subQuery = theSelect; 17 | } 18 | 19 | SQLSelect *SQLSomeExpr::getSubQuery() { 20 | return subQuery; 21 | } 22 | 23 | void SQLSomeExpr::setSubQuery(SQLSelect * theSubQuery) { 24 | subQuery = theSubQuery; 25 | } 26 | 27 | void SQLSomeExpr::output(std::string & buf) { 28 | subQuery->output(buf); 29 | } 30 | 31 | void SQLSomeExpr::accept0(SQLASTVisitor *visitor) { 32 | if (visitor->visit(this)) { 33 | acceptChild(visitor, subQuery); 34 | } 35 | 36 | visitor->endVisit(this); 37 | } 38 | 39 | //int SQLSomeExpr::hashCode() { 40 | //final int prime = 31; 41 | //int result = 1; 42 | //result = prime * result + ((subQuery == null) ? 0 : subQuery.hashCode()); 43 | //return result; 44 | //} 45 | 46 | //bool SQLSomeExpr::equals(Object obj) { 47 | //if (this == obj) { 48 | //return true; 49 | //} 50 | //if (obj == null) { 51 | //return false; 52 | //} 53 | //if (getClass() != obj.getClass()) { 54 | //return false; 55 | //} 56 | //SQLSomeExpr other = (SQLSomeExpr) obj; 57 | //if (subQuery == null) { 58 | //if (other.subQuery != null) { 59 | //return false; 60 | //} 61 | //} else if (!subQuery.equals(other.subQuery)) { 62 | //return false; 63 | //} 64 | //return true; 65 | //} 66 | 67 | -------------------------------------------------------------------------------- /visitor/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | #CFLAGS?= -pedantic -O2 -Wall -DNEBUG -W 4 | CFLAGS?= -pedantic -O0 -W -DDEBUG -g 5 | CC = g++ 6 | 7 | #INCLUDE = -I/home/aa/ssdb/api/cpp 8 | 9 | all: test 10 | 11 | IllegalStateException.o: IllegalStateException.cpp 12 | g++ $(CXXFLAGS) $(INCLUDE) -DTEST_JSON -c $^ -o $@ 13 | 14 | NotAllowCommentException.o: NotAllowCommentException.cpp 15 | g++ $(CXXFLAGS) $(INCLUDE) -DTEST_JSON -c $^ -o $@ 16 | 17 | ExportParameterVisitorUtils.o: ExportParameterVisitorUtils.cpp 18 | g++ $(CXXFLAGS) $(INCLUDE) -c $^ -o $@ 19 | 20 | 21 | NumberFormatException.o: NumberFormatException.cpp 22 | g++ $(CXXFLAGS) $(INCLUDE) -c $^ -o $@ 23 | 24 | 25 | x.o: x.cpp 26 | g++ $(CXXFLAGS) $(INCLUDE) -c $^ -o $@ 27 | 28 | test: x.o ExportParameterVisitorUtils.o 29 | g++ $^ -o $@ 30 | 31 | test_Lexer: Lexer_test.o \ 32 | Lexer.o \ 33 | CharTypes.o \ 34 | Keywords.o \ 35 | IllegalStateException.o \ 36 | NotAllowCommentException.o \ 37 | ParserException.o \ 38 | NumberFormatException.o \ 39 | LayoutCharacters.o 40 | g++ $^ -o $@ 41 | 42 | 43 | test_SQLParser: Lexer.o \ 44 | CharTypes.o \ 45 | Keywords.o \ 46 | IllegalStateException.o \ 47 | NotAllowCommentException.o \ 48 | ParserException.o \ 49 | LayoutCharacters.o \ 50 | SQLParser.o \ 51 | SQLExprParser.o \ 52 | SQLSelectParser.o \ 53 | SQLStatementParser.o \ 54 | SQLDDLParser.o \ 55 | OdpsSelectParser.o \ 56 | SQLCreateTableParser.o \ 57 | NumberFormatException.o \ 58 | SQLParser_test.o 59 | g++ $^ -o $@ 60 | 61 | 62 | clean: 63 | rm -rf *.o 64 | 65 | cleanObj: 66 | rm -rf *.o 67 | -------------------------------------------------------------------------------- /ast/expr/SQLAllExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLAllExpr.h" 2 | 3 | SQLAllExpr::SQLAllExpr(){ 4 | 5 | } 6 | SQLAllExpr::~SQLAllExpr(){ 7 | if (subQuery != NULL) 8 | { 9 | delete subQuery; 10 | subQuery = NULL; 11 | 12 | } 13 | } 14 | SQLAllExpr::SQLAllExpr(SQLSelect * theSelect){ 15 | 16 | subQuery = theSelect; 17 | } 18 | 19 | SQLSelect *SQLAllExpr::getSubQuery() { 20 | return subQuery; 21 | } 22 | 23 | void SQLAllExpr::setSubQuery(SQLSelect *theSubQuery) { 24 | subQuery = theSubQuery; 25 | } 26 | 27 | void SQLAllExpr::output(std::string & buf) { 28 | //this.subQuery.output(buf); 29 | subQuery->output(buf); 30 | } 31 | 32 | void SQLAllExpr::accept0(SQLASTVisitor *visitor) { 33 | if (visitor->visit(this)) { 34 | acceptChild(visitor, subQuery); 35 | } 36 | 37 | visitor->endVisit(this); 38 | } 39 | 40 | //int SQLAllExpr::hashCode() { 41 | //final int prime = 31; 42 | //int result = 1; 43 | //result = prime * result + ((subQuery == null) ? 0 : subQuery.hashCode()); 44 | //return result; 45 | //} 46 | 47 | //bool SQLAllExpr::equals(Object obj) { 48 | //if (this == obj) { 49 | //return true; 50 | //} 51 | //if (obj == null) { 52 | //return false; 53 | //} 54 | //if (getClass() != obj.getClass()) { 55 | //return false; 56 | //} 57 | //SQLAllExpr other = (SQLAllExpr) obj; 58 | //if (subQuery == null) { 59 | //if (other.subQuery != null) { 60 | //return false; 61 | //} 62 | //} else if (!subQuery.equals(other.subQuery)) { 63 | //return false; 64 | //} 65 | //return true; 66 | //} 67 | 68 | -------------------------------------------------------------------------------- /ast/expr/SQLAnyExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLAnyExpr.h" 2 | 3 | SQLAnyExpr::SQLAnyExpr(){ 4 | 5 | } 6 | 7 | SQLAnyExpr::~SQLAnyExpr(){ 8 | if (subQuery != NULL) 9 | { 10 | delete subQuery; 11 | subQuery = NULL; 12 | 13 | } 14 | } 15 | SQLAnyExpr::SQLAnyExpr(SQLSelect *theSelect){ 16 | 17 | subQuery = theSelect; 18 | } 19 | 20 | SQLSelect *SQLAnyExpr::getSubQuery() { 21 | return subQuery; 22 | } 23 | 24 | void SQLAnyExpr::setSubQuery(SQLSelect * theSubQuery) { 25 | subQuery = theSubQuery; 26 | } 27 | 28 | void SQLAnyExpr::output(std::string & buf) { 29 | //this.subQuery.output(buf); 30 | subQuery->output(buf); 31 | } 32 | 33 | void SQLAnyExpr::accept0(SQLASTVisitor *visitor) { 34 | if (visitor->visit(this)) { 35 | acceptChild(visitor, subQuery); 36 | } 37 | 38 | visitor->endVisit(this); 39 | } 40 | 41 | //int SQLAnyExpr::hashCode() { 42 | //final int prime = 31; 43 | //int result = 1; 44 | //result = prime * result + ((subQuery == null) ? 0 : subQuery.hashCode()); 45 | //return result; 46 | //} 47 | 48 | //bool SQLAnyExpr::equals(Object obj) { 49 | //if (this == obj) { 50 | //return true; 51 | //} 52 | //if (obj == null) { 53 | //return false; 54 | //} 55 | //if (getClass() != obj.getClass()) { 56 | //return false; 57 | //} 58 | //SQLAnyExpr other = (SQLAnyExpr) obj; 59 | //if (subQuery == null) { 60 | //if (other.subQuery != null) { 61 | //return false; 62 | //} 63 | //} else if (!subQuery.equals(other.subQuery)) { 64 | //return false; 65 | //} 66 | //return true; 67 | //} 68 | 69 | -------------------------------------------------------------------------------- /deps/xxhash/Makefile: -------------------------------------------------------------------------------- 1 | # ################################################################ 2 | # xxHash Makefile 3 | # Copyright (C) Yann Collet 2012-2014 4 | # GPL v2 License 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License along 17 | # with this program; if not, write to the Free Software Foundation, Inc., 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | # 20 | # You can contact the author at : 21 | # - xxHash source repository : http://code.google.com/p/xxhash/ 22 | # ################################################################ 23 | # xxHash.exe : benchmark program, to demonstrate xxHash speed 24 | # ################################################################ 25 | 26 | CC=gcc 27 | CFLAGS=-I. -std=c99 -Wall -W -Wundef -Wno-implicit-function-declaration 28 | 29 | OS := $(shell uname) 30 | ifeq ($(OS),Linux) 31 | EXT = 32 | else 33 | EXT =.exe 34 | endif 35 | 36 | default: xxHash 37 | 38 | all: xxHash 39 | 40 | xxHash: xxhash.c bench.c 41 | $(CC) -O2 $(CFLAGS) $^ -o $@$(EXT) 42 | 43 | clean: 44 | rm -f core *.o xxHash$(EXT) 45 | -------------------------------------------------------------------------------- /visitor/functions/Unhex.cpp: -------------------------------------------------------------------------------- 1 | #include "Unhex.h" 2 | Unhex::~Unhex() 3 | { 4 | 5 | } 6 | 7 | Unhex * Unhex::instance() 8 | { 9 | static Unhex x; 10 | return &x; 11 | } 12 | 13 | Object *Unhex::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 14 | if (x.getParameters().size() != 1) { 15 | return SQLEvalVisitor.EVAL_ERROR; 16 | } 17 | 18 | SQLExpr param0 = x.getParameters().get(0); 19 | 20 | if (param0 instanceof SQLMethodInvokeExpr) { 21 | SQLMethodInvokeExpr paramMethodExpr = (SQLMethodInvokeExpr) param0; 22 | if (paramMethodExpr.getMethodName().equalsIgnoreCase("hex")) { 23 | SQLExpr subParamExpr = paramMethodExpr.getParameters().get(0); 24 | subParamExpr.accept(visitor); 25 | 26 | Object param0Value = subParamExpr.getAttributes().get(EVAL_VALUE); 27 | if (param0Value == null) { 28 | x.putAttribute(EVAL_EXPR, subParamExpr); 29 | return SQLEvalVisitor.EVAL_ERROR; 30 | } 31 | 32 | return param0Value; 33 | } 34 | } 35 | 36 | param0.accept(visitor); 37 | 38 | Object param0Value = param0.getAttributes().get(EVAL_VALUE); 39 | if (param0Value == null) { 40 | return SQLEvalVisitor.EVAL_ERROR; 41 | } 42 | 43 | if (param0Value instanceof std::string) { 44 | byte[] bytes = HexBin.decode((std::string) param0Value); 45 | if (bytes == null) { 46 | return SQLEvalVisitor.EVAL_VALUE_NULL; 47 | } 48 | 49 | std::string result; 50 | try { 51 | result = new std::string(bytes, "UTF-8"); 52 | } catch (UnsupportedEncodingException e) { 53 | throw new IllegalStateException(e.getMessage(), e); 54 | } 55 | return result; 56 | } 57 | 58 | return SQLEvalVisitor.EVAL_ERROR; 59 | } 60 | 61 | 62 | -------------------------------------------------------------------------------- /ast/expr/SQLQueryExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLQueryExpr.h" 2 | SQLQueryExpr::SQLQueryExpr(){ 3 | 4 | } 5 | 6 | SQLQueryExpr::~SQLQueryExpr(){ 7 | if (subQuery != NULL) 8 | { 9 | delete subQuery; 10 | subQuery = NULL; 11 | 12 | } 13 | } 14 | SQLQueryExpr::SQLQueryExpr(SQLSelect * theSelect){ 15 | setSubQuery(theSelect); 16 | } 17 | 18 | SQLSelect *SQLQueryExpr::getSubQuery() { 19 | return subQuery; 20 | } 21 | 22 | void SQLQueryExpr::setSubQuery(SQLSelect * theSubQuery) { 23 | if (theSubQuery != NULL) { 24 | theSubQuery->setParent(this); 25 | } 26 | subQuery = theSubQuery; 27 | } 28 | 29 | void SQLQueryExpr::output(std::string & buf) { 30 | subQuery->output(buf); 31 | } 32 | 33 | void SQLQueryExpr::accept0(SQLASTVisitor *visitor) { 34 | if (visitor->visit(this)) { 35 | acceptChild(visitor, subQuery); 36 | } 37 | 38 | visitor->endVisit(this); 39 | } 40 | 41 | //int SQLQueryExpr::hashCode() { 42 | //final int prime = 31; 43 | //int result = 1; 44 | //result = prime * result + ((subQuery == NULL) ? 0 : subQuery.hashCode()); 45 | //return result; 46 | //} 47 | 48 | //bool SQLQueryExpr::equals(Object obj) { 49 | //if (this == obj) { 50 | //return true; 51 | //} 52 | //if (obj == NULL) { 53 | //return false; 54 | //} 55 | //if (getClass() != obj.getClass()) { 56 | //return false; 57 | //} 58 | //SQLQueryExpr other = (SQLQueryExpr) obj; 59 | //if (subQuery == NULL) { 60 | //if (other.subQuery != NULL) { 61 | //return false; 62 | //} 63 | //} else if (!subQuery.equals(other.subQuery)) { 64 | //return false; 65 | //} 66 | //return true; 67 | //} 68 | 69 | -------------------------------------------------------------------------------- /ast/expr/SQLNumberExpr.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SQLNumberExpr.h" 3 | SQLNumberExpr::SQLNumberExpr(){ 4 | 5 | } 6 | SQLNumberExpr::~SQLNumberExpr(){ 7 | if (number != NULL) 8 | { 9 | delete number; 10 | number = NULL; 11 | } 12 | } 13 | SQLNumberExpr::SQLNumberExpr(RNumber * theNumber){ 14 | 15 | number = theNumber; 16 | } 17 | 18 | RNumber *SQLNumberExpr::getNumber() { 19 | return number; 20 | } 21 | 22 | void SQLNumberExpr::setNumber(RNumber * theNumber) { 23 | number = theNumber; 24 | } 25 | 26 | void SQLNumberExpr::output(std::string & buf) { 27 | 28 | double a = boost::rational_cast(*number); 29 | std::string s = boost::lexical_cast(a); 30 | buf += s; 31 | 32 | //buf.append(this.number.toString()); 33 | } 34 | 35 | void SQLNumberExpr::accept0(SQLASTVisitor *visitor) { 36 | visitor->visit(this); 37 | visitor->endVisit(this); 38 | } 39 | 40 | //int SQLNumberExpr::hashCode() { 41 | //final int prime = 31; 42 | //int result = 1; 43 | //result = prime * result + ((number == null) ? 0 : number.hashCode()); 44 | //return result; 45 | //} 46 | 47 | //bool SQLNumberExpr::equals(Object obj) { 48 | //if (this == obj) { 49 | //return true; 50 | //} 51 | //if (obj == null) { 52 | //return false; 53 | //} 54 | //if (getClass() != obj.getClass()) { 55 | //return false; 56 | //} 57 | //SQLNumberExpr other = (SQLNumberExpr) obj; 58 | //if (number == null) { 59 | //if (other.number != null) { 60 | //return false; 61 | //} 62 | //} else if (!number.equals(other.number)) { 63 | //return false; 64 | //} 65 | //return true; 66 | //} 67 | 68 | -------------------------------------------------------------------------------- /ast/expr/SQLHexExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLHexExpr.h" 2 | SQLHexExpr::SQLHexExpr(std::string &theHex){ 3 | hex = theHex; 4 | } 5 | SQLHexExpr::~SQLHexExpr(){ 6 | 7 | } 8 | 9 | std::string &SQLHexExpr::getHex() { 10 | return hex; 11 | } 12 | 13 | void SQLHexExpr::output(std::string & buf) { 14 | //buf.append("0x"); 15 | buf += "0x"; 16 | //buf.append(hex); 17 | buf += hex; 18 | 19 | std::string xusing = "USING"; 20 | Object * o = getAttribute(xusing); 21 | 22 | std::string *charset = dynamic_cast(o); 23 | //std::string charset = (std::string) getAttribute(xusing); 24 | 25 | if (*charset != "") { 26 | ////buf.append(" USING "); 27 | buf += " USING "; 28 | ////buf.append(charset); 29 | buf += *charset; 30 | } 31 | 32 | } 33 | 34 | void SQLHexExpr::accept0(SQLASTVisitor *visitor) { 35 | visitor->visit(this); 36 | visitor->endVisit(this); 37 | } 38 | 39 | //int SQLHexExpr::hashCode() { 40 | //final int prime = 31; 41 | //int result = 1; 42 | //result = prime * result + ((hex == NULL) ? 0 : hex.hashCode()); 43 | //return result; 44 | //} 45 | 46 | //bool SQLHexExpr::equals(Object obj) { 47 | //if (this == obj) { 48 | //return true; 49 | //} 50 | //if (obj == NULL) { 51 | //return false; 52 | //} 53 | //if (getClass() != obj.getClass()) { 54 | //return false; 55 | //} 56 | //SQLHexExpr other = (SQLHexExpr) obj; 57 | //if (hex == NULL) { 58 | //if (other.hex != NULL) { 59 | //return false; 60 | //} 61 | //} else if (!hex.equals(other.hex)) { 62 | //return false; 63 | //} 64 | //return true; 65 | //} 66 | 67 | //char[] toBytes() { 68 | //return HexBin.decode(hex); 69 | //} 70 | 71 | -------------------------------------------------------------------------------- /visitor/x.cpp: -------------------------------------------------------------------------------- 1 | // g++ x.cpp -std=c++11 2 | // clearing vectors 3 | #include 4 | #include 5 | #include 6 | /* isalpha example */ 7 | #include 8 | #include 9 | #include 10 | 11 | #include "SQLASTVisitor.h" 12 | #include "ExportParameterVisitor.h" 13 | #include "ExportParameterVisitorUtils.h" 14 | #include "SQLASTVisitorAdapter.h" 15 | #include "SQLASTOutputVisitor.h" 16 | #include "PrintableVisitor.h" 17 | 18 | class A { 19 | 20 | public: 21 | int num; 22 | A () : num(0) {}; 23 | A (int x) : num(x) {}; 24 | void showNum() { 25 | 26 | std::cout << "num is: " << num << std::endl; 27 | } 28 | ~A() { 29 | 30 | std::cout << "in A's destructor, num is: " << num << std::endl; 31 | } 32 | 33 | }; 34 | int main () 35 | { 36 | ExportParameterVisitorUtils *a = new ExportParameterVisitorUtils(); 37 | std::cout << "in main function " << std::endl; 38 | 39 | std::list theList; 40 | theList.push_back(new A(1)); 41 | theList.push_back(new A(2)); 42 | theList.push_back(new A(3)); 43 | 44 | 45 | int counter = 4; 46 | 47 | for (std::list::iterator it = theList.begin(); it != theList.end(); it++) 48 | { 49 | //(*it)->showNum(); 50 | //it = theList.erase(it); 51 | //it = theList.insert(it, (new A(counter++))); 52 | 53 | delete (*it); 54 | (*it) = new A(counter++); 55 | } 56 | 57 | 58 | for (std::list::iterator it = theList.begin(); it != theList.end(); it++) 59 | { 60 | (*it)->showNum(); 61 | } 62 | 63 | for (std::list::iterator it = theList.begin(); it != theList.end(); it++) 64 | { 65 | delete (*it); 66 | } 67 | 68 | std::cout << '\n'; 69 | 70 | 71 | 72 | return 0; 73 | } 74 | 75 | -------------------------------------------------------------------------------- /visitor/functions/Substring.cpp: -------------------------------------------------------------------------------- 1 | #include "Substring.h" 2 | Substring::~Substring() 3 | { 4 | 5 | } 6 | 7 | Substring * Substring::instance() 8 | { 9 | static Substring x; 10 | return &x; 11 | } 12 | 13 | Object *Substring::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 14 | List params = x.getParameters(); 15 | int paramSize = params.size(); 16 | if (paramSize != 2 && paramSize != 3) { 17 | return SQLEvalVisitor.EVAL_ERROR; 18 | } 19 | 20 | SQLExpr param0 = params.get(0); 21 | SQLExpr param1 = params.get(1); 22 | param0.accept(visitor); 23 | param1.accept(visitor); 24 | 25 | Object param0Value = param0.getAttributes().get(EVAL_VALUE); 26 | Object param1Value = param1.getAttributes().get(EVAL_VALUE); 27 | if (param0Value == null || param1Value == null) { 28 | return SQLEvalVisitor.EVAL_ERROR; 29 | } 30 | 31 | std::string str = param0Value.toString(); 32 | int index = ((Number) param1Value).intValue(); 33 | 34 | if (paramSize == 2) { 35 | 36 | if (index < 0) { 37 | int lastIndex = str.length() + index; 38 | return str.substring(lastIndex); 39 | } 40 | 41 | return str.substring(index - 1); 42 | } 43 | 44 | SQLExpr param2 = params.get(2); 45 | param2.accept(visitor); 46 | Object param2Value = param2.getAttributes().get(EVAL_VALUE); 47 | if (param2Value == null) { 48 | return SQLEvalVisitor.EVAL_ERROR; 49 | } 50 | 51 | int len = ((Number) param2Value).intValue(); 52 | 53 | std::string result; 54 | if (index < 0) { 55 | int lastIndex = str.length() + index; 56 | result = str.substring(lastIndex); 57 | } else { 58 | result = str.substring(index - 1); 59 | } 60 | 61 | if (len > result.length()) { 62 | return result; 63 | } 64 | return result.substring(0, len); 65 | } 66 | 67 | 68 | -------------------------------------------------------------------------------- /parser/SQLExprParser_test.cpp: -------------------------------------------------------------------------------- 1 | // g++ x.cpp -std=c++11 2 | #include 3 | #include 4 | #include "Lexer.h" 5 | #include "SQLExprParser.h" 6 | 7 | int main () 8 | { 9 | 10 | try { 11 | 12 | std::string e ("AGE > 506"); 13 | SQLExprParser *exprParser = new SQLExprParser(e); 14 | SQLBinaryOpExpr *binaryOpExpr = dynamic_cast(exprParser->getExpr()); 15 | std::cout << (binaryOpExpr->getOperator())->getName() << std::endl; 16 | 17 | //Assert.assertEquals(SQLBinaryOperator.GreaterThan, binaryOpExpr.getOperator()); 18 | 19 | SQLIdentifierExpr *left = dynamic_cast(binaryOpExpr->getLeft()); 20 | std::cout << (left->getName()) << std::endl; 21 | SQLIntegerExpr *right = dynamic_cast(binaryOpExpr->getRight()); 22 | //RNumber *n = right->getNumber(); 23 | //int a = boost::rational_cast (n); 24 | std::cout << (right->intValue()) << std::endl; 25 | 26 | //Assert.assertEquals("AGE", left.getName()); 27 | //Assert.assertEquals(5, right.getNumber().intValue()); 28 | // 29 | // 30 | 31 | std::string sql ( "a > b"); 32 | std::string sql_c ("a > 2"); 33 | 34 | SQLBinaryOpExpr *exprA, *exprB, *exprC; 35 | { 36 | SQLExprParser *parser = new SQLExprParser(sql); 37 | SQLBinaryOpExpr *exprA = dynamic_cast(parser->getExpr()); 38 | } 39 | { 40 | SQLExprParser *parser = new SQLExprParser(sql); 41 | SQLBinaryOpExpr *exprB = dynamic_cast(parser->getExpr()); 42 | } 43 | { 44 | SQLExprParser *parser = new SQLExprParser(sql); 45 | SQLBinaryOpExpr *exprC = dynamic_cast(parser->getExpr()); 46 | } 47 | } catch (ParserException *e) { 48 | std::cout << e->what() << std::endl; 49 | } 50 | 51 | 52 | return 0; 53 | } 54 | 55 | -------------------------------------------------------------------------------- /ast/expr/SQLCurrentOfCursorExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLCurrentOfCursorExpr.h" 2 | SQLCurrentOfCursorExpr::SQLCurrentOfCursorExpr(){ 3 | 4 | } 5 | 6 | SQLCurrentOfCursorExpr::~SQLCurrentOfCursorExpr(){ 7 | if (cursorName != NULL) 8 | { 9 | delete cursorName; 10 | cursorName = NULL; 11 | 12 | } 13 | } 14 | SQLCurrentOfCursorExpr::SQLCurrentOfCursorExpr(SQLName * theCursorName){ 15 | cursorName = theCursorName; 16 | } 17 | 18 | SQLName *SQLCurrentOfCursorExpr::getCursorName() { 19 | return cursorName; 20 | } 21 | 22 | void SQLCurrentOfCursorExpr::setCursorName(SQLName *theCursorName) { 23 | cursorName = theCursorName; 24 | } 25 | 26 | void SQLCurrentOfCursorExpr::output(std::string & buf) { 27 | //buf.append("CURRENT OF "); 28 | buf += "CURRENT OF "; 29 | cursorName->output(buf); 30 | } 31 | 32 | void SQLCurrentOfCursorExpr::accept0(SQLASTVisitor *visitor) { 33 | if (visitor->visit(this)) { 34 | acceptChild(visitor, cursorName); 35 | } 36 | visitor->endVisit(this); 37 | } 38 | 39 | //int SQLCurrentOfCursorExpr::hashCode() { 40 | //final int prime = 31; 41 | //int result = 1; 42 | //result = prime * result + ((cursorName == NULL) ? 0 : cursorName.hashCode()); 43 | //return result; 44 | //} 45 | 46 | //bool SQLCurrentOfCursorExpr::equals(Object obj) { 47 | //if (this == obj) { 48 | //return true; 49 | //} 50 | //if (obj == NULL) { 51 | //return false; 52 | //} 53 | //if (getClass() != obj.getClass()) { 54 | //return false; 55 | //} 56 | //SQLCurrentOfCursorExpr other = (SQLCurrentOfCursorExpr) obj; 57 | //if (cursorName == NULL) { 58 | //if (other.cursorName != NULL) { 59 | //return false; 60 | //} 61 | //} else if (!cursorName.equals(other.cursorName)) { 62 | //return false; 63 | //} 64 | //return true; 65 | //} 66 | 67 | -------------------------------------------------------------------------------- /ast/expr/SQLIntegerExpr.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SQLIntegerExpr.h" 3 | SQLIntegerExpr::SQLIntegerExpr(RNumber * theNumber){ 4 | 5 | number = theNumber; 6 | } 7 | 8 | SQLIntegerExpr::SQLIntegerExpr(){ 9 | 10 | } 11 | 12 | SQLIntegerExpr::~SQLIntegerExpr(){ 13 | if (number != NULL) 14 | { 15 | delete number; 16 | number = NULL; 17 | } 18 | 19 | } 20 | RNumber *SQLIntegerExpr::getNumber() { 21 | return number; 22 | } 23 | 24 | int SQLIntegerExpr::intValue() { 25 | int a = boost::rational_cast(*number); 26 | return a; 27 | } 28 | void SQLIntegerExpr::setNumber(RNumber *theNumber) { 29 | number = theNumber; 30 | } 31 | 32 | void SQLIntegerExpr::output(std::string & buf) { 33 | int a = boost::rational_cast(*number); 34 | //std::string s = std::to_string(a); 35 | std::string s = boost::lexical_cast(a); 36 | //buf.append(this.number); 37 | buf += s; 38 | } 39 | 40 | void SQLIntegerExpr::accept0(SQLASTVisitor *visitor) { 41 | visitor->visit(this); 42 | 43 | visitor->endVisit(this); 44 | } 45 | 46 | //int SQLIntegerExpr::hashCode() { 47 | //final int prime = 31; 48 | //int result = 1; 49 | //result = prime * result + ((number == NULL) ? 0 : number.hashCode()); 50 | //return result; 51 | //} 52 | 53 | //bool SQLIntegerExpr::equals(Object obj) { 54 | //if (this == obj) { 55 | //return true; 56 | //} 57 | //if (obj == NULL) { 58 | //return false; 59 | //} 60 | //if (getClass() != obj.getClass()) { 61 | //return false; 62 | //} 63 | //SQLIntegerExpr other = (SQLIntegerExpr) obj; 64 | //if (number == NULL) { 65 | //if (other.number != NULL) { 66 | //return false; 67 | //} 68 | //} else if (!number.equals(other.number)) { 69 | //return false; 70 | //} 71 | //return true; 72 | //} 73 | 74 | -------------------------------------------------------------------------------- /parser/SQLParserUtils.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | SQLStatementParser SQLParserUtils::createSQLStatementParser(std::string sql, std::string dbType) { 4 | if (JdbcUtils.ORACLE.equals(dbType) || JdbcUtils.ALI_ORACLE.equals(dbType)) { 5 | return new OracleStatementParser(sql); 6 | } 7 | 8 | if (JdbcUtils.MYSQL.equals(dbType)) { 9 | return new MySqlStatementParser(sql); 10 | } 11 | 12 | if (JdbcUtils.MARIADB.equals(dbType)) { 13 | return new MySqlStatementParser(sql); 14 | } 15 | 16 | if (JdbcUtils.POSTGRESQL.equals(dbType)) { 17 | return new PGSQLStatementParser(sql); 18 | } 19 | 20 | if (JdbcUtils.SQL_SERVER.equals(dbType) || JdbcUtils.JTDS.equals(dbType)) { 21 | return new SQLServerStatementParser(sql); 22 | } 23 | 24 | if (JdbcUtils.H2.equals(dbType)) { 25 | return new MySqlStatementParser(sql); 26 | } 27 | 28 | if (JdbcUtils.DB2.equals(dbType)) { 29 | return new DB2StatementParser(sql); 30 | } 31 | 32 | return new SQLStatementParser(sql); 33 | } 34 | 35 | SQLExprParser SQLParserUtils::createExprParser(std::string sql, std::string dbType) { 36 | if (JdbcUtils.ORACLE.equals(dbType) || JdbcUtils.ALI_ORACLE.equals(dbType)) { 37 | return new OracleExprParser(sql); 38 | } 39 | 40 | if (JdbcUtils.MYSQL.equals(dbType) || // 41 | JdbcUtils.MARIADB.equals(dbType) || // 42 | JdbcUtils.H2.equals(dbType)) { 43 | return new MySqlExprParser(sql); 44 | } 45 | 46 | if (JdbcUtils.POSTGRESQL.equals(dbType)) { 47 | return new PGExprParser(sql); 48 | } 49 | 50 | if (JdbcUtils.SQL_SERVER.equals(dbType) || JdbcUtils.JTDS.equals(dbType)) { 51 | return new SQLServerExprParser(sql); 52 | } 53 | 54 | if (JdbcUtils.DB2.equals(dbType)) { 55 | return new DB2ExprParser(sql); 56 | } 57 | 58 | if (JdbcUtils.ODPS.equals(dbType)) { 59 | return new OdpsExprParser(sql); 60 | } 61 | 62 | return new SQLExprParser(sql); 63 | } 64 | 65 | -------------------------------------------------------------------------------- /visitor/functions/Insert.cpp: -------------------------------------------------------------------------------- 1 | #include "Insert.h" 2 | Insert::~Insert() 3 | { 4 | 5 | } 6 | 7 | Insert * Insert::instance() 8 | { 9 | static Insert x; 10 | return &x; 11 | } 12 | 13 | 14 | Object *Insert::eval(SQLEvalVisitor *visitor, SQLMethodInvokeExpr *x) { 15 | if (x.getParameters().size() != 4) { 16 | return SQLEvalVisitor.EVAL_ERROR; 17 | } 18 | 19 | SQLExpr param0 = x.getParameters().get(0); 20 | SQLExpr param1 = x.getParameters().get(1); 21 | SQLExpr param2 = x.getParameters().get(2); 22 | SQLExpr param3 = x.getParameters().get(3); 23 | param0.accept(visitor); 24 | param1.accept(visitor); 25 | param2.accept(visitor); 26 | param3.accept(visitor); 27 | 28 | Object param0Value = param0.getAttributes().get(EVAL_VALUE); 29 | Object param1Value = param1.getAttributes().get(EVAL_VALUE); 30 | Object param2Value = param2.getAttributes().get(EVAL_VALUE); 31 | Object param3Value = param3.getAttributes().get(EVAL_VALUE); 32 | 33 | if (!(param0Value instanceof String)) { 34 | return SQLEvalVisitor.EVAL_ERROR; 35 | } 36 | if (!(param1Value instanceof Number)) { 37 | return SQLEvalVisitor.EVAL_ERROR; 38 | } 39 | if (!(param2Value instanceof Number)) { 40 | return SQLEvalVisitor.EVAL_ERROR; 41 | } 42 | if (!(param3Value instanceof String)) { 43 | return SQLEvalVisitor.EVAL_ERROR; 44 | } 45 | 46 | String str = (String) param0Value; 47 | int pos = ((Number) param1Value).intValue(); 48 | int len = ((Number) param2Value).intValue(); 49 | String newstr = (String) param3Value; 50 | 51 | if (pos <= 0) { 52 | return str; 53 | } 54 | 55 | if (pos == 1) { 56 | if (len > str.length()) { 57 | return newstr; 58 | } 59 | return newstr + str.substring(len); 60 | } 61 | 62 | String first = str.substring(0, pos - 1); 63 | if (pos + len - 1 > str.length()) { 64 | return first + newstr; 65 | } 66 | 67 | return first + newstr + str.substring(pos + len - 1); 68 | } 69 | -------------------------------------------------------------------------------- /ast/SQLObjectImpl.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SQLObjectImpl_HEADER_H 3 | #define SQLObjectImpl_HEADER_H 4 | //import com.alibaba.druid.sql.visitor.SQLASTVisitor; 5 | #include 6 | #include "Object.h" 7 | #include "SQLObject.h" 8 | #include "SQLExpr.h" 9 | #include "../visitor/SQLASTVisitor.h" 10 | //#include "../visitor/SQLASTVisitor.h" 11 | 12 | #include 13 | #include 14 | 15 | 16 | 17 | //http://stackoverflow.com/questions/11919014/inaccessible-base-class 18 | 19 | class SQLObjectImpl : virtual public SQLObject { 20 | 21 | private: 22 | SQLObject *parent; 23 | 24 | //http://stackoverflow.com/questions/1155142/why-do-i-get-an-error-in-forming-reference-to-reference-type-map 25 | //The map needs a copy of the string to store: 26 | std::map attributes; 27 | 28 | typedef SQLObject super; 29 | std::string buf; 30 | 31 | public: 32 | 33 | SQLObjectImpl(); 34 | virtual ~SQLObjectImpl(); 35 | virtual void accept(SQLASTVisitor *visitor); 36 | virtual void output(std::string &buf); 37 | virtual std::string &toString(); 38 | SQLObject *getParent(); 39 | void setParent(SQLObject* parent); 40 | virtual std::map &getAttributes(); 41 | Object *getAttribute(std::string &name); 42 | virtual void putAttribute(std::string name, Object *value); 43 | virtual std::map &getAttributesDirect(); 44 | 45 | //virtual std::string & getClass() 46 | //{ 47 | //static std::string className = "SQLObjectImpl"; 48 | //return className; 49 | //} 50 | 51 | 52 | protected: 53 | 54 | virtual void accept0(SQLASTVisitor *visitor) = 0; 55 | void acceptChild(SQLASTVisitor *visitor, std::list &children); 56 | void acceptChild(SQLASTVisitor *visitor, std::list &children); 57 | void acceptChild(SQLASTVisitor *visitor, SQLObject *child); 58 | }; 59 | typedef boost::shared_ptr SQLObjectImpl_ptr; 60 | 61 | #endif 62 | 63 | -------------------------------------------------------------------------------- /ast/SQLObject.h: -------------------------------------------------------------------------------- 1 | 2 | //import com.alibaba.druid.sql.visitor.SQLASTVisitor; 3 | 4 | #ifndef SQLObject_HEADER_H 5 | #define SQLObject_HEADER_H 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "Object.h" 12 | 13 | 14 | #include "../visitor/SQLASTVisitor.h" 15 | //class SQLASTVisitor; 16 | class SQLObject : public Object { 17 | 18 | //http://stackoverflow.com/questions/11945993/equivalent-of-java-interfaces-in-c 19 | 20 | typedef Object inherited; 21 | private: 22 | //static std::string x; 23 | //static std::string className; 24 | //static std::string x = "in SQLObject class"; 25 | //static std::string className = "SQLObject"; 26 | public: 27 | virtual void accept(SQLASTVisitor *visitor) = 0; 28 | 29 | virtual SQLObject * getParent() = 0; 30 | 31 | virtual void setParent(SQLObject *parent) = 0; 32 | 33 | virtual std::map& getAttributes() = 0; 34 | 35 | virtual Object *getAttribute(std::string& name) = 0; 36 | 37 | virtual void putAttribute(std::string name, Object* value) = 0; 38 | 39 | virtual std::map &getAttributesDirect() = 0; 40 | 41 | virtual void output(std::string &buf) = 0; 42 | 43 | virtual void accept0(SQLASTVisitor *visitor) = 0; 44 | virtual ~SQLObject() { 45 | 46 | } 47 | 48 | virtual std::string & getClass() 49 | { 50 | 51 | static std::string className = "SQLObject"; 52 | return className; 53 | } 54 | 55 | virtual std::string &toString() 56 | { 57 | 58 | #if WIN32 59 | std::string x = ""; 60 | return x; 61 | #else 62 | 63 | #endif 64 | 65 | } 66 | 67 | }; 68 | 69 | //std::string SQLObject::x = "in SQLObject class"; 70 | //std::string SQLObject::className = "SQLObject"; 71 | 72 | //std::string & SQLObject::getClass() { 73 | //return className; 74 | //} 75 | 76 | //std::string &SQLObject::toString() 77 | //{ 78 | //return x; 79 | //} 80 | 81 | 82 | typedef boost::shared_ptr SQLObject_ptr; 83 | #endif 84 | 85 | -------------------------------------------------------------------------------- /ast/expr/SQLCastExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLCastExpr.h" 2 | 3 | SQLCastExpr::SQLCastExpr(){ 4 | 5 | } 6 | 7 | SQLCastExpr::~SQLCastExpr(){ 8 | if (expr != NULL) 9 | { 10 | delete expr; 11 | expr = NULL; 12 | } 13 | 14 | if (dataType != NULL) 15 | { 16 | delete dataType; 17 | dataType = NULL; 18 | } 19 | 20 | } 21 | SQLExpr *SQLCastExpr::getExpr() { 22 | return expr; 23 | } 24 | 25 | void SQLCastExpr::setExpr(SQLExpr *theExpr) { 26 | if (theExpr != NULL) { 27 | theExpr->setParent(this); 28 | } 29 | expr = theExpr; 30 | } 31 | 32 | SQLDataType *SQLCastExpr::getDataType() { 33 | return dataType; 34 | } 35 | 36 | void SQLCastExpr::setDataType(SQLDataType *theDataType) { 37 | dataType = theDataType; 38 | } 39 | 40 | void SQLCastExpr::accept0(SQLASTVisitor *visitor) { 41 | if (visitor->visit(this)) { 42 | acceptChild(visitor, expr); 43 | acceptChild(visitor, dataType); 44 | } 45 | visitor->endVisit(this); 46 | } 47 | 48 | //int SQLCastExpr::hashCode() { 49 | //final int prime = 31; 50 | //int result = 1; 51 | //result = prime * result + ((dataType == NULL) ? 0 : dataType.hashCode()); 52 | //result = prime * result + ((expr == NULL) ? 0 : expr.hashCode()); 53 | //return result; 54 | //} 55 | 56 | //bool SQLCastExpr::equals(Object obj) { 57 | //if (this == obj) { 58 | //return true; 59 | //} 60 | //if (obj == NULL) { 61 | //return false; 62 | //} 63 | //if (getClass() != obj.getClass()) { 64 | //return false; 65 | //} 66 | //SQLCastExpr other = (SQLCastExpr) obj; 67 | //if (dataType == NULL) { 68 | //if (other.dataType != NULL) { 69 | //return false; 70 | //} 71 | //} else if (!dataType.equals(other.dataType)) { 72 | //return false; 73 | //} 74 | //if (expr == NULL) { 75 | //if (other.expr != NULL) { 76 | //return false; 77 | //} 78 | //} else if (!expr.equals(other.expr)) { 79 | //return false; 80 | //} 81 | //return true; 82 | //} 83 | 84 | -------------------------------------------------------------------------------- /ast/SQLOver.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLOver.h" 2 | SQLOver::SQLOver(){ 3 | 4 | } 5 | SQLOver::~SQLOver(){ 6 | 7 | for(std::list::iterator it = partitionBy.begin(); it != partitionBy.end(); ++it) 8 | { 9 | delete *it; 10 | } 11 | partitionBy.clear(); 12 | 13 | if (orderBy != NULL) 14 | { 15 | 16 | delete orderBy; 17 | orderBy = NULL; 18 | } 19 | 20 | 21 | } 22 | SQLOver::SQLOver(SQLOrderBy *theOrderBy){ 23 | setOrderBy(theOrderBy); 24 | } 25 | 26 | void SQLOver::accept0(SQLASTVisitor *visitor) { 27 | if (visitor->visit(this)) { 28 | acceptChild(visitor, partitionBy); 29 | acceptChild(visitor, orderBy); 30 | } 31 | visitor->endVisit(this); 32 | } 33 | 34 | SQLOrderBy *SQLOver::getOrderBy() { 35 | return orderBy; 36 | } 37 | 38 | void SQLOver::setOrderBy(SQLOrderBy *theOrderBy) { 39 | if (theOrderBy != NULL) { 40 | theOrderBy->setParent(this); 41 | } 42 | orderBy = theOrderBy; 43 | } 44 | 45 | std::list &SQLOver::getPartitionBy() { 46 | return partitionBy; 47 | } 48 | 49 | //int SQLOver::hashCode() { 50 | //int prime = 31; 51 | //int result = 1; 52 | //result = prime * result + ((orderBy == NULL) ? 0 : orderBy.hashCode()); 53 | //result = prime * result + ((partitionBy == NULL) ? 0 : partitionBy.hashCode()); 54 | //return result; 55 | //} 56 | 57 | //bool SQLOver::equals(Object obj) { 58 | //if (this == obj) { 59 | //return true; 60 | //} 61 | //if (obj == NULL) { 62 | //return false; 63 | //} 64 | //if (getClass() != obj.getClass()) { 65 | //return false; 66 | //} 67 | //SQLOver other = (SQLOver) obj; 68 | //if (orderBy == NULL) { 69 | //if (other.orderBy != NULL) { 70 | //return false; 71 | //} 72 | //} else if (!orderBy.equals(other.orderBy)) { 73 | //return false; 74 | //} 75 | //if (partitionBy == NULL) { 76 | //if (other.partitionBy != NULL) { 77 | //return false; 78 | //} 79 | //} else if (!partitionBy.equals(other.partitionBy)) { 80 | //return false; 81 | //} 82 | //return true; 83 | //} 84 | 85 | -------------------------------------------------------------------------------- /ast/expr/SQLUnaryExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLUnaryExpr.h" 2 | SQLUnaryExpr::SQLUnaryExpr(){ 3 | 4 | } 5 | 6 | SQLUnaryExpr::~SQLUnaryExpr(){ 7 | if (expr != NULL) 8 | { 9 | delete expr; 10 | expr = NULL; 11 | } 12 | 13 | //if (xoperator != NULL) 14 | //{ 15 | //delete xoperator; 16 | //xoperator = NULL; 17 | //} 18 | 19 | 20 | 21 | } 22 | SQLUnaryExpr::SQLUnaryExpr(SQLUnaryOperator *theXoperator, SQLExpr *theExpr) : xoperator (theXoperator), expr (theExpr){ 23 | //this.xoperator = xoperator; 24 | //this.expr = expr; 25 | } 26 | 27 | SQLUnaryOperator *SQLUnaryExpr::getOperator() { 28 | return xoperator; 29 | } 30 | 31 | void SQLUnaryExpr::setOperator(SQLUnaryOperator *theXoperator) { 32 | xoperator = theXoperator; 33 | } 34 | 35 | SQLExpr *SQLUnaryExpr::getExpr() { 36 | return expr; 37 | } 38 | 39 | void SQLUnaryExpr::setExpr(SQLExpr *theExpr) { 40 | expr = theExpr; 41 | } 42 | 43 | void SQLUnaryExpr::accept0(SQLASTVisitor *visitor) { 44 | if (visitor->visit(this)) { 45 | acceptChild(visitor, expr); 46 | } 47 | 48 | visitor->endVisit(this); 49 | } 50 | 51 | //int SQLUnaryExpr::hashCode() { 52 | //int prime = 31; 53 | //int result = 1; 54 | //result = prime * result + ((expr == null) ? 0 : expr.hashCode()); 55 | //result = prime * result + ((xoperator == null) ? 0 : xoperator.hashCode()); 56 | //return result; 57 | //} 58 | 59 | //bool SQLUnaryExpr::equals(Object obj) { 60 | //if (this == obj) { 61 | //return true; 62 | //} 63 | //if (obj == null) { 64 | //return false; 65 | //} 66 | //if (getClass() != obj.getClass()) { 67 | //return false; 68 | //} 69 | //SQLUnaryExpr other = (SQLUnaryExpr) obj; 70 | //if (expr == null) { 71 | //if (other.expr != null) { 72 | //return false; 73 | //} 74 | //} else if (!expr.equals(other.expr)) { 75 | //return false; 76 | //} 77 | //if (xoperator != other.xoperator) { 78 | //return false; 79 | //} 80 | //return true; 81 | //} 82 | 83 | -------------------------------------------------------------------------------- /visitor/ParameterizedOutputVisitor.cpp: -------------------------------------------------------------------------------- 1 | #include "ParameterizedOutputVisitor.h" 2 | 3 | ParameterizedOutputVisitor::ParameterizedOutputVisitor(){ 4 | this(new StringBuilder()); 5 | } 6 | ParameterizedOutputVisitor::~ParameterizedOutputVisitor(){ 7 | 8 | } 9 | 10 | ParameterizedOutputVisitor::ParameterizedOutputVisitor(Appendable appender){ 11 | super(appender); 12 | } 13 | 14 | int ParameterizedOutputVisitor::getReplaceCount() { 15 | return this.replaceCount; 16 | } 17 | 18 | void ParameterizedOutputVisitor::incrementReplaceCunt() { 19 | replaceCount++; 20 | } 21 | 22 | bool ParameterizedOutputVisitor::visit(SQLInListExpr *x) { 23 | return ParameterizedOutputVisitorUtils.visit(this, x); 24 | } 25 | 26 | bool ParameterizedOutputVisitor::visit(SQLBinaryOpExpr *x) { 27 | x = ParameterizedOutputVisitorUtils.merge(this, x); 28 | 29 | return super.visit(x); 30 | } 31 | 32 | bool ParameterizedOutputVisitor::visit(SQLIntegerExpr *x) { 33 | if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) { 34 | return super.visit(x); 35 | } 36 | 37 | return ParameterizedOutputVisitorUtils.visit(this, x); 38 | } 39 | 40 | bool ParameterizedOutputVisitor::visit(SQLNumberExpr *x) { 41 | if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) { 42 | return super.visit(x); 43 | } 44 | 45 | return ParameterizedOutputVisitorUtils.visit(this, x); 46 | } 47 | 48 | bool ParameterizedOutputVisitor::visit(SQLCharExpr *x) { 49 | if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) { 50 | return super.visit(x); 51 | } 52 | 53 | return ParameterizedOutputVisitorUtils.visit(this, x); 54 | } 55 | 56 | bool ParameterizedOutputVisitor::visit(SQLNCharExpr *x) { 57 | if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) { 58 | return super.visit(x); 59 | } 60 | 61 | return ParameterizedOutputVisitorUtils.visit(this, x); 62 | } 63 | 64 | bool ParameterizedOutputVisitor::visit(SQLNullExpr *x) { 65 | if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) { 66 | return super.visit(x); 67 | } 68 | 69 | return ParameterizedOutputVisitorUtils.visit(this, x); 70 | } 71 | 72 | -------------------------------------------------------------------------------- /ast/expr/SQLExistsExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLExistsExpr.h" 2 | SQLExistsExpr::SQLExistsExpr() : xnot (false){ 3 | 4 | } 5 | 6 | SQLExistsExpr::~SQLExistsExpr() { 7 | if (subQuery != NULL) 8 | { 9 | delete subQuery; 10 | subQuery = NULL; 11 | 12 | } 13 | 14 | } 15 | SQLExistsExpr::SQLExistsExpr(SQLSelect *theSubQuery) : subQuery(theSubQuery), xnot(false){ 16 | //this.setSubQuery(subQuery); 17 | } 18 | 19 | SQLExistsExpr::SQLExistsExpr(SQLSelect *theSubQuery, bool theNot) : subQuery(theSubQuery), xnot (theNot){ 20 | //this.setSubQuery(subQuery); 21 | //this.xnot = xnot; 22 | } 23 | 24 | bool SQLExistsExpr::isNot() { 25 | return xnot; 26 | } 27 | 28 | void SQLExistsExpr::setNot(bool theNot) { 29 | xnot = theNot; 30 | } 31 | 32 | SQLSelect *SQLExistsExpr::getSubQuery() { 33 | return subQuery; 34 | } 35 | 36 | void SQLExistsExpr::setSubQuery(SQLSelect *theSubQuery) { 37 | if (theSubQuery != NULL) { 38 | theSubQuery->setParent(this); 39 | } 40 | subQuery = theSubQuery; 41 | } 42 | 43 | void SQLExistsExpr::accept0(SQLASTVisitor *visitor) { 44 | if (visitor->visit(this)) { 45 | acceptChild(visitor, subQuery); 46 | } 47 | 48 | visitor->endVisit(this); 49 | } 50 | 51 | //int SQLExistsExpr::hashCode() { 52 | //final int prime = 31; 53 | //int result = 1; 54 | //result = prime * result + (xnot ? 1231 : 1237); 55 | //result = prime * result + ((subQuery == null) ? 0 : subQuery.hashCode()); 56 | //return result; 57 | //} 58 | 59 | //bool SQLExistsExpr::equals(Object obj) { 60 | //if (this == obj) { 61 | //return true; 62 | //} 63 | //if (obj == null) { 64 | //return false; 65 | //} 66 | //if (getClass() != obj.getClass()) { 67 | //return false; 68 | //} 69 | //SQLExistsExpr other = (SQLExistsExpr) obj; 70 | //if (xnot != other.xnot) { 71 | //return false; 72 | //} 73 | //if (subQuery == null) { 74 | //if (other.subQuery != null) { 75 | //return false; 76 | //} 77 | //} else if (!subQuery.equals(other.subQuery)) { 78 | //return false; 79 | //} 80 | //return true; 81 | //} 82 | 83 | -------------------------------------------------------------------------------- /ast/SQLOrderBy.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLOrderBy_HEADER_H 2 | #define SQLOrderBy_HEADER_H 3 | 4 | 5 | //import com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem; 6 | //import com.alibaba.druid.sql.visitor.SQLASTVisitor; 7 | 8 | #include 9 | #include "Object.h" 10 | #include "SQLObject.h" 11 | #include "SQLObjectImpl.h" 12 | #include "SQLExpr.h" 13 | #include "../visitor/SQLASTVisitor.h" 14 | #include "statement/SQLSelectOrderByItem.h" 15 | 16 | class SQLOrderBy : virtual public SQLObject{ 17 | 18 | 19 | private: 20 | SQLObject *parent; 21 | 22 | //http://stackoverflow.com/questions/1155142/why-do-i-get-an-error-in-forming-reference-to-reference-type-map 23 | //The map needs a copy of the string to store: 24 | std::map attributes; 25 | 26 | typedef SQLObject super; 27 | std::string buf; 28 | 29 | 30 | protected: 31 | std::list items; 32 | void accept0(SQLASTVisitor *visitor); 33 | 34 | public: 35 | SQLOrderBy(); 36 | virtual ~SQLOrderBy(); 37 | 38 | SQLOrderBy(SQLExpr *expr); 39 | 40 | void addItem(SQLSelectOrderByItem *item); 41 | 42 | std::list &getItems(); 43 | 44 | 45 | void acceptChild(SQLASTVisitor *visitor, SQLObject *child) ; 46 | void acceptChild(SQLASTVisitor *visitor, std::list &children); 47 | void acceptChild(SQLASTVisitor *visitor, std::list &children); 48 | 49 | virtual void accept(SQLASTVisitor *visitor); 50 | virtual SQLObject * getParent(); 51 | virtual void setParent(SQLObject *parent); 52 | virtual std::map& getAttributes(); 53 | 54 | virtual Object *getAttribute(std::string& name); 55 | 56 | virtual void putAttribute(std::string name, Object* value); 57 | 58 | virtual std::map &getAttributesDirect(); 59 | 60 | virtual void output(std::string &buf); 61 | 62 | 63 | 64 | //int hashCode(); 65 | //bool equals(Object *obj); 66 | 67 | }; 68 | typedef boost::shared_ptr SQLOrderBy_ptr; 69 | 70 | #endif 71 | 72 | -------------------------------------------------------------------------------- /deps/smhasher/lookup3.cpp: -------------------------------------------------------------------------------- 1 | // lookup3 by Bob Jekins, code is public domain. 2 | 3 | #include "Platform.h" 4 | 5 | #define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) 6 | 7 | #define mix(a,b,c) \ 8 | { \ 9 | a -= c; a ^= rot(c, 4); c += b; \ 10 | b -= a; b ^= rot(a, 6); a += c; \ 11 | c -= b; c ^= rot(b, 8); b += a; \ 12 | a -= c; a ^= rot(c,16); c += b; \ 13 | b -= a; b ^= rot(a,19); a += c; \ 14 | c -= b; c ^= rot(b, 4); b += a; \ 15 | } 16 | 17 | #define final(a,b,c) \ 18 | { \ 19 | c ^= b; c -= rot(b,14); \ 20 | a ^= c; a -= rot(c,11); \ 21 | b ^= a; b -= rot(a,25); \ 22 | c ^= b; c -= rot(b,16); \ 23 | a ^= c; a -= rot(c,4); \ 24 | b ^= a; b -= rot(a,14); \ 25 | c ^= b; c -= rot(b,24); \ 26 | } 27 | 28 | uint32_t lookup3 ( const void * key, int length, uint32_t initval ) 29 | { 30 | uint32_t a,b,c; /* internal state */ 31 | 32 | a = b = c = 0xdeadbeef + ((uint32_t)length) + initval; 33 | 34 | const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ 35 | 36 | /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */ 37 | while (length > 12) 38 | { 39 | a += k[0]; 40 | b += k[1]; 41 | c += k[2]; 42 | mix(a,b,c); 43 | length -= 12; 44 | k += 3; 45 | } 46 | 47 | switch(length) 48 | { 49 | case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; 50 | case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break; 51 | case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break; 52 | case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break; 53 | case 8 : b+=k[1]; a+=k[0]; break; 54 | case 7 : b+=k[1]&0xffffff; a+=k[0]; break; 55 | case 6 : b+=k[1]&0xffff; a+=k[0]; break; 56 | case 5 : b+=k[1]&0xff; a+=k[0]; break; 57 | case 4 : a+=k[0]; break; 58 | case 3 : a+=k[0]&0xffffff; break; 59 | case 2 : a+=k[0]&0xffff; break; 60 | case 1 : a+=k[0]&0xff; break; 61 | case 0 : { return c; } /* zero length strings require no mixing */ 62 | } 63 | 64 | final(a,b,c); 65 | 66 | return c; 67 | } 68 | 69 | void lookup3_test ( const void * key, int len, uint32_t seed, void * out ) 70 | { 71 | *(uint32_t*)out = lookup3(key,len,seed); 72 | } 73 | -------------------------------------------------------------------------------- /ast/expr/SQLVariantRefExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLVariantRefExpr.h" 2 | SQLVariantRefExpr::SQLVariantRefExpr(std::string & theName) : name(theName), global (false), index(-1){ 3 | //this.name = name; 4 | } 5 | SQLVariantRefExpr::SQLVariantRefExpr(const char * theName) : name(theName), global (false), index(-1){ 6 | //this.name = name; 7 | } 8 | 9 | SQLVariantRefExpr::SQLVariantRefExpr(std::string &theName, bool theGlobal): name(theName), global (theGlobal), index(-1){ 10 | //this.name = name; 11 | //this.global = global; 12 | } 13 | SQLVariantRefExpr::~SQLVariantRefExpr() { 14 | 15 | } 16 | 17 | SQLVariantRefExpr::SQLVariantRefExpr(){ 18 | 19 | } 20 | 21 | int SQLVariantRefExpr::getIndex() { 22 | return index; 23 | } 24 | 25 | void SQLVariantRefExpr::setIndex(int theIndex) { 26 | index = theIndex; 27 | } 28 | 29 | std::string &SQLVariantRefExpr::getName() { 30 | return name; 31 | } 32 | 33 | void SQLVariantRefExpr::setName(std::string &theName) { 34 | name = theName; 35 | } 36 | 37 | void SQLVariantRefExpr::output(std::string & buf) { 38 | buf += name; 39 | //buf.append(name); 40 | } 41 | 42 | void SQLVariantRefExpr::accept0(SQLASTVisitor *visitor) { 43 | visitor->visit(this); 44 | 45 | visitor->endVisit(this); 46 | } 47 | 48 | //int SQLVariantRefExpr::hashCode() { 49 | //final int prime = 31; 50 | //int result = 1; 51 | //result = prime * result + ((name == null) ? 0 : name.hashCode()); 52 | //return result; 53 | //} 54 | 55 | //bool SQLVariantRefExpr::equals(Object obj) { 56 | //if (this == obj) { 57 | //return true; 58 | //} 59 | //if (obj == null) { 60 | //return false; 61 | //} 62 | //if (!(obj instanceof SQLVariantRefExpr)) { 63 | //return false; 64 | //} 65 | //SQLVariantRefExpr other = (SQLVariantRefExpr) obj; 66 | //if (name == null) { 67 | //if (other.name != null) { 68 | //return false; 69 | //} 70 | //} else if (!name.equals(other.name)) { 71 | //return false; 72 | //} 73 | //return true; 74 | //} 75 | 76 | bool SQLVariantRefExpr::isGlobal() { 77 | return global; 78 | } 79 | 80 | void SQLVariantRefExpr::setGlobal(bool theGlobal) { 81 | global = theGlobal; 82 | } 83 | 84 | 85 | -------------------------------------------------------------------------------- /deps/smhasher/SuperFastHash.cpp: -------------------------------------------------------------------------------- 1 | #include "Platform.h" 2 | #include // for NULL 3 | 4 | /* By Paul Hsieh (C) 2004, 2005. Covered under the Paul Hsieh derivative 5 | license. See: 6 | http://www.azillionmonkeys.com/qed/weblicense.html for license details. 7 | 8 | http://www.azillionmonkeys.com/qed/hash.html */ 9 | 10 | /* 11 | #undef get16bits 12 | #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \ 13 | || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__) 14 | #define get16bits(d) (*((const uint16_t *) (d))) 15 | #endif 16 | 17 | #if !defined (get16bits) 18 | #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\ 19 | +(uint32_t)(((const uint8_t *)(d))[0]) ) 20 | #endif 21 | */ 22 | 23 | FORCE_INLINE uint16_t get16bits ( const void * p ) 24 | { 25 | return *(const uint16_t*)p; 26 | } 27 | 28 | uint32_t SuperFastHash (const signed char * data, int len) { 29 | uint32_t hash = 0, tmp; 30 | int rem; 31 | 32 | if (len <= 0 || data == NULL) return 0; 33 | 34 | rem = len & 3; 35 | len >>= 2; 36 | 37 | /* Main loop */ 38 | for (;len > 0; len--) { 39 | hash += get16bits (data); 40 | tmp = (get16bits (data+2) << 11) ^ hash; 41 | hash = (hash << 16) ^ tmp; 42 | data += 2*sizeof (uint16_t); 43 | hash += hash >> 11; 44 | } 45 | 46 | /* Handle end cases */ 47 | switch (rem) { 48 | case 3: hash += get16bits (data); 49 | hash ^= hash << 16; 50 | hash ^= data[sizeof (uint16_t)] << 18; 51 | hash += hash >> 11; 52 | break; 53 | case 2: hash += get16bits (data); 54 | hash ^= hash << 11; 55 | hash += hash >> 17; 56 | break; 57 | case 1: hash += *data; 58 | hash ^= hash << 10; 59 | hash += hash >> 1; 60 | } 61 | 62 | /* Force "avalanching" of final 127 bits */ 63 | hash ^= hash << 3; 64 | hash += hash >> 5; 65 | hash ^= hash << 4; 66 | hash += hash >> 17; 67 | hash ^= hash << 25; 68 | hash += hash >> 6; 69 | 70 | return hash; 71 | } 72 | 73 | void SuperFastHash ( const void * key, int len, uint32_t /*seed*/, void * out ) 74 | { 75 | *(uint32_t*)out = SuperFastHash((const signed char*)key,len); 76 | } 77 | -------------------------------------------------------------------------------- /ast/expr/SQLPropertyExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLPropertyExpr.h" 2 | SQLPropertyExpr::SQLPropertyExpr(SQLExpr * theOwner, std::string & theName) : owner(theOwner){ 3 | //setOwner(theOwner); 4 | name = theName; 5 | } 6 | 7 | SQLPropertyExpr::~SQLPropertyExpr(){ 8 | if (owner != NULL) 9 | { 10 | delete owner; 11 | owner = NULL; 12 | } 13 | 14 | } 15 | SQLPropertyExpr::SQLPropertyExpr(){ 16 | 17 | } 18 | 19 | std::string &SQLPropertyExpr::getSimleName() { 20 | return name; 21 | } 22 | 23 | SQLExpr *SQLPropertyExpr::getOwner() { 24 | return owner; 25 | } 26 | 27 | void SQLPropertyExpr::setOwner(SQLExpr *theOwner) { 28 | if (theOwner != NULL) { 29 | theOwner->setParent(this); 30 | } 31 | //owner = owner; 32 | } 33 | 34 | std::string &SQLPropertyExpr::getName() { 35 | return name; 36 | } 37 | 38 | void SQLPropertyExpr::setName(std::string &theName) { 39 | name = theName; 40 | } 41 | 42 | void SQLPropertyExpr::output(std::string & buf) { 43 | owner->output(buf); 44 | buf += "."; 45 | buf += name; 46 | } 47 | 48 | void SQLPropertyExpr::accept0(SQLASTVisitor *visitor) { 49 | if (visitor->visit(this)) { 50 | acceptChild(visitor, owner); 51 | } 52 | 53 | visitor->endVisit(this); 54 | } 55 | 56 | //int SQLPropertyExpr::hashCode() { 57 | //final int prime = 31; 58 | //int result = 1; 59 | //result = prime * result + ((name == NULL) ? 0 : name.hashCode()); 60 | //result = prime * result + ((owner == NULL) ? 0 : owner.hashCode()); 61 | //return result; 62 | //} 63 | 64 | //bool SQLPropertyExpr::equals(Object obj) { 65 | //if (this == obj) { 66 | //return true; 67 | //} 68 | //if (obj == NULL) { 69 | //return false; 70 | //} 71 | //if (!(obj instanceof SQLPropertyExpr)) { 72 | //return false; 73 | //} 74 | //SQLPropertyExpr other = (SQLPropertyExpr) obj; 75 | //if (name == NULL) { 76 | //if (other.name != NULL) { 77 | //return false; 78 | //} 79 | //} else if (!name.equals(other.name)) { 80 | //return false; 81 | //} 82 | //if (owner == NULL) { 83 | //if (other.owner != NULL) { 84 | //return false; 85 | //} 86 | //} else if (!owner.equals(other.owner)) { 87 | //return false; 88 | //} 89 | //return true; 90 | //} 91 | 92 | -------------------------------------------------------------------------------- /deps/smhasher/PMurHash.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------- 2 | * MurmurHash3 was written by Austin Appleby, and is placed in the public 3 | * domain. 4 | * 5 | * This implementation was written by Shane Day, and is also public domain. 6 | * 7 | * This is a portable ANSI C implementation of MurmurHash3_x86_32 (Murmur3A) 8 | * with support for progressive processing. 9 | */ 10 | 11 | /* ------------------------------------------------------------------------- */ 12 | /* Determine what native type to use for uint32_t */ 13 | 14 | /* We can't use the name 'uint32_t' here because it will conflict with 15 | * any version provided by the system headers or application. */ 16 | 17 | /* First look for special cases */ 18 | #if defined(_MSC_VER) 19 | #define MH_UINT32 unsigned long 20 | #endif 21 | 22 | /* If the compiler says it's C99 then take its word for it */ 23 | #if !defined(MH_UINT32) && ( \ 24 | defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L ) 25 | #include 26 | #define MH_UINT32 uint32_t 27 | #endif 28 | 29 | /* Otherwise try testing against max value macros from limit.h */ 30 | #if !defined(MH_UINT32) 31 | #include 32 | #if (USHRT_MAX == 0xffffffffUL) 33 | #define MH_UINT32 unsigned short 34 | #elif (UINT_MAX == 0xffffffffUL) 35 | #define MH_UINT32 unsigned int 36 | #elif (ULONG_MAX == 0xffffffffUL) 37 | #define MH_UINT32 unsigned long 38 | #endif 39 | #endif 40 | 41 | #if !defined(MH_UINT32) 42 | #error Unable to determine type name for unsigned 32-bit int 43 | #endif 44 | 45 | /* I'm yet to work on a platform where 'unsigned char' is not 8 bits */ 46 | #define MH_UINT8 unsigned char 47 | 48 | 49 | /* ------------------------------------------------------------------------- */ 50 | /* Prototypes */ 51 | 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | void PMurHash32_Process(MH_UINT32 *ph1, MH_UINT32 *pcarry, const void *key, int len); 57 | MH_UINT32 PMurHash32_Result(MH_UINT32 h1, MH_UINT32 carry, MH_UINT32 total_length); 58 | MH_UINT32 PMurHash32(MH_UINT32 seed, const void *key, int len); 59 | 60 | void PMurHash32_test(const void *key, int len, MH_UINT32 seed, void *out); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | -------------------------------------------------------------------------------- /ast/expr/SQLIdentifierExpr.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SQLIdentifierExpr.h" 3 | SQLIdentifierExpr::SQLIdentifierExpr(){ 4 | 5 | //std::cout << "\t\t\t\t\t\t" << __FILE__ << ": " << __LINE__ << ", in SQLIdentifierExpr::SQLIdentifierExpr, constructor" << std::endl; 6 | } 7 | 8 | SQLIdentifierExpr::~SQLIdentifierExpr(){ 9 | //std::cout << "\t\t\t\t\t\t" << __FILE__ << ": " << __LINE__ << ", in SQLIdentifierExpr::~SQLIdentifierExpr, destructor step 1" << std::endl; 10 | 11 | } 12 | 13 | 14 | SQLIdentifierExpr::SQLIdentifierExpr(std::string &theName){ 15 | name = theName; 16 | } 17 | 18 | std::string &SQLIdentifierExpr::getSimleName() { 19 | return name; 20 | } 21 | 22 | std::string &SQLIdentifierExpr::getName() { 23 | return name; 24 | } 25 | 26 | void SQLIdentifierExpr::setName(std::string &theName) { 27 | name = name; 28 | lowerName = ""; 29 | } 30 | 31 | std::string &SQLIdentifierExpr::getLowerName() { 32 | 33 | if (lowerName == "" && name != "") { 34 | boost::algorithm::to_lower(lowerName); 35 | //lowerName = name.toLowerCase(); 36 | } 37 | 38 | return lowerName; 39 | } 40 | 41 | void SQLIdentifierExpr::setLowerName(std::string &theLowerName) { 42 | lowerName = theLowerName; 43 | } 44 | 45 | void SQLIdentifierExpr::output(std::string &buf) { 46 | buf += name; 47 | //buf.append(name); 48 | } 49 | 50 | void SQLIdentifierExpr::accept0(SQLASTVisitor *visitor) { 51 | visitor->visit(this); 52 | 53 | visitor->endVisit(this); 54 | } 55 | 56 | //int SQLIdentifierExpr::hashCode() { 57 | //final int prime = 31; 58 | //int result = 1; 59 | //result = prime * result + ((name == NULL) ? 0 : name.hashCode()); 60 | //return result; 61 | //} 62 | 63 | //bool SQLIdentifierExpr::equals(Object obj) { 64 | //if (this == obj) { 65 | //return true; 66 | //} 67 | //if (obj == NULL) { 68 | //return false; 69 | //} 70 | //if (!(obj instanceof SQLIdentifierExpr)) { 71 | //return false; 72 | //} 73 | //SQLIdentifierExpr other = (SQLIdentifierExpr) obj; 74 | //if (name == NULL) { 75 | //if (other.name != NULL) { 76 | //return false; 77 | //} 78 | //} else if (!name.equals(other.name)) { 79 | //return false; 80 | //} 81 | //return true; 82 | //} 83 | 84 | 85 | -------------------------------------------------------------------------------- /deps/smhasher/Stats.cpp: -------------------------------------------------------------------------------- 1 | #include "Stats.h" 2 | 3 | //----------------------------------------------------------------------------- 4 | 5 | double chooseK ( int n, int k ) 6 | { 7 | if(k > (n - k)) k = n - k; 8 | 9 | double c = 1; 10 | 11 | for(int i = 0; i < k; i++) 12 | { 13 | double t = double(n-i) / double(i+1); 14 | 15 | c *= t; 16 | } 17 | 18 | return c; 19 | } 20 | 21 | double chooseUpToK ( int n, int k ) 22 | { 23 | double c = 0; 24 | 25 | for(int i = 1; i <= k; i++) 26 | { 27 | c += chooseK(n,i); 28 | } 29 | 30 | return c; 31 | } 32 | 33 | //----------------------------------------------------------------------------- 34 | // Distribution "score" 35 | // TODO - big writeup of what this score means 36 | 37 | // Basically, we're computing a constant that says "The test distribution is as 38 | // uniform, RMS-wise, as a random distribution restricted to (1-X)*100 percent of 39 | // the bins. This makes for a nice uniform way to rate a distribution that isn't 40 | // dependent on the number of bins or the number of keys 41 | 42 | // (as long as # keys > # bins * 3 or so, otherwise random fluctuations show up 43 | // as distribution weaknesses) 44 | 45 | double calcScore ( const int * bins, const int bincount, const int keycount ) 46 | { 47 | double n = bincount; 48 | double k = keycount; 49 | 50 | // compute rms value 51 | 52 | double r = 0; 53 | 54 | for(int i = 0; i < bincount; i++) 55 | { 56 | double b = bins[i]; 57 | 58 | r += b*b; 59 | } 60 | 61 | r = sqrt(r / n); 62 | 63 | // compute fill factor 64 | 65 | double f = (k*k - 1) / (n*r*r - k); 66 | 67 | // rescale to (0,1) with 0 = good, 1 = bad 68 | 69 | return 1 - (f / n); 70 | } 71 | 72 | 73 | //---------------------------------------------------------------------------- 74 | 75 | void plot ( double n ) 76 | { 77 | double n2 = n * 1; 78 | 79 | if(n2 < 0) n2 = 0; 80 | 81 | n2 *= 100; 82 | 83 | if(n2 > 64) n2 = 64; 84 | 85 | int n3 = (int)n2; 86 | 87 | if(n3 == 0) 88 | printf("."); 89 | else 90 | { 91 | char x = '0' + char(n3); 92 | 93 | if(x > '9') x = 'X'; 94 | 95 | printf("%c",x); 96 | } 97 | } 98 | 99 | //----------------------------------------------------------------------------- 100 | -------------------------------------------------------------------------------- /ast/expr/SQLAggregateExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLAggregateExpr.h" 2 | 3 | SQLAggregateExpr::SQLAggregateExpr(std::string & theMethodName): over(NULL), methodName(theMethodName){ 4 | 5 | //methodName = theMethodName; 6 | } 7 | 8 | SQLAggregateExpr::~SQLAggregateExpr(){ 9 | 10 | 11 | for(std::list::iterator it = arguments.begin(); it != arguments.end(); ++it) 12 | { 13 | delete *it; 14 | } 15 | arguments.clear(); 16 | 17 | if (over != NULL) 18 | { 19 | delete over; 20 | over = NULL; 21 | } 22 | 23 | 24 | } 25 | SQLAggregateExpr::SQLAggregateExpr(std::string & theMethodName, Option theOption): over(NULL), methodName(theMethodName), option (theOption){ 26 | //methodName = theMethodName; 27 | //option = theOption; 28 | } 29 | 30 | std::string &SQLAggregateExpr::getMethodName() { 31 | return methodName; 32 | } 33 | 34 | void SQLAggregateExpr::setMethodName(std::string &theMethodName) { 35 | methodName = theMethodName; 36 | } 37 | 38 | SQLAggregateExpr::Option SQLAggregateExpr::getOption() { 39 | return option; 40 | } 41 | 42 | void SQLAggregateExpr::setOption(Option theOption) { 43 | option = theOption; 44 | } 45 | 46 | std::list & SQLAggregateExpr::getArguments() { 47 | return arguments; 48 | } 49 | 50 | SQLOver *SQLAggregateExpr::getOver() { 51 | return over; 52 | } 53 | 54 | void SQLAggregateExpr::setOver(SQLOver * theOver) { 55 | over = theOver; 56 | } 57 | 58 | void SQLAggregateExpr::accept0(SQLASTVisitor *visitor) { 59 | 60 | if (visitor->visit(this)) { 61 | acceptChild(visitor, arguments); 62 | acceptChild(visitor, over); 63 | } 64 | 65 | visitor->endVisit(this); 66 | } 67 | 68 | void SQLAggregateExpr::acceptChild(SQLASTVisitor *visitor, SQLOver * child) 69 | { 70 | if (child == NULL) { 71 | return; 72 | } 73 | 74 | child->accept(visitor); 75 | } 76 | 77 | void SQLAggregateExpr::acceptChild(SQLASTVisitor *visitor, std::list &children) 78 | { 79 | 80 | if (children.empty()) { 81 | return; 82 | } 83 | 84 | std::list::iterator iStart = children.begin() ; 85 | std::list::iterator iEnd = children.end() ; 86 | std::list::iterator it; 87 | for (it=iStart ;it!=iEnd;++it) 88 | { 89 | (*it)->accept(visitor); 90 | //acceptChild(visitor, *it); 91 | } 92 | 93 | } 94 | 95 | 96 | -------------------------------------------------------------------------------- /ast/expr/SQLCaseExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLCaseExpr.h" 2 | SQLCaseExpr::SQLCaseExpr(){ 3 | 4 | } 5 | SQLCaseExpr::~SQLCaseExpr(){ 6 | 7 | for(std::list::iterator it = items.begin(); it != items.end(); ++it) 8 | { 9 | delete *it; 10 | } 11 | items.clear(); 12 | 13 | 14 | if (elseExpr != NULL) 15 | { 16 | 17 | delete elseExpr; 18 | elseExpr = NULL; 19 | } 20 | 21 | if (valueExpr != NULL) 22 | { 23 | 24 | delete valueExpr; 25 | valueExpr = NULL; 26 | } 27 | 28 | } 29 | SQLExpr *SQLCaseExpr::getValueExpr() { 30 | return valueExpr; 31 | } 32 | 33 | void SQLCaseExpr::setValueExpr(SQLExpr *theValueExpr) { 34 | if (theValueExpr != NULL) { 35 | theValueExpr->setParent(this); 36 | } 37 | valueExpr = theValueExpr; 38 | } 39 | 40 | SQLExpr *SQLCaseExpr::getElseExpr() { 41 | return elseExpr; 42 | } 43 | 44 | void SQLCaseExpr::setElseExpr(SQLExpr * theElseExpr) { 45 | if (theElseExpr != NULL) { 46 | theElseExpr->setParent(this); 47 | } 48 | elseExpr = theElseExpr; 49 | } 50 | 51 | std::list & SQLCaseExpr::getItems() { 52 | return items; 53 | } 54 | 55 | void SQLCaseExpr::addItem(SQLCaseExpr_Item * theItem) { 56 | if (theItem != NULL) { 57 | theItem->setParent(this); 58 | items.push_back(theItem); 59 | } 60 | } 61 | 62 | void SQLCaseExpr::accept0(SQLASTVisitor *visitor) { 63 | if (visitor->visit(this)) { 64 | acceptChild(visitor, valueExpr); 65 | acceptChild(visitor, items); 66 | acceptChild(visitor, elseExpr); 67 | } 68 | visitor->endVisit(this); 69 | } 70 | 71 | void SQLCaseExpr::acceptChild(SQLASTVisitor *visitor, std::list &children) 72 | { 73 | 74 | if (children.empty()) { 75 | return; 76 | } 77 | 78 | std::list::iterator iStart = children.begin() ; 79 | std::list::iterator iEnd = children.end() ; 80 | std::list::iterator it; 81 | for (it=iStart ;it!=iEnd;++it) 82 | { 83 | (*it)->accept(visitor); 84 | //acceptChild(visitor, *it); 85 | } 86 | 87 | } 88 | 89 | void SQLCaseExpr::acceptChild(SQLASTVisitor *visitor, SQLExpr * child) 90 | { 91 | if (child == NULL) { 92 | return; 93 | } 94 | 95 | child->accept(visitor); 96 | } 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /visitor/SQLEvalVisitorImpl.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLEvalVisitorImpl_HEADER_H 2 | #define SQLEvalVisitorImpl_HEADER_H 3 | 4 | //import java.util.ArrayList; 5 | //import java.util.HashMap; 6 | //import java.util.std::list; 7 | //import java.util.std::unordered_map; 8 | 9 | //import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; 10 | //import com.alibaba.druid.sql.ast.expr.SQLCaseExpr; 11 | //import com.alibaba.druid.sql.ast.expr.SQLCharExpr; 12 | //import com.alibaba.druid.sql.ast.expr.SQLHexExpr; 13 | //import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; 14 | //import com.alibaba.druid.sql.ast.expr.SQLInListExpr; 15 | //import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr; 16 | //import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr; 17 | //import com.alibaba.druid.sql.ast.expr.SQLNullExpr; 18 | //import com.alibaba.druid.sql.ast.expr.SQLNumberExpr; 19 | //import com.alibaba.druid.sql.ast.expr.SQLQueryExpr; 20 | //import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr; 21 | //import com.alibaba.druid.sql.visitor.functions.Function; 22 | 23 | class SQLEvalVisitorImpl : virtual public SQLASTVisitorAdapter,virtual public SQLEvalVisitor { 24 | 25 | private: 26 | std::list parameters; 27 | 28 | std::unordered_map functions; 29 | 30 | int variantIndex; 31 | 32 | bool markVariantIndex; 33 | 34 | public: 35 | SQLEvalVisitorImpl(); 36 | virtual ~SQLEvalVisitorImpl(); 37 | 38 | SQLEvalVisitorImpl(std::list parameters); 39 | 40 | std::list getParameters(); 41 | 42 | void setParameters(std::list parameters); 43 | 44 | bool visit(SQLCharExpr *x); 45 | 46 | int incrementAndGetVariantIndex(); 47 | 48 | int getVariantIndex(); 49 | 50 | bool visit(SQLVariantRefExpr *x); 51 | 52 | bool visit(SQLBinaryOpExpr *x); 53 | 54 | bool visit(SQLIntegerExpr *x); 55 | 56 | bool visit(SQLNumberExpr *x); 57 | 58 | bool visit(SQLHexExpr *x); 59 | 60 | bool visit(SQLCaseExpr *x); 61 | 62 | bool visit(SQLInListExpr *x); 63 | 64 | bool visit(SQLNullExpr *x); 65 | 66 | bool visit(SQLMethodInvokeExpr *x); 67 | 68 | bool visit(SQLQueryExpr *x); 69 | 70 | bool isMarkVariantIndex(); 71 | 72 | void setMarkVariantIndex(bool markVariantIndex); 73 | 74 | Function getFunction(std::string funcName); 75 | 76 | void registerFunction(std::string funcName, Function function); 77 | 78 | bool visit(SQLIdentifierExpr *x); 79 | 80 | void unregisterFunction(std::string funcName); 81 | }; 82 | #endif 83 | 84 | -------------------------------------------------------------------------------- /parser/SQLSelectParser.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SQLSelectParser_HEADER_H 3 | #define SQLSelectParser_HEADER_H 4 | 5 | #include 6 | 7 | #include "../ast/SQLExpr.h" 8 | #include "../ast/SQLOrderBy.h" 9 | #include "../ast/SQLSetQuantifier.h" 10 | #include "../ast/expr/SQLIdentifierExpr.h" 11 | #include "../ast/statement/SQLExprTableSource.h" 12 | #include "../ast/statement/SQLJoinTableSource.h" 13 | 14 | #include "../ast/statement/SQLSelect.h" 15 | #include "../ast/statement/SQLSelectGroupByClause.h" 16 | #include "../ast/statement/SQLSelectItem.h" 17 | #include "../ast/statement/SQLSelectQuery.h" 18 | #include "../ast/statement/SQLSelectQueryBlock.h" 19 | #include "../ast/statement/SQLSubqueryTableSource.h" 20 | #include "../ast/statement/SQLTableSource.h" 21 | #include "../ast/statement/SQLUnionOperator.h" 22 | #include "../ast/statement/SQLUnionQuery.h" 23 | #include "../ast/statement/SQLWithSubqueryClause.h" 24 | #include "../ast/statement/SQLWithSubqueryClause_Entry.h" 25 | 26 | 27 | #include "SQLParser.h" 28 | 29 | class SQLExprParser; 30 | typedef boost::shared_ptr SQLExprParser_ptr; 31 | class SQLSelectParser : public SQLParser { 32 | 33 | typedef SQLParser super; 34 | 35 | private: 36 | //std::list selectList; 37 | protected: 38 | SQLExprParser *exprParser; 39 | 40 | SQLUnionQuery *createSQLUnionQuery(); 41 | void withSubquery(SQLSelect *select); 42 | void parseWhere(SQLSelectQueryBlock *queryBlock); 43 | void parseGroupBy(SQLSelectQueryBlock *queryBlock); 44 | void parseSelectList(SQLSelectQueryBlock *queryBlock); 45 | SQLSelectItem *parseSelectItem(); 46 | SQLTableSource *parseTableSourceRest(SQLTableSource *tableSource); 47 | 48 | public: 49 | SQLSelectParser(std::string &sql); 50 | ~SQLSelectParser(); 51 | 52 | SQLSelectParser(Lexer *lexer); 53 | 54 | SQLSelectParser(SQLExprParser *exprParser); 55 | 56 | SQLSelect *select(); 57 | SQLUnionQuery *unionRest(SQLUnionQuery *xunion); 58 | SQLSelectQuery *queryRest(SQLSelectQuery *selectQuery); 59 | SQLSelectQuery *query(); 60 | void parseFrom(SQLSelectQueryBlock *queryBlock); 61 | SQLTableSource *parseTableSource(); 62 | SQLExpr *expr(); 63 | SQLOrderBy *parseOrderBy(); 64 | void acceptKeyword(std::string &ident); 65 | 66 | private: 67 | void parseTableSourceQueryTableExpr(SQLExprTableSource *tableReference); 68 | 69 | }; 70 | typedef boost::shared_ptr SQLSelectParser_ptr; 71 | 72 | 73 | #endif 74 | 75 | -------------------------------------------------------------------------------- /ast/expr/SQLInSubQueryExpr.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLInSubQueryExpr.h" 2 | SQLInSubQueryExpr::SQLInSubQueryExpr() : xnot(false){ 3 | 4 | } 5 | 6 | SQLInSubQueryExpr::~SQLInSubQueryExpr() { 7 | if (expr != NULL) 8 | { 9 | 10 | delete expr; 11 | expr = NULL; 12 | } 13 | 14 | } 15 | bool SQLInSubQueryExpr::isNot() { 16 | return xnot; 17 | } 18 | 19 | void SQLInSubQueryExpr::setNot(bool theNot) { 20 | xnot = theNot; 21 | } 22 | 23 | SQLExpr *SQLInSubQueryExpr::getExpr() { 24 | return expr; 25 | } 26 | 27 | void SQLInSubQueryExpr::setExpr(SQLExpr *theExpr) { 28 | expr = theExpr; 29 | } 30 | 31 | SQLInSubQueryExpr::SQLInSubQueryExpr(SQLSelect *theSelect) : subQuery (theSelect), xnot(false){ 32 | 33 | //subQuery = theSelect; 34 | } 35 | 36 | SQLSelect *SQLInSubQueryExpr::getSubQuery() { 37 | return subQuery; 38 | } 39 | 40 | void SQLInSubQueryExpr::setSubQuery(SQLSelect *theSubQuery) { 41 | if (theSubQuery != NULL) { 42 | theSubQuery->setParent(this); 43 | } 44 | subQuery = theSubQuery; 45 | } 46 | 47 | void SQLInSubQueryExpr::output(std::string & buf) { 48 | subQuery->output(buf); 49 | } 50 | 51 | void SQLInSubQueryExpr::accept0(SQLASTVisitor *visitor) { 52 | if (visitor->visit(this)) { 53 | acceptChild(visitor,expr); 54 | acceptChild(visitor,subQuery); 55 | } 56 | 57 | visitor->endVisit(this); 58 | } 59 | 60 | //int SQLInSubQueryExpr::hashCode() { 61 | //final int prime = 31; 62 | //int result = 1; 63 | //result = prime * result + ((expr == NULL) ? 0 : expr.hashCode()); 64 | //result = prime * result + (xnot ? 1231 : 1237); 65 | //result = prime * result + ((subQuery == NULL) ? 0 : subQuery.hashCode()); 66 | //return result; 67 | //} 68 | 69 | //bool SQLInSubQueryExpr::equals(Object obj) { 70 | //if (this == obj) { 71 | //return true; 72 | //} 73 | //if (obj == NULL) { 74 | //return false; 75 | //} 76 | //if (getClass() != obj.getClass()) { 77 | //return false; 78 | //} 79 | //SQLInSubQueryExpr other = (SQLInSubQueryExpr) obj; 80 | //if (expr == NULL) { 81 | //if (other.expr != NULL) { 82 | //return false; 83 | //} 84 | //} else if (!expr.equals(other.expr)) { 85 | //return false; 86 | //} 87 | //if (xnot != other.xnot) { 88 | //return false; 89 | //} 90 | //if (subQuery == NULL) { 91 | //if (other.subQuery != NULL) { 92 | //return false; 93 | //} 94 | //} else if (!subQuery.equals(other.subQuery)) { 95 | //return false; 96 | //} 97 | //return true; 98 | //} 99 | 100 | -------------------------------------------------------------------------------- /deps/smhasher/Platform.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // Platform-specific functions and macros 3 | 4 | #pragma once 5 | 6 | void SetAffinity ( int cpu ); 7 | 8 | //----------------------------------------------------------------------------- 9 | // Microsoft Visual Studio 10 | 11 | #if defined(_MSC_VER) 12 | 13 | #define FORCE_INLINE __forceinline 14 | #define NEVER_INLINE __declspec(noinline) 15 | 16 | #include 17 | #include // Has to be included before intrin.h or VC complains about 'ceil' 18 | #include // for __rdtsc 19 | #include "pstdint.h" 20 | 21 | #define ROTL32(x,y) _rotl(x,y) 22 | #define ROTL64(x,y) _rotl64(x,y) 23 | #define ROTR32(x,y) _rotr(x,y) 24 | #define ROTR64(x,y) _rotr64(x,y) 25 | 26 | #pragma warning(disable : 4127) // "conditional expression is constant" in the if()s for avalanchetest 27 | #pragma warning(disable : 4100) 28 | #pragma warning(disable : 4702) 29 | 30 | #define BIG_CONSTANT(x) (x) 31 | 32 | // RDTSC == Read Time Stamp Counter 33 | 34 | #define rdtsc() __rdtsc() 35 | 36 | //----------------------------------------------------------------------------- 37 | // Other compilers 38 | 39 | #else // defined(_MSC_VER) 40 | 41 | #include 42 | 43 | #define FORCE_INLINE inline __attribute__((always_inline)) 44 | #define NEVER_INLINE __attribute__((noinline)) 45 | 46 | inline uint32_t rotl32 ( uint32_t x, int8_t r ) 47 | { 48 | return (x << r) | (x >> (32 - r)); 49 | } 50 | 51 | inline uint64_t rotl64 ( uint64_t x, int8_t r ) 52 | { 53 | return (x << r) | (x >> (64 - r)); 54 | } 55 | 56 | inline uint32_t rotr32 ( uint32_t x, int8_t r ) 57 | { 58 | return (x >> r) | (x << (32 - r)); 59 | } 60 | 61 | inline uint64_t rotr64 ( uint64_t x, int8_t r ) 62 | { 63 | return (x >> r) | (x << (64 - r)); 64 | } 65 | 66 | #define ROTL32(x,y) rotl32(x,y) 67 | #define ROTL64(x,y) rotl64(x,y) 68 | #define ROTR32(x,y) rotr32(x,y) 69 | #define ROTR64(x,y) rotr64(x,y) 70 | 71 | #define BIG_CONSTANT(x) (x##LLU) 72 | 73 | __inline__ unsigned long long int rdtsc() 74 | { 75 | #ifdef __x86_64__ 76 | unsigned int a, d; 77 | __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d)); 78 | return (unsigned long)a | ((unsigned long)d << 32); 79 | #elif defined(__i386__) 80 | unsigned long long int x; 81 | __asm__ volatile ("rdtsc" : "=A" (x)); 82 | return x; 83 | #else 84 | #define NO_CYCLE_COUNTER 85 | return 0; 86 | #endif 87 | } 88 | 89 | #include 90 | #define _stricmp strcasecmp 91 | 92 | #endif // !defined(_MSC_VER) 93 | 94 | //----------------------------------------------------------------------------- 95 | --------------------------------------------------------------------------------