Commit 9a4acccd authored by sergefp@mysql.com's avatar sergefp@mysql.com

WL#1622 "SQL Syntax for Prepared Statements" - cosmetic code review fixes

parent b55d59fe
...@@ -83,4 +83,10 @@ NULL ...@@ -83,4 +83,10 @@ NULL
NULL NULL
NULL NULL
NULL NULL
prepare stmt6 from 'select 1; select2';
ERROR 42000: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '; select2' at line 1
prepare stmt6 from 'insert into t1 values (5,"five"); select2';
ERROR 42000: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '; select2' at line 1
explain prepare stmt6 from 'insert into t1 values (5,"five"); select2';
ERROR 42000: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'from 'insert into t1 values (5,"five"); select2'' at line 1
drop table t1; drop table t1;
...@@ -75,5 +75,16 @@ execute stmt5 using @nullvar; ...@@ -75,5 +75,16 @@ execute stmt5 using @nullvar;
set @nullvar2=NULL; set @nullvar2=NULL;
execute stmt5 using @nullvar2; execute stmt5 using @nullvar2;
# Check that multiple SQL statements are disabled inside PREPARE
--error 1064
prepare stmt6 from 'select 1; select2';
--error 1064
prepare stmt6 from 'insert into t1 values (5,"five"); select2';
# This shouldn't parse
--error 1064
explain prepare stmt6 from 'insert into t1 values (5,"five"); select2';
drop table t1; drop table t1;
...@@ -1282,8 +1282,8 @@ static void delete_statement_as_hash_key(void *key) ...@@ -1282,8 +1282,8 @@ static void delete_statement_as_hash_key(void *key)
delete (Statement *) key; delete (Statement *) key;
} }
byte *get_stmt_name_hash_key(Statement *entry, uint *length, static byte *get_stmt_name_hash_key(Statement *entry, uint *length,
my_bool not_used __attribute__((unused))) my_bool not_used __attribute__((unused)))
{ {
*length=(uint) entry->name.length; *length=(uint) entry->name.length;
return (byte*) entry->name.str; return (byte*) entry->name.str;
...@@ -1303,8 +1303,8 @@ Statement_map::Statement_map() : ...@@ -1303,8 +1303,8 @@ Statement_map::Statement_map() :
get_statement_id_as_hash_key, get_statement_id_as_hash_key,
delete_statement_as_hash_key, MYF(0)); delete_statement_as_hash_key, MYF(0));
hash_init(&names_hash, &my_charset_bin, START_NAME_HASH_SIZE, 0, 0, hash_init(&names_hash, &my_charset_bin, START_NAME_HASH_SIZE, 0, 0,
(hash_get_key) get_stmt_name_hash_key, (hash_get_key) get_stmt_name_hash_key,
NULL,MYF(0)); NULL,MYF(0));
} }
int Statement_map::insert(Statement *statement) int Statement_map::insert(Statement *statement)
......
...@@ -805,13 +805,13 @@ deallocate: ...@@ -805,13 +805,13 @@ deallocate:
DEALLOCATE_SYM PREPARE_SYM ident DEALLOCATE_SYM PREPARE_SYM ident
{ {
THD *thd=YYTHD; THD *thd=YYTHD;
LEX *lex= thd->lex; LEX *lex= thd->lex;
if (thd->command == COM_PREPARE) if (thd->command == COM_PREPARE)
{ {
yyerror(ER(ER_SYNTAX_ERROR)); yyerror(ER(ER_SYNTAX_ERROR));
YYABORT; YYABORT;
} }
lex->sql_command= SQLCOM_DEALLOCATE_PREPARE; lex->sql_command= SQLCOM_DEALLOCATE_PREPARE;
lex->prepared_stmt_name= $3; lex->prepared_stmt_name= $3;
}; };
...@@ -819,29 +819,28 @@ prepare: ...@@ -819,29 +819,28 @@ prepare:
PREPARE_SYM ident FROM TEXT_STRING_sys PREPARE_SYM ident FROM TEXT_STRING_sys
{ {
THD *thd=YYTHD; THD *thd=YYTHD;
LEX *lex= thd->lex; LEX *lex= thd->lex;
if (thd->command == COM_PREPARE) if (thd->command == COM_PREPARE)
{ {
yyerror(ER(ER_SYNTAX_ERROR)); yyerror(ER(ER_SYNTAX_ERROR));
YYABORT; YYABORT;
} }
lex->sql_command= SQLCOM_PREPARE; lex->sql_command= SQLCOM_PREPARE;
lex->prepared_stmt_name= $2; lex->prepared_stmt_name= $2;
lex->prepared_stmt_code= $4; lex->prepared_stmt_code= $4;
}; };
execute: execute:
EXECUTE_SYM ident EXECUTE_SYM ident
{ {
THD *thd=YYTHD; THD *thd=YYTHD;
LEX *lex= thd->lex; LEX *lex= thd->lex;
if (thd->command == COM_PREPARE) if (thd->command == COM_PREPARE)
{ {
yyerror(ER(ER_SYNTAX_ERROR)); yyerror(ER(ER_SYNTAX_ERROR));
YYABORT; YYABORT;
} }
lex->sql_command= SQLCOM_EXECUTE; lex->sql_command= SQLCOM_EXECUTE;
lex->prepared_stmt_name= $2; lex->prepared_stmt_name= $2;
} }
execute_using execute_using
...@@ -854,8 +853,8 @@ execute_using: ...@@ -854,8 +853,8 @@ execute_using:
; ;
execute_var_list: execute_var_list:
execute_var_list ',' execute_var_ident execute_var_list ',' execute_var_ident
| execute_var_ident | execute_var_ident
; ;
execute_var_ident: '@' ident_or_text execute_var_ident: '@' ident_or_text
...@@ -864,7 +863,7 @@ execute_var_ident: '@' ident_or_text ...@@ -864,7 +863,7 @@ execute_var_ident: '@' ident_or_text
LEX_STRING *lexstr= (LEX_STRING*)sql_memdup(&$2, sizeof(LEX_STRING)); LEX_STRING *lexstr= (LEX_STRING*)sql_memdup(&$2, sizeof(LEX_STRING));
if (!lexstr || lex->prepared_stmt_params.push_back(lexstr)) if (!lexstr || lex->prepared_stmt_params.push_back(lexstr))
YYABORT; YYABORT;
} }
; ;
/* help */ /* help */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment