Bug #17878 | SELECT with WHERE clause SP/cursor does not work | ||
---|---|---|---|
Submitted: | 2 Mar 2006 21:47 | Modified: | 29 Jun 2006 18:16 |
Reporter: | Andrey Hristov | Email Updates: | |
Status: | Duplicate | Impact on me: | |
Category: | MySQL Server: Stored Routines | Severity: | S3 (Non-critical) |
Version: | 5.0 | OS: | |
Assigned to: | Assigned Account | CPU Architecture: | Any |
[2 Mar 2006 21:47]
Andrey Hristov
[28 Jun 2006 22:49]
Petr Chardin
The bug has nothing to deal with logging. That's pure SP+Cursors problem. Here is shortened test case: drop table fordel; create table fordel (a int); insert values (1) into fordel; insert into fordel values (1); insert into fordel values (5); DELIMITER // DROP procedure fetch_n_select // CREATE procedure fetch_n_select() BEGIN DECLARE a INT; DECLARE done INT DEFAULT 0; DECLARE cur1 CURSOR FOR SELECT * FROM fordel WHERE a > 1; DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; SELECT * FROM fordel WHERE a > 1; END // DELIMITER ; SELECT * FROM fordel WHERE a > 1 ; CALL fetch_n_select(); drop table fordel; The output is: mysql> SELECT * FROM fordel WHERE a > 1 ; +------+ | a | +------+ | 5 | +------+ 1 row in set (0.00 sec) mysql> mysql> CALL fetch_n_select(); Empty set (0.02 sec) Query OK, 0 rows affected (0.02 sec)
[29 Jun 2006 12:49]
Petr Chardin
Test case for the bug. in mysqltest format
Attachment: 17878.test (application/octet-stream, text), 529 bytes.
[29 Jun 2006 18:16]
Konstantin Osipov
Thank you for your bug report. This is a duplicate of Bug#5967 "Stored procedure declared variable used instead of column". The reason why the query in the stored procedure returns no rows is that the variable that is used in the WHERE clause refers to the stored procedure stack variable (a), not the table column. To fix your test case you should give the SP variable an unambiguous name.
[29 Jun 2006 18:18]
Konstantin Osipov
The example given in the report works fine after a rename: kostja@bodhi:~> mysql test Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 to server version: 5.0.24-valgrind-max-debug Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> drop table if exists fordel; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> create table fordel (a int); Query OK, 0 rows affected (0.02 sec) mysql> insert into fordel values (1); Query OK, 1 row affected (0.00 sec) mysql> insert into fordel values (5); Query OK, 1 row affected (0.00 sec) mysql> mysql> DELIMITER | mysql> mysql> DROP procedure if exists fetch_n_select | Query OK, 0 rows affected (0.00 sec) mysql> mysql> CREATE procedure fetch_n_select() -> BEGIN -> DECLARE a1 INT; -> DECLARE done INT DEFAULT 0; -> DECLARE cur1 CURSOR FOR SELECT * FROM fordel WHERE a > 1; -> DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; -> -> SELECT * FROM fordel WHERE a > 1; -> END | Query OK, 0 rows affected (0.00 sec) mysql> mysql> DELIMITER ; mysql> mysql> SELECT * FROM fordel WHERE a > 1 ; +------+ | a | +------+ | 5 | +------+ 1 row in set (0.00 sec) mysql> mysql> CALL fetch_n_select(); +------+ | a | +------+ | 5 | +------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec) mysql> mysql> drop table fordel; Query OK, 0 rows affected (0.00 sec)