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:
unknown 2003-12-04 15:17:55 +01:00
parent a17de3dde1
commit 3aaa8ab94e
31 changed files with 81 additions and 10 deletions

View file

@ -333,4 +333,5 @@
#define ER_SP_DUP_COND 1314
#define ER_SP_DUP_CURS 1315
#define ER_SP_CANT_ALTER 1316
#define ER_ERROR_MESSAGES 317
#define ER_SP_SUBSELECT_NYI 1317
#define ER_ERROR_MESSAGES 318

View file

@ -194,3 +194,4 @@ ER_SP_DUP_VAR, "42000", "",
ER_SP_DUP_COND, "42000", "",
ER_SP_DUP_CURS, "42000", "",
/*ER_SP_CANT_ALTER*/
ER_SP_SUBSELECT_NYI, "0A000", "",

View file

@ -270,4 +270,14 @@ ERROR 42S22: Unknown column 'valname' in 'order clause'
drop procedure bug1965;
select 1 into 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;

View file

@ -361,6 +361,23 @@ drop procedure bug1965|
--error 1309
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|

View file

@ -240,6 +240,17 @@ Item_splocal::this_const_item() const
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)
{
if (!my_charset_same(collation, dt.collation))

View file

@ -260,10 +260,7 @@ public:
// Abstract methods inherited from Item. Just defer the call to
// the item in the frame
inline enum Type type() const
{
return this_const_item()->type();
}
enum Type type() const;
inline double val()
{

View file

@ -329,3 +329,4 @@ character-set=latin2
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -323,3 +323,4 @@ character-set=latin1
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -331,3 +331,4 @@ character-set=latin1
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -320,3 +320,4 @@ character-set=latin1
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -325,3 +325,4 @@ character-set=latin7
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -320,3 +320,4 @@ character-set=latin1
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -332,3 +332,4 @@ character-set=latin1
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -320,3 +320,4 @@ character-set=greek
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -322,3 +322,4 @@ character-set=latin2
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -320,3 +320,4 @@ character-set=latin1
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -322,3 +322,4 @@ character-set=ujis
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -320,3 +320,4 @@ character-set=euckr
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -322,3 +322,4 @@ character-set=latin1
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -322,3 +322,4 @@ character-set=latin1
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -324,3 +324,4 @@ character-set=latin2
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -321,3 +321,4 @@ character-set=latin1
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -324,3 +324,4 @@ character-set=latin2
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -322,3 +322,4 @@ character-set=koi8r
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -315,3 +315,4 @@ character-set=cp1250
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -328,3 +328,4 @@ character-set=latin2
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -322,3 +322,4 @@ character-set=latin1
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -320,3 +320,4 @@ character-set=latin1
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -325,3 +325,4 @@ character-set=koi8u
"Duplicate condition: %s"
"Duplicate cursor: %s"
"Failed to ALTER %s %s"
"Subselect value not supported"

View file

@ -714,6 +714,7 @@ sp_instr_stmt::exec_stmt(THD *thd, LEX *lex)
{
LEX *olex; // The other lex
Item *freelist;
SELECT_LEX *sl;
int res;
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
// Also clear ref_pointer_arrays.
for (SELECT_LEX *sl= lex->all_selects_list ;
for (sl= lex->all_selects_list ;
sl ;
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 */
}
for (SELECT_LEX *sl= lex->all_selects_list ;
for (sl= lex->all_selects_list ;
sl ;
sl= sl->next_select_in_list())
{

View file

@ -1548,10 +1548,15 @@ sp_proc_stmt:
}
else
{
sp_instr_freturn *i=
new sp_instr_freturn(lex->sphead->instructions(),
$2, lex->sphead->m_returns);
sp_instr_freturn *i;
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->m_has_return= TRUE;
}
@ -5933,6 +5938,11 @@ option_value:
}
else
{ /* 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_instr_set *i= new sp_instr_set(lex->sphead->instructions(),
spv->offset, $3, spv->type);