summaryrefslogtreecommitdiff
path: root/sql/item_func.cc
diff options
context:
space:
mode:
authorunknown <ibabaev@bk-internal.mysql.com>2007-05-12 23:42:36 +0200
committerunknown <ibabaev@bk-internal.mysql.com>2007-05-12 23:42:36 +0200
commitde34385a565a07536f314813e02f63aec1d0f369 (patch)
tree59d9e31c78caca8be26a8746fa5e83ac54aabb1a /sql/item_func.cc
parent0f6e518a3ba975d84ef192ee295bf330368855b3 (diff)
parent3d501aece0f68183d0a74aa37d0938ccd91733ac (diff)
downloadmariadb-git-clone-5.0.42-build.tar.gz
Merge bk-internal.mysql.com:/data0/bk/mysql-5.0clone-5.0.42-build
into bk-internal.mysql.com:/data0/bk/mysql-5.0-opt
Diffstat (limited to 'sql/item_func.cc')
-rw-r--r--sql/item_func.cc45
1 files changed, 44 insertions, 1 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 7a31b564502..c0a9647e382 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -1050,18 +1050,61 @@ longlong Item_decimal_typecast::val_int()
my_decimal *Item_decimal_typecast::val_decimal(my_decimal *dec)
{
my_decimal tmp_buf, *tmp= args[0]->val_decimal(&tmp_buf);
+ bool sign;
+ uint precision;
+
if ((null_value= args[0]->null_value))
return NULL;
my_decimal_round(E_DEC_FATAL_ERROR, tmp, decimals, FALSE, dec);
+ sign= dec->sign();
+ if (unsigned_flag)
+ {
+ if (sign)
+ {
+ my_decimal_set_zero(dec);
+ goto err;
+ }
+ }
+ precision= my_decimal_length_to_precision(max_length,
+ decimals, unsigned_flag);
+ if (precision - decimals < (uint) my_decimal_intg(dec))
+ {
+ max_my_decimal(dec, precision, decimals);
+ dec->sign(sign);
+ goto err;
+ }
+ return dec;
+
+err:
+ push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
+ ER_WARN_DATA_OUT_OF_RANGE,
+ ER(ER_WARN_DATA_OUT_OF_RANGE),
+ name, 1);
return dec;
}
void Item_decimal_typecast::print(String *str)
{
+ char len_buf[20*3 + 1];
+ char *end;
+
+ uint precision= my_decimal_length_to_precision(max_length, decimals,
+ unsigned_flag);
str->append(STRING_WITH_LEN("cast("));
args[0]->print(str);
- str->append(STRING_WITH_LEN(" as decimal)"));
+ str->append(STRING_WITH_LEN(" as decimal("));
+
+ end=int10_to_str(precision, len_buf,10);
+ str->append(len_buf, (uint32) (end - len_buf));
+
+ str->append(',');
+
+ end=int10_to_str(decimals, len_buf,10);
+ str->append(len_buf, (uint32) (end - len_buf));
+
+ str->append(')');
+ str->append(')');
}