diff options
-rw-r--r-- | mysql-test/r/sp-error.result | 10 | ||||
-rw-r--r-- | mysql-test/t/sp-error.test | 13 | ||||
-rw-r--r-- | sql/item_func.cc | 10 | ||||
-rw-r--r-- | sql/share/errmsg.txt | 3 | ||||
-rw-r--r-- | sql/sql_derived.cc | 1 | ||||
-rw-r--r-- | sql/sql_lex.cc | 10 | ||||
-rw-r--r-- | sql/sql_lex.h | 2 | ||||
-rw-r--r-- | sql/table.cc | 1 |
8 files changed, 49 insertions, 1 deletions
diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result index 35d61ce757d..17ab2b79043 100644 --- a/mysql-test/r/sp-error.result +++ b/mysql-test/r/sp-error.result @@ -1660,3 +1660,13 @@ declare continue handler for sqlstate '00000' set @x=0; end$$ ERROR 42000: Bad SQLSTATE: '00000' LOAD DATA INFILE '../../tmp/proc.txt' INTO TABLE mysql.proc; +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; diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test index 8d7c6d75a34..66b960c938f 100644 --- a/mysql-test/t/sp-error.test +++ b/mysql-test/t/sp-error.test @@ -2435,3 +2435,16 @@ delimiter ;$$ # LOAD DATA INFILE '../../tmp/proc.txt' INTO TABLE mysql.proc; remove_file $MYSQLTEST_VARDIR/tmp/proc.txt; + +# +# 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; diff --git a/sql/item_func.cc b/sql/item_func.cc index 0c8f236a27c..85e5de7b980 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -5802,6 +5802,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 @@ -5834,7 +5842,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); } diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index 2dfc5310643..7c92c827c87 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -6177,3 +6177,6 @@ ER_TOO_LONG_TABLE_COMMENT ER_TOO_LONG_FIELD_COMMENT eng "Comment for field '%-.64s' is too long (max = %lu)" por "Comentário para o campo '%-.64s' é longo demais (max = %lu)" + +ER_FUNC_INEXISTENT_NAME_COLLISION 42000 + eng "FUNCTION %s does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual" diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 41be98621a6..37adf5c403a 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -179,6 +179,7 @@ exit: { if (thd->is_error() && (thd->main_da.sql_errno() == ER_BAD_FIELD_ERROR || + thd->main_da.sql_errno() == ER_FUNC_INEXISTENT_NAME_COLLISION || thd->main_da.sql_errno() == ER_SP_DOES_NOT_EXIST)) { thd->clear_error(); diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index b96ac91679b..03da3c2338a 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -433,6 +433,16 @@ bool is_keyword(const char *name, uint len) return get_hash_symbol(name,len,0)!=0; } +/** + Check if name is a sql function + + @param name checked name + + @return is this a 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); diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 62106a2500b..22b7d2e359c 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1976,4 +1976,6 @@ extern bool is_lex_native_function(const LEX_STRING *name); @} (End of group Semantic_Analysis) */ +int my_missing_function_error(const LEX_STRING &token, const char *name); + #endif /* MYSQL_SERVER */ diff --git a/sql/table.cc b/sql/table.cc index 066bbc953fa..7e8d5ac98b4 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -3341,6 +3341,7 @@ void TABLE_LIST::hide_view_error(THD *thd) if (thd->main_da.sql_errno() == ER_BAD_FIELD_ERROR || thd->main_da.sql_errno() == ER_SP_DOES_NOT_EXIST || + thd->main_da.sql_errno() == ER_FUNC_INEXISTENT_NAME_COLLISION || thd->main_da.sql_errno() == ER_PROCACCESS_DENIED_ERROR || thd->main_da.sql_errno() == ER_COLUMNACCESS_DENIED_ERROR || thd->main_da.sql_errno() == ER_TABLEACCESS_DENIED_ERROR || |