diff options
author | Konstantin Osipov <kostja@sun.com> | 2010-04-14 01:56:19 +0400 |
---|---|---|
committer | Konstantin Osipov <kostja@sun.com> | 2010-04-14 01:56:19 +0400 |
commit | b8d014b8f6671395b9965b5a9953f5b2efa0fd15 (patch) | |
tree | 7a87035df6e8d664a8301574158d57d8305c65cf /mysql-test/r/sp.result | |
parent | 03b1cdd04549c754a24e996f1aefd4e3a050af49 (diff) | |
download | mariadb-git-b8d014b8f6671395b9965b5a9953f5b2efa0fd15.tar.gz |
A fix for Bug#11918 "SP does not accept variables in LIMIT clause"
Allow stored procedure variables in LIMIT clause.
Only allow variables of INTEGER types.
Handle negative values by means of an implicit cast to UNSIGNED
(similarly to prepared statement placeholders).
Add tests.
Make sure replication works by not doing NAME_CONST substitution
for variables in LIMIT clause.
Add replication tests.
Diffstat (limited to 'mysql-test/r/sp.result')
-rw-r--r-- | mysql-test/r/sp.result | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 5a746b330bc..7d24e6db920 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -7192,3 +7192,106 @@ f1 7 DROP TEMPORARY TABLE t1; DROP PROCEDURE p1; +# +# Bug #11918 Can't use a declared variable in LIMIT clause +# +drop table if exists t1; +drop procedure if exists p1; +create table t1 (c1 int); +insert into t1 (c1) values (1), (2), (3), (4), (5); +create procedure p1() +begin +declare a integer; +declare b integer; +select * from t1 limit a, b; +end| +# How do we handle NULL limit values? +call p1(); +c1 +drop table t1; +create table t1 (a int); +insert into t1 (a) values (1), (2), (3), (4), (5); +# +# Do we correctly resolve identifiers in LIMIT? +# Since DROP and CREATE did not invalidate +# the SP cache, we can't test until +# we drop and re-create the procedure. +# +call p1(); +ERROR 42S22: Unknown column 'test.t1.c1' in 'field list' +# +# Drop and recreate the procedure, then repeat +# +drop procedure p1; +create procedure p1() +begin +declare a integer; +declare b integer; +select * from t1 limit a, b; +end| +# Stored procedure variables are resolved correctly in the LIMIT +call p1(); +a +drop table t1; +create table t1 (c1 int); +insert into t1 (c1) values (1), (2), (3), (4), (5); +drop procedure p1; +# Try to create a procedure that +# refers to non-existing variables. +create procedure p1(p1 integer, p2 integer) +select * from t1 limit a, b; +ERROR 42000: Undeclared variable: a +# +# Try to use data types not allowed in LIMIT +# +create procedure p1(p1 date, p2 date) select * from t1 limit p1, p2; +ERROR HY000: A variable of a non-integer type in LIMIT clause +create procedure p1(p1 integer, p2 float) select * from t1 limit p1, p2; +ERROR HY000: A variable of a non-integer type in LIMIT clause +create procedure p1(p1 integer, p2 char(1)) select * from t1 limit p1, p2; +ERROR HY000: A variable of a non-integer type in LIMIT clause +create procedure p1(p1 varchar(5), p2 char(1)) select * from t1 limit p1, p2; +ERROR HY000: A variable of a non-integer type in LIMIT clause +create procedure p1(p1 decimal, p2 decimal) select * from t1 limit p1, p2; +ERROR HY000: A variable of a non-integer type in LIMIT clause +create procedure p1(p1 double, p2 double) select * from t1 limit p1, p2; +ERROR HY000: A variable of a non-integer type in LIMIT clause +# +# Finally, test the valid case. +# +create procedure p1(p1 integer, p2 integer) +select * from t1 limit p1, p2; +call p1(NULL, NULL); +c1 +call p1(0, 0); +c1 +call p1(0, -1); +c1 +1 +2 +3 +4 +5 +call p1(-1, 0); +c1 +call p1(-1, -1); +c1 +call p1(0, 1); +c1 +1 +call p1(1, 0); +c1 +call p1(1, 5); +c1 +2 +3 +4 +5 +call p1(3, 2); +c1 +4 +5 +# Cleanup +drop table t1; +drop procedure p1; +# End of 5.5 test |