#At file:///home/kgeorge/mysql/work/B38159-5.0-bugteam/ based on
revid:sergey.glukhov@stripped
2756 Georgi Kodinov 2009-05-27
Bug #38159: Function parsing problem generates misleading error message
Added a more detailed error message on calling an ambiguous missing function.
@ mysql-test/r/ps.result
Bug #38159: fixed existing tests
@ mysql-test/r/sp-error.result
Bug #38159: test case
@ mysql-test/t/ps.test
Bug #38159: fixed existing tests
@ mysql-test/t/sp-error.test
Bug #38159: test case
@ sql/item_func.cc
Bug #38159: generate more detailed error message
@ sql/share/errmsg.txt
Bug #38159: add a more detailed error message
@ sql/sql_derived.cc
Bug #38159: treat the detailed error message the same way as the
generic one
@ sql/sql_lex.cc
Bug #38159:
- detect if the token is ambiguous and print the appropriate error.
- backport is_lex_native_function() from 5.1
@ sql/sql_lex.h
Bug #38159: detect if the token is ambiguous and print the appropriate error.
@ sql/sql_yacc.yy
Bug #38159: generate more detailed error message
@ sql/table.cc
Bug #38159: treat the detailed error message the same way as the
generic one
modified:
mysql-test/r/ps.result
mysql-test/r/sp-error.result
mysql-test/t/ps.test
mysql-test/t/sp-error.test
sql/item_func.cc
sql/share/errmsg.txt
sql/sql_derived.cc
sql/sql_lex.cc
sql/sql_lex.h
sql/sql_yacc.yy
sql/table.cc
=== modified file 'mysql-test/r/ps.result'
--- a/mysql-test/r/ps.result 2009-02-27 16:07:58 +0000
+++ b/mysql-test/r/ps.result 2009-05-27 13:05:29 +0000
@@ -502,7 +502,7 @@ deallocate prepare stmt;
create table t1 (a varchar(20));
insert into t1 values ('foo');
prepare stmt FROM 'SELECT char_length (a) FROM t1';
-ERROR 42000: FUNCTION test.char_length does not exist
+ERROR 42000: FUNCTION test.char_length does not exist. Check the 'Function Name Parsing
and Resolution' section in the Reference Manual
drop table t1;
prepare stmt from "SELECT SQL_CALC_FOUND_ROWS 'foo' UNION SELECT 'bar' LIMIT 0";
execute stmt;
@@ -1147,7 +1147,7 @@ End of 4.1 tests.
create table t1 (a varchar(20));
insert into t1 values ('foo');
prepare stmt FROM 'SELECT char_length (a) FROM t1';
-ERROR 42000: FUNCTION test.char_length does not exist
+ERROR 42000: FUNCTION test.char_length does not exist. Check the 'Function Name Parsing
and Resolution' section in the Reference Manual
drop table t1;
create table t1 (a char(3) not null, b char(3) not null,
c char(3) not null, primary key (a, b, c));
=== modified file 'mysql-test/r/sp-error.result'
--- a/mysql-test/r/sp-error.result 2008-09-29 14:11:34 +0000
+++ b/mysql-test/r/sp-error.result 2009-05-27 13:05:29 +0000
@@ -1520,3 +1520,13 @@ CALL p1((SELECT * FROM t1))|
ERROR 21000: Subquery returns more than 1 row
DROP PROCEDURE IF EXISTS p1|
DROP TABLE t1|
+CREATE TABLE t1 (a INT, b INT);
+INSERT INTO t1 VALUES (1,1), (2,2);
+SELECT MAX (a) FROM t1 WHERE b = 999999;
+ERROR 42000: FUNCTION test.MAX does not exist. Check the 'Function Name Parsing and
Resolution' section in the Reference Manual
+SELECT AVG (a) FROM t1 WHERE b = 999999;
+AVG (a)
+NULL
+SELECT non_existent (a) FROM t1 WHERE b = 999999;
+ERROR 42000: FUNCTION test.non_existent does not exist
+DROP TABLE t1;
=== modified file 'mysql-test/t/ps.test'
--- a/mysql-test/t/ps.test 2009-02-25 10:37:30 +0000
+++ b/mysql-test/t/ps.test 2009-05-27 13:05:29 +0000
@@ -530,7 +530,7 @@ deallocate prepare stmt;
#
create table t1 (a varchar(20));
insert into t1 values ('foo');
---error 1305
+--error ER_FUNC_INEXISTENT_NAME_COLLISION
prepare stmt FROM 'SELECT char_length (a) FROM t1';
drop table t1;
@@ -1239,7 +1239,7 @@ drop table t1;
#
create table t1 (a varchar(20));
insert into t1 values ('foo');
---error 1305
+--error ER_FUNC_INEXISTENT_NAME_COLLISION
prepare stmt FROM 'SELECT char_length (a) FROM t1';
drop table t1;
=== modified file 'mysql-test/t/sp-error.test'
--- a/mysql-test/t/sp-error.test 2008-09-29 14:11:34 +0000
+++ b/mysql-test/t/sp-error.test 2009-05-27 13:05:29 +0000
@@ -2190,3 +2190,16 @@ delimiter ;|
#drop procedure if exists bugNNNN|
#--enable_warnings
#create procedure bugNNNN...
+
+#
+# Bug #38159: Function parsing problem generates misleading error message
+#
+
+CREATE TABLE t1 (a INT, b INT);
+INSERT INTO t1 VALUES (1,1), (2,2);
+--error ER_FUNC_INEXISTENT_NAME_COLLISION
+SELECT MAX (a) FROM t1 WHERE b = 999999;
+SELECT AVG (a) FROM t1 WHERE b = 999999;
+--error ER_SP_DOES_NOT_EXIST
+SELECT non_existent (a) FROM t1 WHERE b = 999999;
+DROP TABLE t1;
=== modified file 'sql/item_func.cc'
--- a/sql/item_func.cc 2009-05-15 09:29:41 +0000
+++ b/sql/item_func.cc 2009-05-27 13:05:29 +0000
@@ -5401,6 +5401,14 @@ Item_func_sp::func_name() const
}
+int my_missing_function_error(const LEX_STRING &token, const char *func_name)
+{
+ if (token.length && is_lex_native_function (&token))
+ return my_error(ER_FUNC_INEXISTENT_NAME_COLLISION, MYF(0), func_name);
+ else
+ return my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", func_name);
+}
+
/**
@brief Initialize the result field by creating a temporary dummy table
@@ -5434,7 +5442,7 @@ Item_func_sp::init_result_field(THD *thd
if (!(m_sp= sp_find_routine(thd, TYPE_ENUM_FUNCTION, m_name,
&thd->sp_func_cache, TRUE)))
{
- my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname.str);
+ my_missing_function_error (m_name->m_name, m_name->m_qname.str);
context->process_error(thd);
DBUG_RETURN(TRUE);
}
=== modified file 'sql/share/errmsg.txt'
--- a/sql/share/errmsg.txt 2008-10-23 20:56:03 +0000
+++ b/sql/share/errmsg.txt 2009-05-27 13:05:29 +0000
@@ -5649,3 +5649,6 @@ ER_XA_RBTIMEOUT XA106
eng "XA_RBTIMEOUT: Transaction branch was rolled back: took too long"
ER_XA_RBDEADLOCK XA102
eng "XA_RBDEADLOCK: Transaction branch was rolled back: deadlock was detected"
+
+ER_FUNC_INEXISTENT_NAME_COLLISION 42000
+ eng "FUNCTION %s does not exist. Check the 'Function Name Parsing and Resolution'
section in the Reference Manual"
=== modified file 'sql/sql_derived.cc'
--- a/sql/sql_derived.cc 2009-02-10 22:47:54 +0000
+++ b/sql/sql_derived.cc 2009-05-27 13:05:29 +0000
@@ -148,6 +148,7 @@ exit:
if (orig_table_list->view)
{
if (thd->net.last_errno == ER_BAD_FIELD_ERROR ||
+ thd->net.last_errno == ER_FUNC_INEXISTENT_NAME_COLLISION ||
thd->net.last_errno == ER_SP_DOES_NOT_EXIST)
{
thd->clear_error();
=== modified file 'sql/sql_lex.cc'
--- a/sql/sql_lex.cc 2009-05-06 13:06:32 +0000
+++ b/sql/sql_lex.cc 2009-05-27 13:05:29 +0000
@@ -265,6 +265,22 @@ bool is_keyword(const char *name, uint l
return get_hash_symbol(name,len,0)!=0;
}
+/**
+ Check if name is a sql function
+
+ @param name checked name
+
+ @return is this a lex native function or not
+ @retval 0 name is a function
+ @retval 1 name isn't a function
+*/
+
+bool is_lex_native_function(const LEX_STRING *name)
+{
+ DBUG_ASSERT(name != NULL);
+ return (get_hash_symbol(name->str, (uint) name->length, 1) != 0);
+}
+
/* make a copy of token before ptr and set yytoklen */
static LEX_STRING get_token(Lex_input_stream *lip, uint skip, uint length)
=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h 2009-05-06 13:06:32 +0000
+++ b/sql/sql_lex.h 2009-05-27 13:05:29 +0000
@@ -1390,3 +1390,5 @@ extern void lex_end(LEX *lex);
extern int MYSQLlex(void *arg, void *yythd);
extern char *skip_rear_comments(CHARSET_INFO *cs, char *begin, char *end);
+extern bool is_lex_native_function(const LEX_STRING *name);
+int my_missing_function_error(const LEX_STRING &token, const char *name);
=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy 2009-05-06 13:06:32 +0000
+++ b/sql/sql_yacc.yy 2009-05-27 13:05:29 +0000
@@ -5968,8 +5968,7 @@ simple_expr:
Reusing ER_SP_DOES_NOT_EXIST have a message consistent with
the case when a default database exist, see below.
*/
- my_error(ER_SP_DOES_NOT_EXIST, MYF(0),
- "FUNCTION", $1.str);
+ my_missing_function_error ($1, $1.str);
MYSQL_YYABORT;
}
=== modified file 'sql/table.cc'
--- a/sql/table.cc 2009-05-27 10:34:21 +0000
+++ b/sql/table.cc 2009-05-27 13:05:29 +0000
@@ -2138,6 +2138,7 @@ void TABLE_LIST::hide_view_error(THD *th
/* Hide "Unknown column" or "Unknown function" error */
if (thd->net.last_errno == ER_BAD_FIELD_ERROR ||
thd->net.last_errno == ER_SP_DOES_NOT_EXIST ||
+ thd->net.last_errno == ER_FUNC_INEXISTENT_NAME_COLLISION ||
thd->net.last_errno == ER_PROCACCESS_DENIED_ERROR ||
thd->net.last_errno == ER_COLUMNACCESS_DENIED_ERROR ||
thd->net.last_errno == ER_TABLEACCESS_DENIED_ERROR ||
Attachment: [text/bzr-bundle] bzr/joro@sun.com-20090527130529-pufkfszawn0dn0k3.bundle
| Thread |
|---|
| • bzr commit into mysql-5.0-bugteam branch (joro:2756) Bug#38159 | Georgi Kodinov | 27 May 2009 |