diff options
-rw-r--r-- | sql/field.cc | 365 | ||||
-rw-r--r-- | sql/field.h | 126 | ||||
-rw-r--r-- | sql/item.cc | 50 | ||||
-rw-r--r-- | sql/item.h | 20 | ||||
-rw-r--r-- | sql/item_cmpfunc.cc | 3 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 4 | ||||
-rw-r--r-- | sql/item_strfunc.h | 4 | ||||
-rw-r--r-- | sql/item_timefunc.cc | 4 | ||||
-rw-r--r-- | sql/item_timefunc.h | 4 | ||||
-rw-r--r-- | sql/opt_range.cc | 2 | ||||
-rw-r--r-- | sql/sql_base.cc | 4 | ||||
-rw-r--r-- | sql/sql_handler.cc | 2 | ||||
-rw-r--r-- | sql/sql_select.cc | 2 | ||||
-rw-r--r-- | sql/sql_select.h | 4 | ||||
-rw-r--r-- | sql/unireg.cc | 2 |
15 files changed, 401 insertions, 195 deletions
diff --git a/sql/field.cc b/sql/field.cc index a475612fbb0..462088d26a6 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -424,7 +424,7 @@ void Field_decimal::overflow(bool negative) } -void Field_decimal::store(const char *from,uint len,CHARSET_INFO *cs) +int Field_decimal::store(const char *from,uint len,CHARSET_INFO *cs) { reg3 int i; uint tmp_dec; @@ -459,7 +459,7 @@ void Field_decimal::store(const char *from,uint len,CHARSET_INFO *cs) if (!error) current_thd->cuted_fields++; Field_decimal::overflow(1); - return; + return 1; } } } @@ -485,7 +485,7 @@ void Field_decimal::store(const char *from,uint len,CHARSET_INFO *cs) current_thd->cuted_fields++; // too big number, change to max or min number Field_decimal::overflow(decstr.sign && decstr.sign_char == '-'); - return; + return 1; } char *to=ptr; for (i=(int) (field_length-tmp_dec-decstr.nr_length-decstr.extra - decstr.sign) ; @@ -520,16 +520,17 @@ void Field_decimal::store(const char *from,uint len,CHARSET_INFO *cs) } } } + return (error) ? 1 : 0; } -void Field_decimal::store(double nr) +int Field_decimal::store(double nr) { if (unsigned_flag && nr < 0) { overflow(1); current_thd->cuted_fields++; - return; + return 1; } reg4 uint i,length; char fyllchar,*to; @@ -548,6 +549,7 @@ void Field_decimal::store(double nr) { overflow(nr < 0.0); current_thd->cuted_fields++; + return 1; } else { @@ -555,17 +557,18 @@ void Field_decimal::store(double nr) for (i=field_length-length ; i-- > 0 ;) *to++ = fyllchar; memcpy(to,buff,length); + return 0; } } -void Field_decimal::store(longlong nr) +int Field_decimal::store(longlong nr) { if (unsigned_flag && nr < 0) { overflow(1); current_thd->cuted_fields++; - return; + return 1; } char buff[22]; uint length=(uint) (longlong10_to_str(nr,buff,-10)-buff); @@ -575,6 +578,7 @@ void Field_decimal::store(longlong nr) { overflow(test(nr < 0L)); /* purecov: inspected */ current_thd->cuted_fields++; /* purecov: inspected */ + return 1; } else { @@ -588,6 +592,7 @@ void Field_decimal::store(longlong nr) to[length]='.'; bfill(to+length+1,dec,'0'); } + return 0; } } @@ -704,10 +709,11 @@ void Field_decimal::sql_type(String &res) const ** tiny int ****************************************************************************/ -void Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs) +int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs) { String tmp_str(from,len,default_charset_info); long tmp= strtol(tmp_str.c_ptr(),NULL,10); + int error=0; if (unsigned_flag) { @@ -715,14 +721,19 @@ void Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs) { tmp=0; /* purecov: inspected */ current_thd->cuted_fields++; /* purecov: inspected */ + error = 1; } else if (tmp > 255) { tmp= 255; current_thd->cuted_fields++; + error = 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len)) + { current_thd->cuted_fields++; + error = 1; + } } else { @@ -730,21 +741,28 @@ void Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs) { tmp= -128; current_thd->cuted_fields++; + error = 1; } else if (tmp >= 128) { tmp= 127; current_thd->cuted_fields++; + error = 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len)) + { current_thd->cuted_fields++; + error = 1; + } } ptr[0]= (char) tmp; + return error; } -void Field_tiny::store(double nr) +int Field_tiny::store(double nr) { + int error=0; nr=rint(nr); if (unsigned_flag) { @@ -752,11 +770,13 @@ void Field_tiny::store(double nr) { *ptr=0; current_thd->cuted_fields++; + error = 1; } else if (nr > 255.0) { *ptr=(char) 255; current_thd->cuted_fields++; + error = 1; } else *ptr=(char) nr; @@ -767,30 +787,36 @@ void Field_tiny::store(double nr) { *ptr= (char) -128; current_thd->cuted_fields++; + error = 1; } else if (nr > 127.0) { *ptr=127; current_thd->cuted_fields++; + error = 1; } else *ptr=(char) nr; } + return error; } -void Field_tiny::store(longlong nr) +int Field_tiny::store(longlong nr) { + int error=0; if (unsigned_flag) { if (nr < 0L) { *ptr=0; current_thd->cuted_fields++; + error = 1; } else if (nr > 255L) { *ptr= (char) 255; current_thd->cuted_fields++; + error = 1; } else *ptr=(char) nr; @@ -801,15 +827,18 @@ void Field_tiny::store(longlong nr) { *ptr= (char) -128; current_thd->cuted_fields++; + error = 1; } else if (nr > 127L) { *ptr=127; current_thd->cuted_fields++; + error = 1; } else *ptr=(char) nr; } + return error; } @@ -875,24 +904,30 @@ void Field_tiny::sql_type(String &res) const // Note: Sometimes this should be fixed to use one strtol() to use // len and check for garbage after number. -void Field_short::store(const char *from,uint len,CHARSET_INFO *cs) +int Field_short::store(const char *from,uint len,CHARSET_INFO *cs) { String tmp_str(from,len,default_charset_info); long tmp= strtol(tmp_str.c_ptr(),NULL,10); + int error=0; if (unsigned_flag) { if (tmp < 0) { tmp=0; current_thd->cuted_fields++; + error = 1; } else if (tmp > (uint16) ~0) { tmp=(uint16) ~0; current_thd->cuted_fields++; + error = 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len)) + { current_thd->cuted_fields++; + error = 1; + } } else { @@ -900,14 +935,19 @@ void Field_short::store(const char *from,uint len,CHARSET_INFO *cs) { tmp= INT_MIN16; current_thd->cuted_fields++; + error = 1; } else if (tmp > INT_MAX16) { tmp=INT_MAX16; current_thd->cuted_fields++; + error = 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len)) + { current_thd->cuted_fields++; + error = 1; + } } #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) @@ -917,11 +957,13 @@ void Field_short::store(const char *from,uint len,CHARSET_INFO *cs) else #endif shortstore(ptr,(short) tmp); + return error; } -void Field_short::store(double nr) +int Field_short::store(double nr) { + int error=0; int16 res; nr=rint(nr); if (unsigned_flag) @@ -930,11 +972,13 @@ void Field_short::store(double nr) { res=0; current_thd->cuted_fields++; + error = 1; } else if (nr > (double) (uint16) ~0) { res=(int16) (uint16) ~0; current_thd->cuted_fields++; + error = 1; } else res=(int16) (uint16) nr; @@ -945,11 +989,13 @@ void Field_short::store(double nr) { res=INT_MIN16; current_thd->cuted_fields++; + error = 1; } else if (nr > (double) INT_MAX16) { res=INT_MAX16; current_thd->cuted_fields++; + error = 1; } else res=(int16) nr; @@ -962,10 +1008,12 @@ void Field_short::store(double nr) else #endif shortstore(ptr,res); + return error; } -void Field_short::store(longlong nr) +int Field_short::store(longlong nr) { + int error=0; int16 res; if (unsigned_flag) { @@ -973,11 +1021,13 @@ void Field_short::store(longlong nr) { res=0; current_thd->cuted_fields++; + error = 1; } else if (nr > (longlong) (uint16) ~0) { res=(int16) (uint16) ~0; current_thd->cuted_fields++; + error = 1; } else res=(int16) (uint16) nr; @@ -988,11 +1038,13 @@ void Field_short::store(longlong nr) { res=INT_MIN16; current_thd->cuted_fields++; + error = 1; } else if (nr > INT_MAX16) { res=INT_MAX16; current_thd->cuted_fields++; + error = 1; } else res=(int16) nr; @@ -1005,6 +1057,7 @@ void Field_short::store(longlong nr) else #endif shortstore(ptr,res); + return error; } @@ -1115,10 +1168,11 @@ void Field_short::sql_type(String &res) const // Note: Sometimes this should be fixed to use one strtol() to use // len and check for garbage after number. -void Field_medium::store(const char *from,uint len,CHARSET_INFO *cs) +int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs) { String tmp_str(from,len,default_charset_info); long tmp= strtol(tmp_str.c_ptr(),NULL,10); + int error=0; if (unsigned_flag) { @@ -1126,14 +1180,19 @@ void Field_medium::store(const char *from,uint len,CHARSET_INFO *cs) { tmp=0; current_thd->cuted_fields++; + error = 1; } else if (tmp >= (long) (1L << 24)) { tmp=(long) (1L << 24)-1L; current_thd->cuted_fields++; + error = 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len)) + { current_thd->cuted_fields++; + error = 1; + } } else { @@ -1141,22 +1200,29 @@ void Field_medium::store(const char *from,uint len,CHARSET_INFO *cs) { tmp= INT_MIN24; current_thd->cuted_fields++; + error = 1; } else if (tmp > INT_MAX24) { tmp=INT_MAX24; current_thd->cuted_fields++; + error = 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len)) + { current_thd->cuted_fields++; + error = 1; + } } int3store(ptr,tmp); + return error; } -void Field_medium::store(double nr) +int Field_medium::store(double nr) { + int error=0; nr=rint(nr); if (unsigned_flag) { @@ -1164,12 +1230,14 @@ void Field_medium::store(double nr) { int3store(ptr,0); current_thd->cuted_fields++; + error = 1; } else if (nr >= (double) (long) (1L << 24)) { uint32 tmp=(uint32) (1L << 24)-1L; int3store(ptr,tmp); current_thd->cuted_fields++; + error = 1; } else int3store(ptr,(uint32) nr); @@ -1181,32 +1249,38 @@ void Field_medium::store(double nr) long tmp=(long) INT_MIN24; int3store(ptr,tmp); current_thd->cuted_fields++; + error = 1; } else if (nr > (double) INT_MAX24) { long tmp=(long) INT_MAX24; int3store(ptr,tmp); current_thd->cuted_fields++; + error = 1; } else int3store(ptr,(long) nr); } + return error; } -void Field_medium::store(longlong nr) +int Field_medium::store(longlong nr) { + int error=0; if (unsigned_flag) { if (nr < 0L) { int3store(ptr,0); current_thd->cuted_fields++; + error = 1; } else if (nr >= (longlong) (long) (1L << 24)) { long tmp=(long) (1L << 24)-1L;; int3store(ptr,tmp); current_thd->cuted_fields++; + error = 1; } else int3store(ptr,(uint32) nr); @@ -1218,16 +1292,19 @@ void Field_medium::store(longlong nr) long tmp=(long) INT_MIN24; int3store(ptr,tmp); current_thd->cuted_fields++; + error = 1; } else if (nr > (longlong) INT_MAX24) { long tmp=(long) INT_MAX24; int3store(ptr,tmp); current_thd->cuted_fields++; + error = 1; } else int3store(ptr,(long) nr); } + return error; } @@ -1300,13 +1377,14 @@ void Field_medium::sql_type(String &res) const // Note: Sometimes this should be fixed to use one strtol() to use // len and check for garbage after number. -void Field_long::store(const char *from,uint len,CHARSET_INFO *cs) +int Field_long::store(const char *from,uint len,CHARSET_INFO *cs) { while (len && my_isspace(system_charset_info,*from)) { len--; from++; } long tmp; + int error=0; String tmp_str(from,len,default_charset_info); errno=0; if (unsigned_flag) @@ -1315,6 +1393,7 @@ void Field_long::store(const char *from,uint len,CHARSET_INFO *cs) { tmp=0; // Set negative to 0 errno=ERANGE; + error = 1; } else tmp=(long) strtoul(tmp_str.c_ptr(),NULL,10); @@ -1322,7 +1401,10 @@ void Field_long::store(const char *from,uint len,CHARSET_INFO *cs) else tmp=strtol(tmp_str.c_ptr(),NULL,10); if (errno || current_thd->count_cuted_fields && !test_if_int(from,len)) + { current_thd->cuted_fields++; + error = 1; + } #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) { @@ -1331,11 +1413,13 @@ void Field_long::store(const char *from,uint len,CHARSET_INFO *cs) else #endif longstore(ptr,tmp); + return error; } -void Field_long::store(double nr) +int Field_long::store(double nr) { + int error=0; int32 res; nr=rint(nr); if (unsigned_flag) @@ -1344,11 +1428,13 @@ void Field_long::store(double nr) { res=0; current_thd->cuted_fields++; + error = 1; } else if (nr > (double) (ulong) ~0L) { res=(int32) (uint32) ~0L; current_thd->cuted_fields++; + error = 1; } else res=(int32) (ulong) nr; @@ -1359,11 +1445,13 @@ void Field_long::store(double nr) { res=(int32) INT_MIN32; current_thd->cuted_fields++; + error = 1; } else if (nr > (double) INT_MAX32) { res=(int32) INT_MAX32; current_thd->cuted_fields++; + error = 1; } else res=(int32) nr; @@ -1376,11 +1464,13 @@ void Field_long::store(double nr) else #endif longstore(ptr,res); + return error; } -void Field_long::store(longlong nr) +int Field_long::store(longlong nr) { + int error=0; int32 res; if (unsigned_flag) { @@ -1388,11 +1478,13 @@ void Field_long::store(longlong nr) { res=0; current_thd->cuted_fields++; + error = 1; } else if (nr >= (LL(1) << 32)) { res=(int32) (uint32) ~0L; current_thd->cuted_fields++; + error = 1; } else res=(int32) (uint32) nr; @@ -1403,11 +1495,13 @@ void Field_long::store(longlong nr) { res=(int32) INT_MIN32; current_thd->cuted_fields++; + error = 1; } else if (nr > (longlong) INT_MAX32) { res=(int32) INT_MAX32; current_thd->cuted_fields++; + error = 1; } else res=(int32) nr; @@ -1420,6 +1514,7 @@ void Field_long::store(longlong nr) else #endif longstore(ptr,res); + return error; } @@ -1528,7 +1623,7 @@ void Field_long::sql_type(String &res) const ** longlong int ****************************************************************************/ -void Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs) +int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs) { while (len && my_isspace(system_charset_info,*from)) { // For easy error check @@ -1536,6 +1631,7 @@ void Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs) } longlong tmp; String tmp_str(from,len,default_charset_info); + int error=0; errno=0; if (unsigned_flag) { @@ -1543,6 +1639,7 @@ void Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs) { tmp=0; // Set negative to 0 errno=ERANGE; + error = 1; } else tmp=(longlong) strtoull(tmp_str.c_ptr(),NULL,10); @@ -1550,7 +1647,10 @@ void Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs) else tmp=strtoll(tmp_str.c_ptr(),NULL,10); if (errno || current_thd->count_cuted_fields && !test_if_int(from,len)) + { current_thd->cuted_fields++; + error = 1; + } #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) { @@ -1559,11 +1659,13 @@ void Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs) else #endif longlongstore(ptr,tmp); + return error; } -void Field_longlong::store(double nr) +int Field_longlong::store(double nr) { + int error=0; longlong res; nr=rint(nr); if (unsigned_flag) @@ -1572,11 +1674,13 @@ void Field_longlong::store(double nr) { res=0; current_thd->cuted_fields++; + error = 1; } else if (nr >= (double) ~ (ulonglong) 0) { res= ~(longlong) 0; current_thd->cuted_fields++; + error = 1; } else res=(longlong) (ulonglong) nr; @@ -1587,11 +1691,13 @@ void Field_longlong::store(double nr) { res=(longlong) LONGLONG_MIN; current_thd->cuted_fields++; + error = 1; } else if (nr >= (double) LONGLONG_MAX) { res=(longlong) LONGLONG_MAX; current_thd->cuted_fields++; + error = 1; } else res=(longlong) nr; @@ -1604,10 +1710,11 @@ void Field_longlong::store(double nr) else #endif longlongstore(ptr,res); + return error; } -void Field_longlong::store(longlong nr) +int Field_longlong::store(longlong nr) { #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) @@ -1617,6 +1724,7 @@ void Field_longlong::store(longlong nr) else #endif longlongstore(ptr,nr); + return 0; } @@ -1735,35 +1843,43 @@ void Field_longlong::sql_type(String &res) const ** single precision float ****************************************************************************/ -void Field_float::store(const char *from,uint len,CHARSET_INFO *cs) +int Field_float::store(const char *from,uint len,CHARSET_INFO *cs) { String tmp_str(from,len,default_charset_info); errno=0; Field_float::store(atof(tmp_str.c_ptr())); if (errno || current_thd->count_cuted_fields && !test_if_real(from,len)) + { current_thd->cuted_fields++; + return 1; + } + return (errno) ? 1 : 0; } -void Field_float::store(double nr) +int Field_float::store(double nr) { float j; + int error=0; if (dec < NOT_FIXED_DEC) nr=floor(nr*log_10[dec]+0.5)/log_10[dec]; // To fixed point if (unsigned_flag && nr < 0) { current_thd->cuted_fields++; nr=0; + error = 1; } if (nr < -FLT_MAX) { j= -FLT_MAX; current_thd->cuted_fields++; + error = 1; } else if (nr > FLT_MAX) { j=FLT_MAX; current_thd->cuted_fields++; + error = 1; } else j= (float) nr; @@ -1775,16 +1891,19 @@ void Field_float::store(double nr) else #endif memcpy_fixed(ptr,(byte*) &j,sizeof(j)); + return error; } -void Field_float::store(longlong nr) +int Field_float::store(longlong nr) { + int error=0; float j= (float) nr; if (unsigned_flag && j < 0) { current_thd->cuted_fields++; j=0; + error = 1; } #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) @@ -1794,6 +1913,7 @@ void Field_float::store(longlong nr) else #endif memcpy_fixed(ptr,(byte*) &j,sizeof(j)); + return error; } @@ -1985,17 +2105,22 @@ void Field_float::sql_type(String &res) const ** double precision floating point numbers ****************************************************************************/ -void Field_double::store(const char *from,uint len,CHARSET_INFO *cs) +int Field_double::store(const char *from,uint len,CHARSET_INFO *cs) { String tmp_str(from,len,default_charset_info); errno=0; + int error=0; double j= atof(tmp_str.c_ptr()); if (errno || current_thd->count_cuted_fields && !test_if_real(from,len)) + { current_thd->cuted_fields++; + error = 1; + } if (unsigned_flag && j < 0) { current_thd->cuted_fields++; j=0; + error = 1; } #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) @@ -2005,17 +2130,20 @@ void Field_double::store(const char *from,uint len,CHARSET_INFO *cs) else #endif doublestore(ptr,j); + return error; } -void Field_double::store(double nr) +int Field_double::store(double nr) { + int error=0; if (dec < NOT_FIXED_DEC) nr=floor(nr*log_10[dec]+0.5)/log_10[dec]; // To fixed point if (unsigned_flag && nr < 0) { current_thd->cuted_fields++; nr=0; + error = 1; } #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) @@ -2025,15 +2153,18 @@ void Field_double::store(double nr) else #endif doublestore(ptr,nr); + return error; } -void Field_double::store(longlong nr) +int Field_double::store(longlong nr) { double j= (double) nr; + int error=0; if (unsigned_flag && j < 0) { current_thd->cuted_fields++; + error = 1; j=0; } #ifdef WORDS_BIGENDIAN @@ -2044,6 +2175,7 @@ void Field_double::store(longlong nr) else #endif doublestore(ptr,j); + return error; } @@ -2241,7 +2373,7 @@ Field_timestamp::Field_timestamp(char *ptr_arg, uint32 len_arg, } -void Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs) +int Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs) { long tmp=(long) str_to_timestamp(from,len); #ifdef WORDS_BIGENDIAN @@ -2252,9 +2384,10 @@ void Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs) else #endif longstore(ptr,tmp); + return 0; } -void Field_timestamp::fill_and_store(char *from,uint len) +void Field_timestamp::fill_and_store(char *from,uint len) { uint res_length; if (len <= field_length) @@ -2283,14 +2416,17 @@ void Field_timestamp::fill_and_store(char *from,uint len) } -void Field_timestamp::store(double nr) +int Field_timestamp::store(double nr) { + int error=0; if (nr < 0 || nr > 99991231235959.0) { nr=0; // Avoid overflow on buff current_thd->cuted_fields++; + error = 1; } - Field_timestamp::store((longlong) rint(nr)); + error |= Field_timestamp::store((longlong) rint(nr)); + return error; } @@ -2331,7 +2467,7 @@ static longlong fix_datetime(longlong nr) } -void Field_timestamp::store(longlong nr) +int Field_timestamp::store(longlong nr) { TIME l_time; time_t timestamp; @@ -2359,6 +2495,7 @@ void Field_timestamp::store(longlong nr) else #endif longstore(ptr,(uint32) timestamp); + return 0; } @@ -2580,12 +2717,16 @@ void Field_timestamp::set_time() ** Stored as a 3 byte unsigned int ****************************************************************************/ -void Field_time::store(const char *from,uint len,CHARSET_INFO *cs) +int Field_time::store(const char *from,uint len,CHARSET_INFO *cs) { TIME ltime; long tmp; + int error=0; if (str_to_time(from,len,<ime)) + { tmp=0L; + error = 1; + } else { if (ltime.month) @@ -2595,26 +2736,31 @@ void Field_time::store(const char *from,uint len,CHARSET_INFO *cs) { tmp=8385959; current_thd->cuted_fields++; + error = 1; } } if (ltime.neg) tmp= -tmp; - Field_time::store((longlong) tmp); + error |= Field_time::store((longlong) tmp); + return error; } -void Field_time::store(double nr) +int Field_time::store(double nr) { long tmp; + int error=0; if (nr > 8385959.0) { tmp=8385959L; current_thd->cuted_fields++; + error = 1; } else if (nr < -8385959.0) { tmp= -8385959L; current_thd->cuted_fields++; + error = 1; } else { @@ -2625,24 +2771,29 @@ void Field_time::store(double nr) { tmp=0; current_thd->cuted_fields++; + error = 1; } } int3store(ptr,tmp); + return error; } -void Field_time::store(longlong nr) +int Field_time::store(longlong nr) { long tmp; + int error=0; if (nr > (longlong) 8385959L) { tmp=8385959L; current_thd->cuted_fields++; + error = 1; } else if (nr < (longlong) -8385959L) { tmp= -8385959L; current_thd->cuted_fields++; + error = 1; } else { @@ -2651,9 +2802,11 @@ void Field_time::store(longlong nr) { tmp=0; current_thd->cuted_fields++; + error = 1; } } int3store(ptr,tmp); + return error; } @@ -2729,7 +2882,7 @@ void Field_time::sql_type(String &res) const ** Can handle 2 byte or 4 byte years! ****************************************************************************/ -void Field_year::store(const char *from, uint len,CHARSET_INFO *cs) +int Field_year::store(const char *from, uint len,CHARSET_INFO *cs) { String tmp_str(from,len,default_charset_info); long nr= strtol(tmp_str.c_ptr(),NULL,10); @@ -2738,7 +2891,7 @@ void Field_year::store(const char *from, uint len,CHARSET_INFO *cs) { *ptr=0; current_thd->cuted_fields++; - return; + return 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len)) current_thd->cuted_fields++; @@ -2750,23 +2903,27 @@ void Field_year::store(const char *from, uint len,CHARSET_INFO *cs) nr-= 1900; } *ptr= (char) (unsigned char) nr; + return 0; } -void Field_year::store(double nr) +int Field_year::store(double nr) { if (nr < 0.0 || nr >= 2155.0) - Field_year::store((longlong) -1); + { + (void) Field_year::store((longlong) -1); + return 1; + } else - Field_year::store((longlong) nr); + return Field_year::store((longlong) nr); } -void Field_year::store(longlong nr) +int Field_year::store(longlong nr) { if (nr < 0 || nr >= 100 && nr <= 1900 || nr > 2155) { *ptr=0; current_thd->cuted_fields++; - return; + return 1; } if (nr != 0 || field_length != 4) // 0000 -> 0; 00 -> 2000 { @@ -2776,6 +2933,7 @@ void Field_year::store(longlong nr) nr-= 1900; } *ptr= (char) (unsigned char) nr; + return 0; } @@ -2818,12 +2976,16 @@ void Field_year::sql_type(String &res) const ** Stored as a 4 byte unsigned int ****************************************************************************/ -void Field_date::store(const char *from, uint len,CHARSET_INFO *cs) +int Field_date::store(const char *from, uint len,CHARSET_INFO *cs) { TIME l_time; uint32 tmp; + int error=0; if (str_to_TIME(from,len,&l_time,1) == TIMESTAMP_NONE) + { tmp=0; + error = 1; + } else tmp=(uint32) l_time.year*10000L + (uint32) (l_time.month*100+l_time.day); #ifdef WORDS_BIGENDIAN @@ -2834,18 +2996,21 @@ void Field_date::store(const char *from, uint len,CHARSET_INFO *cs) else #endif longstore(ptr,tmp); + return error; } -void Field_date::store(double nr) +int Field_date::store(double nr) { long tmp; + int error=0; if (nr >= 19000000000000.0 && nr <= 99991231235959.0) nr=floor(nr/1000000.0); // Timestamp to date if (nr < 0.0 || nr > 99991231.0) { tmp=0L; current_thd->cuted_fields++; + error = 1; } else tmp=(long) rint(nr); @@ -2857,18 +3022,21 @@ void Field_date::store(double nr) else #endif longstore(ptr,tmp); + return error; } -void Field_date::store(longlong nr) +int Field_date::store(longlong nr) { long tmp; + int error=0; if (nr >= LL(19000000000000) && nr < LL(99991231235959)) nr=nr/LL(1000000); // Timestamp to date if (nr < 0 || nr > LL(99991231)) { tmp=0L; current_thd->cuted_fields++; + error = 1; } else tmp=(long) nr; @@ -2880,6 +3048,7 @@ void Field_date::store(longlong nr) else #endif longstore(ptr,tmp); + return error; } @@ -2975,35 +3144,45 @@ void Field_date::sql_type(String &res) const ** In number context: YYYYMMDD ****************************************************************************/ -void Field_newdate::store(const char *from,uint len,CHARSET_INFO *cs) +int Field_newdate::store(const char *from,uint len,CHARSET_INFO *cs) { TIME l_time; long tmp; + int error=0; if (str_to_TIME(from,len,&l_time,1) == TIMESTAMP_NONE) + { tmp=0L; + error = 1; + } else tmp= l_time.day + l_time.month*32 + l_time.year*16*32; int3store(ptr,tmp); + return error; } -void Field_newdate::store(double nr) +int Field_newdate::store(double nr) { if (nr < 0.0 || nr > 99991231235959.0) - Field_newdate::store((longlong) -1); + { + (void) Field_newdate::store((longlong) -1); + return 1; + } else - Field_newdate::store((longlong) rint(nr)); + return Field_newdate::store((longlong) rint(nr)); } -void Field_newdate::store(longlong nr) +int Field_newdate::store(longlong nr) { int32 tmp; + int error=0; if (nr >= LL(100000000) && nr <= LL(99991231235959)) nr=nr/LL(1000000); // Timestamp to date if (nr < 0L || nr > 99991231L) { tmp=0; current_thd->cuted_fields++; + error = 1; } else { @@ -3021,11 +3200,13 @@ void Field_newdate::store(longlong nr) { tmp=0L; // Don't allow date to change current_thd->cuted_fields++; + error = 1; } else tmp= day + month*32 + (tmp/10000)*16*32; } int3store(ptr,(int32) tmp); + return error; } void Field_newdate::store_time(TIME *ltime,timestamp_type type) @@ -3128,7 +3309,7 @@ void Field_newdate::sql_type(String &res) const ** Stored as a 8 byte unsigned int. Should sometimes be change to a 6 byte int. ****************************************************************************/ -void Field_datetime::store(const char *from,uint len,CHARSET_INFO *cs) +int Field_datetime::store(const char *from,uint len,CHARSET_INFO *cs) { longlong tmp=str_to_datetime(from,len,1); #ifdef WORDS_BIGENDIAN @@ -3139,26 +3320,32 @@ void Field_datetime::store(const char *from,uint len,CHARSET_INFO *cs) else #endif longlongstore(ptr,tmp); + return 0; } -void Field_datetime::store(double nr) +int Field_datetime::store(double nr) { + int error=0; if (nr < 0.0 || nr > 99991231235959.0) { nr=0.0; current_thd->cuted_fields++; + error = 1; } - Field_datetime::store((longlong) rint(nr)); + error |= Field_datetime::store((longlong) rint(nr)); + return error; } -void Field_datetime::store(longlong nr) +int Field_datetime::store(longlong nr) { + int error=0; if (nr < 0 || nr > LL(99991231235959)) { nr=0; current_thd->cuted_fields++; + error = 1; } else nr=fix_datetime(nr); @@ -3170,6 +3357,7 @@ void Field_datetime::store(longlong nr) else #endif longlongstore(ptr,nr); + return error; } void Field_datetime::store_time(TIME *ltime,timestamp_type type) @@ -3344,9 +3532,10 @@ void Field_datetime::sql_type(String &res) const /* Copy a string and fill with space */ -void Field_string::store(const char *from,uint length,CHARSET_INFO *cs) +int Field_string::store(const char *from,uint length,CHARSET_INFO *cs) { field_charset=cs; + int error=0; #ifdef USE_TIS620 if(!binary_flag) { ThNormalize((uchar *)ptr, field_length, (uchar *)from, length); @@ -3372,30 +3561,32 @@ void Field_string::store(const char *from,uint length,CHARSET_INFO *cs) if (!my_isspace(field_charset,*from)) { current_thd->cuted_fields++; + error=1; break; } } } } #endif /* USE_TIS620 */ + return error; } -void Field_string::store(double nr) +int Field_string::store(double nr) { char buff[MAX_FIELD_WIDTH],*end; int width=min(field_length,DBL_DIG+5); sprintf(buff,"%-*.*g",width,max(width-5,0),nr); end=strcend(buff,' '); - Field_string::store(buff,(uint) (end - buff), default_charset_info); + return Field_string::store(buff,(uint) (end - buff), default_charset_info); } -void Field_string::store(longlong nr) +int Field_string::store(longlong nr) { char buff[22]; char *end=longlong10_to_str(nr,buff,-10); - Field_string::store(buff,(uint) (end-buff), default_charset_info); + return Field_string::store(buff,(uint) (end-buff), default_charset_info); } @@ -3554,8 +3745,9 @@ uint Field_string::max_packed_col_length(uint max_length) ****************************************************************************/ -void Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs) +int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs) { + int error=0; field_charset=cs; #ifdef USE_TIS620 if(!binary_flag) @@ -3572,27 +3764,29 @@ void Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs) length=field_length; memcpy(ptr+2,from,field_length); current_thd->cuted_fields++; + error = 1; } #endif /* USE_TIS620 */ int2store(ptr,length); + return error; } -void Field_varstring::store(double nr) +int Field_varstring::store(double nr) { char buff[MAX_FIELD_WIDTH],*end; int width=min(field_length,DBL_DIG+5); sprintf(buff,"%-*.*g",width,max(width-5,0),nr); end=strcend(buff,' '); - Field_varstring::store(buff,(uint) (end - buff), default_charset_info); + return Field_varstring::store(buff,(uint) (end - buff), default_charset_info); } -void Field_varstring::store(longlong nr) +int Field_varstring::store(longlong nr) { char buff[22]; char *end=longlong10_to_str(nr,buff,-10); - Field_varstring::store(buff,(uint) (end-buff), default_charset_info); + return Field_varstring::store(buff,(uint) (end-buff), default_charset_info); } @@ -3877,7 +4071,7 @@ uint32 Field_blob::get_length(const char *pos) } -void Field_blob::store(const char *from,uint len,CHARSET_INFO *cs) +int Field_blob::store(const char *from,uint len,CHARSET_INFO *cs) { field_charset=cs; if (!len) @@ -3911,20 +4105,21 @@ void Field_blob::store(const char *from,uint len,CHARSET_INFO *cs) } bmove(ptr+packlength,(char*) &from,sizeof(char*)); } + return 0; } -void Field_blob::store(double nr) +int Field_blob::store(double nr) { value.set(nr); - Field_blob::store(value.ptr(),(uint) value.length(), default_charset_info); + return Field_blob::store(value.ptr(),(uint) value.length(), default_charset_info); } -void Field_blob::store(longlong nr) +int Field_blob::store(longlong nr) { value.set(nr); - Field_blob::store(value.ptr(), (uint) value.length(), default_charset_info); + return Field_blob::store(value.ptr(), (uint) value.length(), default_charset_info); } @@ -4071,7 +4266,7 @@ void Field_blob::get_key_image(char *buff,uint length, imagetype type) void Field_blob::set_key_image(char *buff,uint length) { length=uint2korr(buff); - Field_blob::store(buff+2,length, default_charset_info); + (void) Field_blob::store(buff+2,length, default_charset_info); } void Field_geom::get_key_image(char *buff,uint length, imagetype type) @@ -4392,8 +4587,9 @@ uint find_enum(TYPELIB *lib,const char *x, uint length) ** (if there isn't a empty value in the enum) */ -void Field_enum::store(const char *from,uint length,CHARSET_INFO *cs) +int Field_enum::store(const char *from,uint length,CHARSET_INFO *cs) { + int error=0; uint tmp=find_enum(typelib,from,length); if (!tmp) { @@ -4413,29 +4609,34 @@ void Field_enum::store(const char *from,uint length,CHARSET_INFO *cs) { tmp=0; current_thd->cuted_fields++; + error=1; } } else current_thd->cuted_fields++; } store_type((ulonglong) tmp); + return error; } -void Field_enum::store(double nr) +int Field_enum::store(double nr) { - Field_enum::store((longlong) nr); + return Field_enum::store((longlong) nr); } -void Field_enum::store(longlong nr) +int Field_enum::store(longlong nr) { + int error=0; if ((uint) nr > typelib->count || nr == 0) { current_thd->cuted_fields++; nr=0; + error=1; } store_type((ulonglong) (uint) nr); + return error; } @@ -4583,8 +4784,9 @@ ulonglong find_set(TYPELIB *lib,const char *x,uint length) } -void Field_set::store(const char *from,uint length,CHARSET_INFO *cs) +int Field_set::store(const char *from,uint length,CHARSET_INFO *cs) { + int error=0; ulonglong tmp=find_set(typelib,from,length); if (!tmp && length && length < 22) { @@ -4600,23 +4802,30 @@ void Field_set::store(const char *from,uint length,CHARSET_INFO *cs) tmp=strtoull(conv,&end,10); if (my_errno || end != conv+length || tmp > (ulonglong) (((longlong) 1 << typelib->count) - (longlong) 1)) + { tmp=0; + error=1; + } else current_thd->cuted_fields--; // Remove warning from find_set } store_type(tmp); + return error; } -void Field_set::store(longlong nr) +int Field_set::store(longlong nr) { + int error=0; if ((ulonglong) nr > (ulonglong) (((longlong) 1 << typelib->count) - (longlong) 1)) { nr&= (longlong) (((longlong) 1 << typelib->count) - (longlong) 1); current_thd->cuted_fields++; + error=1; } store_type((ulonglong) nr); + return error; } diff --git a/sql/field.h b/sql/field.h index 5bc463af48d..88187b2b7aa 100644 --- a/sql/field.h +++ b/sql/field.h @@ -60,9 +60,9 @@ public: utype unireg_check_arg, const char *field_name_arg, struct st_table *table_arg); virtual ~Field() {} - virtual void store(const char *to,uint length,CHARSET_INFO *cs)=0; - virtual void store(double nr)=0; - virtual void store(longlong nr)=0; + virtual int store(const char *to,uint length,CHARSET_INFO *cs)=0; + virtual int store(double nr)=0; + virtual int store(longlong nr)=0; virtual void store_time(TIME *ltime,timestamp_type t_type); virtual double val_real(void)=0; virtual longlong val_int(void)=0; @@ -281,9 +281,9 @@ public: enum ha_base_keytype key_type() const { return zerofill ? HA_KEYTYPE_BINARY : HA_KEYTYPE_NUM; } void reset(void); - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr); - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr); double val_real(void); longlong val_int(void); String *val_str(String*,String *); @@ -310,9 +310,9 @@ public: enum_field_types type() const { return FIELD_TYPE_TINY;} enum ha_base_keytype key_type() const { return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; } - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr); - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr); void reset(void) { ptr[0]=0; } double val_real(void); longlong val_int(void); @@ -339,9 +339,9 @@ public: enum_field_types type() const { return FIELD_TYPE_SHORT;} enum ha_base_keytype key_type() const { return unsigned_flag ? HA_KEYTYPE_USHORT_INT : HA_KEYTYPE_SHORT_INT;} - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr); - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr); void reset(void) { ptr[0]=ptr[1]=0; } double val_real(void); longlong val_int(void); @@ -368,9 +368,9 @@ public: enum_field_types type() const { return FIELD_TYPE_INT24;} enum ha_base_keytype key_type() const { return unsigned_flag ? HA_KEYTYPE_UINT24 : HA_KEYTYPE_INT24; } - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr); - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr); void reset(void) { ptr[0]=ptr[1]=ptr[2]=0; } double val_real(void); longlong val_int(void); @@ -402,9 +402,9 @@ public: enum_field_types type() const { return FIELD_TYPE_LONG;} enum ha_base_keytype key_type() const { return unsigned_flag ? HA_KEYTYPE_ULONG_INT : HA_KEYTYPE_LONG_INT; } - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr); - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr); void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; } double val_real(void); longlong val_int(void); @@ -438,9 +438,9 @@ public: enum_field_types type() const { return FIELD_TYPE_LONGLONG;} enum ha_base_keytype key_type() const { return unsigned_flag ? HA_KEYTYPE_ULONGLONG : HA_KEYTYPE_LONGLONG; } - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr); - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr); void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0; } double val_real(void); longlong val_int(void); @@ -465,9 +465,9 @@ public: {} enum_field_types type() const { return FIELD_TYPE_FLOAT;} enum ha_base_keytype key_type() const { return HA_KEYTYPE_FLOAT; } - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr); - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr); void reset(void) { bzero(ptr,sizeof(float)); } double val_real(void); longlong val_int(void); @@ -497,9 +497,9 @@ public: {} enum_field_types type() const { return FIELD_TYPE_DOUBLE;} enum ha_base_keytype key_type() const { return HA_KEYTYPE_DOUBLE; } - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr); - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr); void reset(void) { bzero(ptr,sizeof(double)); } double val_real(void); longlong val_int(void); @@ -523,9 +523,9 @@ public: unireg_check_arg, field_name_arg, table_arg, default_charset_info) {} enum_field_types type() const { return FIELD_TYPE_NULL;} - void store(const char *to, uint length, CHARSET_INFO *cs) { null[0]=1; } - void store(double nr) { null[0]=1; } - void store(longlong nr) { null[0]=1; } + int store(const char *to, uint length, CHARSET_INFO *cs) { null[0]=1; return 0; } + int store(double nr) { null[0]=1; return 0; } + int store(longlong nr) { null[0]=1; return 0; } void reset(void) {} double val_real(void) { return 0.0;} longlong val_int(void) { return 0;} @@ -547,9 +547,9 @@ public: enum Item_result result_type () const { return field_length == 8 || field_length == 14 ? INT_RESULT : STRING_RESULT; } enum_field_types type() const { return FIELD_TYPE_TIMESTAMP;} enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; } - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr); - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr); void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; } double val_real(void); longlong val_int(void); @@ -587,9 +587,9 @@ public: unireg_check_arg, field_name_arg, table_arg, 1, 1) {} enum_field_types type() const { return FIELD_TYPE_YEAR;} - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr); - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr); double val_real(void); longlong val_int(void); String *val_str(String*,String *); @@ -612,9 +612,9 @@ public: enum_field_types type() const { return FIELD_TYPE_DATE;} enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; } enum Item_result cmp_type () const { return INT_RESULT; } - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr); - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr); void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; } double val_real(void); longlong val_int(void); @@ -639,9 +639,9 @@ public: enum_field_types real_type() const { return FIELD_TYPE_NEWDATE; } enum ha_base_keytype key_type() const { return HA_KEYTYPE_UINT24; } enum Item_result cmp_type () const { return INT_RESULT; } - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr); - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr); void store_time(TIME *ltime,timestamp_type type); void reset(void) { ptr[0]=ptr[1]=ptr[2]=0; } double val_real(void); @@ -673,9 +673,9 @@ public: enum_field_types type() const { return FIELD_TYPE_TIME;} enum ha_base_keytype key_type() const { return HA_KEYTYPE_INT24; } enum Item_result cmp_type () const { return INT_RESULT; } - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr); - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr); void reset(void) { ptr[0]=ptr[1]=ptr[2]=0; } double val_real(void); longlong val_int(void); @@ -707,9 +707,9 @@ public: enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; } #endif enum Item_result cmp_type () const { return INT_RESULT; } - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr); - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr); void store_time(TIME *ltime,timestamp_type type); void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0; } double val_real(void); @@ -761,9 +761,9 @@ public: bool zero_pack() const { return 0; } bool binary() const { return binary_flag; } void reset(void) { bfill(ptr,field_length,' '); } - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr); - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr); double val_real(void); longlong val_int(void); String *val_str(String*,String *); @@ -813,9 +813,9 @@ public: void reset(void) { bzero(ptr,field_length+2); } uint32 pack_length() const { return (uint32) field_length+2; } uint32 key_length() const { return (uint32) field_length; } - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr); - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr); double val_real(void); longlong val_int(void); String *val_str(String*,String *); @@ -856,9 +856,9 @@ public: enum_field_types type() const { return FIELD_TYPE_BLOB;} enum ha_base_keytype key_type() const { return binary_flag ? HA_KEYTYPE_VARBINARY : HA_KEYTYPE_VARTEXT; } - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr); - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr); double val_real(void); longlong val_int(void); String *val_str(String*,String *); @@ -962,9 +962,9 @@ public: enum_field_types type() const { return FIELD_TYPE_STRING; } enum Item_result cmp_type () const { return INT_RESULT; } enum ha_base_keytype key_type() const; - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr); - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr); void reset() { bzero(ptr,packlength); } double val_real(void); longlong val_int(void); @@ -997,9 +997,9 @@ public: { flags=(flags & ~ENUM_FLAG) | SET_FLAG; } - void store(const char *to,uint length,CHARSET_INFO *charset); - void store(double nr) { Field_set::store((longlong) nr); } - void store(longlong nr); + int store(const char *to,uint length,CHARSET_INFO *charset); + int store(double nr) { return Field_set::store((longlong) nr); } + int store(longlong nr); virtual bool zero_pack() const { return 1; } String *val_str(String*,String *); void sql_type(String &str) const; diff --git a/sql/item.cc b/sql/item.cc index 81c5168b72d..f717b78f4bf 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -340,7 +340,7 @@ void Item_param::set_long_end() item_result_type = STRING_RESULT; }; -bool Item_param::save_in_field(Field *field) +int Item_param::save_in_field(Field *field) { if (null_value) return set_field_to_null(field); @@ -349,20 +349,17 @@ bool Item_param::save_in_field(Field *field) if (item_result_type == INT_RESULT) { longlong nr=val_int(); - field->store(nr); - return 0; + return (field->store(nr)) ? -1 : 0; } if (item_result_type == REAL_RESULT) { double nr=val(); - field->store(nr); - return 0; + return (field->store(nr)) ? -1 : 0; } String *result; CHARSET_INFO *cs=default_charset_info;//fix this result=val_str(&str_value); - field->store(result->ptr(),result->length(),cs); - return 0; + return (field->store(result->ptr(),result->length(),cs)) ? -1 : 0; } void Item_param::make_field(Send_field *tmp_field) @@ -615,7 +612,7 @@ void Item_field::save_org_in_field(Field *to) } } -bool Item_field::save_in_field(Field *to) +int Item_field::save_in_field(Field *to) { if (result_field->is_null()) { @@ -632,14 +629,15 @@ bool Item_field::save_in_field(Field *to) } -bool Item_null::save_in_field(Field *field) +int Item_null::save_in_field(Field *field) { return set_field_to_null(field); } -bool Item::save_in_field(Field *field) +int Item::save_in_field(Field *field) { + int error; if (result_type() == STRING_RESULT || result_type() == REAL_RESULT && field->result_type() == STRING_RESULT) @@ -652,7 +650,7 @@ bool Item::save_in_field(Field *field) if (null_value) return set_field_to_null(field); field->set_notnull(); - field->store(result->ptr(),result->length(),cs); + error=field->store(result->ptr(),result->length(),cs); str_value.set_quick(0, 0, cs); } else if (result_type() == REAL_RESULT) @@ -661,7 +659,7 @@ bool Item::save_in_field(Field *field) if (null_value) return set_field_to_null(field); field->set_notnull(); - field->store(nr); + error=field->store(nr); } else { @@ -669,12 +667,12 @@ bool Item::save_in_field(Field *field) if (null_value) return set_field_to_null(field); field->set_notnull(); - field->store(nr); + error=field->store(nr); } - return 0; + return (error) ? -1 : 0; } -bool Item_string::save_in_field(Field *field) +int Item_string::save_in_field(Field *field) { String *result; CHARSET_INFO *cs=field->binary()?default_charset_info:((Field_str*)field)->charset(); @@ -682,28 +680,25 @@ bool Item_string::save_in_field(Field *field) if (null_value) return set_field_to_null(field); field->set_notnull(); - field->store(result->ptr(),result->length(),cs); - return 0; + return (field->store(result->ptr(),result->length(),cs)) ? -1 : 0; } -bool Item_int::save_in_field(Field *field) +int Item_int::save_in_field(Field *field) { longlong nr=val_int(); if (null_value) return set_field_to_null(field); field->set_notnull(); - field->store(nr); - return 0; + return (field->store(nr)) ? -1 : 0; } -bool Item_real::save_in_field(Field *field) +int Item_real::save_in_field(Field *field) { double nr=val(); if (null_value) return set_field_to_null(field); field->set_notnull(); - field->store(nr); - return 0; + return (field->store(nr)) ? -1 : 0; } /**************************************************************************** @@ -751,20 +746,21 @@ longlong Item_varbinary::val_int() } -bool Item_varbinary::save_in_field(Field *field) +int Item_varbinary::save_in_field(Field *field) { + int error; CHARSET_INFO *cs=field->binary()?default_charset_info:((Field_str*)field)->charset(); field->set_notnull(); if (field->result_type() == STRING_RESULT) { - field->store(str_value.ptr(),str_value.length(),cs); + error=field->store(str_value.ptr(),str_value.length(),cs); } else { longlong nr=val_int(); - field->store(nr); + error=field->store(nr); } - return 0; + return (error) ? -1 : 0; } diff --git a/sql/item.h b/sql/item.h index 187e3903b84..a0b637b6030 100644 --- a/sql/item.h +++ b/sql/item.h @@ -53,7 +53,7 @@ public: void set_name(char* str,uint length=0); void init_make_field(Send_field *tmp_field,enum enum_field_types type); virtual bool fix_fields(THD *, struct st_table_list *, Item **); - virtual bool save_in_field(Field *field); + virtual int save_in_field(Field *field); virtual void save_org_in_field(Field *field) { (void) save_in_field(field); } virtual bool send(THD *thd, String *str); @@ -124,7 +124,7 @@ public: bool send(THD *thd, String *str_arg) { return result_field->send(thd,str_arg); } void make_field(Send_field *field); bool fix_fields(THD *, struct st_table_list *, Item **); - bool save_in_field(Field *field); + int save_in_field(Field *field); void save_org_in_field(Field *field); table_map used_tables() const; enum Item_result result_type () const @@ -149,7 +149,7 @@ public: longlong val_int(); String *val_str(String *str); void make_field(Send_field *field); - bool save_in_field(Field *field); + int save_in_field(Field *field); enum Item_result result_type () const { return STRING_RESULT; } bool send(THD *thd, String *str); @@ -178,7 +178,7 @@ public: longlong val_int(); String *val_str(String*); void make_field(Send_field *field); - bool save_in_field(Field *field); + int save_in_field(Field *field); void set_null(); void set_int(longlong i); void set_double(float i); @@ -215,7 +215,7 @@ public: double val() { return (double) value; } String *val_str(String*); void make_field(Send_field *field); - bool save_in_field(Field *field); + int save_in_field(Field *field); bool basic_const_item() const { return 1; } Item *new_item() { return new Item_int(name,value,max_length); } void print(String *str); @@ -254,7 +254,7 @@ public: max_length=length; } Item_real(double value_par) :value(value_par) {} - bool save_in_field(Field *field); + int save_in_field(Field *field); enum Type type() const { return REAL_ITEM; } double val() { return value; } longlong val_int() { return (longlong) (value+(value > 0 ? 0.5 : -0.5));} @@ -297,7 +297,7 @@ public: double val() { return atof(str_value.ptr()); } longlong val_int() { return strtoll(str_value.ptr(),(char**) 0,10); } String *val_str(String*) { return (String*) &str_value; } - bool save_in_field(Field *field); + int save_in_field(Field *field); void make_field(Send_field *field); enum Item_result result_type () const { return STRING_RESULT; } bool basic_const_item() const { return 1; } @@ -334,7 +334,7 @@ public: double val() { return (double) Item_varbinary::val_int(); } longlong val_int(); String *val_str(String*) { return &str_value; } - bool save_in_field(Field *field); + int save_in_field(Field *field); void make_field(Send_field *field); enum Item_result result_type () const { return INT_RESULT; } }; @@ -394,7 +394,7 @@ public: bool send(THD *thd, String *tmp) { return (*ref)->send(thd, tmp); } void make_field(Send_field *field) { (*ref)->make_field(field); } bool fix_fields(THD *, struct st_table_list *, Item **); - bool save_in_field(Field *field) { return (*ref)->save_in_field(field); } + int save_in_field(Field *field) { return (*ref)->save_in_field(field); } void save_org_in_field(Field *field) { (*ref)->save_org_in_field(field); } enum Item_result result_type () const { return (*ref)->result_type(); } table_map used_tables() const { return (*ref)->used_tables(); } @@ -413,7 +413,7 @@ class Item_int_with_ref :public Item_int public: Item_int_with_ref(longlong i, Item *ref_arg) :Item_int(i), ref(ref_arg) {} - bool save_in_field(Field *field) + int save_in_field(Field *field) { return ref->save_in_field(field); } diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 0fc9a1f0e4c..084688f7d3d 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -43,7 +43,8 @@ static bool convert_constant_item(Field *field, Item **item) { if ((*item)->const_item()) { - (*item)->save_in_field(field); + if ((*item)->save_in_field(field)) + return 0; if (!((*item)->null_value)) { Item *tmp=new Item_int_with_ref(field->val_int(), *item); diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index b5b9ed2931e..594049b3870 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1915,7 +1915,7 @@ outp: } -bool Item_func_conv_charset::fix_fields(THD *thd,struct st_table_list *tables) +bool Item_func_conv_charset::fix_fields(THD *thd,struct st_table_list *tables, Item **ref) { char buff[STACK_BUFF_ALLOC]; // Max argument in function binary=0; @@ -1948,7 +1948,7 @@ String *Item_func_set_collation::val_str(String *str) return str; } -bool Item_func_set_collation::fix_fields(THD *thd,struct st_table_list *tables) +bool Item_func_set_collation::fix_fields(THD *thd,struct st_table_list *tables, Item **ref) { char buff[STACK_BUFF_ALLOC]; // Max argument in function binary=0; diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 7f82cd3b5de..becb7981acd 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -489,7 +489,7 @@ class Item_func_conv_charset :public Item_str_func public: Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a) { conv_charset=cs; } - bool fix_fields(THD *thd,struct st_table_list *tables); + bool fix_fields(THD *thd,struct st_table_list *tables,Item **ref); String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "conv_charset"; } @@ -501,7 +501,7 @@ class Item_func_set_collation :public Item_str_func public: Item_func_set_collation(Item *a, CHARSET_INFO *cs) :Item_str_func(a) { set_collation=cs; } - bool fix_fields(THD *thd,struct st_table_list *tables); + bool fix_fields(THD *thd,struct st_table_list *tables, Item **ref); String *val_str(String *); void fix_length_and_dec() { diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 9bbb9e4fe19..297ff30bd9c 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -410,7 +410,7 @@ String *Item_date::val_str(String *str) } -bool Item_date::save_in_field(Field *field) +int Item_date::save_in_field(Field *field) { TIME ltime; timestamp_type t_type=TIMESTAMP_FULL; @@ -525,7 +525,7 @@ bool Item_func_now::get_date(TIME *res, } -bool Item_func_now::save_in_field(Field *to) +int Item_func_now::save_in_field(Field *to) { to->set_notnull(); to->store_time(<ime,TIMESTAMP_FULL); diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 53beb78e1d4..6d016df6eb7 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -228,7 +228,7 @@ public: double val() { return (double) val_int(); } const char *func_name() const { return "date"; } void fix_length_and_dec() { decimals=0; max_length=10; } - bool save_in_field(Field *to); + int save_in_field(Field *to); void make_field(Send_field *tmp_field) { init_make_field(tmp_field,FIELD_TYPE_DATE); @@ -311,7 +311,7 @@ public: enum Item_result result_type () const { return STRING_RESULT; } double val() { return (double) value; } longlong val_int() { return value; } - bool save_in_field(Field *to); + int save_in_field(Field *to); String *val_str(String *str) { str_value.set(buff,buff_length,default_charset_info); return &str_value; } const char *func_name() const { return "now"; } diff --git a/sql/opt_range.cc b/sql/opt_range.cc index ccee7192682..3764ff2d55c 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -1028,7 +1028,7 @@ get_mm_leaf(PARAM *param, Field *field, KEY_PART *key_part, field->cmp_type() != value->result_type()) DBUG_RETURN(0); - if (value->save_in_field(field)) + if (value->save_in_field(field) == 1) { if (type == Item_func::EQUAL_FUNC) { diff --git a/sql/sql_base.cc b/sql/sql_base.cc index b3ef043f582..6185b031c2e 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2113,7 +2113,7 @@ fill_record(List<Item> &fields,List<Item> &values) while ((field=(Item_field*) f++)) { value=v++; - if (value->save_in_field(field->field)) + if (value->save_in_field(field->field) == 1) DBUG_RETURN(1); } DBUG_RETURN(0); @@ -2131,7 +2131,7 @@ fill_record(Field **ptr,List<Item> &values) while ((field = *ptr++)) { value=v++; - if (value->save_in_field(field)) + if (value->save_in_field(field) == 1) DBUG_RETURN(1); } DBUG_RETURN(0); diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index a98012653b3..3668a817165 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -179,7 +179,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, Item *item; for (key_len=0 ; (item=it_ke++) ; key_part++) { - item->save_in_field(key_part->field); + (void) item->save_in_field(key_part->field); key_len+=key_part->store_length; } if (!(key= (byte*) sql_calloc(ALIGN_SIZE(key_len)))) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 76f78009e84..4e7dbd96127 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2478,7 +2478,7 @@ store_val_in_field(Field *field,Item *item) THD *thd=current_thd; ulong cuted_fields=thd->cuted_fields; thd->count_cuted_fields=1; - item->save_in_field(field); + (void) item->save_in_field(field); thd->count_cuted_fields=0; return cuted_fields != thd->cuted_fields; } diff --git a/sql/sql_select.h b/sql/sql_select.h index 3062747a08f..f651f069c13 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -338,7 +338,7 @@ public: {} bool copy() { - item->save_in_field(to_field); + (void) item->save_in_field(to_field); return err != 0; } const char *name() const { return "func"; } @@ -362,7 +362,7 @@ public: if (!inited) { inited=1; - item->save_in_field(to_field); + (void)item->save_in_field(to_field); } return err != 0; } diff --git a/sql/unireg.cc b/sql/unireg.cc index f2d8d6532a9..57a1407ea06 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -590,7 +590,7 @@ static bool make_empty_rec(File file,enum db_type table_type, if (field->def && (regfield->real_type() != FIELD_TYPE_YEAR || field->def->val_int() != 0)) - field->def->save_in_field(regfield); + (void) field->def->save_in_field(regfield); else if (regfield->real_type() == FIELD_TYPE_ENUM && (field->flags & NOT_NULL_FLAG)) { |