From 672e1f20cb0d98b7d3330e367fe0c78b48a39f93 Mon Sep 17 00:00:00 2001 From: "gluh@eagle.intranet.mysql.r18.ru" <> Date: Wed, 13 Jul 2005 14:23:09 +0500 Subject: [PATCH 1/3] Bug #9854 hex() and out of range handling added out of range handling --- mysql-test/r/func_str.result | 3 +++ mysql-test/t/func_str.test | 5 +++++ sql/item_strfunc.cc | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index fb2716fd232..18a04574596 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -865,3 +865,6 @@ abc abc c bc abc abcd abcd d cd bcd abcd abcde abcde e de cde bcde abcde drop table t1; +select hex(29223372036854775809), hex(-29223372036854775809); +hex(29223372036854775809) hex(-29223372036854775809) +FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 668e865d73a..ae3cdc361ab 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -606,3 +606,8 @@ insert t1 values ('ab'), ('abc'), ('abcd'), ('abcde'); select *,substring(b,1),substring(b,-1),substring(b,-2),substring(b,-3),substring(b,-4),substring(b,-5) from t1; select * from (select *,substring(b,1),substring(b,-1),substring(b,-2),substring(b,-3),substring(b,-4),substring(b,-5) from t1) t; drop table t1; + +# +# Bug #9854 hex() and out of range handling +# +select hex(29223372036854775809), hex(-29223372036854775809); diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index d57b3b89bf9..6a4dd0d7418 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2348,9 +2348,21 @@ String *Item_func_hex::val_str(String *str) DBUG_ASSERT(fixed == 1); if (args[0]->result_type() != STRING_RESULT) { - /* Return hex of unsigned longlong value */ - longlong dec= args[0]->val_int(); + ulonglong dec; char ans[65],*ptr; + /* Return hex of unsigned longlong value */ + if (args[0]->result_type() == REAL_RESULT) + { + double val= args[0]->val(); + if ((val <= (double) LONGLONG_MIN) || + (val >= (double) (ulonglong) ULONGLONG_MAX)) + dec= ~(longlong) 0; + else + dec= (ulonglong) (val + (val > 0 ? 0.5 : -0.5)); + } + else + dec= (ulonglong) args[0]->val_int(); + if ((null_value= args[0]->null_value)) return 0; ptr= longlong2str(dec,ans,16); From acf417a7e698891a7093db34ef965fc73b85319f Mon Sep 17 00:00:00 2001 From: "gluh@eagle.intranet.mysql.r18.ru" <> Date: Wed, 13 Jul 2005 16:08:14 +0500 Subject: [PATCH 2/3] Post-merge fix --- sql/item_strfunc.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index a8fd7dcf75d..2fd0f25e699 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2383,9 +2383,10 @@ String *Item_func_hex::val_str(String *str) ulonglong dec; char ans[65],*ptr; /* Return hex of unsigned longlong value */ - if (args[0]->result_type() == REAL_RESULT) + if (args[0]->result_type() == REAL_RESULT || + args[0]->result_type() == DECIMAL_RESULT) { - double val= args[0]->val(); + double val= args[0]->val_real(); if ((val <= (double) LONGLONG_MIN) || (val >= (double) (ulonglong) ULONGLONG_MAX)) dec= ~(longlong) 0; From 1826c398970de0ea20f7329b63768512f0184dbd Mon Sep 17 00:00:00 2001 From: "mats@mysql.com" <> Date: Wed, 13 Jul 2005 13:49:35 +0200 Subject: [PATCH 3/3] Bug#11905: Tables used in rpl_deadlock are not dropped at the end of the test, causing subsequent tests to fail. --- mysql-test/r/rpl_deadlock.result | 2 +- mysql-test/t/rpl_deadlock.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/rpl_deadlock.result b/mysql-test/r/rpl_deadlock.result index 8808a973855..8eb9d64fcae 100644 --- a/mysql-test/r/rpl_deadlock.result +++ b/mysql-test/r/rpl_deadlock.result @@ -84,4 +84,4 @@ a show slave status; Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master # 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 13110 # # master-bin.000001 Yes Yes 0 0 13110 # None 0 No # -drop table t1,t2; +drop table t1,t2,t3,t4; diff --git a/mysql-test/t/rpl_deadlock.test b/mysql-test/t/rpl_deadlock.test index 9ad6362f7e7..da932df5347 100644 --- a/mysql-test/t/rpl_deadlock.test +++ b/mysql-test/t/rpl_deadlock.test @@ -107,5 +107,5 @@ select * from t2; show slave status; connection master; -drop table t1,t2; +drop table t1,t2,t3,t4; sync_slave_with_master;