summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <tnurnberg@white.intern.koehntopp.de>2007-11-17 19:44:19 +0100
committerunknown <tnurnberg@white.intern.koehntopp.de>2007-11-17 19:44:19 +0100
commit7b134c34206da741fae220585bc137d69fe4b612 (patch)
tree8c33fa904eda09f9fd61d2f950471931bdd1f899 /sql
parent67384b69e7b9bc97d56494d5258e307ebf9dba3b (diff)
parente473ffaa7e2c90989706d3c731c88fc6a0136e9c (diff)
downloadmariadb-git-7b134c34206da741fae220585bc137d69fe4b612.tar.gz
Merge tnurnberg@bk-internal.mysql.com:/home/bk/mysql-5.1-maint
into mysql.com:/misc/mysql/24907/51-24907 sql/sql_select.cc: Auto merged
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_select.cc38
1 files changed, 36 insertions, 2 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 2e28663e383..7f757228133 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -9205,9 +9205,43 @@ static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table,
new_field->set_derivation(item->collation.derivation);
break;
case DECIMAL_RESULT:
- new_field= new Field_new_decimal(item->max_length, maybe_null, item->name,
- item->decimals, item->unsigned_flag);
+ {
+ uint8 dec= item->decimals;
+ uint8 intg= ((Item_decimal *) item)->decimal_precision() - dec;
+ uint8 len= item->max_length;
+
+ /*
+ Trying to put too many digits overall in a DECIMAL(prec,dec)
+ will always throw a warning. We must limit dec to
+ DECIMAL_MAX_SCALE however to prevent an assert() later.
+ */
+
+ if (dec > 0)
+ {
+ signed int overflow;
+
+ dec= min(dec, DECIMAL_MAX_SCALE);
+
+ /*
+ If the value still overflows the field with the corrected dec,
+ we'll throw out decimals rather than integers. This is still
+ bad and of course throws a truncation warning.
+ +1: for decimal point
+ */
+
+ overflow= my_decimal_precision_to_length(intg + dec, dec,
+ item->unsigned_flag) - len;
+
+ if (overflow > 0)
+ dec= max(0, dec - overflow); // too long, discard fract
+ else
+ len -= item->decimals - dec; // corrected value fits
+ }
+
+ new_field= new Field_new_decimal(len, maybe_null, item->name,
+ dec, item->unsigned_flag);
break;
+ }
case ROW_RESULT:
default:
// This case should never be choosen