summaryrefslogtreecommitdiff
path: root/sql/field.cc
diff options
context:
space:
mode:
authorunknown <monty@hundin.mysql.fi>2002-05-02 18:04:21 +0300
committerunknown <monty@hundin.mysql.fi>2002-05-02 18:04:21 +0300
commit23bf3689667890dd8da518b6478f10090a5adaf4 (patch)
treee3f51e58cf724cef14bef4aa47370a62fd4d6bdf /sql/field.cc
parentc3703e5568c76669c8277e98206a00e6f652b5fd (diff)
downloadmariadb-git-23bf3689667890dd8da518b6478f10090a5adaf4.tar.gz
Fixed problems with DECIMAL() type on overflow.
Docs/manual.texi: Changlog configure.in: Change to version 3.23.51 Fix for OSF1 include/mysqld_error.h: Added copyright message isam/pack_isam.c: Added copyright message mysql-test/r/type_decimal.result: New test results mysql-test/t/type_decimal.test: New test results strings/Makefile.am: Added mising file
Diffstat (limited to 'sql/field.cc')
-rw-r--r--sql/field.cc48
1 files changed, 37 insertions, 11 deletions
diff --git a/sql/field.cc b/sql/field.cc
index c6a26a48c0c..246427cc2ac 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -63,8 +63,8 @@ const char field_separator=',';
*****************************************************************************/
/*
- ** Calculate length of number and it's parts
- ** Increment cuted_fields if wrong number
+ Calculate length of number and it's parts
+ Increment cuted_fields if wrong number
*/
static bool
@@ -380,13 +380,34 @@ Field_decimal::reset(void)
void Field_decimal::overflow(bool negative)
{
uint len=field_length;
- char *to=ptr;
- if (negative && !unsigned_flag)
+ char *to=ptr, filler= '9';
+ if (negative)
{
- *to++ = '-';
- len--;
+ if (!unsigned_flag)
+ {
+ /* Put - sign as a first digit so we'll have -999..999 or 999..999 */
+ *to++ = '-';
+ len--;
+ }
+ else
+ {
+ filler= '0'; // Fill up with 0
+ if (!zerofill)
+ {
+ /*
+ Handle unsigned integer without zerofill, in which case
+ the number should be of format ' 0' or ' 0.000'
+ */
+ uint whole_part=field_length- (dec ? dec+2 : 1);
+ // Fill with spaces up to the first digit
+ bfill(to, whole_part, ' ');
+ to+= whole_part;
+ len-= whole_part;
+ // The main code will also handle the 0 before the decimal point
+ }
+ }
}
- bfill(to,len,negative && unsigned_flag ? '0' : '9');
+ bfill(to, len, filler);
if (dec)
ptr[field_length-dec-1]='.';
return;
@@ -421,10 +442,15 @@ void Field_decimal::store(const char *from,uint len)
from++;
if (unsigned_flag) // No sign with zerofill
{
- if (!error)
- current_thd->cuted_fields++;
- Field_decimal::overflow(1);
- return;
+ if (decstr.sign_char == '+') // just remove "+"
+ decstr.sign= 0;
+ else
+ {
+ if (!error)
+ current_thd->cuted_fields++;
+ Field_decimal::overflow(1);
+ return;
+ }
}
}
/*