From b5627bb00c8c60caefd428e70bfddfc7f03a5667 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 11 Dec 2003 12:23:50 +0100 Subject: [PATCH] WL#1364: Store some environmental values with SPs and use at invokation sql_mode is stored and used with SPs. sql_select_limit is always unlimited in SPs. mysql-test/r/sp.result: Test case for mode settings. mysql-test/t/sp.test: Test case for mode settings. sql/sp.cc: Store the sql_mode with the SP and reset it on retrieval. sql_select_limit is always maximum (default) in an SP, regardless of the setting at the time of create or call. --- mysql-test/r/sp.result | 28 ++++++++++++++++++++++++++++ mysql-test/t/sp.test | 35 +++++++++++++++++++++++++++++++++++ sql/sp.cc | 10 ++++++++++ 3 files changed, 73 insertions(+) diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 722d8f3773b..e0d72a77832 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -691,6 +691,34 @@ delete from t1; delete from t2; drop table t3; drop procedure cur2; +insert into t1 values ("foo", 1), ("bar", 2), ("zip", 3); +set @@sql_mode = 'ANSI'; +create procedure modes(out c1 int, out c2 int) +begin +declare done int default 0; +declare x int; +declare continue handler for sqlstate '02000' set done = 1; +declare c cursor for select data from t1; +select 1 || 2 into c1; +set c2 = 0; +open c; +repeat +fetch c into x; +if not done then +set c2 = c2 + 1; +end if; +until done end repeat; +close c; +end; +set @@sql_mode = ''; +set sql_select_limit = 1; +call modes(@c1, @c2); +set sql_select_limit = default; +select @c1, @c2; +@c1 @c2 +12 3 +delete from t1; +drop procedure modes; create procedure bug822(a_id char(16), a_data int) begin declare n int; diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 3c4c850ba79..933fe828440 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -816,6 +816,41 @@ drop table t3| drop procedure cur2| +# Check mode settings +insert into t1 values ("foo", 1), ("bar", 2), ("zip", 3)| + +set @@sql_mode = 'ANSI'| +delimiter $| +create procedure modes(out c1 int, out c2 int) +begin + declare done int default 0; + declare x int; + declare continue handler for sqlstate '02000' set done = 1; + declare c cursor for select data from t1; + + select 1 || 2 into c1; + set c2 = 0; + open c; + repeat + fetch c into x; + if not done then + set c2 = c2 + 1; + end if; + until done end repeat; + close c; +end$ +delimiter |$ +set @@sql_mode = ''| + +set sql_select_limit = 1| +call modes(@c1, @c2)| +set sql_select_limit = default| + +select @c1, @c2| +delete from t1| +drop procedure modes| + + # # Test cases for old bugs # diff --git a/sql/sp.cc b/sql/sp.cc index d33114d50fd..42b0ba001a6 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -115,6 +115,7 @@ db_find_routine(THD *thd, int type, char *name, uint namelen, sp_head **sphp) uint length; char buff[65]; String str(buff, sizeof(buff), &my_charset_bin); + ulong sql_mode; ret= db_find_routine_aux(thd, type, name, namelen, TL_READ, &table, &opened); if (ret != SP_OK) @@ -153,6 +154,8 @@ db_find_routine(THD *thd, int type, char *name, uint namelen, sp_head **sphp) if (ptr[0] == 'N') suid= 0; + sql_mode= table->field[MYSQL_PROC_FIELD_SQL_MODE]->val_int(); + table->field[MYSQL_PROC_FIELD_COMMENT]->val_str(&str, &str); ptr= 0; @@ -168,6 +171,11 @@ db_find_routine(THD *thd, int type, char *name, uint namelen, sp_head **sphp) { LEX *oldlex= thd->lex; enum enum_sql_command oldcmd= thd->lex->sql_command; + ulong old_sql_mode= thd->variables.sql_mode; + ha_rows select_limit= thd->variables.select_limit; + + thd->variables.sql_mode= sql_mode; + thd->variables.select_limit= HA_POS_ERROR; lex_start(thd, (uchar*)defstr, strlen(defstr)); if (yyparse(thd) || thd->is_fatal_error || thd->lex->sphead == NULL) @@ -192,6 +200,8 @@ db_find_routine(THD *thd, int type, char *name, uint namelen, sp_head **sphp) ptr, length); } thd->lex->sql_command= oldcmd; + thd->variables.sql_mode= old_sql_mode; + thd->variables.select_limit= select_limit; } done: