Make parameters for execute optional (#107)

This commit is contained in:
mrks 2018-11-23 11:10:31 +01:00 committed by GitHub
parent bd56ba8f7a
commit 1b86e5e624
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 906 additions and 842 deletions

File diff suppressed because it is too large Load Diff

View File

@ -214,7 +214,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
%type <alias_t> opt_table_alias table_alias opt_alias alias %type <alias_t> opt_table_alias table_alias opt_alias alias
%type <str_vec> ident_commalist opt_column_list %type <str_vec> ident_commalist opt_column_list
%type <expr_vec> expr_list select_list literal_list hint_list opt_hints %type <expr_vec> expr_list select_list opt_literal_list literal_list hint_list opt_hints
%type <table_vec> table_ref_commalist %type <table_vec> table_ref_commalist
%type <order_vec> opt_order order_list %type <order_vec> opt_order order_list
%type <update_vec> update_clause_commalist %type <update_vec> update_clause_commalist
@ -360,7 +360,7 @@ execute_statement:
$$ = new ExecuteStatement(); $$ = new ExecuteStatement();
$$->name = $2; $$->name = $2;
} }
| EXECUTE IDENTIFIER '(' literal_list ')' { | EXECUTE IDENTIFIER '(' opt_literal_list ')' {
$$ = new ExecuteStatement(); $$ = new ExecuteStatement();
$$->name = $2; $$->name = $2;
$$->parameters = $4; $$->parameters = $4;
@ -747,6 +747,11 @@ expr_list:
| expr_list ',' expr_alias { $1->push_back($3); $$ = $1; } | expr_list ',' expr_alias { $1->push_back($3); $$ = $1; }
; ;
opt_literal_list:
literal_list { $$ = $1; }
| /* empty */ { $$ = nullptr; }
;
literal_list: literal_list:
literal { $$ = new std::vector<Expr*>(); $$->push_back($1); } literal { $$ = new std::vector<Expr*>(); $$->push_back($1); }
| literal_list ',' literal { $1->push_back($3); $$ = $1; } | literal_list ',' literal { $1->push_back($3); $$ = $1; }

View File

@ -96,3 +96,27 @@ TEST(ExecuteStatementTest) {
ASSERT_STREQ(stmt->name, "test"); ASSERT_STREQ(stmt->name, "test");
ASSERT_EQ(stmt->parameters->size(), 2); ASSERT_EQ(stmt->parameters->size(), 2);
} }
TEST(ExecuteStatementTestNoParam) {
TEST_PARSE_SINGLE_SQL(
"EXECUTE test();",
kStmtExecute,
ExecuteStatement,
result,
stmt);
ASSERT_STREQ(stmt->name, "test");
ASSERT_EQ(stmt->parameters, 0);
}
TEST(ExecuteStatementTestNoParamList) {
TEST_PARSE_SINGLE_SQL(
"EXECUTE test;",
kStmtExecute,
ExecuteStatement,
result,
stmt);
ASSERT_STREQ(stmt->name, "test");
ASSERT_EQ(stmt->parameters, 0);
}