From 25e32d83d6d5fdce25ba4ef68885ffbf9f7a934f Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Jan 2006 14:42:46 +0100 Subject: [PATCH 01/10] fix for bug#15828 problem was not checking 2nd parameter of str_to_date against NULL mysql-test/r/date_formats.result: bk commit --- mysql-test/r/date_formats.result | 6 ++++++ mysql-test/t/date_formats.test | 7 +++++++ sql/item_timefunc.cc | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/date_formats.result b/mysql-test/r/date_formats.result index 34a2dedd976..b2dc1f7a67b 100644 --- a/mysql-test/r/date_formats.result +++ b/mysql-test/r/date_formats.result @@ -464,3 +464,9 @@ d1 d2 02 February 01 January drop table t1; +select str_to_date( 1, NULL ); +str_to_date( 1, NULL ) +NULL +select str_to_date( NULL, 1 ); +str_to_date( NULL, 1 ) +NULL diff --git a/mysql-test/t/date_formats.test b/mysql-test/t/date_formats.test index 6d501865d2c..dd31f1509c0 100644 --- a/mysql-test/t/date_formats.test +++ b/mysql-test/t/date_formats.test @@ -268,4 +268,11 @@ insert into t1 (f1) values ("2005-01-01"); insert into t1 (f1) values ("2005-02-01"); select date_format(f1, "%m") as d1, date_format(f1, "%M") as d2 from t1 order by date_format(f1, "%M"); drop table t1; + +# +# Bug #15828 +# +select str_to_date( 1, NULL ); +select str_to_date( NULL, 1 ); + # End of 4.1 tests diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index eb58b180ed7..d060612c9f6 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2750,7 +2750,7 @@ void Item_func_str_to_date::fix_length_and_dec() cached_field_type= MYSQL_TYPE_STRING; max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; cached_timestamp_type= MYSQL_TIMESTAMP_NONE; - if ((const_item= args[1]->const_item())) + if ((const_item= args[1]->const_item()) && !args[1]->null_value) { format= args[1]->val_str(&format_str); cached_format_type= get_date_time_result_type(format->ptr(), From f36a0feed7232cbb4ca1cbc9e669edb39e714a78 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 14 Jan 2006 09:53:12 +0100 Subject: [PATCH 02/10] item_timefunc.cc: fix for bug#15828 after review sql/item_timefunc.cc: fix for bug#15828 after review --- sql/item_timefunc.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index d060612c9f6..be8c5d2ad15 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2750,7 +2750,8 @@ void Item_func_str_to_date::fix_length_and_dec() cached_field_type= MYSQL_TYPE_STRING; max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; cached_timestamp_type= MYSQL_TIMESTAMP_NONE; - if ((const_item= args[1]->const_item()) && !args[1]->null_value) + if (!args[1]->null_value && (const_item= args[1]->const_item())) + //if ((const_item= args[1]->const_item()) && !args[1]->null_value) { format= args[1]->val_str(&format_str); cached_format_type= get_date_time_result_type(format->ptr(), From 37b104b8ec45d842831c4854a3ddb3443c7bc642 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 14 Jan 2006 16:06:51 +0100 Subject: [PATCH 03/10] item_timefunc.cc: fix for bug #15828 after review sql/item_timefunc.cc: fix for bug #15828 after review --- sql/item_timefunc.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index be8c5d2ad15..b5a9064c960 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2751,7 +2751,6 @@ void Item_func_str_to_date::fix_length_and_dec() max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; cached_timestamp_type= MYSQL_TIMESTAMP_NONE; if (!args[1]->null_value && (const_item= args[1]->const_item())) - //if ((const_item= args[1]->const_item()) && !args[1]->null_value) { format= args[1]->val_str(&format_str); cached_format_type= get_date_time_result_type(format->ptr(), From e5f077f79a7872147a8858d353060ee08ffa5dcd Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 16 Jan 2006 15:46:37 +0100 Subject: [PATCH 04/10] date_formats.test: fix for bug #15828 after review doing val_str now before testing of null value secures the function for null values returned by dynamic functions - the fix before was incomplete andy covered constant null values mysql-test/t/date_formats.test: fix for bug #15828 after review doing val_str now before testing of null value secures the function for null values returned by dynamic functions - the fix before was incomplete andy covered constant null values --- mysql-test/r/date_formats.result | 3 +++ mysql-test/t/date_formats.test | 2 +- sql/item_timefunc.cc | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/date_formats.result b/mysql-test/r/date_formats.result index b2dc1f7a67b..014eeed27e7 100644 --- a/mysql-test/r/date_formats.result +++ b/mysql-test/r/date_formats.result @@ -470,3 +470,6 @@ NULL select str_to_date( NULL, 1 ); str_to_date( NULL, 1 ) NULL +select str_to_date( 1, IF(1=1,NULL,NULL) ); +str_to_date( 1, IF(1=1,NULL,NULL) ) +NULL diff --git a/mysql-test/t/date_formats.test b/mysql-test/t/date_formats.test index dd31f1509c0..78b4482a94a 100644 --- a/mysql-test/t/date_formats.test +++ b/mysql-test/t/date_formats.test @@ -274,5 +274,5 @@ drop table t1; # select str_to_date( 1, NULL ); select str_to_date( NULL, 1 ); - +select str_to_date( 1, IF(1=1,NULL,NULL) ); # End of 4.1 tests diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index b5a9064c960..d6b57464d59 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2750,9 +2750,9 @@ void Item_func_str_to_date::fix_length_and_dec() cached_field_type= MYSQL_TYPE_STRING; max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; cached_timestamp_type= MYSQL_TIMESTAMP_NONE; + format= args[1]->val_str(&format_str); if (!args[1]->null_value && (const_item= args[1]->const_item())) { - format= args[1]->val_str(&format_str); cached_format_type= get_date_time_result_type(format->ptr(), format->length()); switch (cached_format_type) { From cc037976c3205a010d522c6318ba86cb67017c4e Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 25 Jan 2006 17:19:54 +0100 Subject: [PATCH 05/10] Fixed BUGS#15011: error handler for mysql errno in nested block not activated For nested sql errno handlers (unlike sqlexception and other), we didn't stop searching when the innermost handler was found - now make sure we do. mysql-test/r/sp.result: Updated result for BUG#15011. mysql-test/t/sp.test: New testcase for BUG#15011. sql/sp_rcontext.cc: Make sure we stop at the innermost sql_errno handler. --- mysql-test/r/sp.result | 19 +++++++++++++++++++ mysql-test/t/sp.test | 31 +++++++++++++++++++++++++++++++ sql/sp_rcontext.cc | 3 ++- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 904cd7d8642..90020573df3 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -4497,4 +4497,23 @@ drop procedure if exists bug15231_1| drop procedure if exists bug15231_2| drop procedure if exists bug15231_3| drop procedure if exists bug15231_4| +drop procedure if exists bug15011| +create table t3 (c1 int primary key)| +insert into t3 values (1)| +create procedure bug15011() +deterministic +begin +declare continue handler for 1062 +select 'Outer' as 'Handler'; +begin +declare continue handler for 1062 +select 'Inner' as 'Handler'; +insert into t3 values (1); +end; +end| +call bug15011()| +Handler +Inner +drop procedure bug15011| +drop table t3| drop table t1,t2; diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 8235686a74a..32299ad7e0b 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -5283,6 +5283,37 @@ drop procedure if exists bug15231_3| drop procedure if exists bug15231_4| +# +# BUG#15011: error handler in nested block not activated +# +--disable_warnings +drop procedure if exists bug15011| +--enable_warnings + +create table t3 (c1 int primary key)| + +insert into t3 values (1)| + +create procedure bug15011() + deterministic +begin + declare continue handler for 1062 + select 'Outer' as 'Handler'; + + begin + declare continue handler for 1062 + select 'Inner' as 'Handler'; + + insert into t3 values (1); + end; +end| + +call bug15011()| + +drop procedure bug15011| +drop table t3| + + # # BUG#NNNN: New bug synopsis # diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc index 215de01e657..4818ffbbe31 100644 --- a/sql/sp_rcontext.cc +++ b/sql/sp_rcontext.cc @@ -188,7 +188,8 @@ sp_rcontext::find_handler(uint sql_errno, switch (cond->type) { case sp_cond_type_t::number: - if (sql_errno == cond->mysqlerr) + if (sql_errno == cond->mysqlerr && + (found < 0 || m_handler[found].cond->type > sp_cond_type_t::number)) found= i; // Always the most specific break; case sp_cond_type_t::state: From c3612b4134d6841279c64af6196c171ebbe267fb Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 31 Jan 2006 16:27:57 +0100 Subject: [PATCH 06/10] Added test case for BUG#14270: Stored procedures: crash if load index which was fixed by earlier changesets; LOAD INDEX is not allowed in functions. Also testing CACHE INDEX, while OPTIMIZE and CHECK were covered by existing tests already. mysql-test/r/sp-error.result: Updated result for new test case (BUG#14270). mysql-test/t/sp-error.test: New test case for BUG#14270. --- mysql-test/r/sp-error.result | 16 ++++++++++++++++ mysql-test/t/sp-error.test | 29 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result index 8483f6dc664..fb544ccd8de 100644 --- a/mysql-test/r/sp-error.result +++ b/mysql-test/r/sp-error.result @@ -1147,3 +1147,19 @@ show procedure status; Db Name Type Definer Modified Created Security_type Comment test bug15658 PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER drop procedure ` bug15658`; +drop function if exists bug14270; +drop table if exists t1; +create table t1 (s1 int primary key); +create function bug14270() returns int +begin +load index into cache t1; +return 1; +end| +ERROR 0A000: Not allowed to return a result set from a function +create function bug14270() returns int +begin +cache index t1 key (`primary`) in keycache1; +return 1; +end| +ERROR 0A000: Not allowed to return a result set from a function +drop table t1; diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test index 25944144d21..22cc325f55e 100644 --- a/mysql-test/t/sp-error.test +++ b/mysql-test/t/sp-error.test @@ -1643,6 +1643,35 @@ show procedure status; drop procedure ` bug15658`; +# +# BUG#14270: Stored procedures: crash if load index +# +--disable_warnings +drop function if exists bug14270; +drop table if exists t1; +--enable_warnings + +create table t1 (s1 int primary key); + +delimiter |; +--error ER_SP_NO_RETSET +create function bug14270() returns int +begin + load index into cache t1; + return 1; +end| + +--error ER_SP_NO_RETSET +create function bug14270() returns int +begin + cache index t1 key (`primary`) in keycache1; + return 1; +end| +delimiter ;| + +drop table t1; + + # # BUG#NNNN: New bug synopsis # From fd61a0c08dc9398c8ca902b437b068c7a8b97934 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 31 Jan 2006 17:00:50 +0100 Subject: [PATCH 07/10] Added test case for BUG#15091: Sp Returns Unknown error in order clause....and there is no order by clause which was fixed by earlier changesets. The error message is now the more generic "Unknown table ... in field list". mysql-test/r/sp-error.result: Updated results for new test case (BUG#15091). mysql-test/t/sp-error.test: New test case for BUG#15091. --- mysql-test/r/sp-error.result | 13 +++++++++++++ mysql-test/t/sp-error.test | 31 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result index fb544ccd8de..2766dca5845 100644 --- a/mysql-test/r/sp-error.result +++ b/mysql-test/r/sp-error.result @@ -1163,3 +1163,16 @@ return 1; end| ERROR 0A000: Not allowed to return a result set from a function drop table t1; +drop procedure if exists bug15091; +create procedure bug15091() +begin +declare selectstr varchar(6000) default ' '; +declare conditionstr varchar(5000) default ''; +set selectstr = concat(selectstr, +' and ', +c.operatorid, +'in (',conditionstr, ')'); +end| +call bug15091(); +ERROR 42S02: Unknown table 'c' in field list +drop procedure bug15091; diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test index 22cc325f55e..e1839b4b98f 100644 --- a/mysql-test/t/sp-error.test +++ b/mysql-test/t/sp-error.test @@ -1672,6 +1672,37 @@ delimiter ;| drop table t1; +# +# BUG#15091: Sp Returns Unknown error in order clause....and +# there is no order by clause +# +--disable_warnings +drop procedure if exists bug15091; +--enable_warnings + +delimiter |; +create procedure bug15091() +begin + declare selectstr varchar(6000) default ' '; + declare conditionstr varchar(5000) default ''; + + set selectstr = concat(selectstr, + ' and ', + c.operatorid, + 'in (',conditionstr, ')'); +end| +delimiter ;| + +# The error message used to be: +# ERROR 1109 (42S02): Unknown table 'c' in order clause +# but is now rephrased to something less misleading: +# ERROR 1109 (42S02): Unknown table 'c' in field list +--error ER_UNKNOWN_TABLE +call bug15091(); + +drop procedure bug15091; + + # # BUG#NNNN: New bug synopsis # From 8a7bbefc2fbd99d21a9fda19e8667bc23eec7d72 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 Feb 2006 14:46:30 +0100 Subject: [PATCH 08/10] Added new test case for BUG#14533: 'desc tbl' in stored procedure causes error 1142 which is no longer repeatable. (Unclear when this was fixed.) mysql-test/r/sp-security.result: Updated results for new test case (BUG#14533) mysql-test/t/sp-security.test: New test case for BUG#14533. --- mysql-test/r/sp-security.result | 23 ++++++++++++++++++++ mysql-test/t/sp-security.test | 38 +++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/mysql-test/r/sp-security.result b/mysql-test/r/sp-security.result index b223c0cd487..ff729e87f97 100644 --- a/mysql-test/r/sp-security.result +++ b/mysql-test/r/sp-security.result @@ -291,3 +291,26 @@ drop user user1_bug14834@localhost; drop user user2_bug14834@localhost; drop user user3_bug14834@localhost; drop database db_bug14834; +create database db_bug14533; +use db_bug14533; +create table t1 (id int); +create user user_bug14533@localhost identified by ''; +create procedure bug14533_1() +sql security definer +desc db_bug14533.t1; +create procedure bug14533_2() +sql security definer +select * from db_bug14533.t1; +grant execute on procedure db_bug14533.bug14533_1 to user_bug14533@localhost; +grant execute on procedure db_bug14533.bug14533_2 to user_bug14533@localhost; +call db_bug14533.bug14533_1(); +Field Type Null Key Default Extra +id int(11) YES NULL +call db_bug14533.bug14533_2(); +id +desc db_bug14533.t1; +ERROR 42000: SELECT command denied to user 'user_bug14533'@'localhost' for table 't1' +select * from db_bug14533.t1; +ERROR 42000: SELECT command denied to user 'user_bug14533'@'localhost' for table 't1' +drop user user_bug14533@localhost; +drop database db_bug14533; diff --git a/mysql-test/t/sp-security.test b/mysql-test/t/sp-security.test index 223bc09b9fc..90160780618 100644 --- a/mysql-test/t/sp-security.test +++ b/mysql-test/t/sp-security.test @@ -487,4 +487,42 @@ drop user user2_bug14834@localhost; drop user user3_bug14834@localhost; drop database db_bug14834; + +# +# BUG#14533: 'desc tbl' in stored procedure causes error 1142 +# +create database db_bug14533; +use db_bug14533; +create table t1 (id int); +create user user_bug14533@localhost identified by ''; + +create procedure bug14533_1() + sql security definer + desc db_bug14533.t1; + +create procedure bug14533_2() + sql security definer + select * from db_bug14533.t1; + +grant execute on procedure db_bug14533.bug14533_1 to user_bug14533@localhost; +grant execute on procedure db_bug14533.bug14533_2 to user_bug14533@localhost; + +connect (user_bug14533,localhost,user_bug14533,,test); + +# These should work +call db_bug14533.bug14533_1(); +call db_bug14533.bug14533_2(); + +# For reference, these should not work +--error ER_TABLEACCESS_DENIED_ERROR +desc db_bug14533.t1; +--error ER_TABLEACCESS_DENIED_ERROR +select * from db_bug14533.t1; + +# Cleanup +connection default; +disconnect user_bug14533; +drop user user_bug14533@localhost; +drop database db_bug14533; + # End of 5.0 bugs. From 6643f3202865658ae88b52ea24ac4c331d588bc1 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 Feb 2006 16:00:11 +0100 Subject: [PATCH 09/10] Post-review fix for BUG#15011. Added comments. sql/sp_rcontext.cc: Added comments to sp_rcontext::find_handler() --- sql/sp_rcontext.cc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc index 4818ffbbe31..af4e41c29be 100644 --- a/sql/sp_rcontext.cc +++ b/sql/sp_rcontext.cc @@ -164,6 +164,33 @@ sp_rcontext::set_return_value(THD *thd, Item *return_value_item) #define IS_NOT_FOUND_CONDITION(S) ((S)[0] == '0' && (S)[1] == '2') #define IS_EXCEPTION_CONDITION(S) ((S)[0] != '0' || (S)[1] > '2') +/* + Find a handler for the given errno. + This is called from all error message functions (e.g. push_warning, + net_send_error, et al) when a sp_rcontext is in effect. If a handler + is found, no error is sent, and the the SP execution loop will instead + invoke the found handler. + This might be called several times before we get back to the execution + loop, so m_hfound can be >= 0 if a handler has already been found. + (In which case we don't search again - the first found handler will + be used.) + Handlers are pushed on the stack m_handler, with the latest/innermost + one on the top; we then search for matching handlers from the top and + down. + We search through all the handlers, looking for the most specific one + (sql_errno more specific than sqlstate more specific than the rest). + Note that mysql error code handlers is a MySQL extension, not part of + the standard. + + SYNOPSIS + sql_errno The error code + level Warning level + + RETURN + 1 if a handler was found, m_hfound is set to its index (>= 0) + 0 if not found, m_hfound is -1 +*/ + bool sp_rcontext::find_handler(uint sql_errno, MYSQL_ERROR::enum_warning_level level) @@ -174,11 +201,13 @@ sp_rcontext::find_handler(uint sql_errno, const char *sqlstate= mysql_errno_to_sqlstate(sql_errno); int i= m_hcount, found= -1; + /* Search handlers from the latest (innermost) to the oldest (outermost) */ while (i--) { sp_cond_type_t *cond= m_handler[i].cond; int j= m_ihsp; + /* Check active handlers, to avoid invoking one recursively */ while (j--) if (m_in_handler[j] == m_handler[i].handler) break; From 86f9bdf8b2e5ea624e3eff2962c531b8c3c6e3c0 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 2 Feb 2006 21:27:23 +0100 Subject: [PATCH 10/10] item_timefunc.cc: manual adding the fix for bug#15828 which did not automerge sql/item_timefunc.cc: manual adding the fix for bug#15828 which did not automerge --- sql/item_timefunc.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 61449d3c671..17f25b49bcc 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -3023,9 +3023,9 @@ void Item_func_str_to_date::fix_length_and_dec() cached_field_type= MYSQL_TYPE_STRING; max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; cached_timestamp_type= MYSQL_TIMESTAMP_NONE; - if ((const_item= args[1]->const_item())) + format= args[1]->val_str(&format_str); + if (!args[1]->null_value && (const_item= args[1]->const_item())) { - format= args[1]->val_str(&format_str); cached_format_type= get_date_time_result_type(format->ptr(), format->length()); switch (cached_format_type) {