Commit 34266291 authored by unknown's avatar unknown

Added check for selects without into in SPs, and updated error messages and tests

accordingly.


include/mysqld_error.h:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/czech/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/danish/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/dutch/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/english/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/estonian/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/french/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/german/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/greek/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/hungarian/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/italian/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/japanese/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/korean/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/norwegian-ny/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/norwegian/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/polish/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/portuguese/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/romanian/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/russian/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/serbian/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/slovak/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/spanish/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/swedish/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
sql/share/ukrainian/errmsg.txt:
  Added bad select in SP error (and fixed leave/iterate label mismatch error).
mysql-test/r/sp.result:
  New test for repeat(...) and select with and without into in SPs.
mysql-test/t/sp.test:
  New test for repeat(...) and select with and without into in SPs.
sql/sql_yacc.yy:
  Check if an SP substatement is a SELECT and if so, has an INTO. If not, it's an
  error.
parent a5146e74
...@@ -271,10 +271,10 @@ ...@@ -271,10 +271,10 @@
#define ER_SP_DOES_NOT_EXIST 1252 #define ER_SP_DOES_NOT_EXIST 1252
#define ER_SP_DROP_FAILED 1253 #define ER_SP_DROP_FAILED 1253
#define ER_SP_STORE_FAILED 1254 #define ER_SP_STORE_FAILED 1254
#define ER_SP_LEAVE_MISMATCH 1255 #define ER_SP_LILABEL_MISMATCH 1255
#define ER_SP_ITERATE_MISMATCH 1256 #define ER_SP_LABEL_REDEFINE 1256
#define ER_SP_LABEL_REDEFINE 1257 #define ER_SP_LABEL_MISMATCH 1257
#define ER_SP_LABEL_MISMATCH 1258 #define ER_SP_UNINIT_VAR 1258
#define ER_SP_UNINIT_VAR 1259 #define ER_SP_BADSELECT 1259
#define ER_ERROR_MESSAGES 260 #define ER_ERROR_MESSAGES 260
...@@ -76,6 +76,19 @@ repeat ...@@ -76,6 +76,19 @@ repeat
insert into test.t1 values (repeat("b",3), x); insert into test.t1 values (repeat("b",3), x);
set x = x-1; set x = x-1;
until x = 0 end repeat; 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) create procedure c(x int)
hmm: while x > 0 do hmm: while x > 0 do
insert into test.t1 values ("c", x); insert into test.t1 values ("c", x);
......
...@@ -127,6 +127,24 @@ repeat ...@@ -127,6 +127,24 @@ repeat
set x = x-1; set x = x-1;
until x = 0 end repeat| 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) # Labelled WHILE with ITERATE (pointless really)
create procedure c(x int) create procedure c(x int)
hmm: while x > 0 do hmm: while x > 0 do
......
...@@ -264,9 +264,9 @@ v/* ...@@ -264,9 +264,9 @@ v/*
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -258,9 +258,9 @@ ...@@ -258,9 +258,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -266,9 +266,9 @@ ...@@ -266,9 +266,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -256,8 +256,8 @@ ...@@ -256,8 +256,8 @@
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to CREATE PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -260,9 +260,9 @@ ...@@ -260,9 +260,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -255,9 +255,9 @@ ...@@ -255,9 +255,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -265,9 +265,9 @@ ...@@ -265,9 +265,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -255,9 +255,9 @@ ...@@ -255,9 +255,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -257,9 +257,9 @@ ...@@ -257,9 +257,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -255,9 +255,9 @@ ...@@ -255,9 +255,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -257,9 +257,9 @@ ...@@ -257,9 +257,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -255,9 +255,9 @@ ...@@ -255,9 +255,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -257,9 +257,9 @@ ...@@ -257,9 +257,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -257,9 +257,9 @@ ...@@ -257,9 +257,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -259,9 +259,9 @@ ...@@ -259,9 +259,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -255,9 +255,9 @@ ...@@ -255,9 +255,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -259,9 +259,9 @@ ...@@ -259,9 +259,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -258,9 +258,9 @@ ...@@ -258,9 +258,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -251,9 +251,9 @@ ...@@ -251,9 +251,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -263,9 +263,9 @@ ...@@ -263,9 +263,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -256,9 +256,9 @@ ...@@ -256,9 +256,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -255,9 +255,9 @@ ...@@ -255,9 +255,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -260,9 +260,9 @@ ...@@ -260,9 +260,9 @@
"PROCEDURE already exists" "PROCEDURE already exists"
"PROCEDURE does not exist" "PROCEDURE does not exist"
"Failed to DROP PROCEDURE" "Failed to DROP PROCEDURE"
"Failed to store PROCEDURE" "Failed to CREATE PROCEDURE"
"LEAVE with no matching label" "%s with no matching label"
"ITERATE with no matching label"
"Redefining label" "Redefining label"
"End-label without match" "End-label without match"
"Referring to uninitialized variable" "Referring to uninitialized variable"
"SELECT in a stored procedure must have INTO"
...@@ -1041,11 +1041,20 @@ sp_proc_stmt: ...@@ -1041,11 +1041,20 @@ sp_proc_stmt:
statement statement
{ {
LEX *lex= Lex; LEX *lex= Lex;
sp_instr_stmt *i= new sp_instr_stmt(lex->sphead->instructions());
i->set_lex(lex); if (lex->sql_command == SQLCOM_SELECT && !lex->result)
lex->sphead->add_instr(i); {
lex->sphead->restore_lex(YYTHD); 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 {} | IF sp_if END IF {}
| CASE_SYM WHEN_SYM | CASE_SYM WHEN_SYM
...@@ -1096,7 +1105,7 @@ sp_proc_stmt: ...@@ -1096,7 +1105,7 @@ sp_proc_stmt:
if (! lab) if (! lab)
{ {
send_error(YYTHD, ER_SP_LEAVE_MISMATCH); send_error(YYTHD, ER_SP_LILABEL_MISMATCH, "LEAVE");
YYABORT; YYABORT;
} }
else else
...@@ -1114,7 +1123,7 @@ sp_proc_stmt: ...@@ -1114,7 +1123,7 @@ sp_proc_stmt:
if (! lab) if (! lab)
{ {
send_error(YYTHD, ER_SP_ITERATE_MISMATCH); send_error(YYTHD, ER_SP_LILABEL_MISMATCH, "ITERATE");
YYABORT; YYABORT;
} }
else else
......
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