From eddd799c26660b7f811ad1cbc78b35adff922183 Mon Sep 17 00:00:00 2001 From: Pedro Flemming Date: Thu, 6 Apr 2017 17:25:47 +0200 Subject: [PATCH 01/12] rename operators to match constant naming style. Move the enum out of Expr --- src/parser/bison_parser.y | 24 +++++++-------- src/sql/Expr.cpp | 14 ++++----- src/sql/Expr.h | 63 ++++++++++++++++++++------------------- src/sqlhelper.cpp | 8 ++--- test/select_tests.cpp | 8 ++--- test/tpc_h_tests.cpp | 6 ++-- 6 files changed, 62 insertions(+), 61 deletions(-) diff --git a/src/parser/bison_parser.y b/src/parser/bison_parser.y index 7593212..4ecdb93 100644 --- a/src/parser/bison_parser.y +++ b/src/parser/bison_parser.y @@ -651,8 +651,8 @@ scalar_expr: ; unary_expr: - '-' operand { $$ = Expr::makeOpUnary(Expr::UMINUS, $2); } - | NOT operand { $$ = Expr::makeOpUnary(Expr::NOT, $2); } + '-' operand { $$ = Expr::makeOpUnary(kOpMinus, $2); } + | NOT operand { $$ = Expr::makeOpUnary(kOpNot, $2); } ; binary_expr: @@ -663,20 +663,20 @@ binary_expr: | operand '*' operand { $$ = Expr::makeOpBinary($1, '*', $3); } | operand '%' operand { $$ = Expr::makeOpBinary($1, '%', $3); } | operand '^' operand { $$ = Expr::makeOpBinary($1, '^', $3); } - | operand LIKE operand { $$ = Expr::makeOpBinary($1, Expr::LIKE, $3); } - | operand NOT LIKE operand { $$ = Expr::makeOpBinary($1, Expr::NOT_LIKE, $4); } + | operand LIKE operand { $$ = Expr::makeOpBinary($1, kOpLike, $3); } + | operand NOT LIKE operand { $$ = Expr::makeOpBinary($1, kOpNotLike, $4); } ; logic_expr: - expr AND expr { $$ = Expr::makeOpBinary($1, Expr::AND, $3); } - | expr OR expr { $$ = Expr::makeOpBinary($1, Expr::OR, $3); } + expr AND expr { $$ = Expr::makeOpBinary($1, kOpAnd, $3); } + | expr OR expr { $$ = Expr::makeOpBinary($1, kOpOr, $3); } ; in_expr: operand IN '(' expr_list ')' { $$ = Expr::makeInOperator($1, $4); } - | operand NOT IN '(' expr_list ')' { $$ = Expr::makeOpUnary(Expr::NOT, Expr::makeInOperator($1, $5)); } + | operand NOT IN '(' expr_list ')' { $$ = Expr::makeOpUnary(kOpNot, Expr::makeInOperator($1, $5)); } | operand IN '(' select_no_paren ')' { $$ = Expr::makeInOperator($1, $4); } - | operand NOT IN '(' select_no_paren ')' { $$ = Expr::makeOpUnary(Expr::NOT, Expr::makeInOperator($1, $5)); } + | operand NOT IN '(' select_no_paren ')' { $$ = Expr::makeOpUnary(kOpNot, Expr::makeInOperator($1, $5)); } ; // TODO: allow no else specified @@ -686,16 +686,16 @@ case_expr: exists_expr: EXISTS '(' select_no_paren ')' { $$ = Expr::makeExists($3); } - | NOT EXISTS '(' select_no_paren ')' { $$ = Expr::makeOpUnary(Expr::NOT, Expr::makeExists($4)); } + | NOT EXISTS '(' select_no_paren ')' { $$ = Expr::makeOpUnary(kOpNot, Expr::makeExists($4)); } ; comp_expr: operand '=' operand { $$ = Expr::makeOpBinary($1, '=', $3); } - | operand NOTEQUALS operand { $$ = Expr::makeOpBinary($1, Expr::NOT_EQUALS, $3); } + | operand NOTEQUALS operand { $$ = Expr::makeOpBinary($1, kOpNotEquals, $3); } | operand '<' operand { $$ = Expr::makeOpBinary($1, '<', $3); } | operand '>' operand { $$ = Expr::makeOpBinary($1, '>', $3); } - | operand LESSEQ operand { $$ = Expr::makeOpBinary($1, Expr::LESS_EQ, $3); } - | operand GREATEREQ operand { $$ = Expr::makeOpBinary($1, Expr::GREATER_EQ, $3); } + | operand LESSEQ operand { $$ = Expr::makeOpBinary($1, kOpLessEq, $3); } + | operand GREATEREQ operand { $$ = Expr::makeOpBinary($1, kOpGreaterEq, $3); } ; function_expr: diff --git a/src/sql/Expr.cpp b/src/sql/Expr.cpp index f1ebe9b..40209ab 100644 --- a/src/sql/Expr.cpp +++ b/src/sql/Expr.cpp @@ -51,7 +51,7 @@ namespace hsql { Expr* Expr::makeOpBinary(Expr* expr1, char op, Expr* expr2) { Expr* e = new Expr(kExprOperator); - e->opType = SIMPLE_OP; + e->opType = kOpSimple; e->opChar = op; e->expr = expr1; e->expr2 = expr2; @@ -61,7 +61,7 @@ namespace hsql { Expr* Expr::makeBetween(Expr* expr, Expr* left, Expr* right) { Expr* e = new Expr(kExprOperator); e->expr = expr; - e->opType = BETWEEN; + e->opType = kOpBetween; e->exprList = new std::vector(); e->exprList->push_back(left); e->exprList->push_back(right); @@ -71,7 +71,7 @@ namespace hsql { Expr* Expr::makeCase(Expr* expr, Expr* then, Expr* other) { Expr* e = new Expr(kExprOperator); e->expr = expr; - e->opType = CASE; + e->opType = kOpCase; e->exprList = new std::vector(); e->exprList->push_back(then); e->exprList->push_back(other); @@ -132,14 +132,14 @@ namespace hsql { Expr* Expr::makeExists(SelectStatement* select) { Expr* e = new Expr(kExprOperator); - e->opType = EXISTS; + e->opType = kOpExists; e->select = select; return e; } Expr* Expr::makeInOperator(Expr* expr, std::vector* exprList) { Expr* e = new Expr(kExprOperator); - e->opType = IN; + e->opType = kOpIn; e->expr = expr; e->exprList = exprList; @@ -148,7 +148,7 @@ namespace hsql { Expr* Expr::makeInOperator(Expr* expr, SelectStatement* select) { Expr* e = new Expr(kExprOperator); - e->opType = IN; + e->opType = kOpIn; e->expr = expr; e->select = select; @@ -177,7 +177,7 @@ namespace hsql { } bool Expr::isSimpleOp() { - return opType == SIMPLE_OP; + return opType == kOpSimple; } bool Expr::isSimpleOp(char op) { diff --git a/src/sql/Expr.h b/src/sql/Expr.h index 3284802..810895b 100644 --- a/src/sql/Expr.h +++ b/src/sql/Expr.h @@ -24,42 +24,43 @@ namespace hsql { kExprSelect }; + // Operator types. These are important for expressions of type kExprOperator. + // Trivial types are those that can be described by a single character e.g: + // + - * / < > = % + // Non-trivial are: <> <= >= LIKE ISNULL NOT + enum OperatorType { + kOpNone, + + // Ternary operators + kOpBetween, + kOpCase, + + // Binary operators. + // Simple operators are identified by the opChar field (e.g. =, >, <). + kOpSimple, + + kOpNotEquals, + kOpLessEq, + kOpGreaterEq, + kOpLike, + kOpNotLike, + kOpAnd, + kOpOr, + kOpIn, + + // Unary operators. + kOpNot, + kOpMinus, + kOpIsNull, + kOpExists + }; + typedef struct Expr Expr; // Represents SQL expressions (i.e. literals, operators, column_refs). // TODO: When destructing a placeholder expression, we might need to alter the placeholder_list. struct Expr { - // Operator types. These are important for expressions of type kExprOperator. - // Trivial types are those that can be described by a single character e.g: - // + - * / < > = % - // Non-trivial are: <> <= >= LIKE ISNULL NOT - enum OperatorType { - NONE, - - // Ternary operators - BETWEEN, - CASE, - - // Binary operators. - SIMPLE_OP, - NOT_EQUALS, - LESS_EQ, - GREATER_EQ, - LIKE, - NOT_LIKE, - AND, - OR, - IN, - - // Unary operators. - NOT, - UMINUS, - ISNULL, - EXISTS - }; - - - + Expr(ExprType type); // Interesting side-effect: diff --git a/src/sqlhelper.cpp b/src/sqlhelper.cpp index 529cead..36aefc8 100644 --- a/src/sqlhelper.cpp +++ b/src/sqlhelper.cpp @@ -63,16 +63,16 @@ namespace hsql { } switch (expr->opType) { - case Expr::SIMPLE_OP: + case kOpSimple: inprintC(expr->opChar, numIndent); break; - case Expr::AND: + case kOpAnd: inprint("AND", numIndent); break; - case Expr::OR: + case kOpOr: inprint("OR", numIndent); break; - case Expr::NOT: + case kOpNot: inprint("NOT", numIndent); break; default: diff --git a/test/select_tests.cpp b/test/select_tests.cpp index 7a0ddd3..1e034f3 100644 --- a/test/select_tests.cpp +++ b/test/select_tests.cpp @@ -144,7 +144,7 @@ TEST(SelectBetweenTest) { Expr* where = stmt->whereClause; ASSERT_NOTNULL(where); ASSERT(where->isType(kExprOperator)); - ASSERT_EQ(where->opType, Expr::BETWEEN); + ASSERT_EQ(where->opType, kOpBetween); ASSERT_STREQ(where->expr->getName(), "grade"); ASSERT(where->expr->isType(kExprColumnRef)); @@ -169,7 +169,7 @@ TEST(SelectConditionalSelectTest) { Expr* where = stmt->whereClause; ASSERT_NOTNULL(where); ASSERT(where->isType(kExprOperator)); - ASSERT_EQ(where->opType, Expr::AND); + ASSERT_EQ(where->opType, kOpAnd); // a = (SELECT ...) Expr* cond1 = where->expr; @@ -189,7 +189,7 @@ TEST(SelectConditionalSelectTest) { // EXISTS (SELECT ...) Expr* cond2 = where->expr2; - ASSERT_EQ(cond2->opType, Expr::EXISTS); + ASSERT_EQ(cond2->opType, kOpExists); ASSERT_NOTNULL(cond2->select); SelectStatement* ex_select = cond2->select; @@ -216,7 +216,7 @@ TEST(SelectCaseWhen) { Expr* caseExpr = func->exprList->at(0); ASSERT_NOTNULL(caseExpr); ASSERT(caseExpr->isType(kExprOperator)); - ASSERT_EQ(caseExpr->opType, Expr::CASE); + ASSERT_EQ(caseExpr->opType, kOpCase); ASSERT(caseExpr->expr->isType(kExprOperator)); ASSERT(caseExpr->expr->isSimpleOp('=')); ASSERT_EQ(caseExpr->exprList->size(), 2); diff --git a/test/tpc_h_tests.cpp b/test/tpc_h_tests.cpp index 9da1b13..6b3387a 100644 --- a/test/tpc_h_tests.cpp +++ b/test/tpc_h_tests.cpp @@ -69,18 +69,18 @@ TEST(TPCHQueryDetailTest) { Expr* where = select20->whereClause; ASSERT_NOTNULL(where); ASSERT(where->isType(kExprOperator)); - ASSERT_EQ(where->opType, Expr::AND); + ASSERT_EQ(where->opType, kOpAnd); Expr* andExpr2 = where->expr; ASSERT_NOTNULL(andExpr2); ASSERT(andExpr2->isType(kExprOperator)); - ASSERT_EQ(andExpr2->opType, Expr::AND); + ASSERT_EQ(andExpr2->opType, kOpAnd); // Test IN expression. Expr* inExpr = andExpr2->expr; ASSERT_NOTNULL(inExpr); ASSERT(inExpr->isType(kExprOperator)); - ASSERT_EQ(inExpr->opType, Expr::IN); + ASSERT_EQ(inExpr->opType, kOpIn); ASSERT_STREQ(inExpr->expr->getName(), "S_SUPPKEY"); ASSERT_NOTNULL(inExpr->select); From 7bce903eb8423c1e2f848ca53d30b671bf26d4ac Mon Sep 17 00:00:00 2001 From: Pedro Flemming Date: Thu, 6 Apr 2017 17:42:46 +0200 Subject: [PATCH 02/12] fix various const constraints and comments --- src/SQLParserResult.h | 4 ++-- src/sql/Expr.cpp | 16 ++++++++-------- src/sql/Expr.h | 24 ++++++++++-------------- src/sql/SelectStatement.h | 4 +--- src/sql/Table.h | 4 ++-- src/sql/statements.cpp | 4 ++-- 6 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/SQLParserResult.h b/src/SQLParserResult.h index 96e19cf..0e4e562 100644 --- a/src/SQLParserResult.h +++ b/src/SQLParserResult.h @@ -15,7 +15,7 @@ namespace hsql { // Takes ownership of the statement. SQLParserResult(SQLStatement* stmt); - // Deletes all statements in the resul. + // Deletes all statements in the result. virtual ~SQLParserResult(); // Returns true if parsing was successful. @@ -40,7 +40,7 @@ namespace hsql { SQLStatement* getMutableStatement(int index); // Adds a statement to the result list of statements. - // Takes ownership of the statement. + // SQLParserResult takes ownership of the statement. void addStatement(SQLStatement* stmt); // Set whether parsing was successful. diff --git a/src/sql/Expr.cpp b/src/sql/Expr.cpp index 40209ab..1345714 100644 --- a/src/sql/Expr.cpp +++ b/src/sql/Expr.cpp @@ -155,32 +155,32 @@ namespace hsql { return e; } - bool Expr::isType(ExprType e_type) { - return e_type == type; + bool Expr::isType(ExprType exprType) const { + return exprType == type; } - bool Expr::isLiteral() { + bool Expr::isLiteral() const { return isType(kExprLiteralInt) || isType(kExprLiteralFloat) || isType(kExprLiteralString) || isType(kExprPlaceholder); } - bool Expr::hasAlias() { + bool Expr::hasAlias() const { return alias != NULL; } - bool Expr::hasTable() { + bool Expr::hasTable() const { return table != NULL; } - char* Expr::getName() { + const char* Expr::getName() const { if (alias != NULL) return alias; else return name; } - bool Expr::isSimpleOp() { + bool Expr::isSimpleOp() const { return opType == kOpSimple; } - bool Expr::isSimpleOp(char op) { + bool Expr::isSimpleOp(char op) const { return isSimpleOp() && opChar == op; } diff --git a/src/sql/Expr.h b/src/sql/Expr.h index 810895b..536bd31 100644 --- a/src/sql/Expr.h +++ b/src/sql/Expr.h @@ -36,7 +36,7 @@ namespace hsql { kOpCase, // Binary operators. - // Simple operators are identified by the opChar field (e.g. =, >, <). + // Simple operators are identified by the opChar field (e.g. +, -, =, >, <). kOpSimple, kOpNotEquals, @@ -60,13 +60,9 @@ namespace hsql { // Represents SQL expressions (i.e. literals, operators, column_refs). // TODO: When destructing a placeholder expression, we might need to alter the placeholder_list. struct Expr { - - Expr(ExprType type); - // Interesting side-effect: - // Making the destructor virtual used to cause segmentation faults. - // TODO: inspect. - ~Expr(); + Expr(ExprType type); + virtual ~Expr(); ExprType type; @@ -89,19 +85,19 @@ namespace hsql { // Convenience accessor methods. - bool isType(ExprType e_type); + bool isType(ExprType exprType) const; - bool isLiteral(); + bool isLiteral() const; - bool hasAlias(); + bool hasAlias() const; - bool hasTable(); + bool hasTable() const; - char* getName(); + const char* getName() const; - bool isSimpleOp(); + bool isSimpleOp() const; - bool isSimpleOp(char op); + bool isSimpleOp(char op) const; // Static constructors. diff --git a/src/sql/SelectStatement.h b/src/sql/SelectStatement.h index bb60836..7606e68 100644 --- a/src/sql/SelectStatement.h +++ b/src/sql/SelectStatement.h @@ -13,7 +13,6 @@ namespace hsql { /** * Description of the order by clause within a select statement - * TODO: hold multiple expressions to be sorted by */ struct OrderDescription { OrderDescription(OrderType type, Expr* expr); @@ -41,8 +40,7 @@ namespace hsql { */ struct GroupByDescription { GroupByDescription(); - // TODO: make virtual - ~GroupByDescription(); + virtual ~GroupByDescription(); std::vector* columns; Expr* having; diff --git a/src/sql/Table.h b/src/sql/Table.h index 58ecca4..745d5f1 100644 --- a/src/sql/Table.h +++ b/src/sql/Table.h @@ -35,10 +35,10 @@ namespace hsql { JoinDefinition* join; // Returns true if a schema is set. - bool hasSchema(); + bool hasSchema() const; // Returns the alias, if it is set. Otherwise the name. - char* getName(); + const char* getName() const; }; // Possible types of joins. diff --git a/src/sql/statements.cpp b/src/sql/statements.cpp index 69ffc84..75b794f 100644 --- a/src/sql/statements.cpp +++ b/src/sql/statements.cpp @@ -268,11 +268,11 @@ namespace hsql { } } - bool TableRef::hasSchema() { + bool TableRef::hasSchema() const { return schema != NULL; } - char* TableRef::getName() { + const char* TableRef::getName() const { if (alias != NULL) return alias; else return name; } From de48a0bafd91a28081b5876ddbb53a9d2df82573 Mon Sep 17 00:00:00 2001 From: Pedro Flemming Date: Thu, 6 Apr 2017 18:27:47 +0200 Subject: [PATCH 03/12] adjust define guard namings --- src/SQLParser.h | 4 ++-- src/SQLParserResult.h | 6 +++--- src/sql/CreateStatement.h | 4 ++-- src/sql/DeleteStatement.h | 4 ++-- src/sql/DropStatement.h | 4 ++-- src/sql/ExecuteStatement.h | 4 ++-- src/sql/Expr.h | 4 ++-- src/sql/ImportStatement.h | 4 ++-- src/sql/InsertStatement.h | 4 ++-- src/sql/PrepareStatement.h | 4 ++-- src/sql/SQLStatement.h | 6 +++--- src/sql/SelectStatement.h | 4 ++-- src/sql/Table.h | 4 ++-- src/sql/UpdateStatement.h | 4 ++-- src/sql/statements.h | 6 +++--- 15 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/SQLParser.h b/src/SQLParser.h index 5bb2a4a..7ee774e 100644 --- a/src/SQLParser.h +++ b/src/SQLParser.h @@ -1,5 +1,5 @@ -#ifndef __SQLPARSER_H_ -#define __SQLPARSER_H_ +#ifndef __SQLPARSER__SQLPARSER_H__ +#define __SQLPARSER__SQLPARSER_H__ #include "SQLParserResult.h" #include "sql/statements.h" diff --git a/src/SQLParserResult.h b/src/SQLParserResult.h index 0e4e562..a39c1cb 100644 --- a/src/SQLParserResult.h +++ b/src/SQLParserResult.h @@ -1,5 +1,5 @@ -#ifndef __SQLPARSERRESULT__ -#define __SQLPARSERRESULT__ +#ifndef __SQLPARSER__SQLPARSER_RESULT_H__ +#define __SQLPARSER__SQLPARSER_RESULT_H__ #include "sql/SQLStatement.h" @@ -70,4 +70,4 @@ namespace hsql { } // namespace hsql -#endif // __SQLPARSERRESULT__ \ No newline at end of file +#endif // __SQLPARSER__SQLPARSER_RESULT_H__ \ No newline at end of file diff --git a/src/sql/CreateStatement.h b/src/sql/CreateStatement.h index 5b96d33..92e4d39 100644 --- a/src/sql/CreateStatement.h +++ b/src/sql/CreateStatement.h @@ -1,5 +1,5 @@ -#ifndef __CREATE_STATEMENT_H__ -#define __CREATE_STATEMENT_H__ +#ifndef __SQLPARSER__CREATE_STATEMENT_H__ +#define __SQLPARSER__CREATE_STATEMENT_H__ #include "SQLStatement.h" diff --git a/src/sql/DeleteStatement.h b/src/sql/DeleteStatement.h index ed4d77d..af34352 100644 --- a/src/sql/DeleteStatement.h +++ b/src/sql/DeleteStatement.h @@ -1,5 +1,5 @@ -#ifndef __DELETE_STATEMENT_H__ -#define __DELETE_STATEMENT_H__ +#ifndef __SQLPARSER__DELETE_STATEMENT_H__ +#define __SQLPARSER__DELETE_STATEMENT_H__ #include "SQLStatement.h" diff --git a/src/sql/DropStatement.h b/src/sql/DropStatement.h index 08c1b53..18b1363 100644 --- a/src/sql/DropStatement.h +++ b/src/sql/DropStatement.h @@ -1,5 +1,5 @@ -#ifndef __DROP_STATEMENT_H__ -#define __DROP_STATEMENT_H__ +#ifndef __SQLPARSER__DROP_STATEMENT_H__ +#define __SQLPARSER__DROP_STATEMENT_H__ #include "SQLStatement.h" diff --git a/src/sql/ExecuteStatement.h b/src/sql/ExecuteStatement.h index 2f5db10..0bd9c42 100644 --- a/src/sql/ExecuteStatement.h +++ b/src/sql/ExecuteStatement.h @@ -1,5 +1,5 @@ -#ifndef __EXECUTE_STATEMENT_H__ -#define __EXECUTE_STATEMENT_H__ +#ifndef __SQLPARSER__EXECUTE_STATEMENT_H__ +#define __SQLPARSER__EXECUTE_STATEMENT_H__ #include "SQLStatement.h" diff --git a/src/sql/Expr.h b/src/sql/Expr.h index 536bd31..bba37bd 100644 --- a/src/sql/Expr.h +++ b/src/sql/Expr.h @@ -1,5 +1,5 @@ -#ifndef __EXPRESSION_H__ -#define __EXPRESSION_H__ +#ifndef __SQLPARSER__EXPR_H__ +#define __SQLPARSER__EXPR_H__ #include #include diff --git a/src/sql/ImportStatement.h b/src/sql/ImportStatement.h index 4fb3e3e..1290713 100644 --- a/src/sql/ImportStatement.h +++ b/src/sql/ImportStatement.h @@ -1,5 +1,5 @@ -#ifndef __IMPORT_STATEMENT_H__ -#define __IMPORT_STATEMENT_H__ +#ifndef __SQLPARSER__IMPORT_STATEMENT_H__ +#define __SQLPARSER__IMPORT_STATEMENT_H__ #include "SQLStatement.h" diff --git a/src/sql/InsertStatement.h b/src/sql/InsertStatement.h index 06184fa..3aa8fd2 100644 --- a/src/sql/InsertStatement.h +++ b/src/sql/InsertStatement.h @@ -1,5 +1,5 @@ -#ifndef __INSERT_STATEMENT_H__ -#define __INSERT_STATEMENT_H__ +#ifndef __SQLPARSER__INSERT_STATEMENT_H__ +#define __SQLPARSER__INSERT_STATEMENT_H__ #include "SQLStatement.h" #include "SelectStatement.h" diff --git a/src/sql/PrepareStatement.h b/src/sql/PrepareStatement.h index 9455952..c65e7f4 100644 --- a/src/sql/PrepareStatement.h +++ b/src/sql/PrepareStatement.h @@ -1,5 +1,5 @@ -#ifndef __PREPARE_STATEMENT_H__ -#define __PREPARE_STATEMENT_H__ +#ifndef __SQLPARSER__PREPARE_STATEMENT_H__ +#define __SQLPARSER__PREPARE_STATEMENT_H__ #include "../SQLParserResult.h" #include "SQLStatement.h" diff --git a/src/sql/SQLStatement.h b/src/sql/SQLStatement.h index 4c87cb8..1e1e643 100644 --- a/src/sql/SQLStatement.h +++ b/src/sql/SQLStatement.h @@ -1,5 +1,5 @@ -#ifndef __SQLSTATEMENT_H__ -#define __SQLSTATEMENT_H__ +#ifndef __SQLPARSER__SQLSTATEMENT_H__ +#define __SQLPARSER__SQLSTATEMENT_H__ #include "Expr.h" #include @@ -36,4 +36,4 @@ namespace hsql { }; } // namespace hsql -#endif // __SQLSTATEMENT_H__ +#endif // __SQLPARSER__SQLSTATEMENT_H__ diff --git a/src/sql/SelectStatement.h b/src/sql/SelectStatement.h index 7606e68..095310e 100644 --- a/src/sql/SelectStatement.h +++ b/src/sql/SelectStatement.h @@ -1,5 +1,5 @@ -#ifndef __SELECT_STATEMENT_H__ -#define __SELECT_STATEMENT_H__ +#ifndef __SQLPARSER__SELECT_STATEMENT_H__ +#define __SQLPARSER__SELECT_STATEMENT_H__ #include "SQLStatement.h" #include "Expr.h" diff --git a/src/sql/Table.h b/src/sql/Table.h index 745d5f1..96ee775 100644 --- a/src/sql/Table.h +++ b/src/sql/Table.h @@ -1,5 +1,5 @@ -#ifndef __TABLEREF_H__ -#define __TABLEREF_H__ +#ifndef __SQLPARSER__TABLEREF_H__ +#define __SQLPARSER__TABLEREF_H__ #include "Expr.h" #include diff --git a/src/sql/UpdateStatement.h b/src/sql/UpdateStatement.h index b4d6e28..744d55b 100644 --- a/src/sql/UpdateStatement.h +++ b/src/sql/UpdateStatement.h @@ -1,5 +1,5 @@ -#ifndef __UPDATE_STATEMENT_H__ -#define __UPDATE_STATEMENT_H__ +#ifndef __SQLPARSER__UPDATE_STATEMENT_H__ +#define __SQLPARSER__UPDATE_STATEMENT_H__ #include "SQLStatement.h" diff --git a/src/sql/statements.h b/src/sql/statements.h index 13c4a30..d9e59ea 100644 --- a/src/sql/statements.h +++ b/src/sql/statements.h @@ -1,5 +1,5 @@ -#ifndef __STATEMENTS_H__ -#define __STATEMENTS_H__ +#ifndef __SQLPARSER__STATEMENTS_H__ +#define __SQLPARSER__STATEMENTS_H__ #include "SelectStatement.h" #include "ImportStatement.h" @@ -11,4 +11,4 @@ #include "PrepareStatement.h" #include "ExecuteStatement.h" -#endif // __STATEMENTS_H__ \ No newline at end of file +#endif // __SQLPARSER__STATEMENTS_H__ \ No newline at end of file From 1a97db687b861e7414a015dbc44e90c98ac9004b Mon Sep 17 00:00:00 2001 From: Pedro Flemming Date: Thu, 6 Apr 2017 18:28:22 +0200 Subject: [PATCH 04/12] update parser and lexer --- src/parser/bison_parser.cpp | 24 ++-- src/parser/flex_lexer.cpp | 244 +++++++++++++++++++----------------- src/parser/flex_lexer.h | 46 +++---- 3 files changed, 161 insertions(+), 153 deletions(-) diff --git a/src/parser/bison_parser.cpp b/src/parser/bison_parser.cpp index 6db91ac..42eab82 100644 --- a/src/parser/bison_parser.cpp +++ b/src/parser/bison_parser.cpp @@ -3029,13 +3029,13 @@ yyreduce: case 102: #line 654 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.expr) = Expr::makeOpUnary(Expr::UMINUS, (yyvsp[0].expr)); } + { (yyval.expr) = Expr::makeOpUnary(kOpMinus, (yyvsp[0].expr)); } #line 3034 "bison_parser.cpp" /* yacc.c:1646 */ break; case 103: #line 655 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.expr) = Expr::makeOpUnary(Expr::NOT, (yyvsp[0].expr)); } + { (yyval.expr) = Expr::makeOpUnary(kOpNot, (yyvsp[0].expr)); } #line 3040 "bison_parser.cpp" /* yacc.c:1646 */ break; @@ -3077,25 +3077,25 @@ yyreduce: case 111: #line 666 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), Expr::LIKE, (yyvsp[0].expr)); } + { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), kOpLike, (yyvsp[0].expr)); } #line 3082 "bison_parser.cpp" /* yacc.c:1646 */ break; case 112: #line 667 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.expr) = Expr::makeOpBinary((yyvsp[-3].expr), Expr::NOT_LIKE, (yyvsp[0].expr)); } + { (yyval.expr) = Expr::makeOpBinary((yyvsp[-3].expr), kOpNotLike, (yyvsp[0].expr)); } #line 3088 "bison_parser.cpp" /* yacc.c:1646 */ break; case 113: #line 671 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), Expr::AND, (yyvsp[0].expr)); } + { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), kOpAnd, (yyvsp[0].expr)); } #line 3094 "bison_parser.cpp" /* yacc.c:1646 */ break; case 114: #line 672 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), Expr::OR, (yyvsp[0].expr)); } + { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), kOpOr, (yyvsp[0].expr)); } #line 3100 "bison_parser.cpp" /* yacc.c:1646 */ break; @@ -3107,7 +3107,7 @@ yyreduce: case 116: #line 677 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.expr) = Expr::makeOpUnary(Expr::NOT, Expr::makeInOperator((yyvsp[-5].expr), (yyvsp[-1].expr_vec))); } + { (yyval.expr) = Expr::makeOpUnary(kOpNot, Expr::makeInOperator((yyvsp[-5].expr), (yyvsp[-1].expr_vec))); } #line 3112 "bison_parser.cpp" /* yacc.c:1646 */ break; @@ -3119,7 +3119,7 @@ yyreduce: case 118: #line 679 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.expr) = Expr::makeOpUnary(Expr::NOT, Expr::makeInOperator((yyvsp[-5].expr), (yyvsp[-1].select_stmt))); } + { (yyval.expr) = Expr::makeOpUnary(kOpNot, Expr::makeInOperator((yyvsp[-5].expr), (yyvsp[-1].select_stmt))); } #line 3124 "bison_parser.cpp" /* yacc.c:1646 */ break; @@ -3137,7 +3137,7 @@ yyreduce: case 121: #line 689 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.expr) = Expr::makeOpUnary(Expr::NOT, Expr::makeExists((yyvsp[-1].select_stmt))); } + { (yyval.expr) = Expr::makeOpUnary(kOpNot, Expr::makeExists((yyvsp[-1].select_stmt))); } #line 3142 "bison_parser.cpp" /* yacc.c:1646 */ break; @@ -3149,7 +3149,7 @@ yyreduce: case 123: #line 694 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), Expr::NOT_EQUALS, (yyvsp[0].expr)); } + { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), kOpNotEquals, (yyvsp[0].expr)); } #line 3154 "bison_parser.cpp" /* yacc.c:1646 */ break; @@ -3167,13 +3167,13 @@ yyreduce: case 126: #line 697 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), Expr::LESS_EQ, (yyvsp[0].expr)); } + { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), kOpLessEq, (yyvsp[0].expr)); } #line 3172 "bison_parser.cpp" /* yacc.c:1646 */ break; case 127: #line 698 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), Expr::GREATER_EQ, (yyvsp[0].expr)); } + { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), kOpGreaterEq, (yyvsp[0].expr)); } #line 3178 "bison_parser.cpp" /* yacc.c:1646 */ break; diff --git a/src/parser/flex_lexer.cpp b/src/parser/flex_lexer.cpp index 0da323a..cf6073b 100644 --- a/src/parser/flex_lexer.cpp +++ b/src/parser/flex_lexer.cpp @@ -8,8 +8,8 @@ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 35 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 1 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif @@ -88,25 +88,13 @@ typedef unsigned int flex_uint32_t; #endif /* ! FLEXINT_H */ -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST +/* TODO: this is always defined, so inline it */ #define yyconst const + +#if defined(__GNUC__) && __GNUC__ >= 3 +#define yynoreturn __attribute__((__noreturn__)) #else -#define yyconst +#define yynoreturn #endif /* Returned upon end-of-file. */ @@ -179,11 +167,17 @@ typedef void* yyscan_t; typedef struct yy_buffer_state *YY_BUFFER_STATE; #endif +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 #define YY_LESS_LINENO(n) + #define YY_LINENO_REWIND_TO(ptr) /* Return all but the first "n" matched characters back to the input stream. */ #define yyless(n) \ @@ -201,11 +195,6 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; #define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE struct yy_buffer_state @@ -218,7 +207,7 @@ struct yy_buffer_state /* Size of input buffer in bytes, not including room for EOB * characters. */ - yy_size_t yy_buf_size; + int yy_buf_size; /* Number of characters read into yy_ch_buf, not including EOB * characters. @@ -246,7 +235,7 @@ struct yy_buffer_state int yy_bs_lineno; /**< The line count. */ int yy_bs_column; /**< The column count. */ - + /* Whether to try to fill the input buffer when we reach the * end of it. */ @@ -334,7 +323,7 @@ void hsql_free (void * ,yyscan_t yyscanner ); /* Begin user sect3 */ -#define hsql_wrap(n) 1 +#define hsql_wrap(yyscanner) (/*CONSTCOND*/1) #define YY_SKIP_YYWRAP typedef unsigned char YY_CHAR; @@ -346,14 +335,14 @@ typedef int yy_state_type; static yy_state_type yy_get_previous_state (yyscan_t yyscanner ); static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner); static int yy_get_next_buffer (yyscan_t yyscanner ); -static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner ); +static void yynoreturn yy_fatal_error (yyconst char* msg ,yyscan_t yyscanner ); /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ #define YY_DO_BEFORE_ACTION \ yyg->yytext_ptr = yy_bp; \ - yyleng = (size_t) (yy_cp - yy_bp); \ + yyleng = (int) (yy_cp - yy_bp); \ yyg->yy_hold_char = *yy_cp; \ *yy_cp = '\0'; \ yyg->yy_c_buf_p = yy_cp; @@ -472,7 +461,7 @@ static yyconst flex_int16_t yy_accept[914] = 2, 2, 0 } ; -static yyconst flex_int32_t yy_ec[256] = +static yyconst YY_CHAR yy_ec[256] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -504,7 +493,7 @@ static yyconst flex_int32_t yy_ec[256] = 1, 1, 1, 1, 1 } ; -static yyconst flex_int32_t yy_meta[66] = +static yyconst YY_CHAR yy_meta[66] = { 0, 1, 1, 2, 3, 1, 1, 1, 1, 4, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, @@ -515,7 +504,7 @@ static yyconst flex_int32_t yy_meta[66] = 4, 4, 4, 4, 4 } ; -static yyconst flex_int16_t yy_base[921] = +static yyconst flex_uint16_t yy_base[921] = { 0, 0, 0, 65, 0, 349, 3639, 129, 131, 0, 3639, 338, 332, 310, 127, 126, 305, 123, 123, 131, 177, @@ -725,7 +714,7 @@ static yyconst flex_int16_t yy_def[921] = 52, 52, 0, 913, 913, 913, 913, 913, 913, 913 } ; -static yyconst flex_int16_t yy_nxt[3705] = +static yyconst flex_uint16_t yy_nxt[3705] = { 0, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10, 16, 17, 18, 19, 20, 21, 22, 23, 24, @@ -1585,7 +1574,7 @@ static yyconst flex_int16_t yy_chk[3705] = /*************************** ** Section 3: Rules ***************************/ -#line 1589 "flex_lexer.cpp" +#line 1578 "flex_lexer.cpp" #define INITIAL 0 #define COMMENT 1 @@ -1667,19 +1656,23 @@ void hsql_set_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner ); FILE *hsql_get_in (yyscan_t yyscanner ); -void hsql_set_in (FILE * in_str ,yyscan_t yyscanner ); +void hsql_set_in (FILE * _in_str ,yyscan_t yyscanner ); FILE *hsql_get_out (yyscan_t yyscanner ); -void hsql_set_out (FILE * out_str ,yyscan_t yyscanner ); +void hsql_set_out (FILE * _out_str ,yyscan_t yyscanner ); -int hsql_get_leng (yyscan_t yyscanner ); + int hsql_get_leng (yyscan_t yyscanner ); char *hsql_get_text (yyscan_t yyscanner ); int hsql_get_lineno (yyscan_t yyscanner ); -void hsql_set_lineno (int line_number ,yyscan_t yyscanner ); +void hsql_set_lineno (int _line_number ,yyscan_t yyscanner ); + +int hsql_get_column (yyscan_t yyscanner ); + +void hsql_set_column (int _column_no ,yyscan_t yyscanner ); YYSTYPE * hsql_get_lval (yyscan_t yyscanner ); @@ -1701,6 +1694,10 @@ extern int hsql_wrap (yyscan_t yyscanner ); #endif #endif +#ifndef YY_NO_UNPUT + +#endif + #ifndef yytext_ptr static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner); #endif @@ -1734,7 +1731,7 @@ static int input (yyscan_t yyscanner ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) +#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, @@ -1758,7 +1755,7 @@ static int input (yyscan_t yyscanner ); else \ { \ errno=0; \ - while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ + while ( (result = (int) fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ { \ if( errno != EINTR) \ { \ @@ -1815,7 +1812,7 @@ extern int hsql_lex \ /* Code executed at the end of each rule. */ #ifndef YY_BREAK -#define YY_BREAK break; +#define YY_BREAK /*LINTED*/break; #endif #define YY_RULE_SETUP \ @@ -1825,16 +1822,11 @@ extern int hsql_lex \ */ YY_DECL { - register yy_state_type yy_current_state; - register char *yy_cp, *yy_bp; - register int yy_act; + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; -#line 51 "flex_lexer.l" - - -#line 1837 "flex_lexer.cpp" - yylval = yylval_param; yylloc = yylloc_param; @@ -1865,7 +1857,13 @@ YY_DECL hsql__load_buffer_state(yyscanner ); } - while ( 1 ) /* loops until end-of-file is reached */ + { +#line 51 "flex_lexer.l" + + +#line 1865 "flex_lexer.cpp" + + while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { yy_cp = yyg->yy_c_buf_p; @@ -1881,7 +1879,7 @@ YY_DECL yy_match: do { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; if ( yy_accept[yy_current_state] ) { yyg->yy_last_accepting_state = yy_current_state; @@ -1893,7 +1891,7 @@ yy_match: if ( yy_current_state >= 914 ) yy_c = yy_meta[(unsigned int) yy_c]; } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; ++yy_cp; } while ( yy_current_state != 913 ); @@ -2592,7 +2590,7 @@ YY_RULE_SETUP #line 213 "flex_lexer.l" ECHO; YY_BREAK -#line 2596 "flex_lexer.cpp" +#line 2594 "flex_lexer.cpp" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(COMMENT): yyterminate(); @@ -2725,6 +2723,7 @@ case YY_STATE_EOF(COMMENT): "fatal flex scanner internal error--no action found" ); } /* end of action switch */ } /* end of scanning one token */ + } /* end of user's declarations */ } /* end of hsql_lex */ /* yy_get_next_buffer - try to read in a new buffer @@ -2737,9 +2736,9 @@ case YY_STATE_EOF(COMMENT): static int yy_get_next_buffer (yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - register char *source = yyg->yytext_ptr; - register int number_to_move, i; + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = yyg->yytext_ptr; + yy_size_t number_to_move, i; int ret_val; if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] ) @@ -2768,7 +2767,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) /* Try to read more data. */ /* First move last chars to start of buffer. */ - number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1; + number_to_move = (yy_size_t) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1; for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); @@ -2788,7 +2787,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) { /* Not enough room in the buffer - grow it. */ /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER; + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; int yy_c_buf_p_offset = (int) (yyg->yy_c_buf_p - b->yy_ch_buf); @@ -2808,7 +2807,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) } else /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; + b->yy_ch_buf = NULL; if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( @@ -2826,7 +2825,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) /* Read in more data. */ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - yyg->yy_n_chars, (size_t) num_to_read ); + yyg->yy_n_chars, num_to_read ); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } @@ -2850,9 +2849,9 @@ static int yy_get_next_buffer (yyscan_t yyscanner) else ret_val = EOB_ACT_CONTINUE_SCAN; - if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + if ((int) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { /* Extend the array by 50%, plus the number we really need. */ - yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); + int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) hsql_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner ); if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); @@ -2871,15 +2870,15 @@ static int yy_get_next_buffer (yyscan_t yyscanner) static yy_state_type yy_get_previous_state (yyscan_t yyscanner) { - register yy_state_type yy_current_state; - register char *yy_cp; + yy_state_type yy_current_state; + char *yy_cp; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; yy_current_state = yyg->yy_start; for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) { - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); if ( yy_accept[yy_current_state] ) { yyg->yy_last_accepting_state = yy_current_state; @@ -2891,7 +2890,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) if ( yy_current_state >= 914 ) yy_c = yy_meta[(unsigned int) yy_c]; } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; } return yy_current_state; @@ -2904,11 +2903,11 @@ static int yy_get_next_buffer (yyscan_t yyscanner) */ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) { - register int yy_is_jam; + int yy_is_jam; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ - register char *yy_cp = yyg->yy_c_buf_p; + char *yy_cp = yyg->yy_c_buf_p; - register YY_CHAR yy_c = 1; + YY_CHAR yy_c = 1; if ( yy_accept[yy_current_state] ) { yyg->yy_last_accepting_state = yy_current_state; @@ -2920,12 +2919,17 @@ static int yy_get_next_buffer (yyscan_t yyscanner) if ( yy_current_state >= 914 ) yy_c = yy_meta[(unsigned int) yy_c]; } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; yy_is_jam = (yy_current_state == 913); + (void)yyg; return yy_is_jam ? 0 : yy_current_state; } +#ifndef YY_NO_UNPUT + +#endif + #ifndef YY_NO_INPUT #ifdef __cplusplus static int yyinput (yyscan_t yyscanner) @@ -2975,7 +2979,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) case EOB_ACT_END_OF_FILE: { if ( hsql_wrap(yyscanner ) ) - return EOF; + return 0; if ( ! yyg->yy_did_buffer_switch_on_eof ) YY_NEW_FILE; @@ -3079,7 +3083,7 @@ static void hsql__load_buffer_state (yyscan_t yyscanner) if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in hsql__create_buffer()" ); - b->yy_buf_size = size; + b->yy_buf_size = (yy_size_t)size; /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. @@ -3240,15 +3244,15 @@ static void hsql_ensure_buffer_stack (yyscan_t yyscanner) * scanner will even need a stack. We use 2 instead of 1 to avoid an * immediate realloc on the next call. */ - num_to_alloc = 1; + num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ yyg->yy_buffer_stack = (struct yy_buffer_state**)hsql_alloc (num_to_alloc * sizeof(struct yy_buffer_state*) , yyscanner); if ( ! yyg->yy_buffer_stack ) YY_FATAL_ERROR( "out of dynamic memory in hsql_ensure_buffer_stack()" ); - + memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - + yyg->yy_buffer_stack_max = num_to_alloc; yyg->yy_buffer_stack_top = 0; return; @@ -3257,7 +3261,7 @@ static void hsql_ensure_buffer_stack (yyscan_t yyscanner) if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ /* Increase the buffer to prepare for a possible push. */ - int grow_size = 8 /* arbitrary grow size */; + yy_size_t grow_size = 8 /* arbitrary grow size */; num_to_alloc = yyg->yy_buffer_stack_max + grow_size; yyg->yy_buffer_stack = (struct yy_buffer_state**)hsql_realloc @@ -3277,7 +3281,7 @@ static void hsql_ensure_buffer_stack (yyscan_t yyscanner) * @param base the character buffer * @param size the size in bytes of the character buffer * @param yyscanner The scanner object. - * @return the newly allocated buffer state object. + * @return the newly allocated buffer state object. */ YY_BUFFER_STATE hsql__scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner) { @@ -3287,7 +3291,7 @@ YY_BUFFER_STATE hsql__scan_buffer (char * base, yy_size_t size , yyscan_t yysc base[size-2] != YY_END_OF_BUFFER_CHAR || base[size-1] != YY_END_OF_BUFFER_CHAR ) /* They forgot to leave room for the EOB's. */ - return 0; + return NULL; b = (YY_BUFFER_STATE) hsql_alloc(sizeof( struct yy_buffer_state ) ,yyscanner ); if ( ! b ) @@ -3296,7 +3300,7 @@ YY_BUFFER_STATE hsql__scan_buffer (char * base, yy_size_t size , yyscan_t yysc b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ b->yy_buf_pos = b->yy_ch_buf = base; b->yy_is_our_buffer = 0; - b->yy_input_file = 0; + b->yy_input_file = NULL; b->yy_n_chars = b->yy_buf_size; b->yy_is_interactive = 0; b->yy_at_bol = 1; @@ -3319,7 +3323,7 @@ YY_BUFFER_STATE hsql__scan_buffer (char * base, yy_size_t size , yyscan_t yysc YY_BUFFER_STATE hsql__scan_string (yyconst char * yystr , yyscan_t yyscanner) { - return hsql__scan_bytes(yystr,strlen(yystr) ,yyscanner); + return hsql__scan_bytes(yystr,(int) strlen(yystr) ,yyscanner); } /** Setup the input buffer state to scan the given bytes. The next call to hsql_lex() will @@ -3334,10 +3338,10 @@ YY_BUFFER_STATE hsql__scan_bytes (yyconst char * yybytes, int _yybytes_len , y YY_BUFFER_STATE b; char *buf; yy_size_t n; - int i; + yy_size_t i; /* Get memory for full buffer, including space for trailing EOB's. */ - n = _yybytes_len + 2; + n = (yy_size_t) _yybytes_len + 2; buf = (char *) hsql_alloc(n ,yyscanner ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in hsql__scan_bytes()" ); @@ -3363,9 +3367,11 @@ YY_BUFFER_STATE hsql__scan_bytes (yyconst char * yybytes, int _yybytes_len , y #define YY_EXIT_FAILURE 2 #endif -static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner) +static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner) { - (void) fprintf( stderr, "%s\n", msg ); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + (void) fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE ); } @@ -3403,7 +3409,7 @@ YY_EXTRA_TYPE hsql_get_extra (yyscan_t yyscanner) int hsql_get_lineno (yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - + if (! YY_CURRENT_BUFFER) return 0; @@ -3416,7 +3422,7 @@ int hsql_get_lineno (yyscan_t yyscanner) int hsql_get_column (yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - + if (! YY_CURRENT_BUFFER) return 0; @@ -3471,51 +3477,51 @@ void hsql_set_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner) } /** Set the current line number. - * @param line_number + * @param _line_number line number * @param yyscanner The scanner object. */ -void hsql_set_lineno (int line_number , yyscan_t yyscanner) +void hsql_set_lineno (int _line_number , yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* lineno is only valid if an input buffer exists. */ if (! YY_CURRENT_BUFFER ) - yy_fatal_error( "hsql_set_lineno called with no buffer" , yyscanner); + YY_FATAL_ERROR( "hsql_set_lineno called with no buffer" ); - yylineno = line_number; + yylineno = _line_number; } /** Set the current column. - * @param line_number + * @param _column_no column number * @param yyscanner The scanner object. */ -void hsql_set_column (int column_no , yyscan_t yyscanner) +void hsql_set_column (int _column_no , yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* column is only valid if an input buffer exists. */ if (! YY_CURRENT_BUFFER ) - yy_fatal_error( "hsql_set_column called with no buffer" , yyscanner); + YY_FATAL_ERROR( "hsql_set_column called with no buffer" ); - yycolumn = column_no; + yycolumn = _column_no; } /** Set the input stream. This does not discard the current * input buffer. - * @param in_str A readable stream. + * @param _in_str A readable stream. * @param yyscanner The scanner object. * @see hsql__switch_to_buffer */ -void hsql_set_in (FILE * in_str , yyscan_t yyscanner) +void hsql_set_in (FILE * _in_str , yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyin = in_str ; + yyin = _in_str ; } -void hsql_set_out (FILE * out_str , yyscan_t yyscanner) +void hsql_set_out (FILE * _out_str , yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyout = out_str ; + yyout = _out_str ; } int hsql_get_debug (yyscan_t yyscanner) @@ -3524,10 +3530,10 @@ int hsql_get_debug (yyscan_t yyscanner) return yy_flex_debug; } -void hsql_set_debug (int bdebug , yyscan_t yyscanner) +void hsql_set_debug (int _bdebug , yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yy_flex_debug = bdebug ; + yy_flex_debug = _bdebug ; } /* Accessor methods for yylval and yylloc */ @@ -3603,20 +3609,20 @@ int hsql_lex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals ) errno = EINVAL; return 1; } - + *ptr_yy_globals = (yyscan_t) hsql_alloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); - + if (*ptr_yy_globals == NULL){ errno = ENOMEM; return 1; } - + /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */ memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); - + hsql_set_extra (yy_user_defined, *ptr_yy_globals); - + return yy_init_globals ( *ptr_yy_globals ); } @@ -3627,10 +3633,10 @@ static int yy_init_globals (yyscan_t yyscanner) * This function is called from hsql_lex_destroy(), so don't allocate here. */ - yyg->yy_buffer_stack = 0; + yyg->yy_buffer_stack = NULL; yyg->yy_buffer_stack_top = 0; yyg->yy_buffer_stack_max = 0; - yyg->yy_c_buf_p = (char *) 0; + yyg->yy_c_buf_p = NULL; yyg->yy_init = 0; yyg->yy_start = 0; @@ -3643,8 +3649,8 @@ static int yy_init_globals (yyscan_t yyscanner) yyin = stdin; yyout = stdout; #else - yyin = (FILE *) 0; - yyout = (FILE *) 0; + yyin = NULL; + yyout = NULL; #endif /* For future reference: Set errno on error, since we are called by @@ -3690,7 +3696,10 @@ int hsql_lex_destroy (yyscan_t yyscanner) #ifndef yytext_ptr static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner) { - register int i; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + + int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; } @@ -3699,7 +3708,7 @@ static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yysca #ifdef YY_NEED_STRLEN static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner) { - register int n; + int n; for ( n = 0; s[n]; ++n ) ; @@ -3709,11 +3718,16 @@ static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner) void *hsql_alloc (yy_size_t size , yyscan_t yyscanner) { - return (void *) malloc( size ); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + return malloc(size); } void *hsql_realloc (void * ptr, yy_size_t size , yyscan_t yyscanner) { + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those * that use void* generic pointers. It works with the latter @@ -3721,11 +3735,13 @@ void *hsql_realloc (void * ptr, yy_size_t size , yyscan_t yyscanner) * any pointer type to void*, and deal with argument conversions * as though doing an assignment. */ - return (void *) realloc( (char *) ptr, size ); + return realloc(ptr, size); } void hsql_free (void * ptr , yyscan_t yyscanner) { + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; free( (char *) ptr ); /* see hsql_realloc() for (char *) cast */ } diff --git a/src/parser/flex_lexer.h b/src/parser/flex_lexer.h index 6a80353..548c672 100644 --- a/src/parser/flex_lexer.h +++ b/src/parser/flex_lexer.h @@ -12,8 +12,8 @@ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 35 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 1 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif @@ -92,25 +92,13 @@ typedef unsigned int flex_uint32_t; #endif /* ! FLEXINT_H */ -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST +/* TODO: this is always defined, so inline it */ #define yyconst const + +#if defined(__GNUC__) && __GNUC__ >= 3 +#define yynoreturn __attribute__((__noreturn__)) #else -#define yyconst +#define yynoreturn #endif /* An opaque pointer. */ @@ -165,7 +153,7 @@ struct yy_buffer_state /* Size of input buffer in bytes, not including room for EOB * characters. */ - yy_size_t yy_buf_size; + int yy_buf_size; /* Number of characters read into yy_ch_buf, not including EOB * characters. @@ -193,7 +181,7 @@ struct yy_buffer_state int yy_bs_lineno; /**< The line count. */ int yy_bs_column; /**< The column count. */ - + /* Whether to try to fill the input buffer when we reach the * end of it. */ @@ -222,7 +210,7 @@ void hsql_free (void * ,yyscan_t yyscanner ); /* Begin user sect3 */ -#define hsql_wrap(n) 1 +#define hsql_wrap(yyscanner) (/*CONSTCOND*/1) #define YY_SKIP_YYWRAP #define yytext_ptr yytext_r @@ -264,19 +252,23 @@ void hsql_set_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner ); FILE *hsql_get_in (yyscan_t yyscanner ); -void hsql_set_in (FILE * in_str ,yyscan_t yyscanner ); +void hsql_set_in (FILE * _in_str ,yyscan_t yyscanner ); FILE *hsql_get_out (yyscan_t yyscanner ); -void hsql_set_out (FILE * out_str ,yyscan_t yyscanner ); +void hsql_set_out (FILE * _out_str ,yyscan_t yyscanner ); -int hsql_get_leng (yyscan_t yyscanner ); + int hsql_get_leng (yyscan_t yyscanner ); char *hsql_get_text (yyscan_t yyscanner ); int hsql_get_lineno (yyscan_t yyscanner ); -void hsql_set_lineno (int line_number ,yyscan_t yyscanner ); +void hsql_set_lineno (int _line_number ,yyscan_t yyscanner ); + +int hsql_get_column (yyscan_t yyscanner ); + +void hsql_set_column (int _column_no ,yyscan_t yyscanner ); YYSTYPE * hsql_get_lval (yyscan_t yyscanner ); @@ -355,6 +347,6 @@ extern int hsql_lex \ #line 213 "flex_lexer.l" -#line 359 "flex_lexer.h" +#line 351 "flex_lexer.h" #undef hsql_IN_HEADER #endif /* hsql_HEADER_H */ From e6cd70f02901471b762cd6dbce02074e84d88476 Mon Sep 17 00:00:00 2001 From: Pedro Flemming Date: Fri, 7 Apr 2017 15:47:51 +0200 Subject: [PATCH 05/12] move sqlhelper into util/. Add convenience methods --- example/example.cpp | 2 +- src/sql/SQLStatement.h | 4 +++- src/sql/statements.cpp | 4 ++++ src/{ => util}/sqlhelper.cpp | 0 src/{ => util}/sqlhelper.h | 6 +++--- test/sql_tests.cpp | 6 ++++-- test/tpc_h_tests.cpp | 6 ++++-- 7 files changed, 19 insertions(+), 9 deletions(-) rename src/{ => util}/sqlhelper.cpp (100%) rename src/{ => util}/sqlhelper.h (90%) diff --git a/example/example.cpp b/example/example.cpp index 62a5077..91e5d17 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -6,7 +6,7 @@ #include "SQLParser.h" // contains printing utilities -#include "sqlhelper.h" +#include "util/sqlhelper.h" int main(int argc, char *argv[]) { if (argc <= 1) { diff --git a/src/sql/SQLStatement.h b/src/sql/SQLStatement.h index 1e1e643..9d491d4 100644 --- a/src/sql/SQLStatement.h +++ b/src/sql/SQLStatement.h @@ -29,7 +29,9 @@ namespace hsql { virtual ~SQLStatement(); - virtual StatementType type() const; + StatementType type() const; + + bool isType(StatementType type) const; private: StatementType type_; diff --git a/src/sql/statements.cpp b/src/sql/statements.cpp index 75b794f..bcdece3 100644 --- a/src/sql/statements.cpp +++ b/src/sql/statements.cpp @@ -13,6 +13,10 @@ namespace hsql { return type_; } + bool SQLStatement::isType(StatementType type) const { + return (type_ == type); + } + // ColumnDefinition ColumnDefinition::ColumnDefinition(char* name, DataType type) : name(name), diff --git a/src/sqlhelper.cpp b/src/util/sqlhelper.cpp similarity index 100% rename from src/sqlhelper.cpp rename to src/util/sqlhelper.cpp diff --git a/src/sqlhelper.h b/src/util/sqlhelper.h similarity index 90% rename from src/sqlhelper.h rename to src/util/sqlhelper.h index ea6edd1..7c7e811 100644 --- a/src/sqlhelper.h +++ b/src/util/sqlhelper.h @@ -1,7 +1,7 @@ -#ifndef __SQLHELPER_H__ -#define __SQLHELPER_H__ +#ifndef __SQLPARSER__SQLHELPER_H__ +#define __SQLPARSER__SQLHELPER_H__ -#include "sql/statements.h" +#include "../sql/statements.h" namespace hsql { diff --git a/test/sql_tests.cpp b/test/sql_tests.cpp index 89ccf60..7f7f59a 100644 --- a/test/sql_tests.cpp +++ b/test/sql_tests.cpp @@ -3,9 +3,11 @@ */ #include "thirdparty/microtest/microtest.h" -#include "sql_asserts.h" + #include "SQLParser.h" -#include "sqlhelper.h" +#include "util/sqlhelper.h" + +#include "sql_asserts.h" using namespace hsql; diff --git a/test/tpc_h_tests.cpp b/test/tpc_h_tests.cpp index 6b3387a..288802a 100644 --- a/test/tpc_h_tests.cpp +++ b/test/tpc_h_tests.cpp @@ -1,7 +1,9 @@ #include "thirdparty/microtest/microtest.h" -#include "sql_asserts.h" + #include "SQLParser.h" -#include "sqlhelper.h" +#include "util/sqlhelper.h" + +#include "sql_asserts.h" #include #include From 074c564cc424722c1dd53cb92a88c42c6922cf0f Mon Sep 17 00:00:00 2001 From: Pedro Flemming Date: Fri, 7 Apr 2017 16:07:14 +0200 Subject: [PATCH 06/12] move initialization of SQLParserResult to SQLParser from bison_parser --- src/SQLParser.cpp | 5 +++-- src/parser/bison_parser.y | 35 +++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/SQLParser.cpp b/src/SQLParser.cpp index 55ae5f7..5f89911 100644 --- a/src/SQLParser.cpp +++ b/src/SQLParser.cpp @@ -13,20 +13,21 @@ namespace hsql { } SQLParserResult* SQLParser::parseSQLString(const char* text) { - SQLParserResult* result = NULL; + SQLParserResult* result = new SQLParserResult(); yyscan_t scanner; YY_BUFFER_STATE state; if (hsql_lex_init(&scanner)) { // Couldn't initialize the lexer. fprintf(stderr, "[Error] SQLParser: Error when initializing lexer!\n"); + delete result; return NULL; } state = hsql__scan_string(text, scanner); // Parser and return early if it failed. - if (hsql_parse(&result, scanner)) { + if (hsql_parse(result, scanner)) { // Returns an error stmt object. hsql__delete_buffer(state, scanner); hsql_lex_destroy(scanner); diff --git a/src/parser/bison_parser.y b/src/parser/bison_parser.y index 4ecdb93..c0252d0 100644 --- a/src/parser/bison_parser.y +++ b/src/parser/bison_parser.y @@ -18,14 +18,9 @@ using namespace hsql; -int yyerror(YYLTYPE* llocp, SQLParserResult** result, yyscan_t scanner, const char *msg) { - delete *result; - - SQLParserResult* list = new SQLParserResult(); - list->setIsValid(false); - list->setErrorDetails(strdup(msg), llocp->first_line, llocp->first_column); - - *result = list; +int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const char *msg) { + result->setIsValid(false); + result->setErrorDetails(strdup(msg), llocp->first_line, llocp->first_column); return 0; } @@ -90,7 +85,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult** result, yyscan_t scanner, const ch %lex-param { yyscan_t scanner } // Define additional parameters for yyparse -%parse-param { hsql::SQLParserResult** result } +%parse-param { hsql::SQLParserResult* result } %parse-param { yyscan_t scanner } @@ -124,7 +119,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult** result, yyscan_t scanner, const ch hsql::GroupByDescription* group_t; hsql::UpdateClause* update_t; - hsql::SQLParserResult* stmt_list; + std::vector* stmt_vec; std::vector* str_vec; std::vector* table_vec; @@ -147,7 +142,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult** result, yyscan_t scanner, const ch } } delete ($$); -} +} %destructor { delete ($$); } <*> @@ -178,7 +173,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult** result, yyscan_t scanner, const ch /********************************* ** Non-Terminal types (http://www.gnu.org/software/bison/manual/html_node/Type-Decl.html) *********************************/ -%type statement_list +%type statement_list %type statement preparable_statement %type execute_statement %type prepare_statement @@ -243,14 +238,18 @@ int yyerror(YYLTYPE* llocp, SQLParserResult** result, yyscan_t scanner, const ch // Defines our general input. input: statement_list opt_semicolon { - *result = $1; + for (SQLStatement* stmt : *$1) { + // Transfers ownership of the statement. + result->addStatement(stmt); + } + delete $1; } ; statement_list: - statement { $$ = new SQLParserResult($1); } - | statement_list ';' statement { $1->addStatement($3); $$ = $1; } + statement { $$ = new std::vector(); $$->push_back($1); } + | statement_list ';' statement { $1->push_back($3); $$ = $1; } ; statement: @@ -288,7 +287,11 @@ prepare_statement: | PREPARE IDENTIFIER '{' statement_list opt_semicolon '}' { $$ = new PrepareStatement(); $$->name = $2; - $$->query = $4; + $$->query = new SQLParserResult(); + for (SQLStatement* stmt : *$4) { + $$->query->addStatement(stmt); + } + delete $4; } ; From e16925e7a5f9d2e05592da374bc18c1d65ae04c9 Mon Sep 17 00:00:00 2001 From: Pedro Flemming Date: Fri, 7 Apr 2017 16:16:25 +0200 Subject: [PATCH 07/12] add parseSQLString method with output parameter instead of return value --- src/SQLParser.cpp | 40 +++++++++++++++++++++++++-------------- src/SQLParser.h | 10 ++++++++++ test/sql_grammar_test.cpp | 9 ++++----- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/SQLParser.cpp b/src/SQLParser.cpp index 5f89911..9f6ee5b 100644 --- a/src/SQLParser.cpp +++ b/src/SQLParser.cpp @@ -12,37 +12,49 @@ namespace hsql { fprintf(stderr, "SQLParser only has static methods atm! Do not initialize!\n"); } - SQLParserResult* SQLParser::parseSQLString(const char* text) { - SQLParserResult* result = new SQLParserResult(); + // static + bool SQLParser::parseSQLString(const char* text, SQLParserResult* result) { yyscan_t scanner; YY_BUFFER_STATE state; if (hsql_lex_init(&scanner)) { // Couldn't initialize the lexer. fprintf(stderr, "[Error] SQLParser: Error when initializing lexer!\n"); - delete result; - return NULL; + return false; } state = hsql__scan_string(text, scanner); - // Parser and return early if it failed. - if (hsql_parse(result, scanner)) { - // Returns an error stmt object. - hsql__delete_buffer(state, scanner); - hsql_lex_destroy(scanner); - return result; - } + // Parse the tokens. + // If parsing fails, the result will contain an error object. + hsql_parse(result, scanner); hsql__delete_buffer(state, scanner); hsql_lex_destroy(scanner); + + return true; + } + + // static + bool SQLParser::parseSQLString(const std::string& text, SQLParserResult* result) { + return parseSQLString(text.c_str(), result); + } + + // static + SQLParserResult* SQLParser::parseSQLString(const char* text) { + SQLParserResult* result = new SQLParserResult(); + + if (!SQLParser::parseSQLString(text, result)) { + delete result; + return NULL; + } + return result; } - + // static SQLParserResult* SQLParser::parseSQLString(const std::string& text) { return parseSQLString(text.c_str()); } - -} // namespace hsql \ No newline at end of file +} // namespace hsql diff --git a/src/SQLParser.h b/src/SQLParser.h index 7ee774e..dffdcea 100644 --- a/src/SQLParser.h +++ b/src/SQLParser.h @@ -9,10 +9,20 @@ namespace hsql { // Static methods used to parse SQL strings. class SQLParser { public: + // Parses a given constant character SQL string into the result object. + static bool parseSQLString(const char* sql, SQLParserResult* result); + + // Parses a given SQL string into the result object. + static bool parseSQLString(const std::string& sql, SQLParserResult* result); + // Parses a given constant character SQL string. + // Note: This is kept for legacy reasons. It is recommended to use + // the (const char*, SQLParserResult*) implementation. static SQLParserResult* parseSQLString(const char* sql); // Parses an SQL std::string. + // Note: This is kept for legacy reasons. It is recommended to use + // the (const std::string&, SQLParserResult*) implementation. static SQLParserResult* parseSQLString(const std::string& sql); private: diff --git a/test/sql_grammar_test.cpp b/test/sql_grammar_test.cpp index 3bfecc8..0daf0c0 100644 --- a/test/sql_grammar_test.cpp +++ b/test/sql_grammar_test.cpp @@ -79,23 +79,22 @@ TEST(AutoGrammarTest) { start = std::chrono::system_clock::now(); // Parsing - SQLParserResult* result = SQLParser::parseSQLString(sql.c_str()); + SQLParserResult result; + SQLParser::parseSQLString(sql.c_str(), &result); end = std::chrono::system_clock::now(); std::chrono::duration elapsed_seconds = end - start; double us = elapsed_seconds.count() * 1000 * 1000; - if (expectFalse == result->isValid()) { + if (expectFalse == result.isValid()) { printf("\033[0;31m{ failed}\033[0m\n"); - printf("\t\033[0;31m%s (L%d:%d)\n\033[0m", result->errorMsg(), result->errorLine(), result->errorColumn()); + printf("\t\033[0;31m%s (L%d:%d)\n\033[0m", result.errorMsg(), result.errorLine(), result.errorColumn()); printf("\t%s\n", sql.c_str()); numFailed++; } else { // TODO: indicate whether expectFalse was set printf("\033[0;32m{ ok} (%.1fus)\033[0m %s\n", us, sql.c_str()); } - - delete result; } if (numFailed == 0) { From 6b22e2216225af3056e7559442e8ffd62d502f6d Mon Sep 17 00:00:00 2001 From: Pedro Flemming Date: Fri, 7 Apr 2017 16:26:00 +0200 Subject: [PATCH 08/12] update tests to use the new Parser interface --- example/example.cpp | 23 +++++++---------- test/select_tests.cpp | 18 -------------- test/sql_asserts.h | 15 ++++++------ test/sql_tests.cpp | 57 ++++++++++++++++++------------------------- 4 files changed, 41 insertions(+), 72 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index aa17b82..9961d3d 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -16,31 +16,26 @@ int main(int argc, char *argv[]) { std::string query = argv[1]; // parse a given query - hsql::SQLParserResult* result = hsql::SQLParser::parseSQLString(query); + hsql::SQLParserResult result; + hsql::SQLParser::parseSQLString(query, &result); // check whether the parsing was successful - if (!result) { - return -1; - } - if (result->isValid()) { + if (result.isValid()) { printf("Parsed successfully!\n"); - printf("Number of statements: %lu\n", result->size()); + printf("Number of statements: %lu\n", result.size()); - for (uint i = 0; i < result->size(); ++i) { + for (uint i = 0; i < result.size(); ++i) { // Print a statement summary. - hsql::printStatementInfo(result->getStatement(i)); + hsql::printStatementInfo(result.getStatement(i)); } - - delete result; return 0; } else { fprintf(stderr, "Given string is not a valid SQL query.\n"); fprintf(stderr, "%s (L%d:%d)\n", - result->errorMsg(), - result->errorLine(), - result->errorColumn()); - delete result; + result.errorMsg(), + result.errorLine(), + result.errorColumn()); return -1; } } diff --git a/test/select_tests.cpp b/test/select_tests.cpp index 1e034f3..0256cf2 100644 --- a/test/select_tests.cpp +++ b/test/select_tests.cpp @@ -16,8 +16,6 @@ TEST(SelectTest) { ASSERT_NULL(stmt->whereClause); ASSERT_NULL(stmt->groupBy); - - delete result; } TEST(SelectExprTest) { @@ -55,8 +53,6 @@ TEST(SelectExprTest) { ASSERT_EQ(stmt->selectList->at(2)->exprList->at(1)->exprList->size(), 1); ASSERT(stmt->selectList->at(2)->exprList->at(1)->exprList->at(0)->isType(kExprColumnRef)); ASSERT_STREQ(stmt->selectList->at(2)->exprList->at(1)->exprList->at(0)->getName(), "un"); - - delete result; } @@ -76,8 +72,6 @@ TEST(SelectHavingTest) { ASSERT(group->having->isSimpleOp('<')); ASSERT(group->having->expr->isType(kExprFunctionRef)); ASSERT(group->having->expr2->isType(kExprLiteralFloat)); - - delete result; } @@ -91,8 +85,6 @@ TEST(SelectDistinctTest) { ASSERT(stmt->selectDistinct); ASSERT_NULL(stmt->whereClause); - - delete result; } TEST(SelectGroupDistinctTest) { @@ -107,8 +99,6 @@ TEST(SelectGroupDistinctTest) { ASSERT_EQ(stmt->selectList->size(), 3); ASSERT(!stmt->selectList->at(1)->distinct); ASSERT(stmt->selectList->at(2)->distinct); - - delete result; } TEST(OrderByTest) { @@ -128,8 +118,6 @@ TEST(OrderByTest) { ASSERT_EQ(stmt->order->at(1)->type, kOrderDesc); ASSERT_STREQ(stmt->order->at(1)->expr->name, "city"); - - delete result; } TEST(SelectBetweenTest) { @@ -154,8 +142,6 @@ TEST(SelectBetweenTest) { ASSERT_EQ(where->exprList->at(0)->ival, 1); ASSERT(where->exprList->at(1)->isType(kExprColumnRef)); ASSERT_STREQ(where->exprList->at(1)->getName(), "c"); - - delete result; } TEST(SelectConditionalSelectTest) { @@ -194,8 +180,6 @@ TEST(SelectConditionalSelectTest) { SelectStatement* ex_select = cond2->select; ASSERT_STREQ(ex_select->fromTable->getName(), "test"); - - delete result; } TEST(SelectCaseWhen) { @@ -220,6 +204,4 @@ TEST(SelectCaseWhen) { ASSERT(caseExpr->expr->isType(kExprOperator)); ASSERT(caseExpr->expr->isSimpleOp('=')); ASSERT_EQ(caseExpr->exprList->size(), 2); - - delete result; } diff --git a/test/sql_asserts.h b/test/sql_asserts.h index bf3a703..2c70b3b 100644 --- a/test/sql_asserts.h +++ b/test/sql_asserts.h @@ -3,20 +3,21 @@ #define TEST_PARSE_SQL_QUERY(query, result, numStatements) \ - const SQLParserResult* result = SQLParser::parseSQLString(query); \ - ASSERT(result->isValid()); \ - ASSERT_EQ(result->size(), numStatements); + SQLParserResult result; \ + SQLParser::parseSQLString(query, &result); \ + ASSERT(result.isValid()); \ + ASSERT_EQ(result.size(), numStatements); #define TEST_PARSE_SINGLE_SQL(query, stmtType, stmtClass, result, outputVar) \ TEST_PARSE_SQL_QUERY(query, result, 1); \ - ASSERT_EQ(result->getStatement(0)->type(), stmtType); \ - const stmtClass* outputVar = (const stmtClass*) result->getStatement(0); + ASSERT_EQ(result.getStatement(0)->type(), stmtType); \ + const stmtClass* outputVar = (const stmtClass*) result.getStatement(0); #define TEST_CAST_STMT(result, stmt_index, stmtType, stmtClass, outputVar) \ - ASSERT_EQ(result->getStatement(stmt_index)->type(), stmtType); \ - const stmtClass* outputVar = (const stmtClass*) result->getStatement(stmt_index); + ASSERT_EQ(result.getStatement(stmt_index)->type(), stmtType); \ + const stmtClass* outputVar = (const stmtClass*) result.getStatement(stmt_index); #endif diff --git a/test/sql_tests.cpp b/test/sql_tests.cpp index 7f7f59a..56fb5a2 100644 --- a/test/sql_tests.cpp +++ b/test/sql_tests.cpp @@ -13,28 +13,30 @@ using namespace hsql; TEST(DeleteStatementTest) { - const SQLParserResult* result = SQLParser::parseSQLString("DELETE FROM students WHERE grade > 2.0;"); - ASSERT(result->isValid()); - ASSERT_EQ(result->size(), 1); - ASSERT(result->getStatement(0)->type() == kStmtDelete); + SQLParserResult result; + SQLParser::parseSQLString("DELETE FROM students WHERE grade > 2.0;", &result); - const DeleteStatement* stmt = (const DeleteStatement*) result->getStatement(0); + ASSERT(result.isValid()); + ASSERT_EQ(result.size(), 1); + ASSERT(result.getStatement(0)->type() == kStmtDelete); + + const DeleteStatement* stmt = (const DeleteStatement*) result.getStatement(0); ASSERT_STREQ(stmt->tableName, "students"); ASSERT_NOTNULL(stmt->expr); ASSERT(stmt->expr->isType(kExprOperator)); ASSERT_STREQ(stmt->expr->expr->name, "grade"); ASSERT_EQ(stmt->expr->expr2->fval, 2.0); - - delete result; } TEST(CreateStatementTest) { - const SQLParserResult* result = SQLParser::parseSQLString("CREATE TABLE students (name TEXT, student_number INT, city INTEGER, grade DOUBLE)"); - ASSERT(result->isValid()); - ASSERT_EQ(result->size(), 1); - ASSERT_EQ(result->getStatement(0)->type(), kStmtCreate); + SQLParserResult result; + SQLParser::parseSQLString("CREATE TABLE students (name TEXT, student_number INT, city INTEGER, grade DOUBLE)", &result); - const CreateStatement* stmt = (const CreateStatement*) result->getStatement(0); + ASSERT(result.isValid()); + ASSERT_EQ(result.size(), 1); + ASSERT_EQ(result.getStatement(0)->type(), kStmtCreate); + + const CreateStatement* stmt = (const CreateStatement*) result.getStatement(0); ASSERT_EQ(stmt->type, CreateStatement::kTable); ASSERT_STREQ(stmt->tableName, "students"); ASSERT_NOTNULL(stmt->columns); @@ -47,18 +49,18 @@ TEST(CreateStatementTest) { ASSERT_EQ(stmt->columns->at(1)->type, ColumnDefinition::INT); ASSERT_EQ(stmt->columns->at(2)->type, ColumnDefinition::INT); ASSERT_EQ(stmt->columns->at(3)->type, ColumnDefinition::DOUBLE); - - delete result; } TEST(UpdateStatementTest) { - const SQLParserResult* result = SQLParser::parseSQLString("UPDATE students SET grade = 5.0, name = 'test' WHERE name = 'Max Mustermann';"); - ASSERT(result->isValid()); - ASSERT_EQ(result->size(), 1); - ASSERT_EQ(result->getStatement(0)->type(), kStmtUpdate); + SQLParserResult result; + SQLParser::parseSQLString("UPDATE students SET grade = 5.0, name = 'test' WHERE name = 'Max Mustermann';", &result); - const UpdateStatement* stmt = (const UpdateStatement*) result->getStatement(0); + ASSERT(result.isValid()); + ASSERT_EQ(result.size(), 1); + ASSERT_EQ(result.getStatement(0)->type(), kStmtUpdate); + + const UpdateStatement* stmt = (const UpdateStatement*) result.getStatement(0); ASSERT_NOTNULL(stmt->table); ASSERT_STREQ(stmt->table->name, "students"); @@ -76,9 +78,6 @@ TEST(UpdateStatementTest) { ASSERT(stmt->where->isSimpleOp('=')); ASSERT_STREQ(stmt->where->expr->name, "name"); ASSERT_STREQ(stmt->where->expr2->name, "Max Mustermann"); - \ - - delete result; } @@ -92,8 +91,6 @@ TEST(InsertStatementTest) { ASSERT_EQ(stmt->values->size(), 4); // TODO - - delete result; } @@ -108,8 +105,6 @@ TEST(DropTableStatementTest) { ASSERT_EQ(stmt->type, DropStatement::kTable); ASSERT_NOTNULL(stmt->name); ASSERT_STREQ(stmt->name, "students"); - - delete result; } @@ -132,8 +127,8 @@ TEST(PrepareStatementTest) { ASSERT_EQ(prep1->placeholders.size(), 3); ASSERT_EQ(prep1->query->size(), 2); - TEST_CAST_STMT(prep1->query, 0, kStmtInsert, InsertStatement, insert); - TEST_CAST_STMT(prep1->query, 1, kStmtSelect, SelectStatement, select); + TEST_CAST_STMT((*prep1->query), 0, kStmtInsert, InsertStatement, insert); + TEST_CAST_STMT((*prep1->query), 1, kStmtSelect, SelectStatement, select); ASSERT(insert->values->at(0)->isType(kExprPlaceholder)); ASSERT(select->selectList->at(0)->isType(kExprPlaceholder)); @@ -156,8 +151,6 @@ TEST(PrepareStatementTest) { // Deallocate Statement ASSERT_EQ(drop->type, DropStatement::kPreparedStatement); ASSERT_STREQ(drop->name, "stmt"); - - delete result; } @@ -166,8 +159,6 @@ TEST(ExecuteStatementTest) { ASSERT_STREQ(stmt->name, "test"); ASSERT_EQ(stmt->parameters->size(), 2); - - delete result; } -TEST_MAIN(); \ No newline at end of file +TEST_MAIN(); From cfe69a44de60e3cd65672192c971acecba29ab76 Mon Sep 17 00:00:00 2001 From: Pedro Flemming Date: Fri, 7 Apr 2017 16:26:20 +0200 Subject: [PATCH 09/12] update parser sources --- src/parser/bison_parser.cpp | 986 ++++++++++++++++++------------------ src/parser/bison_parser.h | 8 +- 2 files changed, 502 insertions(+), 492 deletions(-) diff --git a/src/parser/bison_parser.cpp b/src/parser/bison_parser.cpp index 42eab82..4c71941 100644 --- a/src/parser/bison_parser.cpp +++ b/src/parser/bison_parser.cpp @@ -91,21 +91,16 @@ using namespace hsql; -int yyerror(YYLTYPE* llocp, SQLParserResult** result, yyscan_t scanner, const char *msg) { - delete *result; - - SQLParserResult* list = new SQLParserResult(); - list->setIsValid(false); - list->setErrorDetails(strdup(msg), llocp->first_line, llocp->first_column); - - *result = list; +int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const char *msg) { + result->setIsValid(false); + result->setErrorDetails(strdup(msg), llocp->first_line, llocp->first_column); return 0; } -#line 109 "bison_parser.cpp" /* yacc.c:339 */ +#line 104 "bison_parser.cpp" /* yacc.c:339 */ # ifndef YY_NULLPTR # if defined __cplusplus && 201103L <= __cplusplus @@ -143,7 +138,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult** result, yyscan_t scanner, const ch extern int hsql_debug; #endif /* "%code requires" blocks. */ -#line 41 "bison_parser.y" /* yacc.c:355 */ +#line 36 "bison_parser.y" /* yacc.c:355 */ // %code requires block @@ -166,7 +161,7 @@ extern int hsql_debug; } \ } -#line 170 "bison_parser.cpp" /* yacc.c:355 */ +#line 165 "bison_parser.cpp" /* yacc.c:355 */ /* Token type. */ #ifndef HSQL_TOKENTYPE @@ -309,7 +304,7 @@ extern int hsql_debug; union HSQL_STYPE { -#line 100 "bison_parser.y" /* yacc.c:355 */ +#line 95 "bison_parser.y" /* yacc.c:355 */ double fval; int64_t ival; @@ -337,7 +332,7 @@ union HSQL_STYPE hsql::GroupByDescription* group_t; hsql::UpdateClause* update_t; - hsql::SQLParserResult* stmt_list; + std::vector* stmt_vec; std::vector* str_vec; std::vector* table_vec; @@ -346,7 +341,7 @@ union HSQL_STYPE std::vector* expr_vec; std::vector* order_vec; -#line 350 "bison_parser.cpp" /* yacc.c:355 */ +#line 345 "bison_parser.cpp" /* yacc.c:355 */ }; typedef union HSQL_STYPE HSQL_STYPE; @@ -370,13 +365,13 @@ struct HSQL_LTYPE -int hsql_parse (hsql::SQLParserResult** result, yyscan_t scanner); +int hsql_parse (hsql::SQLParserResult* result, yyscan_t scanner); #endif /* !YY_HSQL_BISON_PARSER_H_INCLUDED */ /* Copy the second part of user declarations. */ -#line 380 "bison_parser.cpp" /* yacc.c:358 */ +#line 375 "bison_parser.cpp" /* yacc.c:358 */ #ifdef short # undef short @@ -688,24 +683,24 @@ static const yytype_uint8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 245, 245, 252, 253, 257, 262, 267, 268, 269, - 270, 271, 272, 273, 274, 275, 283, 288, 296, 300, - 312, 320, 324, 334, 340, 346, 356, 357, 361, 362, - 366, 373, 374, 375, 376, 386, 390, 394, 406, 414, - 426, 432, 442, 443, 453, 462, 463, 467, 479, 480, - 484, 485, 489, 499, 513, 527, 528, 529, 533, 545, - 546, 550, 554, 559, 560, 564, 569, 573, 574, 577, - 578, 582, 583, 587, 591, 592, 593, 599, 600, 604, - 605, 606, 613, 614, 618, 619, 623, 630, 631, 632, - 633, 634, 635, 639, 640, 641, 642, 643, 644, 648, - 649, 650, 654, 655, 659, 660, 661, 662, 663, 664, - 665, 666, 667, 671, 672, 676, 677, 678, 679, 684, - 688, 689, 693, 694, 695, 696, 697, 698, 702, 706, - 710, 711, 715, 716, 717, 721, 726, 727, 731, 735, - 739, 750, 751, 761, 762, 768, 773, 774, 779, 789, - 797, 798, 803, 804, 808, 809, 817, 829, 830, 831, - 832, 833, 834, 835, 836, 837, 843, 849, 853, 862, - 863, 868, 869 + 0, 240, 240, 251, 252, 256, 261, 266, 267, 268, + 269, 270, 271, 272, 273, 274, 282, 287, 299, 303, + 315, 323, 327, 337, 343, 349, 359, 360, 364, 365, + 369, 376, 377, 378, 379, 389, 393, 397, 409, 417, + 429, 435, 445, 446, 456, 465, 466, 470, 482, 483, + 487, 488, 492, 502, 516, 530, 531, 532, 536, 548, + 549, 553, 557, 562, 563, 567, 572, 576, 577, 580, + 581, 585, 586, 590, 594, 595, 596, 602, 603, 607, + 608, 609, 616, 617, 621, 622, 626, 633, 634, 635, + 636, 637, 638, 642, 643, 644, 645, 646, 647, 651, + 652, 653, 657, 658, 662, 663, 664, 665, 666, 667, + 668, 669, 670, 674, 675, 679, 680, 681, 682, 687, + 691, 692, 696, 697, 698, 699, 700, 701, 705, 709, + 713, 714, 718, 719, 720, 724, 729, 730, 734, 738, + 742, 753, 754, 764, 765, 771, 776, 777, 782, 792, + 800, 801, 806, 807, 811, 812, 820, 832, 833, 834, + 835, 836, 837, 838, 839, 840, 846, 852, 856, 865, + 866, 871, 872 }; #endif @@ -1221,7 +1216,7 @@ do { \ `----------------------------------------*/ static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, hsql::SQLParserResult** result, yyscan_t scanner) +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, hsql::SQLParserResult* result, yyscan_t scanner) { FILE *yyo = yyoutput; YYUSE (yyo); @@ -1243,7 +1238,7 @@ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvalue `--------------------------------*/ static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, hsql::SQLParserResult** result, yyscan_t scanner) +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, hsql::SQLParserResult* result, yyscan_t scanner) { YYFPRINTF (yyoutput, "%s %s (", yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); @@ -1283,7 +1278,7 @@ do { \ `------------------------------------------------*/ static void -yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, hsql::SQLParserResult** result, yyscan_t scanner) +yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, hsql::SQLParserResult* result, yyscan_t scanner) { unsigned long int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; @@ -1563,7 +1558,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, `-----------------------------------------------*/ static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, hsql::SQLParserResult** result, yyscan_t scanner) +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, hsql::SQLParserResult* result, yyscan_t scanner) { YYUSE (yyvaluep); YYUSE (yylocationp); @@ -1577,109 +1572,116 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio switch (yytype) { case 3: /* IDENTIFIER */ -#line 142 "bison_parser.y" /* yacc.c:1257 */ +#line 137 "bison_parser.y" /* yacc.c:1257 */ { free( (((*yyvaluep).sval)) ); } -#line 1583 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1578 "bison_parser.cpp" /* yacc.c:1257 */ break; case 4: /* STRING */ -#line 142 "bison_parser.y" /* yacc.c:1257 */ +#line 137 "bison_parser.y" /* yacc.c:1257 */ { free( (((*yyvaluep).sval)) ); } -#line 1589 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1584 "bison_parser.cpp" /* yacc.c:1257 */ break; case 5: /* FLOATVAL */ -#line 141 "bison_parser.y" /* yacc.c:1257 */ +#line 136 "bison_parser.y" /* yacc.c:1257 */ { } -#line 1595 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1590 "bison_parser.cpp" /* yacc.c:1257 */ break; case 6: /* INTVAL */ -#line 141 "bison_parser.y" /* yacc.c:1257 */ +#line 136 "bison_parser.y" /* yacc.c:1257 */ { } -#line 1601 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1596 "bison_parser.cpp" /* yacc.c:1257 */ break; case 7: /* NOTEQUALS */ -#line 141 "bison_parser.y" /* yacc.c:1257 */ +#line 136 "bison_parser.y" /* yacc.c:1257 */ { } -#line 1607 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1602 "bison_parser.cpp" /* yacc.c:1257 */ break; case 8: /* LESSEQ */ -#line 141 "bison_parser.y" /* yacc.c:1257 */ +#line 136 "bison_parser.y" /* yacc.c:1257 */ { } -#line 1613 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1608 "bison_parser.cpp" /* yacc.c:1257 */ break; case 9: /* GREATEREQ */ -#line 141 "bison_parser.y" /* yacc.c:1257 */ +#line 136 "bison_parser.y" /* yacc.c:1257 */ { } -#line 1619 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1614 "bison_parser.cpp" /* yacc.c:1257 */ break; case 153: /* statement_list */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ - { delete (((*yyvaluep).stmt_list)); } -#line 1625 "bison_parser.cpp" /* yacc.c:1257 */ +#line 138 "bison_parser.y" /* yacc.c:1257 */ + { + if ((((*yyvaluep).stmt_vec)) != NULL) { + for (auto ptr : *(((*yyvaluep).stmt_vec))) { + delete ptr; + } + } + delete (((*yyvaluep).stmt_vec)); +} +#line 1627 "bison_parser.cpp" /* yacc.c:1257 */ break; case 154: /* statement */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).statement)); } -#line 1631 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1633 "bison_parser.cpp" /* yacc.c:1257 */ break; case 155: /* preparable_statement */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).statement)); } -#line 1637 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1639 "bison_parser.cpp" /* yacc.c:1257 */ break; case 156: /* prepare_statement */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).prep_stmt)); } -#line 1643 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1645 "bison_parser.cpp" /* yacc.c:1257 */ break; case 157: /* execute_statement */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).exec_stmt)); } -#line 1649 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1651 "bison_parser.cpp" /* yacc.c:1257 */ break; case 158: /* import_statement */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).import_stmt)); } -#line 1655 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1657 "bison_parser.cpp" /* yacc.c:1257 */ break; case 159: /* import_file_type */ -#line 141 "bison_parser.y" /* yacc.c:1257 */ +#line 136 "bison_parser.y" /* yacc.c:1257 */ { } -#line 1661 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1663 "bison_parser.cpp" /* yacc.c:1257 */ break; case 160: /* file_path */ -#line 142 "bison_parser.y" /* yacc.c:1257 */ +#line 137 "bison_parser.y" /* yacc.c:1257 */ { free( (((*yyvaluep).sval)) ); } -#line 1667 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1669 "bison_parser.cpp" /* yacc.c:1257 */ break; case 161: /* create_statement */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).create_stmt)); } -#line 1673 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1675 "bison_parser.cpp" /* yacc.c:1257 */ break; case 162: /* opt_not_exists */ -#line 141 "bison_parser.y" /* yacc.c:1257 */ +#line 136 "bison_parser.y" /* yacc.c:1257 */ { } -#line 1679 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1681 "bison_parser.cpp" /* yacc.c:1257 */ break; case 163: /* column_def_commalist */ -#line 143 "bison_parser.y" /* yacc.c:1257 */ +#line 138 "bison_parser.y" /* yacc.c:1257 */ { if ((((*yyvaluep).column_vec)) != NULL) { for (auto ptr : *(((*yyvaluep).column_vec))) { @@ -1688,47 +1690,47 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio } delete (((*yyvaluep).column_vec)); } -#line 1692 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1694 "bison_parser.cpp" /* yacc.c:1257 */ break; case 164: /* column_def */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).column_t)); } -#line 1698 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1700 "bison_parser.cpp" /* yacc.c:1257 */ break; case 165: /* column_type */ -#line 141 "bison_parser.y" /* yacc.c:1257 */ +#line 136 "bison_parser.y" /* yacc.c:1257 */ { } -#line 1704 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1706 "bison_parser.cpp" /* yacc.c:1257 */ break; case 166: /* drop_statement */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).drop_stmt)); } -#line 1710 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1712 "bison_parser.cpp" /* yacc.c:1257 */ break; case 167: /* delete_statement */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).delete_stmt)); } -#line 1716 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1718 "bison_parser.cpp" /* yacc.c:1257 */ break; case 168: /* truncate_statement */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).delete_stmt)); } -#line 1722 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1724 "bison_parser.cpp" /* yacc.c:1257 */ break; case 169: /* insert_statement */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).insert_stmt)); } -#line 1728 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1730 "bison_parser.cpp" /* yacc.c:1257 */ break; case 170: /* opt_column_list */ -#line 143 "bison_parser.y" /* yacc.c:1257 */ +#line 138 "bison_parser.y" /* yacc.c:1257 */ { if ((((*yyvaluep).str_vec)) != NULL) { for (auto ptr : *(((*yyvaluep).str_vec))) { @@ -1737,17 +1739,17 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio } delete (((*yyvaluep).str_vec)); } -#line 1741 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1743 "bison_parser.cpp" /* yacc.c:1257 */ break; case 171: /* update_statement */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).update_stmt)); } -#line 1747 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1749 "bison_parser.cpp" /* yacc.c:1257 */ break; case 172: /* update_clause_commalist */ -#line 143 "bison_parser.y" /* yacc.c:1257 */ +#line 138 "bison_parser.y" /* yacc.c:1257 */ { if ((((*yyvaluep).update_vec)) != NULL) { for (auto ptr : *(((*yyvaluep).update_vec))) { @@ -1756,47 +1758,47 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio } delete (((*yyvaluep).update_vec)); } -#line 1760 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1762 "bison_parser.cpp" /* yacc.c:1257 */ break; case 173: /* update_clause */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).update_t)); } -#line 1766 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1768 "bison_parser.cpp" /* yacc.c:1257 */ break; case 174: /* select_statement */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).select_stmt)); } -#line 1772 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1774 "bison_parser.cpp" /* yacc.c:1257 */ break; case 175: /* select_with_paren */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).select_stmt)); } -#line 1778 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1780 "bison_parser.cpp" /* yacc.c:1257 */ break; case 176: /* select_no_paren */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).select_stmt)); } -#line 1784 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1786 "bison_parser.cpp" /* yacc.c:1257 */ break; case 178: /* select_clause */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).select_stmt)); } -#line 1790 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1792 "bison_parser.cpp" /* yacc.c:1257 */ break; case 179: /* opt_distinct */ -#line 141 "bison_parser.y" /* yacc.c:1257 */ +#line 136 "bison_parser.y" /* yacc.c:1257 */ { } -#line 1796 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1798 "bison_parser.cpp" /* yacc.c:1257 */ break; case 180: /* select_list */ -#line 143 "bison_parser.y" /* yacc.c:1257 */ +#line 138 "bison_parser.y" /* yacc.c:1257 */ { if ((((*yyvaluep).expr_vec)) != NULL) { for (auto ptr : *(((*yyvaluep).expr_vec))) { @@ -1805,35 +1807,35 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio } delete (((*yyvaluep).expr_vec)); } -#line 1809 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1811 "bison_parser.cpp" /* yacc.c:1257 */ break; case 181: /* from_clause */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).table)); } -#line 1815 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1817 "bison_parser.cpp" /* yacc.c:1257 */ break; case 182: /* opt_where */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 1821 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1823 "bison_parser.cpp" /* yacc.c:1257 */ break; case 183: /* opt_group */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).group_t)); } -#line 1827 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1829 "bison_parser.cpp" /* yacc.c:1257 */ break; case 184: /* opt_having */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 1833 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1835 "bison_parser.cpp" /* yacc.c:1257 */ break; case 185: /* opt_order */ -#line 143 "bison_parser.y" /* yacc.c:1257 */ +#line 138 "bison_parser.y" /* yacc.c:1257 */ { if ((((*yyvaluep).order_vec)) != NULL) { for (auto ptr : *(((*yyvaluep).order_vec))) { @@ -1842,11 +1844,11 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio } delete (((*yyvaluep).order_vec)); } -#line 1846 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1848 "bison_parser.cpp" /* yacc.c:1257 */ break; case 186: /* order_list */ -#line 143 "bison_parser.y" /* yacc.c:1257 */ +#line 138 "bison_parser.y" /* yacc.c:1257 */ { if ((((*yyvaluep).order_vec)) != NULL) { for (auto ptr : *(((*yyvaluep).order_vec))) { @@ -1855,35 +1857,35 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio } delete (((*yyvaluep).order_vec)); } -#line 1859 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1861 "bison_parser.cpp" /* yacc.c:1257 */ break; case 187: /* order_desc */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).order)); } -#line 1865 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1867 "bison_parser.cpp" /* yacc.c:1257 */ break; case 188: /* opt_order_type */ -#line 141 "bison_parser.y" /* yacc.c:1257 */ +#line 136 "bison_parser.y" /* yacc.c:1257 */ { } -#line 1871 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1873 "bison_parser.cpp" /* yacc.c:1257 */ break; case 189: /* opt_top */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).limit)); } -#line 1877 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1879 "bison_parser.cpp" /* yacc.c:1257 */ break; case 190: /* opt_limit */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).limit)); } -#line 1883 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1885 "bison_parser.cpp" /* yacc.c:1257 */ break; case 191: /* expr_list */ -#line 143 "bison_parser.y" /* yacc.c:1257 */ +#line 138 "bison_parser.y" /* yacc.c:1257 */ { if ((((*yyvaluep).expr_vec)) != NULL) { for (auto ptr : *(((*yyvaluep).expr_vec))) { @@ -1892,11 +1894,11 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio } delete (((*yyvaluep).expr_vec)); } -#line 1896 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1898 "bison_parser.cpp" /* yacc.c:1257 */ break; case 192: /* literal_list */ -#line 143 "bison_parser.y" /* yacc.c:1257 */ +#line 138 "bison_parser.y" /* yacc.c:1257 */ { if ((((*yyvaluep).expr_vec)) != NULL) { for (auto ptr : *(((*yyvaluep).expr_vec))) { @@ -1905,143 +1907,143 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio } delete (((*yyvaluep).expr_vec)); } -#line 1909 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1911 "bison_parser.cpp" /* yacc.c:1257 */ break; case 193: /* expr_alias */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 1915 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1917 "bison_parser.cpp" /* yacc.c:1257 */ break; case 194: /* expr */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 1921 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1923 "bison_parser.cpp" /* yacc.c:1257 */ break; case 195: /* operand */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 1927 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1929 "bison_parser.cpp" /* yacc.c:1257 */ break; case 196: /* scalar_expr */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 1933 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1935 "bison_parser.cpp" /* yacc.c:1257 */ break; case 197: /* unary_expr */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 1939 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1941 "bison_parser.cpp" /* yacc.c:1257 */ break; case 198: /* binary_expr */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 1945 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1947 "bison_parser.cpp" /* yacc.c:1257 */ break; case 199: /* logic_expr */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 1951 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1953 "bison_parser.cpp" /* yacc.c:1257 */ break; case 200: /* in_expr */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 1957 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1959 "bison_parser.cpp" /* yacc.c:1257 */ break; case 201: /* case_expr */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 1963 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1965 "bison_parser.cpp" /* yacc.c:1257 */ break; case 202: /* exists_expr */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 1969 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1971 "bison_parser.cpp" /* yacc.c:1257 */ break; case 203: /* comp_expr */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 1975 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1977 "bison_parser.cpp" /* yacc.c:1257 */ break; case 204: /* function_expr */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 1981 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1983 "bison_parser.cpp" /* yacc.c:1257 */ break; case 205: /* between_expr */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 1987 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1989 "bison_parser.cpp" /* yacc.c:1257 */ break; case 206: /* column_name */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 1993 "bison_parser.cpp" /* yacc.c:1257 */ +#line 1995 "bison_parser.cpp" /* yacc.c:1257 */ break; case 207: /* literal */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 1999 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2001 "bison_parser.cpp" /* yacc.c:1257 */ break; case 208: /* string_literal */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 2005 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2007 "bison_parser.cpp" /* yacc.c:1257 */ break; case 209: /* num_literal */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 2011 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2013 "bison_parser.cpp" /* yacc.c:1257 */ break; case 210: /* int_literal */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 2017 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2019 "bison_parser.cpp" /* yacc.c:1257 */ break; case 211: /* star_expr */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 2023 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2025 "bison_parser.cpp" /* yacc.c:1257 */ break; case 212: /* placeholder_expr */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 2029 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2031 "bison_parser.cpp" /* yacc.c:1257 */ break; case 213: /* table_ref */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).table)); } -#line 2035 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2037 "bison_parser.cpp" /* yacc.c:1257 */ break; case 214: /* table_ref_atomic */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).table)); } -#line 2041 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2043 "bison_parser.cpp" /* yacc.c:1257 */ break; case 215: /* table_ref_commalist */ -#line 143 "bison_parser.y" /* yacc.c:1257 */ +#line 138 "bison_parser.y" /* yacc.c:1257 */ { if ((((*yyvaluep).table_vec)) != NULL) { for (auto ptr : *(((*yyvaluep).table_vec))) { @@ -2050,65 +2052,65 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio } delete (((*yyvaluep).table_vec)); } -#line 2054 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2056 "bison_parser.cpp" /* yacc.c:1257 */ break; case 216: /* table_ref_name */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).table)); } -#line 2060 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2062 "bison_parser.cpp" /* yacc.c:1257 */ break; case 217: /* table_ref_name_no_alias */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).table)); } -#line 2066 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2068 "bison_parser.cpp" /* yacc.c:1257 */ break; case 218: /* table_name */ -#line 142 "bison_parser.y" /* yacc.c:1257 */ +#line 137 "bison_parser.y" /* yacc.c:1257 */ { free( (((*yyvaluep).sval)) ); } -#line 2072 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2074 "bison_parser.cpp" /* yacc.c:1257 */ break; case 219: /* alias */ -#line 142 "bison_parser.y" /* yacc.c:1257 */ +#line 137 "bison_parser.y" /* yacc.c:1257 */ { free( (((*yyvaluep).sval)) ); } -#line 2078 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2080 "bison_parser.cpp" /* yacc.c:1257 */ break; case 220: /* opt_alias */ -#line 142 "bison_parser.y" /* yacc.c:1257 */ +#line 137 "bison_parser.y" /* yacc.c:1257 */ { free( (((*yyvaluep).sval)) ); } -#line 2084 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2086 "bison_parser.cpp" /* yacc.c:1257 */ break; case 221: /* join_clause */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).table)); } -#line 2090 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2092 "bison_parser.cpp" /* yacc.c:1257 */ break; case 222: /* opt_join_type */ -#line 141 "bison_parser.y" /* yacc.c:1257 */ +#line 136 "bison_parser.y" /* yacc.c:1257 */ { } -#line 2096 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2098 "bison_parser.cpp" /* yacc.c:1257 */ break; case 223: /* join_table */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).table)); } -#line 2102 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2104 "bison_parser.cpp" /* yacc.c:1257 */ break; case 224: /* join_condition */ -#line 151 "bison_parser.y" /* yacc.c:1257 */ +#line 146 "bison_parser.y" /* yacc.c:1257 */ { delete (((*yyvaluep).expr)); } -#line 2108 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2110 "bison_parser.cpp" /* yacc.c:1257 */ break; case 226: /* ident_commalist */ -#line 143 "bison_parser.y" /* yacc.c:1257 */ +#line 138 "bison_parser.y" /* yacc.c:1257 */ { if ((((*yyvaluep).str_vec)) != NULL) { for (auto ptr : *(((*yyvaluep).str_vec))) { @@ -2117,7 +2119,7 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio } delete (((*yyvaluep).str_vec)); } -#line 2121 "bison_parser.cpp" /* yacc.c:1257 */ +#line 2123 "bison_parser.cpp" /* yacc.c:1257 */ break; @@ -2135,7 +2137,7 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio `----------*/ int -yyparse (hsql::SQLParserResult** result, yyscan_t scanner) +yyparse (hsql::SQLParserResult* result, yyscan_t scanner) { /* The lookahead symbol. */ int yychar; @@ -2225,7 +2227,7 @@ YYLTYPE yylloc = yyloc_default; yychar = YYEMPTY; /* Cause a token to be read. */ /* User initialization code. */ -#line 78 "bison_parser.y" /* yacc.c:1429 */ +#line 73 "bison_parser.y" /* yacc.c:1429 */ { // Initialize yylloc.first_column = 0; @@ -2236,7 +2238,7 @@ YYLTYPE yylloc = yyloc_default; yylloc.placeholder_id = 0; } -#line 2240 "bison_parser.cpp" /* yacc.c:1429 */ +#line 2242 "bison_parser.cpp" /* yacc.c:1429 */ yylsp[0] = yylloc; goto yysetstate; @@ -2423,174 +2425,182 @@ yyreduce: switch (yyn) { case 2: -#line 245 "bison_parser.y" /* yacc.c:1646 */ +#line 240 "bison_parser.y" /* yacc.c:1646 */ { - *result = (yyvsp[-1].stmt_list); + for (SQLStatement* stmt : *(yyvsp[-1].stmt_vec)) { + // Transfers ownership of the statement. + result->addStatement(stmt); + } + delete (yyvsp[-1].stmt_vec); } -#line 2431 "bison_parser.cpp" /* yacc.c:1646 */ - break; - - case 3: -#line 252 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.stmt_list) = new SQLParserResult((yyvsp[0].statement)); } #line 2437 "bison_parser.cpp" /* yacc.c:1646 */ break; - case 4: -#line 253 "bison_parser.y" /* yacc.c:1646 */ - { (yyvsp[-2].stmt_list)->addStatement((yyvsp[0].statement)); (yyval.stmt_list) = (yyvsp[-2].stmt_list); } + case 3: +#line 251 "bison_parser.y" /* yacc.c:1646 */ + { (yyval.stmt_vec) = new std::vector(); (yyval.stmt_vec)->push_back((yyvsp[0].statement)); } #line 2443 "bison_parser.cpp" /* yacc.c:1646 */ break; + case 4: +#line 252 "bison_parser.y" /* yacc.c:1646 */ + { (yyvsp[-2].stmt_vec)->push_back((yyvsp[0].statement)); (yyval.stmt_vec) = (yyvsp[-2].stmt_vec); } +#line 2449 "bison_parser.cpp" /* yacc.c:1646 */ + break; + case 5: -#line 257 "bison_parser.y" /* yacc.c:1646 */ +#line 256 "bison_parser.y" /* yacc.c:1646 */ { (yyvsp[0].prep_stmt)->setPlaceholders(yyloc.placeholder_list); yyloc.placeholder_list.clear(); (yyval.statement) = (yyvsp[0].prep_stmt); } -#line 2453 "bison_parser.cpp" /* yacc.c:1646 */ - break; - - case 7: -#line 267 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.statement) = (yyvsp[0].select_stmt); } #line 2459 "bison_parser.cpp" /* yacc.c:1646 */ break; - case 8: -#line 268 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.statement) = (yyvsp[0].import_stmt); } + case 7: +#line 266 "bison_parser.y" /* yacc.c:1646 */ + { (yyval.statement) = (yyvsp[0].select_stmt); } #line 2465 "bison_parser.cpp" /* yacc.c:1646 */ break; - case 9: -#line 269 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.statement) = (yyvsp[0].create_stmt); } + case 8: +#line 267 "bison_parser.y" /* yacc.c:1646 */ + { (yyval.statement) = (yyvsp[0].import_stmt); } #line 2471 "bison_parser.cpp" /* yacc.c:1646 */ break; - case 10: -#line 270 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.statement) = (yyvsp[0].insert_stmt); } + case 9: +#line 268 "bison_parser.y" /* yacc.c:1646 */ + { (yyval.statement) = (yyvsp[0].create_stmt); } #line 2477 "bison_parser.cpp" /* yacc.c:1646 */ break; - case 11: -#line 271 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.statement) = (yyvsp[0].delete_stmt); } + case 10: +#line 269 "bison_parser.y" /* yacc.c:1646 */ + { (yyval.statement) = (yyvsp[0].insert_stmt); } #line 2483 "bison_parser.cpp" /* yacc.c:1646 */ break; - case 12: -#line 272 "bison_parser.y" /* yacc.c:1646 */ + case 11: +#line 270 "bison_parser.y" /* yacc.c:1646 */ { (yyval.statement) = (yyvsp[0].delete_stmt); } #line 2489 "bison_parser.cpp" /* yacc.c:1646 */ break; - case 13: -#line 273 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.statement) = (yyvsp[0].update_stmt); } + case 12: +#line 271 "bison_parser.y" /* yacc.c:1646 */ + { (yyval.statement) = (yyvsp[0].delete_stmt); } #line 2495 "bison_parser.cpp" /* yacc.c:1646 */ break; - case 14: -#line 274 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.statement) = (yyvsp[0].drop_stmt); } + case 13: +#line 272 "bison_parser.y" /* yacc.c:1646 */ + { (yyval.statement) = (yyvsp[0].update_stmt); } #line 2501 "bison_parser.cpp" /* yacc.c:1646 */ break; - case 15: -#line 275 "bison_parser.y" /* yacc.c:1646 */ - { (yyval.statement) = (yyvsp[0].exec_stmt); } + case 14: +#line 273 "bison_parser.y" /* yacc.c:1646 */ + { (yyval.statement) = (yyvsp[0].drop_stmt); } #line 2507 "bison_parser.cpp" /* yacc.c:1646 */ break; + case 15: +#line 274 "bison_parser.y" /* yacc.c:1646 */ + { (yyval.statement) = (yyvsp[0].exec_stmt); } +#line 2513 "bison_parser.cpp" /* yacc.c:1646 */ + break; + case 16: -#line 283 "bison_parser.y" /* yacc.c:1646 */ +#line 282 "bison_parser.y" /* yacc.c:1646 */ { (yyval.prep_stmt) = new PrepareStatement(); (yyval.prep_stmt)->name = (yyvsp[-2].sval); (yyval.prep_stmt)->query = new SQLParserResult((yyvsp[0].statement)); } -#line 2517 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2523 "bison_parser.cpp" /* yacc.c:1646 */ break; case 17: -#line 288 "bison_parser.y" /* yacc.c:1646 */ +#line 287 "bison_parser.y" /* yacc.c:1646 */ { (yyval.prep_stmt) = new PrepareStatement(); (yyval.prep_stmt)->name = (yyvsp[-4].sval); - (yyval.prep_stmt)->query = (yyvsp[-2].stmt_list); + (yyval.prep_stmt)->query = new SQLParserResult(); + for (SQLStatement* stmt : *(yyvsp[-2].stmt_vec)) { + (yyval.prep_stmt)->query->addStatement(stmt); + } + delete (yyvsp[-2].stmt_vec); } -#line 2527 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2537 "bison_parser.cpp" /* yacc.c:1646 */ break; case 18: -#line 296 "bison_parser.y" /* yacc.c:1646 */ +#line 299 "bison_parser.y" /* yacc.c:1646 */ { (yyval.exec_stmt) = new ExecuteStatement(); (yyval.exec_stmt)->name = (yyvsp[0].sval); } -#line 2536 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2546 "bison_parser.cpp" /* yacc.c:1646 */ break; case 19: -#line 300 "bison_parser.y" /* yacc.c:1646 */ +#line 303 "bison_parser.y" /* yacc.c:1646 */ { (yyval.exec_stmt) = new ExecuteStatement(); (yyval.exec_stmt)->name = (yyvsp[-3].sval); (yyval.exec_stmt)->parameters = (yyvsp[-1].expr_vec); } -#line 2546 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2556 "bison_parser.cpp" /* yacc.c:1646 */ break; case 20: -#line 312 "bison_parser.y" /* yacc.c:1646 */ +#line 315 "bison_parser.y" /* yacc.c:1646 */ { (yyval.import_stmt) = new ImportStatement((ImportStatement::ImportType) (yyvsp[-4].uval)); (yyval.import_stmt)->filePath = (yyvsp[-2].sval); (yyval.import_stmt)->tableName = (yyvsp[0].sval); } -#line 2556 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2566 "bison_parser.cpp" /* yacc.c:1646 */ break; case 21: -#line 320 "bison_parser.y" /* yacc.c:1646 */ +#line 323 "bison_parser.y" /* yacc.c:1646 */ { (yyval.uval) = ImportStatement::kImportCSV; } -#line 2562 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2572 "bison_parser.cpp" /* yacc.c:1646 */ break; case 22: -#line 324 "bison_parser.y" /* yacc.c:1646 */ +#line 327 "bison_parser.y" /* yacc.c:1646 */ { (yyval.sval) = strdup((yyvsp[0].expr)->name); delete (yyvsp[0].expr); } -#line 2568 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2578 "bison_parser.cpp" /* yacc.c:1646 */ break; case 23: -#line 334 "bison_parser.y" /* yacc.c:1646 */ +#line 337 "bison_parser.y" /* yacc.c:1646 */ { (yyval.create_stmt) = new CreateStatement(CreateStatement::kTableFromTbl); (yyval.create_stmt)->ifNotExists = (yyvsp[-5].bval); (yyval.create_stmt)->tableName = (yyvsp[-4].sval); (yyval.create_stmt)->filePath = (yyvsp[0].sval); } -#line 2579 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2589 "bison_parser.cpp" /* yacc.c:1646 */ break; case 24: -#line 340 "bison_parser.y" /* yacc.c:1646 */ +#line 343 "bison_parser.y" /* yacc.c:1646 */ { (yyval.create_stmt) = new CreateStatement(CreateStatement::kTable); (yyval.create_stmt)->ifNotExists = (yyvsp[-4].bval); (yyval.create_stmt)->tableName = (yyvsp[-3].sval); (yyval.create_stmt)->columns = (yyvsp[-1].column_vec); } -#line 2590 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2600 "bison_parser.cpp" /* yacc.c:1646 */ break; case 25: -#line 346 "bison_parser.y" /* yacc.c:1646 */ +#line 349 "bison_parser.y" /* yacc.c:1646 */ { (yyval.create_stmt) = new CreateStatement(CreateStatement::kView); (yyval.create_stmt)->ifNotExists = (yyvsp[-4].bval); @@ -2598,192 +2608,192 @@ yyreduce: (yyval.create_stmt)->viewColumns = (yyvsp[-2].str_vec); (yyval.create_stmt)->select = (yyvsp[0].select_stmt); } -#line 2602 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2612 "bison_parser.cpp" /* yacc.c:1646 */ break; case 26: -#line 356 "bison_parser.y" /* yacc.c:1646 */ +#line 359 "bison_parser.y" /* yacc.c:1646 */ { (yyval.bval) = true; } -#line 2608 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2618 "bison_parser.cpp" /* yacc.c:1646 */ break; case 27: -#line 357 "bison_parser.y" /* yacc.c:1646 */ +#line 360 "bison_parser.y" /* yacc.c:1646 */ { (yyval.bval) = false; } -#line 2614 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2624 "bison_parser.cpp" /* yacc.c:1646 */ break; case 28: -#line 361 "bison_parser.y" /* yacc.c:1646 */ +#line 364 "bison_parser.y" /* yacc.c:1646 */ { (yyval.column_vec) = new std::vector(); (yyval.column_vec)->push_back((yyvsp[0].column_t)); } -#line 2620 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2630 "bison_parser.cpp" /* yacc.c:1646 */ break; case 29: -#line 362 "bison_parser.y" /* yacc.c:1646 */ +#line 365 "bison_parser.y" /* yacc.c:1646 */ { (yyvsp[-2].column_vec)->push_back((yyvsp[0].column_t)); (yyval.column_vec) = (yyvsp[-2].column_vec); } -#line 2626 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2636 "bison_parser.cpp" /* yacc.c:1646 */ break; case 30: -#line 366 "bison_parser.y" /* yacc.c:1646 */ +#line 369 "bison_parser.y" /* yacc.c:1646 */ { (yyval.column_t) = new ColumnDefinition((yyvsp[-1].sval), (ColumnDefinition::DataType) (yyvsp[0].uval)); } -#line 2634 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2644 "bison_parser.cpp" /* yacc.c:1646 */ break; case 31: -#line 373 "bison_parser.y" /* yacc.c:1646 */ +#line 376 "bison_parser.y" /* yacc.c:1646 */ { (yyval.uval) = ColumnDefinition::INT; } -#line 2640 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2650 "bison_parser.cpp" /* yacc.c:1646 */ break; case 32: -#line 374 "bison_parser.y" /* yacc.c:1646 */ +#line 377 "bison_parser.y" /* yacc.c:1646 */ { (yyval.uval) = ColumnDefinition::INT; } -#line 2646 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2656 "bison_parser.cpp" /* yacc.c:1646 */ break; case 33: -#line 375 "bison_parser.y" /* yacc.c:1646 */ +#line 378 "bison_parser.y" /* yacc.c:1646 */ { (yyval.uval) = ColumnDefinition::DOUBLE; } -#line 2652 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2662 "bison_parser.cpp" /* yacc.c:1646 */ break; case 34: -#line 376 "bison_parser.y" /* yacc.c:1646 */ +#line 379 "bison_parser.y" /* yacc.c:1646 */ { (yyval.uval) = ColumnDefinition::TEXT; } -#line 2658 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2668 "bison_parser.cpp" /* yacc.c:1646 */ break; case 35: -#line 386 "bison_parser.y" /* yacc.c:1646 */ +#line 389 "bison_parser.y" /* yacc.c:1646 */ { (yyval.drop_stmt) = new DropStatement(DropStatement::kTable); (yyval.drop_stmt)->name = (yyvsp[0].sval); } -#line 2667 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2677 "bison_parser.cpp" /* yacc.c:1646 */ break; case 36: -#line 390 "bison_parser.y" /* yacc.c:1646 */ +#line 393 "bison_parser.y" /* yacc.c:1646 */ { (yyval.drop_stmt) = new DropStatement(DropStatement::kView); (yyval.drop_stmt)->name = (yyvsp[0].sval); } -#line 2676 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2686 "bison_parser.cpp" /* yacc.c:1646 */ break; case 37: -#line 394 "bison_parser.y" /* yacc.c:1646 */ +#line 397 "bison_parser.y" /* yacc.c:1646 */ { (yyval.drop_stmt) = new DropStatement(DropStatement::kPreparedStatement); (yyval.drop_stmt)->name = (yyvsp[0].sval); } -#line 2685 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2695 "bison_parser.cpp" /* yacc.c:1646 */ break; case 38: -#line 406 "bison_parser.y" /* yacc.c:1646 */ +#line 409 "bison_parser.y" /* yacc.c:1646 */ { (yyval.delete_stmt) = new DeleteStatement(); (yyval.delete_stmt)->tableName = (yyvsp[-1].sval); (yyval.delete_stmt)->expr = (yyvsp[0].expr); } -#line 2695 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2705 "bison_parser.cpp" /* yacc.c:1646 */ break; case 39: -#line 414 "bison_parser.y" /* yacc.c:1646 */ +#line 417 "bison_parser.y" /* yacc.c:1646 */ { (yyval.delete_stmt) = new DeleteStatement(); (yyval.delete_stmt)->tableName = (yyvsp[0].sval); } -#line 2704 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2714 "bison_parser.cpp" /* yacc.c:1646 */ break; case 40: -#line 426 "bison_parser.y" /* yacc.c:1646 */ +#line 429 "bison_parser.y" /* yacc.c:1646 */ { (yyval.insert_stmt) = new InsertStatement(InsertStatement::kInsertValues); (yyval.insert_stmt)->tableName = (yyvsp[-5].sval); (yyval.insert_stmt)->columns = (yyvsp[-4].str_vec); (yyval.insert_stmt)->values = (yyvsp[-1].expr_vec); } -#line 2715 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2725 "bison_parser.cpp" /* yacc.c:1646 */ break; case 41: -#line 432 "bison_parser.y" /* yacc.c:1646 */ +#line 435 "bison_parser.y" /* yacc.c:1646 */ { (yyval.insert_stmt) = new InsertStatement(InsertStatement::kInsertSelect); (yyval.insert_stmt)->tableName = (yyvsp[-2].sval); (yyval.insert_stmt)->columns = (yyvsp[-1].str_vec); (yyval.insert_stmt)->select = (yyvsp[0].select_stmt); } -#line 2726 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2736 "bison_parser.cpp" /* yacc.c:1646 */ break; case 42: -#line 442 "bison_parser.y" /* yacc.c:1646 */ +#line 445 "bison_parser.y" /* yacc.c:1646 */ { (yyval.str_vec) = (yyvsp[-1].str_vec); } -#line 2732 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2742 "bison_parser.cpp" /* yacc.c:1646 */ break; case 43: -#line 443 "bison_parser.y" /* yacc.c:1646 */ +#line 446 "bison_parser.y" /* yacc.c:1646 */ { (yyval.str_vec) = NULL; } -#line 2738 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2748 "bison_parser.cpp" /* yacc.c:1646 */ break; case 44: -#line 453 "bison_parser.y" /* yacc.c:1646 */ +#line 456 "bison_parser.y" /* yacc.c:1646 */ { (yyval.update_stmt) = new UpdateStatement(); (yyval.update_stmt)->table = (yyvsp[-3].table); (yyval.update_stmt)->updates = (yyvsp[-1].update_vec); (yyval.update_stmt)->where = (yyvsp[0].expr); } -#line 2749 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2759 "bison_parser.cpp" /* yacc.c:1646 */ break; case 45: -#line 462 "bison_parser.y" /* yacc.c:1646 */ +#line 465 "bison_parser.y" /* yacc.c:1646 */ { (yyval.update_vec) = new std::vector(); (yyval.update_vec)->push_back((yyvsp[0].update_t)); } -#line 2755 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2765 "bison_parser.cpp" /* yacc.c:1646 */ break; case 46: -#line 463 "bison_parser.y" /* yacc.c:1646 */ +#line 466 "bison_parser.y" /* yacc.c:1646 */ { (yyvsp[-2].update_vec)->push_back((yyvsp[0].update_t)); (yyval.update_vec) = (yyvsp[-2].update_vec); } -#line 2761 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2771 "bison_parser.cpp" /* yacc.c:1646 */ break; case 47: -#line 467 "bison_parser.y" /* yacc.c:1646 */ +#line 470 "bison_parser.y" /* yacc.c:1646 */ { (yyval.update_t) = new UpdateClause(); (yyval.update_t)->column = (yyvsp[-2].sval); (yyval.update_t)->value = (yyvsp[0].expr); } -#line 2771 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2781 "bison_parser.cpp" /* yacc.c:1646 */ break; case 50: -#line 484 "bison_parser.y" /* yacc.c:1646 */ +#line 487 "bison_parser.y" /* yacc.c:1646 */ { (yyval.select_stmt) = (yyvsp[-1].select_stmt); } -#line 2777 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2787 "bison_parser.cpp" /* yacc.c:1646 */ break; case 51: -#line 485 "bison_parser.y" /* yacc.c:1646 */ +#line 488 "bison_parser.y" /* yacc.c:1646 */ { (yyval.select_stmt) = (yyvsp[-1].select_stmt); } -#line 2783 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2793 "bison_parser.cpp" /* yacc.c:1646 */ break; case 52: -#line 489 "bison_parser.y" /* yacc.c:1646 */ +#line 492 "bison_parser.y" /* yacc.c:1646 */ { (yyval.select_stmt) = (yyvsp[-2].select_stmt); (yyval.select_stmt)->order = (yyvsp[-1].order_vec); @@ -2794,11 +2804,11 @@ yyreduce: (yyval.select_stmt)->limit = (yyvsp[0].limit); } } -#line 2798 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2808 "bison_parser.cpp" /* yacc.c:1646 */ break; case 53: -#line 499 "bison_parser.y" /* yacc.c:1646 */ +#line 502 "bison_parser.y" /* yacc.c:1646 */ { // TODO: allow multiple unions (through linked list) // TODO: capture type of set_operator @@ -2813,11 +2823,11 @@ yyreduce: (yyval.select_stmt)->limit = (yyvsp[0].limit); } } -#line 2817 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2827 "bison_parser.cpp" /* yacc.c:1646 */ break; case 54: -#line 513 "bison_parser.y" /* yacc.c:1646 */ +#line 516 "bison_parser.y" /* yacc.c:1646 */ { (yyval.select_stmt) = (yyvsp[-4].select_stmt); (yyval.select_stmt)->unionSelect = (yyvsp[-2].select_stmt); @@ -2829,11 +2839,11 @@ yyreduce: (yyval.select_stmt)->limit = (yyvsp[0].limit); } } -#line 2833 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2843 "bison_parser.cpp" /* yacc.c:1646 */ break; case 58: -#line 533 "bison_parser.y" /* yacc.c:1646 */ +#line 536 "bison_parser.y" /* yacc.c:1646 */ { (yyval.select_stmt) = new SelectStatement(); (yyval.select_stmt)->limit = (yyvsp[-5].limit); @@ -2843,465 +2853,465 @@ yyreduce: (yyval.select_stmt)->whereClause = (yyvsp[-1].expr); (yyval.select_stmt)->groupBy = (yyvsp[0].group_t); } -#line 2847 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2857 "bison_parser.cpp" /* yacc.c:1646 */ break; case 59: -#line 545 "bison_parser.y" /* yacc.c:1646 */ +#line 548 "bison_parser.y" /* yacc.c:1646 */ { (yyval.bval) = true; } -#line 2853 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2863 "bison_parser.cpp" /* yacc.c:1646 */ break; case 60: -#line 546 "bison_parser.y" /* yacc.c:1646 */ +#line 549 "bison_parser.y" /* yacc.c:1646 */ { (yyval.bval) = false; } -#line 2859 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2869 "bison_parser.cpp" /* yacc.c:1646 */ break; case 62: -#line 554 "bison_parser.y" /* yacc.c:1646 */ +#line 557 "bison_parser.y" /* yacc.c:1646 */ { (yyval.table) = (yyvsp[0].table); } -#line 2865 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2875 "bison_parser.cpp" /* yacc.c:1646 */ break; case 63: -#line 559 "bison_parser.y" /* yacc.c:1646 */ +#line 562 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = (yyvsp[0].expr); } -#line 2871 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2881 "bison_parser.cpp" /* yacc.c:1646 */ break; case 64: -#line 560 "bison_parser.y" /* yacc.c:1646 */ +#line 563 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = NULL; } -#line 2877 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2887 "bison_parser.cpp" /* yacc.c:1646 */ break; case 65: -#line 564 "bison_parser.y" /* yacc.c:1646 */ +#line 567 "bison_parser.y" /* yacc.c:1646 */ { (yyval.group_t) = new GroupByDescription(); (yyval.group_t)->columns = (yyvsp[-1].expr_vec); (yyval.group_t)->having = (yyvsp[0].expr); } -#line 2887 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2897 "bison_parser.cpp" /* yacc.c:1646 */ break; case 66: -#line 569 "bison_parser.y" /* yacc.c:1646 */ +#line 572 "bison_parser.y" /* yacc.c:1646 */ { (yyval.group_t) = NULL; } -#line 2893 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2903 "bison_parser.cpp" /* yacc.c:1646 */ break; case 67: -#line 573 "bison_parser.y" /* yacc.c:1646 */ +#line 576 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = (yyvsp[0].expr); } -#line 2899 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2909 "bison_parser.cpp" /* yacc.c:1646 */ break; case 68: -#line 574 "bison_parser.y" /* yacc.c:1646 */ +#line 577 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = NULL; } -#line 2905 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2915 "bison_parser.cpp" /* yacc.c:1646 */ break; case 69: -#line 577 "bison_parser.y" /* yacc.c:1646 */ +#line 580 "bison_parser.y" /* yacc.c:1646 */ { (yyval.order_vec) = (yyvsp[0].order_vec); } -#line 2911 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2921 "bison_parser.cpp" /* yacc.c:1646 */ break; case 70: -#line 578 "bison_parser.y" /* yacc.c:1646 */ +#line 581 "bison_parser.y" /* yacc.c:1646 */ { (yyval.order_vec) = NULL; } -#line 2917 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2927 "bison_parser.cpp" /* yacc.c:1646 */ break; case 71: -#line 582 "bison_parser.y" /* yacc.c:1646 */ +#line 585 "bison_parser.y" /* yacc.c:1646 */ { (yyval.order_vec) = new std::vector(); (yyval.order_vec)->push_back((yyvsp[0].order)); } -#line 2923 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2933 "bison_parser.cpp" /* yacc.c:1646 */ break; case 72: -#line 583 "bison_parser.y" /* yacc.c:1646 */ +#line 586 "bison_parser.y" /* yacc.c:1646 */ { (yyvsp[-2].order_vec)->push_back((yyvsp[0].order)); (yyval.order_vec) = (yyvsp[-2].order_vec); } -#line 2929 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2939 "bison_parser.cpp" /* yacc.c:1646 */ break; case 73: -#line 587 "bison_parser.y" /* yacc.c:1646 */ +#line 590 "bison_parser.y" /* yacc.c:1646 */ { (yyval.order) = new OrderDescription((yyvsp[0].order_type), (yyvsp[-1].expr)); } -#line 2935 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2945 "bison_parser.cpp" /* yacc.c:1646 */ break; case 74: -#line 591 "bison_parser.y" /* yacc.c:1646 */ +#line 594 "bison_parser.y" /* yacc.c:1646 */ { (yyval.order_type) = kOrderAsc; } -#line 2941 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2951 "bison_parser.cpp" /* yacc.c:1646 */ break; case 75: -#line 592 "bison_parser.y" /* yacc.c:1646 */ +#line 595 "bison_parser.y" /* yacc.c:1646 */ { (yyval.order_type) = kOrderDesc; } -#line 2947 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2957 "bison_parser.cpp" /* yacc.c:1646 */ break; case 76: -#line 593 "bison_parser.y" /* yacc.c:1646 */ +#line 596 "bison_parser.y" /* yacc.c:1646 */ { (yyval.order_type) = kOrderAsc; } -#line 2953 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2963 "bison_parser.cpp" /* yacc.c:1646 */ break; case 77: -#line 599 "bison_parser.y" /* yacc.c:1646 */ +#line 602 "bison_parser.y" /* yacc.c:1646 */ { (yyval.limit) = new LimitDescription((yyvsp[0].expr)->ival, kNoOffset); delete (yyvsp[0].expr); } -#line 2959 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2969 "bison_parser.cpp" /* yacc.c:1646 */ break; case 78: -#line 600 "bison_parser.y" /* yacc.c:1646 */ +#line 603 "bison_parser.y" /* yacc.c:1646 */ { (yyval.limit) = NULL; } -#line 2965 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2975 "bison_parser.cpp" /* yacc.c:1646 */ break; case 79: -#line 604 "bison_parser.y" /* yacc.c:1646 */ +#line 607 "bison_parser.y" /* yacc.c:1646 */ { (yyval.limit) = new LimitDescription((yyvsp[0].expr)->ival, kNoOffset); delete (yyvsp[0].expr); } -#line 2971 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2981 "bison_parser.cpp" /* yacc.c:1646 */ break; case 80: -#line 605 "bison_parser.y" /* yacc.c:1646 */ +#line 608 "bison_parser.y" /* yacc.c:1646 */ { (yyval.limit) = new LimitDescription((yyvsp[-2].expr)->ival, (yyvsp[0].expr)->ival); delete (yyvsp[-2].expr); delete (yyvsp[0].expr); } -#line 2977 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2987 "bison_parser.cpp" /* yacc.c:1646 */ break; case 81: -#line 606 "bison_parser.y" /* yacc.c:1646 */ +#line 609 "bison_parser.y" /* yacc.c:1646 */ { (yyval.limit) = NULL; } -#line 2983 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2993 "bison_parser.cpp" /* yacc.c:1646 */ break; case 82: -#line 613 "bison_parser.y" /* yacc.c:1646 */ +#line 616 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr_vec) = new std::vector(); (yyval.expr_vec)->push_back((yyvsp[0].expr)); } -#line 2989 "bison_parser.cpp" /* yacc.c:1646 */ +#line 2999 "bison_parser.cpp" /* yacc.c:1646 */ break; case 83: -#line 614 "bison_parser.y" /* yacc.c:1646 */ +#line 617 "bison_parser.y" /* yacc.c:1646 */ { (yyvsp[-2].expr_vec)->push_back((yyvsp[0].expr)); (yyval.expr_vec) = (yyvsp[-2].expr_vec); } -#line 2995 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3005 "bison_parser.cpp" /* yacc.c:1646 */ break; case 84: -#line 618 "bison_parser.y" /* yacc.c:1646 */ +#line 621 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr_vec) = new std::vector(); (yyval.expr_vec)->push_back((yyvsp[0].expr)); } -#line 3001 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3011 "bison_parser.cpp" /* yacc.c:1646 */ break; case 85: -#line 619 "bison_parser.y" /* yacc.c:1646 */ +#line 622 "bison_parser.y" /* yacc.c:1646 */ { (yyvsp[-2].expr_vec)->push_back((yyvsp[0].expr)); (yyval.expr_vec) = (yyvsp[-2].expr_vec); } -#line 3007 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3017 "bison_parser.cpp" /* yacc.c:1646 */ break; case 86: -#line 623 "bison_parser.y" /* yacc.c:1646 */ +#line 626 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = (yyvsp[-1].expr); (yyval.expr)->alias = (yyvsp[0].sval); } -#line 3016 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3026 "bison_parser.cpp" /* yacc.c:1646 */ break; case 93: -#line 639 "bison_parser.y" /* yacc.c:1646 */ +#line 642 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = (yyvsp[-1].expr); } -#line 3022 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3032 "bison_parser.cpp" /* yacc.c:1646 */ break; case 98: -#line 644 "bison_parser.y" /* yacc.c:1646 */ +#line 647 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeSelect((yyvsp[-1].select_stmt)); } -#line 3028 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3038 "bison_parser.cpp" /* yacc.c:1646 */ break; case 102: -#line 654 "bison_parser.y" /* yacc.c:1646 */ +#line 657 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpUnary(kOpMinus, (yyvsp[0].expr)); } -#line 3034 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3044 "bison_parser.cpp" /* yacc.c:1646 */ break; case 103: -#line 655 "bison_parser.y" /* yacc.c:1646 */ +#line 658 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpUnary(kOpNot, (yyvsp[0].expr)); } -#line 3040 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3050 "bison_parser.cpp" /* yacc.c:1646 */ break; case 105: -#line 660 "bison_parser.y" /* yacc.c:1646 */ +#line 663 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), '-', (yyvsp[0].expr)); } -#line 3046 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3056 "bison_parser.cpp" /* yacc.c:1646 */ break; case 106: -#line 661 "bison_parser.y" /* yacc.c:1646 */ +#line 664 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), '+', (yyvsp[0].expr)); } -#line 3052 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3062 "bison_parser.cpp" /* yacc.c:1646 */ break; case 107: -#line 662 "bison_parser.y" /* yacc.c:1646 */ +#line 665 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), '/', (yyvsp[0].expr)); } -#line 3058 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3068 "bison_parser.cpp" /* yacc.c:1646 */ break; case 108: -#line 663 "bison_parser.y" /* yacc.c:1646 */ +#line 666 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), '*', (yyvsp[0].expr)); } -#line 3064 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3074 "bison_parser.cpp" /* yacc.c:1646 */ break; case 109: -#line 664 "bison_parser.y" /* yacc.c:1646 */ +#line 667 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), '%', (yyvsp[0].expr)); } -#line 3070 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3080 "bison_parser.cpp" /* yacc.c:1646 */ break; case 110: -#line 665 "bison_parser.y" /* yacc.c:1646 */ +#line 668 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), '^', (yyvsp[0].expr)); } -#line 3076 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3086 "bison_parser.cpp" /* yacc.c:1646 */ break; case 111: -#line 666 "bison_parser.y" /* yacc.c:1646 */ +#line 669 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), kOpLike, (yyvsp[0].expr)); } -#line 3082 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3092 "bison_parser.cpp" /* yacc.c:1646 */ break; case 112: -#line 667 "bison_parser.y" /* yacc.c:1646 */ +#line 670 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpBinary((yyvsp[-3].expr), kOpNotLike, (yyvsp[0].expr)); } -#line 3088 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3098 "bison_parser.cpp" /* yacc.c:1646 */ break; case 113: -#line 671 "bison_parser.y" /* yacc.c:1646 */ +#line 674 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), kOpAnd, (yyvsp[0].expr)); } -#line 3094 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3104 "bison_parser.cpp" /* yacc.c:1646 */ break; case 114: -#line 672 "bison_parser.y" /* yacc.c:1646 */ +#line 675 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), kOpOr, (yyvsp[0].expr)); } -#line 3100 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3110 "bison_parser.cpp" /* yacc.c:1646 */ break; case 115: -#line 676 "bison_parser.y" /* yacc.c:1646 */ +#line 679 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeInOperator((yyvsp[-4].expr), (yyvsp[-1].expr_vec)); } -#line 3106 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3116 "bison_parser.cpp" /* yacc.c:1646 */ break; case 116: -#line 677 "bison_parser.y" /* yacc.c:1646 */ +#line 680 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpUnary(kOpNot, Expr::makeInOperator((yyvsp[-5].expr), (yyvsp[-1].expr_vec))); } -#line 3112 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3122 "bison_parser.cpp" /* yacc.c:1646 */ break; case 117: -#line 678 "bison_parser.y" /* yacc.c:1646 */ +#line 681 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeInOperator((yyvsp[-4].expr), (yyvsp[-1].select_stmt)); } -#line 3118 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3128 "bison_parser.cpp" /* yacc.c:1646 */ break; case 118: -#line 679 "bison_parser.y" /* yacc.c:1646 */ +#line 682 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpUnary(kOpNot, Expr::makeInOperator((yyvsp[-5].expr), (yyvsp[-1].select_stmt))); } -#line 3124 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3134 "bison_parser.cpp" /* yacc.c:1646 */ break; case 119: -#line 684 "bison_parser.y" /* yacc.c:1646 */ +#line 687 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeCase((yyvsp[-5].expr), (yyvsp[-3].expr), (yyvsp[-1].expr)); } -#line 3130 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3140 "bison_parser.cpp" /* yacc.c:1646 */ break; case 120: -#line 688 "bison_parser.y" /* yacc.c:1646 */ +#line 691 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeExists((yyvsp[-1].select_stmt)); } -#line 3136 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3146 "bison_parser.cpp" /* yacc.c:1646 */ break; case 121: -#line 689 "bison_parser.y" /* yacc.c:1646 */ +#line 692 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpUnary(kOpNot, Expr::makeExists((yyvsp[-1].select_stmt))); } -#line 3142 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3152 "bison_parser.cpp" /* yacc.c:1646 */ break; case 122: -#line 693 "bison_parser.y" /* yacc.c:1646 */ +#line 696 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), '=', (yyvsp[0].expr)); } -#line 3148 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3158 "bison_parser.cpp" /* yacc.c:1646 */ break; case 123: -#line 694 "bison_parser.y" /* yacc.c:1646 */ +#line 697 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), kOpNotEquals, (yyvsp[0].expr)); } -#line 3154 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3164 "bison_parser.cpp" /* yacc.c:1646 */ break; case 124: -#line 695 "bison_parser.y" /* yacc.c:1646 */ +#line 698 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), '<', (yyvsp[0].expr)); } -#line 3160 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3170 "bison_parser.cpp" /* yacc.c:1646 */ break; case 125: -#line 696 "bison_parser.y" /* yacc.c:1646 */ +#line 699 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), '>', (yyvsp[0].expr)); } -#line 3166 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3176 "bison_parser.cpp" /* yacc.c:1646 */ break; case 126: -#line 697 "bison_parser.y" /* yacc.c:1646 */ +#line 700 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), kOpLessEq, (yyvsp[0].expr)); } -#line 3172 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3182 "bison_parser.cpp" /* yacc.c:1646 */ break; case 127: -#line 698 "bison_parser.y" /* yacc.c:1646 */ +#line 701 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeOpBinary((yyvsp[-2].expr), kOpGreaterEq, (yyvsp[0].expr)); } -#line 3178 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3188 "bison_parser.cpp" /* yacc.c:1646 */ break; case 128: -#line 702 "bison_parser.y" /* yacc.c:1646 */ +#line 705 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeFunctionRef((yyvsp[-4].sval), (yyvsp[-1].expr_vec), (yyvsp[-2].bval)); } -#line 3184 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3194 "bison_parser.cpp" /* yacc.c:1646 */ break; case 129: -#line 706 "bison_parser.y" /* yacc.c:1646 */ +#line 709 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeBetween((yyvsp[-4].expr), (yyvsp[-2].expr), (yyvsp[0].expr)); } -#line 3190 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3200 "bison_parser.cpp" /* yacc.c:1646 */ break; case 130: -#line 710 "bison_parser.y" /* yacc.c:1646 */ +#line 713 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeColumnRef((yyvsp[0].sval)); } -#line 3196 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3206 "bison_parser.cpp" /* yacc.c:1646 */ break; case 131: -#line 711 "bison_parser.y" /* yacc.c:1646 */ +#line 714 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeColumnRef((yyvsp[-2].sval), (yyvsp[0].sval)); } -#line 3202 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3212 "bison_parser.cpp" /* yacc.c:1646 */ break; case 135: -#line 721 "bison_parser.y" /* yacc.c:1646 */ +#line 724 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeLiteral((yyvsp[0].sval)); } -#line 3208 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3218 "bison_parser.cpp" /* yacc.c:1646 */ break; case 136: -#line 726 "bison_parser.y" /* yacc.c:1646 */ +#line 729 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeLiteral((yyvsp[0].fval)); } -#line 3214 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3224 "bison_parser.cpp" /* yacc.c:1646 */ break; case 138: -#line 731 "bison_parser.y" /* yacc.c:1646 */ +#line 734 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makeLiteral((yyvsp[0].ival)); } -#line 3220 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3230 "bison_parser.cpp" /* yacc.c:1646 */ break; case 139: -#line 735 "bison_parser.y" /* yacc.c:1646 */ +#line 738 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = new Expr(kExprStar); } -#line 3226 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3236 "bison_parser.cpp" /* yacc.c:1646 */ break; case 140: -#line 739 "bison_parser.y" /* yacc.c:1646 */ +#line 742 "bison_parser.y" /* yacc.c:1646 */ { (yyval.expr) = Expr::makePlaceholder(yylloc.total_column); yyloc.placeholder_list.push_back((yyval.expr)); } -#line 3235 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3245 "bison_parser.cpp" /* yacc.c:1646 */ break; case 142: -#line 751 "bison_parser.y" /* yacc.c:1646 */ +#line 754 "bison_parser.y" /* yacc.c:1646 */ { (yyvsp[0].table_vec)->push_back((yyvsp[-2].table)); auto tbl = new TableRef(kTableCrossProduct); tbl->list = (yyvsp[0].table_vec); (yyval.table) = tbl; } -#line 3246 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3256 "bison_parser.cpp" /* yacc.c:1646 */ break; case 144: -#line 762 "bison_parser.y" /* yacc.c:1646 */ +#line 765 "bison_parser.y" /* yacc.c:1646 */ { auto tbl = new TableRef(kTableSelect); tbl->select = (yyvsp[-2].select_stmt); tbl->alias = (yyvsp[0].sval); (yyval.table) = tbl; } -#line 3257 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3267 "bison_parser.cpp" /* yacc.c:1646 */ break; case 146: -#line 773 "bison_parser.y" /* yacc.c:1646 */ +#line 776 "bison_parser.y" /* yacc.c:1646 */ { (yyval.table_vec) = new std::vector(); (yyval.table_vec)->push_back((yyvsp[0].table)); } -#line 3263 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3273 "bison_parser.cpp" /* yacc.c:1646 */ break; case 147: -#line 774 "bison_parser.y" /* yacc.c:1646 */ +#line 777 "bison_parser.y" /* yacc.c:1646 */ { (yyvsp[-2].table_vec)->push_back((yyvsp[0].table)); (yyval.table_vec) = (yyvsp[-2].table_vec); } -#line 3269 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3279 "bison_parser.cpp" /* yacc.c:1646 */ break; case 148: -#line 779 "bison_parser.y" /* yacc.c:1646 */ +#line 782 "bison_parser.y" /* yacc.c:1646 */ { auto tbl = new TableRef(kTableName); tbl->name = (yyvsp[-1].sval); tbl->alias = (yyvsp[0].sval); (yyval.table) = tbl; } -#line 3280 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3290 "bison_parser.cpp" /* yacc.c:1646 */ break; case 149: -#line 789 "bison_parser.y" /* yacc.c:1646 */ +#line 792 "bison_parser.y" /* yacc.c:1646 */ { (yyval.table) = new TableRef(kTableName); (yyval.table)->name = (yyvsp[0].sval); } -#line 3289 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3299 "bison_parser.cpp" /* yacc.c:1646 */ break; case 152: -#line 803 "bison_parser.y" /* yacc.c:1646 */ +#line 806 "bison_parser.y" /* yacc.c:1646 */ { (yyval.sval) = (yyvsp[0].sval); } -#line 3295 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3305 "bison_parser.cpp" /* yacc.c:1646 */ break; case 155: -#line 809 "bison_parser.y" /* yacc.c:1646 */ +#line 812 "bison_parser.y" /* yacc.c:1646 */ { (yyval.sval) = NULL; } -#line 3301 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3311 "bison_parser.cpp" /* yacc.c:1646 */ break; case 156: -#line 818 "bison_parser.y" /* yacc.c:1646 */ +#line 821 "bison_parser.y" /* yacc.c:1646 */ { (yyval.table) = new TableRef(kTableJoin); (yyval.table)->join = new JoinDefinition(); @@ -3310,88 +3320,88 @@ yyreduce: (yyval.table)->join->right = (yyvsp[-2].table); (yyval.table)->join->condition = (yyvsp[0].expr); } -#line 3314 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3324 "bison_parser.cpp" /* yacc.c:1646 */ break; case 157: -#line 829 "bison_parser.y" /* yacc.c:1646 */ +#line 832 "bison_parser.y" /* yacc.c:1646 */ { (yyval.uval) = kJoinInner; } -#line 3320 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3330 "bison_parser.cpp" /* yacc.c:1646 */ break; case 158: -#line 830 "bison_parser.y" /* yacc.c:1646 */ +#line 833 "bison_parser.y" /* yacc.c:1646 */ { (yyval.uval) = kJoinOuter; } -#line 3326 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3336 "bison_parser.cpp" /* yacc.c:1646 */ break; case 159: -#line 831 "bison_parser.y" /* yacc.c:1646 */ +#line 834 "bison_parser.y" /* yacc.c:1646 */ { (yyval.uval) = kJoinLeftOuter; } -#line 3332 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3342 "bison_parser.cpp" /* yacc.c:1646 */ break; case 160: -#line 832 "bison_parser.y" /* yacc.c:1646 */ +#line 835 "bison_parser.y" /* yacc.c:1646 */ { (yyval.uval) = kJoinRightOuter; } -#line 3338 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3348 "bison_parser.cpp" /* yacc.c:1646 */ break; case 161: -#line 833 "bison_parser.y" /* yacc.c:1646 */ +#line 836 "bison_parser.y" /* yacc.c:1646 */ { (yyval.uval) = kJoinLeft; } -#line 3344 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3354 "bison_parser.cpp" /* yacc.c:1646 */ break; case 162: -#line 834 "bison_parser.y" /* yacc.c:1646 */ +#line 837 "bison_parser.y" /* yacc.c:1646 */ { (yyval.uval) = kJoinRight; } -#line 3350 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3360 "bison_parser.cpp" /* yacc.c:1646 */ break; case 163: -#line 835 "bison_parser.y" /* yacc.c:1646 */ +#line 838 "bison_parser.y" /* yacc.c:1646 */ { (yyval.uval) = kJoinCross; } -#line 3356 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3366 "bison_parser.cpp" /* yacc.c:1646 */ break; case 164: -#line 836 "bison_parser.y" /* yacc.c:1646 */ +#line 839 "bison_parser.y" /* yacc.c:1646 */ { (yyval.uval) = kJoinNatural; } -#line 3362 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3372 "bison_parser.cpp" /* yacc.c:1646 */ break; case 165: -#line 837 "bison_parser.y" /* yacc.c:1646 */ +#line 840 "bison_parser.y" /* yacc.c:1646 */ { (yyval.uval) = kJoinInner; } -#line 3368 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3378 "bison_parser.cpp" /* yacc.c:1646 */ break; case 166: -#line 843 "bison_parser.y" /* yacc.c:1646 */ +#line 846 "bison_parser.y" /* yacc.c:1646 */ { auto tbl = new TableRef(kTableSelect); tbl->select = (yyvsp[-2].select_stmt); tbl->alias = (yyvsp[0].sval); (yyval.table) = tbl; } -#line 3379 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3389 "bison_parser.cpp" /* yacc.c:1646 */ break; case 171: -#line 868 "bison_parser.y" /* yacc.c:1646 */ +#line 871 "bison_parser.y" /* yacc.c:1646 */ { (yyval.str_vec) = new std::vector(); (yyval.str_vec)->push_back((yyvsp[0].sval)); } -#line 3385 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3395 "bison_parser.cpp" /* yacc.c:1646 */ break; case 172: -#line 869 "bison_parser.y" /* yacc.c:1646 */ +#line 872 "bison_parser.y" /* yacc.c:1646 */ { (yyvsp[-2].str_vec)->push_back((yyvsp[0].sval)); (yyval.str_vec) = (yyvsp[-2].str_vec); } -#line 3391 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3401 "bison_parser.cpp" /* yacc.c:1646 */ break; -#line 3395 "bison_parser.cpp" /* yacc.c:1646 */ +#line 3405 "bison_parser.cpp" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -3626,7 +3636,7 @@ yyreturn: #endif return yyresult; } -#line 872 "bison_parser.y" /* yacc.c:1906 */ +#line 875 "bison_parser.y" /* yacc.c:1906 */ /********************************* ** Section 4: Additional C code diff --git a/src/parser/bison_parser.h b/src/parser/bison_parser.h index 2790efe..fecc6aa 100644 --- a/src/parser/bison_parser.h +++ b/src/parser/bison_parser.h @@ -48,7 +48,7 @@ extern int hsql_debug; #endif /* "%code requires" blocks. */ -#line 41 "bison_parser.y" /* yacc.c:1909 */ +#line 36 "bison_parser.y" /* yacc.c:1909 */ // %code requires block @@ -214,7 +214,7 @@ extern int hsql_debug; union HSQL_STYPE { -#line 100 "bison_parser.y" /* yacc.c:1909 */ +#line 95 "bison_parser.y" /* yacc.c:1909 */ double fval; int64_t ival; @@ -242,7 +242,7 @@ union HSQL_STYPE hsql::GroupByDescription* group_t; hsql::UpdateClause* update_t; - hsql::SQLParserResult* stmt_list; + std::vector* stmt_vec; std::vector* str_vec; std::vector* table_vec; @@ -275,6 +275,6 @@ struct HSQL_LTYPE -int hsql_parse (hsql::SQLParserResult** result, yyscan_t scanner); +int hsql_parse (hsql::SQLParserResult* result, yyscan_t scanner); #endif /* !YY_HSQL_BISON_PARSER_H_INCLUDED */ From d318ef0de457cdf90cabd13b6bf600886ad0752c Mon Sep 17 00:00:00 2001 From: Pedro Flemming Date: Fri, 7 Apr 2017 16:28:33 +0200 Subject: [PATCH 10/12] update tpch tests to use new interface --- test/tpc_h_tests.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/test/tpc_h_tests.cpp b/test/tpc_h_tests.cpp index 288802a..310972d 100644 --- a/test/tpc_h_tests.cpp +++ b/test/tpc_h_tests.cpp @@ -39,15 +39,15 @@ TEST(TPCHQueryGrammarTests) { for (const std::string& file_path : files) { std::string query = readFileContents(file_path); - SQLParserResult* result = SQLParser::parseSQLString(query.c_str()); - if (!result->isValid()) { + SQLParserResult result; + SQLParser::parseSQLString(query.c_str(), &result); + if (!result.isValid()) { mt::printFailed(file_path.c_str()); - printf("%s %s (L%d:%d)%s\n", mt::red(), result->errorMsg(), result->errorLine(), result->errorColumn(), mt::def()); + printf("%s %s (L%d:%d)%s\n", mt::red(), result.errorMsg(), result.errorLine(), result.errorColumn(), mt::def()); ++testsFailed; } else { mt::printOk(file_path.c_str()); } - delete result; } ASSERT_EQ(testsFailed, 0); } @@ -55,11 +55,12 @@ TEST(TPCHQueryGrammarTests) { TEST(TPCHQueryDetailTest) { std::string query = readFileContents("test/queries/tpc-h-16-22.sql"); - SQLParserResult* result = SQLParser::parseSQLString(query.c_str()); - ASSERT(result->isValid()); - ASSERT_EQ(result->size(), 7); + SQLParserResult result; + SQLParser::parseSQLString(query.c_str(), &result); + ASSERT(result.isValid()); + ASSERT_EQ(result.size(), 7); - const SQLStatement* stmt20 = result->getStatement(4); + const SQLStatement* stmt20 = result.getStatement(4); ASSERT_EQ(stmt20->type(), kStmtSelect); const SelectStatement* select20 = (const SelectStatement*) stmt20; @@ -95,6 +96,4 @@ TEST(TPCHQueryDetailTest) { ASSERT_EQ(select20->order->size(), 1); ASSERT(select20->order->at(0)->expr->isType(kExprColumnRef)); ASSERT_STREQ(select20->order->at(0)->expr->getName(), "S_NAME"); - - delete result; -} \ No newline at end of file +} From e94e80e674824ab59a2c79cf08bf4e4572a171a6 Mon Sep 17 00:00:00 2001 From: Pedro Flemming Date: Sat, 8 Apr 2017 02:37:30 +0200 Subject: [PATCH 11/12] add various utility methods to SQLParserResult like releaseStatements --- src/SQLParser.cpp | 4 +++- src/SQLParser.h | 5 +++++ src/SQLParserResult.cpp | 38 ++++++++++++++++++++++++++++++-------- src/SQLParserResult.h | 27 ++++++++++++++++++--------- test/sql_tests.cpp | 20 ++++++++++++++++++++ 5 files changed, 76 insertions(+), 18 deletions(-) diff --git a/src/SQLParser.cpp b/src/SQLParser.cpp index 9f6ee5b..a33f84d 100644 --- a/src/SQLParser.cpp +++ b/src/SQLParser.cpp @@ -27,7 +27,9 @@ namespace hsql { // Parse the tokens. // If parsing fails, the result will contain an error object. - hsql_parse(result, scanner); + int ret = hsql_parse(result, scanner); + bool success = (ret == 0); + result->setIsValid(success); hsql__delete_buffer(state, scanner); hsql_lex_destroy(scanner); diff --git a/src/SQLParser.h b/src/SQLParser.h index dffdcea..e494680 100644 --- a/src/SQLParser.h +++ b/src/SQLParser.h @@ -10,16 +10,21 @@ namespace hsql { class SQLParser { public: // Parses a given constant character SQL string into the result object. + // Returns true if the lexer and parser could run without internal errors. + // This does NOT mean that the SQL string was valid SQL. To check that + // you need to check result->isValid(); static bool parseSQLString(const char* sql, SQLParserResult* result); // Parses a given SQL string into the result object. static bool parseSQLString(const std::string& sql, SQLParserResult* result); + // Deprecated: // Parses a given constant character SQL string. // Note: This is kept for legacy reasons. It is recommended to use // the (const char*, SQLParserResult*) implementation. static SQLParserResult* parseSQLString(const char* sql); + // Deprecated: // Parses an SQL std::string. // Note: This is kept for legacy reasons. It is recommended to use // the (const std::string&, SQLParserResult*) implementation. diff --git a/src/SQLParserResult.cpp b/src/SQLParserResult.cpp index ca106c9..b8df999 100644 --- a/src/SQLParserResult.cpp +++ b/src/SQLParserResult.cpp @@ -4,21 +4,17 @@ namespace hsql { SQLParserResult::SQLParserResult() : - isValid_(true), + isValid_(false), errorMsg_(NULL) {}; SQLParserResult::SQLParserResult(SQLStatement* stmt) : - isValid_(true), + isValid_(false), errorMsg_(NULL) { addStatement(stmt); }; SQLParserResult::~SQLParserResult() { - for (SQLStatement* statement : statements_) { - delete statement; - } - - free(errorMsg_); + reset(); } void SQLParserResult::addStatement(SQLStatement* stmt) { @@ -63,4 +59,30 @@ namespace hsql { errorColumn_ = errorColumn; } -} // namespace hsql \ No newline at end of file + const std::vector& SQLParserResult::getStatements() const { + return statements_; + } + + std::vector SQLParserResult::releaseStatements() { + std::vector copy = statements_; + + statements_.clear(); + + return copy; + } + + void SQLParserResult::reset() { + for (SQLStatement* statement : statements_) { + delete statement; + } + statements_.clear(); + + isValid_ = false; + + free(errorMsg_); + errorMsg_ = NULL; + errorLine_ = -1; + errorColumn_ = -1; + } + +} // namespace hsql diff --git a/src/SQLParserResult.h b/src/SQLParserResult.h index a39c1cb..570664c 100644 --- a/src/SQLParserResult.h +++ b/src/SQLParserResult.h @@ -18,12 +18,19 @@ namespace hsql { // Deletes all statements in the result. virtual ~SQLParserResult(); + // Set whether parsing was successful. + void setIsValid(bool isValid); + // Returns true if parsing was successful. bool isValid() const; // Returns the number of statements in the result. size_t size() const; + // Set the details of the error, if available. + // Takes ownership of errorMsg. + void setErrorDetails(char* errorMsg, int errorLine, int errorColumn); + // Returns the error message, if an error occurred. const char* errorMsg() const; @@ -33,23 +40,25 @@ namespace hsql { // Returns the column number of the occurrance of the error in the query. int errorColumn() const; + // Adds a statement to the result list of statements. + // SQLParserResult takes ownership of the statement. + void addStatement(SQLStatement* stmt); + // Gets the SQL statement with the given index. const SQLStatement* getStatement(int index) const; // Gets the non const SQL statement with the given index. SQLStatement* getMutableStatement(int index); - // Adds a statement to the result list of statements. - // SQLParserResult takes ownership of the statement. - void addStatement(SQLStatement* stmt); + // Get the list of all statements. + const std::vector& getStatements() const; - // Set whether parsing was successful. - void setIsValid(bool isValid); - - // Set the details of the error, if available. - // Takes ownership of errorMsg. - void setErrorDetails(char* errorMsg, int errorLine, int errorColumn); + // Returns a copy of the list of all statements in this result. + // Removes them from this result. + std::vector releaseStatements(); + // Deletes all statements and other data within the result. + void reset(); private: // List of statements within the result. diff --git a/test/sql_tests.cpp b/test/sql_tests.cpp index 56fb5a2..3e3d359 100644 --- a/test/sql_tests.cpp +++ b/test/sql_tests.cpp @@ -161,4 +161,24 @@ TEST(ExecuteStatementTest) { ASSERT_EQ(stmt->parameters->size(), 2); } +TEST(ReleaseStatementTest) { + TEST_PARSE_SINGLE_SQL( + "SELECT * FROM students;", + kStmtSelect, + SelectStatement, + result, + stmt); + + ASSERT_EQ(1, result.size()); + ASSERT_NULL(stmt->whereClause); + + std::vector statements = result.releaseStatements(); + + ASSERT_EQ(0, result.size()); + + for (SQLStatement* stmt : statements) { + delete stmt; + } +} + TEST_MAIN(); From 927c8ec40a30422a2a0b07b7b9c5b48a531fce9a Mon Sep 17 00:00:00 2001 From: Pedro Flemming Date: Sun, 9 Apr 2017 13:34:40 +0200 Subject: [PATCH 12/12] add tests and benchmarks for prepare and execute --- benchmark/Makefile | 7 ++- benchmark/parser_benchmark.cpp | 12 +++++ src/sql/PrepareStatement.h | 2 + test/prepare_tests.cpp | 82 ++++++++++++++++++++++++++++++++++ test/sql_asserts.h | 4 +- test/sql_tests.cpp | 54 ---------------------- 6 files changed, 103 insertions(+), 58 deletions(-) create mode 100644 test/prepare_tests.cpp diff --git a/benchmark/Makefile b/benchmark/Makefile index a05a8cb..a33b9d4 100644 --- a/benchmark/Makefile +++ b/benchmark/Makefile @@ -1,4 +1,7 @@ +SRC = ./ +CPP = $(shell find $(SRC) -name '*.cpp') + CFLAGS = -std=c++11 -lstdc++ -Wall -I../src/ -L../ all: parser_benchmark @@ -6,8 +9,8 @@ all: parser_benchmark run: parser_benchmark @export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:../ && ./parser_benchmark -parser_benchmark: parser_benchmark.cpp - $(CXX) $(CFLAGS) parser_benchmark.cpp -o parser_benchmark -lbenchmark -lpthread -lsqlparser +parser_benchmark: $(CPP) + $(CXX) $(CFLAGS) $(CPP) -o parser_benchmark -lbenchmark -lpthread -lsqlparser clean: rm -f parser_benchmark diff --git a/benchmark/parser_benchmark.cpp b/benchmark/parser_benchmark.cpp index 9f0fa07..cea4709 100644 --- a/benchmark/parser_benchmark.cpp +++ b/benchmark/parser_benchmark.cpp @@ -31,6 +31,18 @@ PARSE_QUERY_BENCHMARK(BM_LongSelectElement26, PARSE_QUERY_BENCHMARK(BM_LongSelectElement52, "SELECT aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa FROM test;"); +// Prepare and Execute benchmarks. +PARSE_QUERY_BENCHMARK(BM_ExecuteStatement, + "EXECUTE procedure;"); + +PARSE_QUERY_BENCHMARK(BM_ExecuteWith2ParametersStatement, + "EXECUTE procedure(11, 'test');"); + +PARSE_QUERY_BENCHMARK(BM_ExecuteWith10ParametersStatement, + "EXECUTE procedure(11, 'test', 5.6, 4.2, 'abc', 6, 7, 8, 9, 10000);"); + + + // Benchmark the influence of increasing size of the query, while // the number of tokens remains unchanged. static void BM_CharacterCount(benchmark::State& st) { diff --git a/src/sql/PrepareStatement.h b/src/sql/PrepareStatement.h index c65e7f4..62891eb 100644 --- a/src/sql/PrepareStatement.h +++ b/src/sql/PrepareStatement.h @@ -24,6 +24,8 @@ namespace hsql { void setPlaceholders(std::vector ph); char* name; + + // The result that is stored within this prepared statement. SQLParserResult* query; // The expressions are not owned by this statement. diff --git a/test/prepare_tests.cpp b/test/prepare_tests.cpp new file mode 100644 index 0000000..bd8c51d --- /dev/null +++ b/test/prepare_tests.cpp @@ -0,0 +1,82 @@ + +#include "thirdparty/microtest/microtest.h" +#include "sql_asserts.h" +#include "SQLParser.h" + +using hsql::kExprPlaceholder; + +using hsql::kStmtDrop; +using hsql::kStmtExecute; +using hsql::kStmtInsert; +using hsql::kStmtPrepare; +using hsql::kStmtSelect; + +using hsql::DropStatement; +using hsql::ExecuteStatement; +using hsql::InsertStatement; +using hsql::PrepareStatement; +using hsql::SelectStatement; + + +TEST(PrepareSingleStatementTest) { + const std::string query = "PREPARE test: SELECT * FROM students WHERE grade = ?;"; + TEST_PARSE_SINGLE_SQL(query, kStmtPrepare, PrepareStatement, result, prepare); + + const SelectStatement* select = (const SelectStatement*) prepare->query->getStatement(0); + + ASSERT(select->whereClause->isSimpleOp('=')); + ASSERT_EQ(select->whereClause->expr2, prepare->placeholders[0]) +} + +TEST(PrepareMultiStatementTest) { + const std::string query = "PREPARE test {" + "INSERT INTO test VALUES(?);" + "SELECT ?, test FROM test WHERE c1 = ?;" + "};" + "PREPARE stmt: SELECT * FROM data WHERE c1 = ?;" + "DEALLOCATE PREPARE stmt;"; + + TEST_PARSE_SQL_QUERY(query, result, 3); + + TEST_CAST_STMT(result, 0, kStmtPrepare, PrepareStatement, prep1); + TEST_CAST_STMT(result, 1, kStmtPrepare, PrepareStatement, prep2); + TEST_CAST_STMT(result, 2, kStmtDrop, DropStatement, drop); + + // Prepare Statement #1 + ASSERT_STREQ(prep1->name, "test"); + ASSERT_EQ(prep1->placeholders.size(), 3); + ASSERT_EQ(prep1->query->size(), 2); + + TEST_CAST_STMT((*prep1->query), 0, kStmtInsert, InsertStatement, insert); + TEST_CAST_STMT((*prep1->query), 1, kStmtSelect, SelectStatement, select); + + ASSERT(insert->values->at(0)->isType(kExprPlaceholder)); + ASSERT(select->selectList->at(0)->isType(kExprPlaceholder)); + ASSERT(select->whereClause->expr2->isType(kExprPlaceholder)); + + // Check IDs of placeholders + ASSERT_EQ(insert->values->at(0)->ival, 0); + ASSERT_EQ(insert->values->at(0), prep1->placeholders[0]); + + ASSERT_EQ(select->selectList->at(0)->ival, 1); + ASSERT_EQ(select->selectList->at(0), prep1->placeholders[1]); + + ASSERT_EQ(select->whereClause->expr2->ival, 2); + ASSERT_EQ(select->whereClause->expr2, prep1->placeholders[2]); + + // Prepare Statement #2 + ASSERT_STREQ(prep2->name, "stmt"); + ASSERT_EQ(prep2->placeholders.size(), 1); + + // Deallocate Statement + ASSERT_EQ(drop->type, DropStatement::kPreparedStatement); + ASSERT_STREQ(drop->name, "stmt"); +} + + +TEST(ExecuteStatementTest) { + TEST_PARSE_SINGLE_SQL("EXECUTE test(1, 2);", kStmtExecute, ExecuteStatement, result, stmt); + + ASSERT_STREQ(stmt->name, "test"); + ASSERT_EQ(stmt->parameters->size(), 2); +} diff --git a/test/sql_asserts.h b/test/sql_asserts.h index 2c70b3b..13496cd 100644 --- a/test/sql_asserts.h +++ b/test/sql_asserts.h @@ -3,8 +3,8 @@ #define TEST_PARSE_SQL_QUERY(query, result, numStatements) \ - SQLParserResult result; \ - SQLParser::parseSQLString(query, &result); \ + hsql::SQLParserResult result; \ + hsql::SQLParser::parseSQLString(query, &result); \ ASSERT(result.isValid()); \ ASSERT_EQ(result.size(), numStatements); diff --git a/test/sql_tests.cpp b/test/sql_tests.cpp index 3e3d359..fce09d9 100644 --- a/test/sql_tests.cpp +++ b/test/sql_tests.cpp @@ -107,60 +107,6 @@ TEST(DropTableStatementTest) { ASSERT_STREQ(stmt->name, "students"); } - -TEST(PrepareStatementTest) { - std::string query = "PREPARE test {" - "INSERT INTO test VALUES(?);" - "SELECT ?, test FROM test WHERE c1 = ?;" - "};" - "PREPARE stmt: SELECT * FROM data WHERE c1 = ?;" - "DEALLOCATE PREPARE stmt;"; - - TEST_PARSE_SQL_QUERY(query, result, 3); - - TEST_CAST_STMT(result, 0, kStmtPrepare, PrepareStatement, prep1); - TEST_CAST_STMT(result, 1, kStmtPrepare, PrepareStatement, prep2); - TEST_CAST_STMT(result, 2, kStmtDrop, DropStatement, drop); - - // Prepare Statement #1 - ASSERT_STREQ(prep1->name, "test"); - ASSERT_EQ(prep1->placeholders.size(), 3); - ASSERT_EQ(prep1->query->size(), 2); - - TEST_CAST_STMT((*prep1->query), 0, kStmtInsert, InsertStatement, insert); - TEST_CAST_STMT((*prep1->query), 1, kStmtSelect, SelectStatement, select); - - ASSERT(insert->values->at(0)->isType(kExprPlaceholder)); - ASSERT(select->selectList->at(0)->isType(kExprPlaceholder)); - ASSERT(select->whereClause->expr2->isType(kExprPlaceholder)); - - // Check IDs of placeholders - ASSERT_EQ(insert->values->at(0)->ival, 0); - ASSERT_EQ(insert->values->at(0), prep1->placeholders[0]); - - ASSERT_EQ(select->selectList->at(0)->ival, 1); - ASSERT_EQ(select->selectList->at(0), prep1->placeholders[1]); - - ASSERT_EQ(select->whereClause->expr2->ival, 2); - ASSERT_EQ(select->whereClause->expr2, prep1->placeholders[2]); - - // Prepare Statement #2 - ASSERT_STREQ(prep2->name, "stmt"); - ASSERT_EQ(prep2->placeholders.size(), 1); - - // Deallocate Statement - ASSERT_EQ(drop->type, DropStatement::kPreparedStatement); - ASSERT_STREQ(drop->name, "stmt"); -} - - -TEST(ExecuteStatementTest) { - TEST_PARSE_SINGLE_SQL("EXECUTE test(1, 2);", kStmtExecute, ExecuteStatement, result, stmt); - - ASSERT_STREQ(stmt->name, "test"); - ASSERT_EQ(stmt->parameters->size(), 2); -} - TEST(ReleaseStatementTest) { TEST_PARSE_SINGLE_SQL( "SELECT * FROM students;",