Hi Davi
Implementing the fix for 5.0 is not required, as per internal discussions.
Please prepare the same patch for 5.1,
with 1 code change (see below)
The patch is basically approved,
but I am not declaring "ok to push" yet so I can have a chance to read
the 5.1 diff,
and it most likely will be approved right away.
Thanks,
Marc
Davi Arnaut wrote:
> Below is the list of changes that have just been committed into a local
> 5.0 repository of davi. When davi does a push these changes will
> be propagated to the main repository and, within 24 hours after the
> push, to the public repository.
> For information on how to access the public repository
> see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
>
> ChangeSet@stripped, 2007-09-12 16:24:47-03:00, davi@stripped +4 -0
> Bug#29223 declare cursor c for SHOW .....
>
> Disallow declaring cursors for non-SELECT statements (status commands).
> This was never a supported feature and could turn out to be a burden
> later if we ever need/decide to change how status commands works (show
> tables, etc).
>
> mysql-test/r/sp-error.result@stripped, 2007-09-12 16:24:42-03:00, davi@stripped
> +11 -0
> Add test case result for Bug#29223
>
> mysql-test/t/information_schema.test@stripped, 2007-09-12 16:24:42-03:00,
> davi@stripped +1 -1
> Only SELECT statements are allowed in cursors.
>
> mysql-test/t/sp-error.test@stripped, 2007-09-12 16:24:42-03:00, davi@stripped +21
> -0
> Add test case for Bug#29223
>
> sql/sql_yacc.yy@stripped, 2007-09-12 16:24:42-03:00, davi@stripped +2 -1
> Only allow declaring cursors for SELECT statements to avoid
> possible further confusion/problems.
>
> diff -Nrup a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result
> --- a/mysql-test/r/sp-error.result 2007-06-22 06:55:46 -03:00
> +++ b/mysql-test/r/sp-error.result 2007-09-12 16:24:42 -03:00
> @@ -1452,3 +1452,14 @@ end
> until true end repeat retry;
> end//
> ERROR 42000: LEAVE with no matching label: retry
> +DROP PROCEDURE IF EXISTS p1;
> +CREATE PROCEDURE p1()
> +BEGIN
> +DECLARE c char(100);
> +DECLARE cur1 CURSOR FOR SHOW TABLES;
> +OPEN cur1;
> +FETCH cur1 INTO c;
> +select c;
> +CLOSE cur1;
> +END|
> +ERROR 42000: Cursor statement must be a SELECT
> diff -Nrup a/mysql-test/t/information_schema.test
> b/mysql-test/t/information_schema.test
> --- a/mysql-test/t/information_schema.test 2007-08-20 03:23:06 -03:00
> +++ b/mysql-test/t/information_schema.test 2007-09-12 16:24:42 -03:00
> @@ -949,7 +949,7 @@ BEGIN
> DECLARE col1, col2, col3, col4, col6 CHAR(255);
> DECLARE default_val VARCHAR(65532);
> DECLARE done INT DEFAULT 0;
> - DECLARE cur1 CURSOR FOR SHOW COLUMNS FROM bug23037;
> + DECLARE cur1 CURSOR FOR SELECT COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE, COLUMN_KEY,
> COLUMN_DEFAULT, EXTRA FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='bug23037';
> DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
> OPEN cur1;
> FETCH cur1 INTO col1, col2, col3, col4, default_val, col6;
> diff -Nrup a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test
> --- a/mysql-test/t/sp-error.test 2007-06-22 06:55:46 -03:00
> +++ b/mysql-test/t/sp-error.test 2007-09-12 16:24:42 -03:00
> @@ -2090,6 +2090,27 @@ end//
> delimiter ;//
>
> #
> +# Bug#29223 declare cursor c for SHOW .....
> +#
> +
> +--disable_warnings
> +DROP PROCEDURE IF EXISTS p1;
> +--enable_warnings
> +--delimiter |
> +--error ER_SP_BAD_CURSOR_QUERY
> +CREATE PROCEDURE p1()
> +BEGIN
> + DECLARE c char(100);
> + DECLARE cur1 CURSOR FOR SHOW TABLES;
> +
> + OPEN cur1;
> + FETCH cur1 INTO c;
> + select c;
> + CLOSE cur1;
> +END|
> +--delimiter ;
> +
> +#
> # BUG#NNNN: New bug synopsis
> #
> #--disable_warnings
> diff -Nrup a/sql/sql_yacc.yy b/sql/sql_yacc.yy
> --- a/sql/sql_yacc.yy 2007-08-28 14:16:02 -03:00
> +++ b/sql/sql_yacc.yy 2007-09-12 16:24:42 -03:00
> @@ -2074,7 +2074,8 @@ sp_cursor_stmt:
> {
> LEX *lex= Lex;
>
> - if (lex->sql_command != SQLCOM_SELECT)
> + if (lex->sql_command != SQLCOM_SELECT ||
> + lex->orig_sql_command != SQLCOM_END)
> {
> my_message(ER_SP_BAD_CURSOR_QUERY, ER(ER_SP_BAD_CURSOR_QUERY),
> MYF(0));
>
Instead of having the grammar implement:
sp_cursor_stmt --> statement
statement --> select | ...
in the syntax, and then test for SQLCOM_SELECT in the actions,
simply have the grammar rule implement:
sp_cursor_stmt --> select
The result is that the error
- ER_SP_BAD_CURSOR_QUERY
will not be raised any more in the parser,
and a syntax error will occur instead,
which is the expected result.
Please make sure to adjust all the tests results accordingly,
and do *not* remove this error from errmsg.txt
Free free to ask for help if needed.