mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
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.
This commit is contained in:
@ -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;
|
||||
|
@ -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
|
||||
#
|
||||
|
10
sql/sp.cc
10
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:
|
||||
|
Reference in New Issue
Block a user