Commit e8634f80 authored by pem@mysql.telia.com's avatar pem@mysql.telia.com

Check that a FUNCTION contains RETURN and that we actually get a return value.

parent dbf45cbc
......@@ -312,4 +312,6 @@
#define ER_QUERY_INTERRUPTED 1293
#define ER_SP_WRONG_NO_OF_ARGS 1294
#define ER_SP_COND_MISMATCH 1295
#define ER_ERROR_MESSAGES 296
#define ER_SP_NORETURN 1296
#define ER_SP_NORETURNEND 1297
#define ER_ERROR_MESSAGES 298
......@@ -121,3 +121,20 @@ set res = 1;
end if;
end;
ERROR HY000: Undefined CONDITION: bar
create function f(val int) returns int
begin
declare x int;
set x = val+3;
end;
ERROR HY000: No RETURN found in FUNCTION f
create function f(val int) returns int
begin
declare x int;
set x = val+3;
if x < 4 then
return x;
end if;
end;
select f(10);
ERROR HY000: FUNCTION f ended without RETURN
drop function f;
......@@ -171,4 +171,27 @@ begin
end if;
end|
--error 1296
create function f(val int) returns int
begin
declare x int;
set x = val+3;
end|
create function f(val int) returns int
begin
declare x int;
set x = val+3;
if x < 4 then
return x;
end if;
end|
--error 1297
select f(10)|
drop function f|
delimiter ;|
......@@ -308,3 +308,5 @@ character-set=latin2
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -302,3 +302,5 @@ character-set=latin1
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -310,3 +310,5 @@ character-set=latin1
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -299,3 +299,5 @@ character-set=latin1
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -304,3 +304,5 @@ character-set=latin7
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -299,3 +299,5 @@ character-set=latin1
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -308,3 +308,5 @@ character-set=latin1
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -299,3 +299,5 @@ character-set=greek
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -301,3 +301,5 @@ character-set=latin2
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -299,3 +299,5 @@ character-set=latin1
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -301,3 +301,5 @@ character-set=ujis
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -299,3 +299,5 @@ character-set=euckr
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -301,3 +301,5 @@ character-set=latin1
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -301,3 +301,5 @@ character-set=latin1
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -303,3 +303,5 @@ character-set=latin2
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -300,3 +300,5 @@ character-set=latin1
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -303,3 +303,5 @@ character-set=latin2
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -301,3 +301,5 @@ character-set=koi8r
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -294,3 +294,5 @@ character-set=cp1250
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -307,3 +307,5 @@ character-set=latin2
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -301,3 +301,5 @@ character-set=latin1
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -299,3 +299,5 @@ character-set=latin1
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -304,3 +304,5 @@ character-set=koi8u
"Query execution was interrupted"
"Wrong number of arguments for %s %s, expected %u, got %u"
"Undefined CONDITION: %s"
"No RETURN found in FUNCTION %s"
"FUNCTION %s ended without RETURN"
......@@ -120,7 +120,8 @@ sp_head::operator delete(void *ptr, size_t size)
}
sp_head::sp_head()
: Sql_alloc(), m_simple_case(FALSE), m_multi_results(FALSE), m_free_list(NULL)
: Sql_alloc(), m_has_return(FALSE), m_simple_case(FALSE),
m_multi_results(FALSE), m_free_list(NULL)
{
DBUG_ENTER("sp_head::sp_head");
......@@ -321,7 +322,18 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, Item **resp)
ret= execute(thd);
if (ret == 0)
*resp= nctx->get_result();
{
Item *it= nctx->get_result();
if (it)
*resp= it;
else
{
my_printf_error(ER_SP_NORETURNEND, ER(ER_SP_NORETURNEND), MYF(0),
m_name.str);
ret= -1;
}
}
thd->spcont= octx;
DBUG_RETURN(ret);
......
......@@ -47,6 +47,7 @@ public:
int m_type; // TYPE_ENUM_FUNCTION or TYPE_ENUM_PROCEDURE
enum enum_field_types m_returns; // For FUNCTIONs only
my_bool m_has_return; // For FUNCTIONs only
my_bool m_simple_case; // TRUE if parsing simple case, FALSE otherwise
my_bool m_multi_results; // TRUE if a procedure with SELECT(s)
uint m_old_cmq; // Old CLIENT_MULTI_QUERIES value
......
......@@ -3226,6 +3226,13 @@ mysql_execute_command(THD *thd)
}
}
#endif
if (lex->sphead->m_type == TYPE_ENUM_FUNCTION &&
!lex->sphead->m_has_return)
{
net_printf(thd, ER_SP_NORETURN, name);
goto error;
}
res= lex->sphead->create(thd);
switch (res)
......
......@@ -1424,6 +1424,7 @@ sp_proc_stmt:
$2, lex->sphead->m_returns);
lex->sphead->add_instr(i);
lex->sphead->m_has_return= TRUE;
}
}
| IF sp_if END IF {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment