diff --git a/src/lib/Expr.h b/src/lib/Expr.h index 7673bf3..cd7c2f4 100644 --- a/src/lib/Expr.h +++ b/src/lib/Expr.h @@ -16,6 +16,7 @@ typedef enum { kExprLiteralString, kExprLiteralInt, kExprStar, + kExprPlaceholder, kExprColumnRef, kExprFunctionRef, kExprOperator diff --git a/src/parser/bison_parser.y b/src/parser/bison_parser.y index a4f7559..a9eff8c 100644 --- a/src/parser/bison_parser.y +++ b/src/parser/bison_parser.y @@ -26,7 +26,7 @@ int yyerror(YYLTYPE* llocp, SQLStatementList** result, yyscan_t scanner, const c list->parser_msg = strdup(msg); list->error_line = llocp->first_line; list->error_col = llocp->first_column; - + *result = list; return 0; } @@ -153,7 +153,8 @@ typedef void* yyscan_t; ** Non-Terminal types (http://www.gnu.org/software/bison/manual/html_node/Type-Decl.html) *********************************/ %type statement_list -%type statement preparable_statement prepare_statement +%type statement preparable_statement +%type prepare_statement execute_statement %type select_statement select_with_paren select_no_paren select_clause %type import_statement %type create_statement @@ -166,7 +167,7 @@ typedef void* yyscan_t; %type import_file_type opt_join_type column_type %type from_clause table_ref table_ref_atomic table_ref_name %type
join_clause join_table table_ref_name_no_alias -%type expr scalar_expr unary_expr binary_expr function_expr star_expr expr_alias +%type expr scalar_expr unary_expr binary_expr function_expr star_expr expr_alias placeholder_expr %type column_name literal int_literal num_literal string_literal %type comp_expr opt_where join_condition %type expr_list opt_group select_list literal_list @@ -234,6 +235,7 @@ preparable_statement: | truncate_statement { $$ = $1; } | update_statement { $$ = $1; } | drop_statement { $$ = $1; } + | execute_statement { $$ = $1; } ; @@ -244,6 +246,9 @@ prepare_statement: PREPARE IDENTIFIER ':' preparable_statement { $$ = NULL; } ; +execute_statement: + EXECUTE IDENTIFIER '(' literal_list ')' { $$ = NULL; } + ; /****************************** @@ -558,6 +563,7 @@ column_name: literal: string_literal | num_literal + | placeholder_expr ; string_literal: @@ -578,6 +584,11 @@ star_expr: '*' { $$ = new Expr(kExprStar); } ; +/* TODO: keep list of placeholders */ +placeholder_expr: + '?' { $$ = new Expr(kExprPlaceholder); } + ; + /****************************** * Table diff --git a/test/valid_queries.sql b/test/valid_queries.sql index f5a1b96..cd295ad 100644 --- a/test/valid_queries.sql +++ b/test/valid_queries.sql @@ -4,7 +4,7 @@ SELECT a FROM foo WHERE a > 12 OR b > 3 AND NOT c LIMIT 10 SELECT col1 AS myname, col2, 'test' FROM "table", foo AS t WHERE age > 12 AND zipcode = 12345 GROUP BY col1; SELECT * from "table" JOIN table2 ON a = b WHERE (b OR NOT a) AND a = 12.5 (SELECT a FROM foo WHERE a > 12 OR b > 3 AND c NOT LIKE 's%' LIMIT 10); -SELECT * FROM "table" LIMIT 10 OFFSET 10; +SELECT * FROM "table" LIMIT 10 OFFSET 10; SELECT * FROM second; SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY col1; # SELECT * FROM t1 UNION (SELECT * FROM t2 UNION SELECT * FROM t3) ORDER BY col1; # JOIN