From a1d21d892ec580171c04fc65e891d1e4cd853fee Mon Sep 17 00:00:00 2001 From: "pem@mysql.com" <> Date: Thu, 23 Jan 2003 14:00:32 +0100 Subject: [PATCH] Added check for selects without into in SPs, and updated error messages and tests accordingly. --- include/mysqld_error.h | 10 +++++----- mysql-test/r/sp.result | 13 +++++++++++++ mysql-test/t/sp.test | 18 ++++++++++++++++++ sql/share/czech/errmsg.txt | 6 +++--- sql/share/danish/errmsg.txt | 6 +++--- sql/share/dutch/errmsg.txt | 6 +++--- sql/share/english/errmsg.txt | 4 ++-- sql/share/estonian/errmsg.txt | 6 +++--- sql/share/french/errmsg.txt | 6 +++--- sql/share/german/errmsg.txt | 6 +++--- sql/share/greek/errmsg.txt | 6 +++--- sql/share/hungarian/errmsg.txt | 6 +++--- sql/share/italian/errmsg.txt | 6 +++--- sql/share/japanese/errmsg.txt | 6 +++--- sql/share/korean/errmsg.txt | 6 +++--- sql/share/norwegian-ny/errmsg.txt | 6 +++--- sql/share/norwegian/errmsg.txt | 6 +++--- sql/share/polish/errmsg.txt | 6 +++--- sql/share/portuguese/errmsg.txt | 6 +++--- sql/share/romanian/errmsg.txt | 6 +++--- sql/share/russian/errmsg.txt | 6 +++--- sql/share/serbian/errmsg.txt | 6 +++--- sql/share/slovak/errmsg.txt | 6 +++--- sql/share/spanish/errmsg.txt | 6 +++--- sql/share/swedish/errmsg.txt | 6 +++--- sql/share/ukrainian/errmsg.txt | 6 +++--- sql/sql_yacc.yy | 21 +++++++++++++++------ 27 files changed, 119 insertions(+), 79 deletions(-) diff --git a/include/mysqld_error.h b/include/mysqld_error.h index e540b8371d8..f52fc75be86 100644 --- a/include/mysqld_error.h +++ b/include/mysqld_error.h @@ -271,10 +271,10 @@ #define ER_SP_DOES_NOT_EXIST 1252 #define ER_SP_DROP_FAILED 1253 #define ER_SP_STORE_FAILED 1254 -#define ER_SP_LEAVE_MISMATCH 1255 -#define ER_SP_ITERATE_MISMATCH 1256 -#define ER_SP_LABEL_REDEFINE 1257 -#define ER_SP_LABEL_MISMATCH 1258 -#define ER_SP_UNINIT_VAR 1259 +#define ER_SP_LILABEL_MISMATCH 1255 +#define ER_SP_LABEL_REDEFINE 1256 +#define ER_SP_LABEL_MISMATCH 1257 +#define ER_SP_UNINIT_VAR 1258 +#define ER_SP_BADSELECT 1259 #define ER_ERROR_MESSAGES 260 diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 0463ad0caf2..f66649ba28e 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -76,6 +76,19 @@ repeat insert into test.t1 values (repeat("b",3), x); set x = x-1; until x = 0 end repeat; +create procedure b2(x int) +repeat(select 1 into outfile 'b2'); +insert into test.t1 values (repeat("b2",3), x); +set x = x-1; +until x = 0 end repeat; +drop procedure b2; +create procedure b3(x int) +repeat +select * from test.t1; # No INTO! +insert into test.t1 values (repeat("b3",3), x); +set x = x-1; +until x = 0 end repeat; +SELECT in a stored procedure must have INTO create procedure c(x int) hmm: while x > 0 do insert into test.t1 values ("c", x); diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index e146d629f1b..73bdcbcde15 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -127,6 +127,24 @@ repeat set x = x-1; until x = 0 end repeat| +# Check that repeat isn't parsed the wrong way +create procedure b2(x int) +repeat(select 1 into outfile 'b2'); + insert into test.t1 values (repeat("b2",3), x); + set x = x-1; +until x = 0 end repeat| +# We don't actually want to call it. +drop procedure b2| + +# Btw, this should generate an error +--error 1259 +create procedure b3(x int) +repeat + select * from test.t1; # No INTO! + insert into test.t1 values (repeat("b3",3), x); + set x = x-1; +until x = 0 end repeat| + # Labelled WHILE with ITERATE (pointless really) create procedure c(x int) hmm: while x > 0 do diff --git a/sql/share/czech/errmsg.txt b/sql/share/czech/errmsg.txt index 79dae19dbc8..dd2df4c5243 100644 --- a/sql/share/czech/errmsg.txt +++ b/sql/share/czech/errmsg.txt @@ -264,9 +264,9 @@ v/* "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/danish/errmsg.txt b/sql/share/danish/errmsg.txt index a77c2b59622..3c66c5a64f2 100644 --- a/sql/share/danish/errmsg.txt +++ b/sql/share/danish/errmsg.txt @@ -258,9 +258,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/dutch/errmsg.txt b/sql/share/dutch/errmsg.txt index 5f78ba6c21d..cdae9092602 100644 --- a/sql/share/dutch/errmsg.txt +++ b/sql/share/dutch/errmsg.txt @@ -266,9 +266,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/english/errmsg.txt b/sql/share/english/errmsg.txt index 9fe52f075dc..811fb015fb7 100644 --- a/sql/share/english/errmsg.txt +++ b/sql/share/english/errmsg.txt @@ -256,8 +256,8 @@ "PROCEDURE does not exist" "Failed to DROP PROCEDURE" "Failed to CREATE PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/estonian/errmsg.txt b/sql/share/estonian/errmsg.txt index 8202d782408..af32e4cc630 100644 --- a/sql/share/estonian/errmsg.txt +++ b/sql/share/estonian/errmsg.txt @@ -260,9 +260,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/french/errmsg.txt b/sql/share/french/errmsg.txt index 799cb76d8c0..147948d567f 100644 --- a/sql/share/french/errmsg.txt +++ b/sql/share/french/errmsg.txt @@ -255,9 +255,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/german/errmsg.txt b/sql/share/german/errmsg.txt index d6c9a2fb8ed..c3b4713241a 100644 --- a/sql/share/german/errmsg.txt +++ b/sql/share/german/errmsg.txt @@ -265,9 +265,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/greek/errmsg.txt b/sql/share/greek/errmsg.txt index c78d410df83..43ba3c3b173 100644 --- a/sql/share/greek/errmsg.txt +++ b/sql/share/greek/errmsg.txt @@ -255,9 +255,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/hungarian/errmsg.txt b/sql/share/hungarian/errmsg.txt index b42c4a87c4f..9355daa634e 100644 --- a/sql/share/hungarian/errmsg.txt +++ b/sql/share/hungarian/errmsg.txt @@ -257,9 +257,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/italian/errmsg.txt b/sql/share/italian/errmsg.txt index 937f2d41379..aee2c229f80 100644 --- a/sql/share/italian/errmsg.txt +++ b/sql/share/italian/errmsg.txt @@ -255,9 +255,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/japanese/errmsg.txt b/sql/share/japanese/errmsg.txt index 136e4c77fb6..2b7515c12d1 100644 --- a/sql/share/japanese/errmsg.txt +++ b/sql/share/japanese/errmsg.txt @@ -257,9 +257,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/korean/errmsg.txt b/sql/share/korean/errmsg.txt index 08c496984a8..b8e0e7a4f25 100644 --- a/sql/share/korean/errmsg.txt +++ b/sql/share/korean/errmsg.txt @@ -255,9 +255,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/norwegian-ny/errmsg.txt b/sql/share/norwegian-ny/errmsg.txt index 7c7387da2fe..15894decc4a 100644 --- a/sql/share/norwegian-ny/errmsg.txt +++ b/sql/share/norwegian-ny/errmsg.txt @@ -257,9 +257,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/norwegian/errmsg.txt b/sql/share/norwegian/errmsg.txt index fc42860af0d..01ce52ec060 100644 --- a/sql/share/norwegian/errmsg.txt +++ b/sql/share/norwegian/errmsg.txt @@ -257,9 +257,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/polish/errmsg.txt b/sql/share/polish/errmsg.txt index f907222ea28..a2440d5928e 100644 --- a/sql/share/polish/errmsg.txt +++ b/sql/share/polish/errmsg.txt @@ -259,9 +259,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/portuguese/errmsg.txt b/sql/share/portuguese/errmsg.txt index a26d6dae971..86b44f4d97d 100644 --- a/sql/share/portuguese/errmsg.txt +++ b/sql/share/portuguese/errmsg.txt @@ -255,9 +255,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/romanian/errmsg.txt b/sql/share/romanian/errmsg.txt index e2ac7eade01..f6cc343a70d 100644 --- a/sql/share/romanian/errmsg.txt +++ b/sql/share/romanian/errmsg.txt @@ -259,9 +259,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/russian/errmsg.txt b/sql/share/russian/errmsg.txt index 8d350e62f00..33dc4e5d3b8 100644 --- a/sql/share/russian/errmsg.txt +++ b/sql/share/russian/errmsg.txt @@ -258,9 +258,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/serbian/errmsg.txt b/sql/share/serbian/errmsg.txt index e12c2953805..eb699fc812c 100644 --- a/sql/share/serbian/errmsg.txt +++ b/sql/share/serbian/errmsg.txt @@ -251,9 +251,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/slovak/errmsg.txt b/sql/share/slovak/errmsg.txt index 391b531cfdb..b1253642081 100644 --- a/sql/share/slovak/errmsg.txt +++ b/sql/share/slovak/errmsg.txt @@ -263,9 +263,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/spanish/errmsg.txt b/sql/share/spanish/errmsg.txt index 528c89893cc..6be74571317 100644 --- a/sql/share/spanish/errmsg.txt +++ b/sql/share/spanish/errmsg.txt @@ -256,9 +256,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/swedish/errmsg.txt b/sql/share/swedish/errmsg.txt index e8f1d4eec0f..512314cf856 100644 --- a/sql/share/swedish/errmsg.txt +++ b/sql/share/swedish/errmsg.txt @@ -255,9 +255,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/share/ukrainian/errmsg.txt b/sql/share/ukrainian/errmsg.txt index 965da3cd29d..337157829a9 100644 --- a/sql/share/ukrainian/errmsg.txt +++ b/sql/share/ukrainian/errmsg.txt @@ -260,9 +260,9 @@ "PROCEDURE already exists" "PROCEDURE does not exist" "Failed to DROP PROCEDURE" -"Failed to store PROCEDURE" -"LEAVE with no matching label" -"ITERATE with no matching label" +"Failed to CREATE PROCEDURE" +"%s with no matching label" "Redefining label" "End-label without match" "Referring to uninitialized variable" +"SELECT in a stored procedure must have INTO" diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 3248048d304..b8440943ac1 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1041,11 +1041,20 @@ sp_proc_stmt: statement { LEX *lex= Lex; - sp_instr_stmt *i= new sp_instr_stmt(lex->sphead->instructions()); - i->set_lex(lex); - lex->sphead->add_instr(i); - lex->sphead->restore_lex(YYTHD); + if (lex->sql_command == SQLCOM_SELECT && !lex->result) + { + send_error(YYTHD, ER_SP_BADSELECT); + YYABORT; + } + else + { + sp_instr_stmt *i= new sp_instr_stmt(lex->sphead->instructions()); + + i->set_lex(lex); + lex->sphead->add_instr(i); + lex->sphead->restore_lex(YYTHD); + } } | IF sp_if END IF {} | CASE_SYM WHEN_SYM @@ -1096,7 +1105,7 @@ sp_proc_stmt: if (! lab) { - send_error(YYTHD, ER_SP_LEAVE_MISMATCH); + send_error(YYTHD, ER_SP_LILABEL_MISMATCH, "LEAVE"); YYABORT; } else @@ -1114,7 +1123,7 @@ sp_proc_stmt: if (! lab) { - send_error(YYTHD, ER_SP_ITERATE_MISMATCH); + send_error(YYTHD, ER_SP_LILABEL_MISMATCH, "ITERATE"); YYABORT; } else