summaryrefslogtreecommitdiff
path: root/sql/item_strfunc.cc
diff options
context:
space:
mode:
authorunknown <jimw@mysql.com>2006-03-14 02:04:43 -0800
committerunknown <jimw@mysql.com>2006-03-14 02:04:43 -0800
commitd48cfa8ac7b7e240b883cbe2287c7f5729e37140 (patch)
tree2033188416a3c924f91998eeca2181e1a9de3508 /sql/item_strfunc.cc
parent358e08836a1647a90ad3ecfc9dcef3549c00f4fe (diff)
downloadmariadb-git-d48cfa8ac7b7e240b883cbe2287c7f5729e37140.tar.gz
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. mysql-test/r/func_str.result: Add new results mysql-test/t/func_str.test: Add new regression test sql/item_strfunc.cc: Convert string function results to decimal using string-to-decimal conversion sql/item_strfunc.h: Add Item_str_func::val_decimal()
Diffstat (limited to 'sql/item_strfunc.cc')
-rw-r--r--sql/item_strfunc.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index a3e47154bc3..60183ac9b5a 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -80,6 +80,20 @@ String *Item_str_func::check_well_formed_result(String *str)
}
+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);