From: Date: March 14 2006 11:04am Subject: bk commit into 5.0 tree (jimw:1.2085) BUG#17043 List-Archive: http://lists.mysql.com/commits/3815 X-Bug: 17043 Message-Id: <20060314100449.0E3C7A804C@rama.trainedmonkey.com> Below is the list of changes that have just been committed into a local 5.0 repository of jimw. When jimw does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.2085 06/03/14 02:04:43 jimw@stripped +4 -0 Bug #17043: Casting trimmed string to decimal loses precision Results of string functions were being converted to decimals by first being converted to integers, resulting in a loss of precision. sql/item_strfunc.h 1.105 06/03/14 02:03:38 jimw@stripped +1 -0 Add Item_str_func::val_decimal() sql/item_strfunc.cc 1.264 06/03/14 02:03:12 jimw@stripped +14 -0 Convert string function results to decimal using string-to-decimal conversion mysql-test/t/func_str.test 1.85 06/03/14 02:02:56 jimw@stripped +8 -1 Add new regression test mysql-test/r/func_str.result 1.111 06/03/14 02:02:51 jimw@stripped +10 -0 Add new results # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: jimw # Host: rama.(none) # Root: /home/jimw/my/mysql-5.0-17043 --- 1.263/sql/item_strfunc.cc 2006-02-17 08:32:46 -08:00 +++ 1.264/sql/item_strfunc.cc 2006-03-14 02:03:12 -08:00 @@ -80,6 +80,20 @@ } +my_decimal *Item_str_func::val_decimal(my_decimal *decimal_value) +{ + DBUG_ASSERT(fixed == 1); + char buff[64]; + String *res, tmp(buff,sizeof(buff), &my_charset_bin); + res= val_str(&tmp); + if (!res) + return 0; + (void)str2my_decimal(E_DEC_FATAL_ERROR, (char*) res->ptr(), + res->length(), res->charset(), decimal_value); + return decimal_value; +} + + double Item_str_func::val_real() { DBUG_ASSERT(fixed == 1); --- 1.104/sql/item_strfunc.h 2006-03-06 00:51:16 -08:00 +++ 1.105/sql/item_strfunc.h 2006-03-14 02:03:38 -08:00 @@ -33,6 +33,7 @@ Item_str_func(List &list) :Item_func(list) {decimals=NOT_FIXED_DEC; } longlong val_int(); double val_real(); + my_decimal *val_decimal(my_decimal *); enum Item_result result_type () const { return STRING_RESULT; } void left_right_max_length(); String *check_well_formed_result(String *str); --- 1.110/mysql-test/r/func_str.result 2005-11-23 16:49:03 -08:00 +++ 1.111/mysql-test/r/func_str.result 2006-03-14 02:02:51 -08:00 @@ -1030,3 +1030,13 @@ y,abc abc y,abc abc drop table t1; +select cast(rtrim(' 20.06 ') as decimal(19,2)); +cast(rtrim(' 20.06 ') as decimal(19,2)) +20.06 +select cast(ltrim(' 20.06 ') as decimal(19,2)); +cast(ltrim(' 20.06 ') as decimal(19,2)) +20.06 +select cast(rtrim(ltrim(' 20.06 ')) as decimal(19,2)); +cast(rtrim(ltrim(' 20.06 ')) as decimal(19,2)) +20.06 +End of 5.0 tests --- 1.84/mysql-test/t/func_str.test 2005-11-23 16:49:03 -08:00 +++ 1.85/mysql-test/t/func_str.test 2006-03-14 02:02:56 -08:00 @@ -684,4 +684,11 @@ select c, substring_index(lcase(c), @q:=',', -1) as res from t1; drop table t1; -# End of 5.0 tests +# +# Bug #17043: Casting trimmed string to decimal loses precision +# +select cast(rtrim(' 20.06 ') as decimal(19,2)); +select cast(ltrim(' 20.06 ') as decimal(19,2)); +select cast(rtrim(ltrim(' 20.06 ')) as decimal(19,2)); + +--echo End of 5.0 tests