mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Fixed BUG#336: Subselects with tables does not work as values for local SP variables
and BUG#1654: Stored Procedure Crash if contains subquery and set function Disallowed subselects in RETURN (for FUNCTIONs) and SET of local variables. The latter should work, but turned out to be difficult to fix, so we just disallow it for the time being. include/mysqld_error.h: New error message for unsupported subselect as SP set values (for the time being). include/sql_state.h: New error message for unsupported subselect as SP set values (for the time being). mysql-test/r/sp-error.result: Test cases for BUG#336 and BUG#1654. (Unsupported use of subselect) mysql-test/t/sp-error.test: Test cases for BUG#336 and BUG#1654. (Unsupported use of subselect) sql/item.cc: Made Item_splocal::type() work at compile time, for error checking. sql/item.h: Made Item_splocal::type() work at compile time, for error checking. sql/share/czech/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/danish/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/dutch/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/english/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/estonian/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/french/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/german/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/greek/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/hungarian/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/italian/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/japanese/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/korean/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/norwegian-ny/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/norwegian/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/polish/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/portuguese/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/romanian/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/russian/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/serbian/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/slovak/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/spanish/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/swedish/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/share/ukrainian/errmsg.txt: New error message for unsupported subselect as SP set values (for the time being). sql/sp_head.cc: Fixed (bogus) compile error on HP-UX alpha. sql/sql_yacc.yy: Disallowed subselects in RETURN (for FUNCTIONs) and SET of local variables. The latter should work, but turned out to be difficult to fix, so we just disallow it for the time being.
This commit is contained in:
@ -333,4 +333,5 @@
|
|||||||
#define ER_SP_DUP_COND 1314
|
#define ER_SP_DUP_COND 1314
|
||||||
#define ER_SP_DUP_CURS 1315
|
#define ER_SP_DUP_CURS 1315
|
||||||
#define ER_SP_CANT_ALTER 1316
|
#define ER_SP_CANT_ALTER 1316
|
||||||
#define ER_ERROR_MESSAGES 317
|
#define ER_SP_SUBSELECT_NYI 1317
|
||||||
|
#define ER_ERROR_MESSAGES 318
|
||||||
|
@ -194,3 +194,4 @@ ER_SP_DUP_VAR, "42000", "",
|
|||||||
ER_SP_DUP_COND, "42000", "",
|
ER_SP_DUP_COND, "42000", "",
|
||||||
ER_SP_DUP_CURS, "42000", "",
|
ER_SP_DUP_CURS, "42000", "",
|
||||||
/*ER_SP_CANT_ALTER*/
|
/*ER_SP_CANT_ALTER*/
|
||||||
|
ER_SP_SUBSELECT_NYI, "0A000", "",
|
||||||
|
@ -270,4 +270,14 @@ ERROR 42S22: Unknown column 'valname' in 'order clause'
|
|||||||
drop procedure bug1965;
|
drop procedure bug1965;
|
||||||
select 1 into a;
|
select 1 into a;
|
||||||
ERROR 42000: Undeclared variable: a
|
ERROR 42000: Undeclared variable: a
|
||||||
|
create procedure bug336(id char(16))
|
||||||
|
begin
|
||||||
|
declare x int;
|
||||||
|
set x = (select sum(t.data) from test.t2 t);
|
||||||
|
end;
|
||||||
|
ERROR 0A000: Subselect value not supported
|
||||||
|
create function bug1654()
|
||||||
|
returns int
|
||||||
|
return (select sum(t.data) from test.t2 t);
|
||||||
|
ERROR 0A000: Statements like SELECT, INSERT, UPDATE (and others) are not allowed in a FUNCTION
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
@ -361,6 +361,23 @@ drop procedure bug1965|
|
|||||||
--error 1309
|
--error 1309
|
||||||
select 1 into a|
|
select 1 into a|
|
||||||
|
|
||||||
|
#
|
||||||
|
# BUG#336
|
||||||
|
#
|
||||||
|
--error 1317
|
||||||
|
create procedure bug336(id char(16))
|
||||||
|
begin
|
||||||
|
declare x int;
|
||||||
|
set x = (select sum(t.data) from test.t2 t);
|
||||||
|
end|
|
||||||
|
|
||||||
|
#
|
||||||
|
# BUG#1654
|
||||||
|
#
|
||||||
|
--error 1296
|
||||||
|
create function bug1654()
|
||||||
|
returns int
|
||||||
|
return (select sum(t.data) from test.t2 t)|
|
||||||
|
|
||||||
drop table t1|
|
drop table t1|
|
||||||
|
|
||||||
|
11
sql/item.cc
11
sql/item.cc
@ -240,6 +240,17 @@ Item_splocal::this_const_item() const
|
|||||||
return thd->spcont->get_item(m_offset);
|
return thd->spcont->get_item(m_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Item::Type
|
||||||
|
Item_splocal::type() const
|
||||||
|
{
|
||||||
|
THD *thd= current_thd;
|
||||||
|
|
||||||
|
if (thd->spcont)
|
||||||
|
return thd->spcont->get_item(m_offset)->type();
|
||||||
|
return NULL_ITEM; // Anything but SUBSELECT_ITEM
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool DTCollation::aggregate(DTCollation &dt)
|
bool DTCollation::aggregate(DTCollation &dt)
|
||||||
{
|
{
|
||||||
if (!my_charset_same(collation, dt.collation))
|
if (!my_charset_same(collation, dt.collation))
|
||||||
|
@ -260,10 +260,7 @@ public:
|
|||||||
|
|
||||||
// Abstract methods inherited from Item. Just defer the call to
|
// Abstract methods inherited from Item. Just defer the call to
|
||||||
// the item in the frame
|
// the item in the frame
|
||||||
inline enum Type type() const
|
enum Type type() const;
|
||||||
{
|
|
||||||
return this_const_item()->type();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline double val()
|
inline double val()
|
||||||
{
|
{
|
||||||
|
@ -329,3 +329,4 @@ character-set=latin2
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -323,3 +323,4 @@ character-set=latin1
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -331,3 +331,4 @@ character-set=latin1
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -320,3 +320,4 @@ character-set=latin1
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -325,3 +325,4 @@ character-set=latin7
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -320,3 +320,4 @@ character-set=latin1
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -332,3 +332,4 @@ character-set=latin1
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -320,3 +320,4 @@ character-set=greek
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -322,3 +322,4 @@ character-set=latin2
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -320,3 +320,4 @@ character-set=latin1
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -322,3 +322,4 @@ character-set=ujis
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -320,3 +320,4 @@ character-set=euckr
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -322,3 +322,4 @@ character-set=latin1
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -322,3 +322,4 @@ character-set=latin1
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -324,3 +324,4 @@ character-set=latin2
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -321,3 +321,4 @@ character-set=latin1
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -324,3 +324,4 @@ character-set=latin2
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -322,3 +322,4 @@ character-set=koi8r
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -315,3 +315,4 @@ character-set=cp1250
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -328,3 +328,4 @@ character-set=latin2
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -322,3 +322,4 @@ character-set=latin1
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -320,3 +320,4 @@ character-set=latin1
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -325,3 +325,4 @@ character-set=koi8u
|
|||||||
"Duplicate condition: %s"
|
"Duplicate condition: %s"
|
||||||
"Duplicate cursor: %s"
|
"Duplicate cursor: %s"
|
||||||
"Failed to ALTER %s %s"
|
"Failed to ALTER %s %s"
|
||||||
|
"Subselect value not supported"
|
||||||
|
@ -714,6 +714,7 @@ sp_instr_stmt::exec_stmt(THD *thd, LEX *lex)
|
|||||||
{
|
{
|
||||||
LEX *olex; // The other lex
|
LEX *olex; // The other lex
|
||||||
Item *freelist;
|
Item *freelist;
|
||||||
|
SELECT_LEX *sl;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
olex= thd->lex; // Save the other lex
|
olex= thd->lex; // Save the other lex
|
||||||
@ -726,7 +727,7 @@ sp_instr_stmt::exec_stmt(THD *thd, LEX *lex)
|
|||||||
|
|
||||||
// Copy WHERE clause pointers to avoid damaging by optimisation
|
// Copy WHERE clause pointers to avoid damaging by optimisation
|
||||||
// Also clear ref_pointer_arrays.
|
// Also clear ref_pointer_arrays.
|
||||||
for (SELECT_LEX *sl= lex->all_selects_list ;
|
for (sl= lex->all_selects_list ;
|
||||||
sl ;
|
sl ;
|
||||||
sl= sl->next_select_in_list())
|
sl= sl->next_select_in_list())
|
||||||
{
|
{
|
||||||
@ -772,7 +773,7 @@ sp_instr_stmt::exec_stmt(THD *thd, LEX *lex)
|
|||||||
close_thread_tables(thd); /* Free tables */
|
close_thread_tables(thd); /* Free tables */
|
||||||
}
|
}
|
||||||
|
|
||||||
for (SELECT_LEX *sl= lex->all_selects_list ;
|
for (sl= lex->all_selects_list ;
|
||||||
sl ;
|
sl ;
|
||||||
sl= sl->next_select_in_list())
|
sl= sl->next_select_in_list())
|
||||||
{
|
{
|
||||||
|
@ -1548,10 +1548,15 @@ sp_proc_stmt:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sp_instr_freturn *i=
|
sp_instr_freturn *i;
|
||||||
new sp_instr_freturn(lex->sphead->instructions(),
|
|
||||||
$2, lex->sphead->m_returns);
|
|
||||||
|
|
||||||
|
if ($2->type() == Item::SUBSELECT_ITEM)
|
||||||
|
{ /* QQ For now, just disallow subselects as values */
|
||||||
|
send_error(lex->thd, ER_SP_BADSTATEMENT);
|
||||||
|
YYABORT;
|
||||||
|
}
|
||||||
|
i= new sp_instr_freturn(lex->sphead->instructions(),
|
||||||
|
$2, lex->sphead->m_returns);
|
||||||
lex->sphead->add_instr(i);
|
lex->sphead->add_instr(i);
|
||||||
lex->sphead->m_has_return= TRUE;
|
lex->sphead->m_has_return= TRUE;
|
||||||
}
|
}
|
||||||
@ -5933,6 +5938,11 @@ option_value:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ /* An SP local variable */
|
{ /* An SP local variable */
|
||||||
|
if ($3 && $3->type() == Item::SUBSELECT_ITEM)
|
||||||
|
{ /* QQ For now, just disallow subselects as values */
|
||||||
|
send_error(lex->thd, ER_SP_SUBSELECT_NYI);
|
||||||
|
YYABORT;
|
||||||
|
}
|
||||||
sp_pvar_t *spv= lex->spcont->find_pvar(&$1.base_name);
|
sp_pvar_t *spv= lex->spcont->find_pvar(&$1.base_name);
|
||||||
sp_instr_set *i= new sp_instr_set(lex->sphead->instructions(),
|
sp_instr_set *i= new sp_instr_set(lex->sphead->instructions(),
|
||||||
spv->offset, $3, spv->type);
|
spv->offset, $3, spv->type);
|
||||||
|
Reference in New Issue
Block a user