diff options
Diffstat (limited to 'sql/field.cc')
-rw-r--r-- | sql/field.cc | 884 |
1 files changed, 539 insertions, 345 deletions
diff --git a/sql/field.cc b/sql/field.cc index 462088d26a6..c9669c93c04 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -42,7 +42,7 @@ #endif /***************************************************************************** -** Instansiate templates and static variables + Instansiate templates and static variables *****************************************************************************/ #ifdef __GNUC__ @@ -50,70 +50,13 @@ template class List<create_field>; template class List_iterator<create_field>; #endif -struct st_decstr { - uint nr_length,nr_dec,sign,extra; - char sign_char; -}; - uchar Field_null::null[1]={1}; const char field_separator=','; /***************************************************************************** -** Static help functions + Static help functions *****************************************************************************/ - /* - Calculate length of number and its parts - Increment cuted_fields if wrong number - */ - -static bool -number_dec(CHARSET_INFO *cs, struct st_decstr *sdec, - const char *str, const char *end) -{ - sdec->sign=sdec->extra=0; - if (str == end) - { - current_thd->cuted_fields++; - sdec->nr_length=sdec->nr_dec=sdec->sign=0; - sdec->extra=1; // We must put one 0 before . - return 1; - } - - if (*str == '-' || *str == '+') /* sign */ - { - sdec->sign_char= *str; - sdec->sign=1; - str++; - } - const char *start=str; - while (str != end && my_isdigit(cs,*str)) - str++; - if (!(sdec->nr_length=(uint) (str-start))) - sdec->extra=1; // We must put one 0 before . - start=str; - if (str != end && *str == '.') - { - str++; - start=str; - while (str != end && my_isdigit(cs,*str)) - str++; - } - sdec->nr_dec=(uint) (str-start); - if (current_thd->count_cuted_fields) - { - while (str != end && my_isspace(cs,*str)) - str++; /* purecov: inspected */ - if (str != end) - { - current_thd->cuted_fields++; - return 1; - } - } - return 0; -} - - void Field_num::prepend_zeros(String *value) { int diff; @@ -128,8 +71,8 @@ void Field_num::prepend_zeros(String *value) } /* -** Test if given number is a int (or a fixed format float with .000) -** This is only used to give warnings in ALTER TABLE or LOAD DATA... + Test if given number is a int (or a fixed format float with .000) + This is only used to give warnings in ALTER TABLE or LOAD DATA... */ bool test_if_int(const char *str,int length) @@ -143,7 +86,7 @@ bool test_if_int(const char *str,int length) str++; if (str == end) return 0; // Error: Empty string - for ( ; str != end ; str++) + for (; str != end ; str++) { if (!my_isdigit(system_charset_info,*str)) { @@ -207,7 +150,7 @@ static bool test_if_real(const char *str,int length) length--; str++; } } - for ( ; length ; length--, str++) + for (; length ; length--, str++) { // Allow end space if (!my_isspace(system_charset_info,*str)) return 0; @@ -262,7 +205,7 @@ bool Field::send(THD *thd, String *packet) String tmp(buff,sizeof(buff),default_charset_info); val_str(&tmp,&tmp); CONVERT *convert; - if ((convert=thd->convert_set)) + if ((convert=thd->variables.convert_set)) return convert->store(packet,tmp.ptr(),tmp.length()); return net_store_data(packet,tmp.ptr(),tmp.length()); } @@ -279,6 +222,7 @@ void Field_num::add_zerofill_and_unsigned(String &res) const void Field_num::make_field(Send_field *field) { + /* table_cache_key is not set for temp tables */ field->db_name=table->table_cache_key ? table->table_cache_key : ""; field->org_table_name=table->real_name; field->table_name=table_name; @@ -292,6 +236,7 @@ void Field_num::make_field(Send_field *field) void Field_str::make_field(Send_field *field) { + /* table_cache_key is not set for temp tables */ field->db_name=table->table_cache_key ? table->table_cache_key : ""; field->org_table_name=table->real_name; field->table_name=table_name; @@ -363,9 +308,10 @@ void Field::store_time(TIME *ltime,timestamp_type type) store(buff,19,default_charset_info); break; case TIMESTAMP_TIME: - sprintf(buff, "%02d:%02d:%02d", - ltime->hour,ltime->minute,ltime->second); - store(buff,(uint) strlen(buff),default_charset_info); + { + ulong length= my_sprintf(buff, (buff, "%02d:%02d:%02d", + ltime->hour,ltime->minute,ltime->second)); + store(buff,(uint) length, default_charset_info); break; } } @@ -377,8 +323,8 @@ bool Field::optimize_range(uint idx) } /**************************************************************************** -** Functions for the Field_decimal class -** This is an unpacked number. + Functions for the Field_decimal class + This is an number stored as a pre-space (or pre-zero) string ****************************************************************************/ void @@ -391,6 +337,8 @@ void Field_decimal::overflow(bool negative) { uint len=field_length; char *to=ptr, filler= '9'; + + current_thd->cuted_fields++; if (negative) { if (!unsigned_flag) @@ -424,114 +372,362 @@ void Field_decimal::overflow(bool negative) } -int 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; - char fyllchar; - const char *end=from+len; - struct st_decstr decstr; - bool error; + const char *end= from+len; + /* The pointer where the field value starts (i.e., "where to write") */ + char *to=ptr; + uint tmp_dec, tmp_uint; + /* + The sign of the number : will be 0 (means positive but sign not + specified), '+' or '-' + */ + char sign_char=0; + /* The pointers where prezeros start and stop */ + const char *pre_zeros_from, *pre_zeros_end; + /* The pointers where digits at the left of '.' start and stop */ + const char *int_digits_from, *int_digits_end; + /* The pointers where digits at the right of '.' start and stop */ + const char *frac_digits_from, *frac_digits_end; + /* The sign of the exponent : will be 0 (means no exponent), '+' or '-' */ + char expo_sign_char=0; + uint exponent=0; // value of the exponent + /* + Pointers used when digits move from the left of the '.' to the + right of the '.' (explained below) + */ + const char *int_digits_tail_from; + /* Number of 0 that need to be added at the left of the '.' (1E3: 3 zeros) */ + uint int_digits_added_zeros; + /* + Pointer used when digits move from the right of the '.' to the left + of the '.' + */ + const char *frac_digits_head_end; + /* Number of 0 that need to be added at the right of the '.' (for 1E-3) */ + uint frac_digits_added_zeros; + char *pos,*tmp_left_pos,*tmp_right_pos; + /* Pointers that are used as limits (begin and end of the field buffer) */ + char *left_wall,*right_wall; + char tmp_char; + /* + To remember if current_thd->cuted_fields has already been incremented, + to do that only once + */ + bool is_cuted_fields_incr=0; + + LINT_INIT(int_digits_tail_from); + LINT_INIT(int_digits_added_zeros); + LINT_INIT(frac_digits_head_end); + LINT_INIT(frac_digits_added_zeros); + + /* + There are three steps in this function : + - parse the input string + - modify the position of digits around the decimal dot '.' + according to the exponent value (if specified) + - write the formatted number + */ + + if ((tmp_dec=dec)) + tmp_dec++; - if ((tmp_dec= dec)) - tmp_dec++; // Calculate pos of '.' + /* skip pre-space */ while (from != end && my_isspace(system_charset_info,*from)) from++; - if (zerofill) - { - fyllchar = '0'; - if (from != end) - while (*from == '0' && from != end-1) // Skip prezero - from++; - } - else - fyllchar=' '; - error=number_dec(system_charset_info,&decstr,from,end); - if (decstr.sign) + if (from == end) { - from++; - if (unsigned_flag) // No sign with zerofill - { - if (decstr.sign_char == '+') // just remove "+" - decstr.sign= 0; - else + current_thd->cuted_fields++; + is_cuted_fields_incr=1; + } + else if (*from == '+' || *from == '-') // Found some sign ? + { + sign_char= *from++; + /* + We allow "+" for unsigned decimal unless defined different + Both options allowed as one may wish not to have "+" for unsigned numbers + because of data processing issues + */ + if (unsigned_flag) + { + if (sign_char=='-') { - if (!error) - current_thd->cuted_fields++; - Field_decimal::overflow(1); - return 1; + Field_decimal::overflow(1); + return 1; } + /* + Defining this will not store "+" for unsigned decimal type even if + it is passed in numeric string. This will make some tests to fail + */ +#ifdef DONT_ALLOW_UNSIGNED_PLUS + else + sign_char=0; +#endif } } + + pre_zeros_from= from; + for (; from!=end && *from == '0'; from++) ; // Read prezeros + pre_zeros_end=int_digits_from=from; + /* Read non zero digits at the left of '.'*/ + for (; from != end && my_isdigit(system_charset_info, *from) ; from++) ; + int_digits_end=from; + if (from!=end && *from == '.') // Some '.' ? + from++; + frac_digits_from= from; + /* Read digits at the right of '.' */ + for (;from!=end && my_isdigit(system_charset_info, (*from); from++) ; + frac_digits_end=from; + // Some exponentiation symbol ? + if (from != end && (*from == 'e' || *from == 'E')) + { + from++; + if (from != end && (*from == '+' || *from == '-')) // Some exponent sign ? + expo_sign_char= *from++; + else + expo_sign_char= '+'; + /* + Read digits of the exponent and compute its value + 'exponent' overflow (e.g. if 1E10000000000000000) is not a problem + (the value of the field will be overflow anyway, or 0 anyway, + it does not change anything if the exponent is 2^32 or more + */ + for (;from!=end && my_isdigit(system_charset_info, (*from)); from++) + exponent=10*exponent+(*from-'0'); + } + /* - ** Remove pre-zeros if too big number + We only have to generate warnings if count_cuted_fields is set. + This is to avoid extra checks of the number when they are not needed. + Even if this flag is not set, it's ok to increment warnings, if + it makes the code easer to read. */ - for (i= (int) (decstr.nr_length+decstr.extra -(field_length-tmp_dec)+ - decstr.sign) ; - i > 0 ; - i--) + + if (current_thd->count_cuted_fields) { - if (*from == '0') + for (;from != end && isspace(*from); from++) ; // Read end spaces + if (from != end) // If still something left, warn { - from++; - decstr.nr_length--; - continue; + current_thd->cuted_fields++; + is_cuted_fields_incr=1; } - if (decstr.sign && decstr.sign_char == '+' && i == 1) - { // Remove pre '+' - decstr.sign=0; - break; + } + + /* + Now "move" digits around the decimal dot according to the exponent value, + and add necessary zeros. + Examples : + - 1E+3 : needs 3 more zeros at the left of '.' (int_digits_added_zeros=3) + - 1E-3 : '1' moves at the right of '.', and 2 more zeros are needed + between '.' and '1' + - 1234.5E-3 : '234' moves at the right of '.' + These moves are implemented with pointers which point at the begin + and end of each moved segment. Examples : + - 1234.5E-3 : before the code below is executed, the int_digits part is + from '1' to '4' and the frac_digits part from '5' to '5'. After the code + below, the int_digits part is from '1' to '1', the frac_digits_head + part is from '2' to '4', and the frac_digits part from '5' to '5'. + - 1234.5E3 : before the code below is executed, the int_digits part is + from '1' to '4' and the frac_digits part from '5' to '5'. After the code + below, the int_digits part is from '1' to '4', the int_digits_tail + part is from '5' to '5', the frac_digits part is empty, and + int_digits_added_zeros=2 (to make 1234500). + */ + + if (!expo_sign_char) + tmp_uint=tmp_dec+(uint)(int_digits_end-int_digits_from); + else if (expo_sign_char == '-') + { + tmp_uint=min(exponent,(uint)(int_digits_end-int_digits_from)); + frac_digits_added_zeros=exponent-tmp_uint; + int_digits_end -= tmp_uint; + frac_digits_head_end=int_digits_end+tmp_uint; + tmp_uint=tmp_dec+(uint)(int_digits_end-int_digits_from); + } + else // (expo_sign_char=='+') + { + tmp_uint=min(exponent,(uint)(frac_digits_end-frac_digits_from)); + int_digits_added_zeros=exponent-tmp_uint; + int_digits_tail_from=frac_digits_from; + frac_digits_from=frac_digits_from+tmp_uint; + /* + We "eat" the heading zeros of the + int_digits.int_digits_tail.int_digits_added_zeros concatenation + (for example 0.003e3 must become 3 and not 0003) + */ + if (int_digits_from == int_digits_end) + { + /* + There was nothing in the int_digits part, so continue + eating int_digits_tail zeros + */ + for (; int_digits_tail_from != frac_digits_from && + *int_digits_tail_from == '0'; int_digits_tail_from++) ; + if (int_digits_tail_from == frac_digits_from) + { + // there were only zeros in int_digits_tail too + int_digits_added_zeros=0; + } } - current_thd->cuted_fields++; + tmp_uint=(tmp_dec+(uint)(int_digits_end-int_digits_from) + +(uint)(frac_digits_from-int_digits_tail_from)+ + int_digits_added_zeros); + } + + /* + Now write the formated number + + First the digits of the int_% parts. + Do we have enough room to write these digits ? + If the sign is defined and '-', we need one position for it + */ + + if (field_length < tmp_uint + (int) (sign_char == '-')) + { // too big number, change to max or min number - Field_decimal::overflow(decstr.sign && decstr.sign_char == '-'); + Field_decimal::overflow(sign_char == '-'); return 1; } - char *to=ptr; - for (i=(int) (field_length-tmp_dec-decstr.nr_length-decstr.extra - decstr.sign) ; - i-- > 0 ;) - *to++ = fyllchar; - if (decstr.sign) - *to++= decstr.sign_char; - if (decstr.extra) - *to++ = '0'; - for (i=(int) decstr.nr_length ; i-- > 0 ; ) - *to++ = *from++; - if (tmp_dec--) - { - *to++ ='.'; - if (decstr.nr_dec) from++; // Skip '.' - for (i=(int) min(decstr.nr_dec,tmp_dec) ; i-- > 0 ; ) *to++ = *from++; - for (i=(int) (tmp_dec-min(decstr.nr_dec,tmp_dec)) ; i-- > 0 ; ) *to++ = '0'; + + /* + Tmp_left_pos is the position where the leftmost digit of + the int_% parts will be written + */ + tmp_left_pos=pos=to+(uint)(field_length-tmp_uint); + + // Write all digits of the int_% parts + while (int_digits_from != int_digits_end) + *pos++ = *int_digits_from++ ; + + if (expo_sign_char == '+') + { + while (int_digits_tail_from != frac_digits_from) + *pos++= *int_digits_tail_from++; + while (int_digits_added_zeros-- >0) + *pos++= '0'; } + /* + Note the position where the rightmost digit of the int_% parts has been + written (this is to later check if the int_% parts contained nothing, + meaning an extra 0 is needed). + */ + tmp_right_pos=pos; /* - ** Check for incorrect string if in batch mode (ALTER TABLE/LOAD DATA...) + Step back to the position of the leftmost digit of the int_% parts, + to write sign and fill with zeros or blanks or prezeros. */ - if (!error && current_thd->count_cuted_fields && from != end) - { // Check if number was cuted - for (; from != end ; from++) + pos=tmp_left_pos-1; + if (zerofill) + { + left_wall=to-1; + while (pos != left_wall) // Fill with zeros + *pos--='0'; + } + else + { + left_wall=to+(sign_char != 0)-1; + if (!expo_sign_char) // If exponent was specified, ignore prezeros + { + for (;pos != left_wall && pre_zeros_from !=pre_zeros_end; + pre_zeros_from++) + *pos--= '0'; + } + if (pos == tmp_right_pos-1) + *pos--= '0'; // no 0 has ever been written, so write one + left_wall= to-1; + if (sign_char && pos != left_wall) + { + /* Write sign if possible (it is if sign is '-') */ + *pos--= sign_char; + } + while (pos != left_wall) + *pos--=' '; //fill with blanks + } + + if (tmp_dec) // This field has decimals + { + /* + Write digits of the frac_% parts ; + Depending on current_thd->count_cutted_fields, we may also want + to know if some non-zero tail of these parts will + be truncated (for example, 0.002->0.00 will generate a warning, + while 0.000->0.00 will not) + (and 0E1000000000 will not, while 1E-1000000000 will) + */ + + pos=to+(uint)(field_length-tmp_dec); // Calculate post to '.' + *pos++='.'; + right_wall=to+field_length; + + if (expo_sign_char == '-') { - if (*from != '0') + while (frac_digits_added_zeros-- > 0) { - if (!my_isspace(system_charset_info,*from)) // Space is ok - current_thd->cuted_fields++; - break; + if (pos == right_wall) + { + if (current_thd->count_cuted_fields && !is_cuted_fields_incr) + break; // Go on below to see if we lose non zero digits + return 0; + } + *pos++='0'; + } + while (int_digits_end != frac_digits_head_end) + { + tmp_char= *int_digits_end++; + if (pos == right_wall) + { + if (tmp_char != '0') // Losing a non zero digit ? + { + if (!is_cuted_fields_incr) + current_thd->cuted_fields++; + return 0; + } + continue; + } + *pos++= tmp_char; + } + } + + for (;frac_digits_from!=frac_digits_end;) + { + tmp_char= *frac_digits_from++; + if (pos == right_wall) + { + if (tmp_char != '0') // Losing a non zero digit ? + { + if (!is_cuted_fields_incr) + current_thd->cuted_fields++; + return 0; + } + continue; } + *pos++= tmp_char; } + + while (pos != right_wall) + *pos++='0'; // Fill with zeros at right of '.' } - return (error) ? 1 : 0; + return 0; } -int Field_decimal::store(double nr) +int Field_decimal::store(double nr) { if (unsigned_flag && nr < 0) { overflow(1); - current_thd->cuted_fields++; return 1; } + +#ifdef HAVE_FINITE + if (!finite(nr)) // Handle infinity as special case + { + overflow(nr < 0.0); + return 1; + } +#endif + reg4 uint i,length; char fyllchar,*to; char buff[320]; @@ -548,7 +744,6 @@ int Field_decimal::store(double nr) if (length > field_length) { overflow(nr < 0.0); - current_thd->cuted_fields++; return 1; } else @@ -562,12 +757,11 @@ int Field_decimal::store(double nr) } -int Field_decimal::store(longlong nr) +int Field_decimal::store(longlong nr) { if (unsigned_flag && nr < 0) { overflow(1); - current_thd->cuted_fields++; return 1; } char buff[22]; @@ -577,7 +771,6 @@ int Field_decimal::store(longlong nr) if (length > int_part) { overflow(test(nr < 0L)); /* purecov: inspected */ - current_thd->cuted_fields++; /* purecov: inspected */ return 1; } else @@ -673,8 +866,8 @@ void Field_decimal::sort_string(char *to,uint length) char *str,*end; for (str=ptr,end=ptr+length; str != end && - ((my_isspace(system_charset_info,*str) || *str == '+' || *str == '0')) ; - + ((my_isspace(system_charset_info,*str) || *str == '+' || + *str == '0')) ; str++) *to++=' '; if (str == end) @@ -693,6 +886,7 @@ void Field_decimal::sort_string(char *to,uint length) else memcpy(to,str,(uint) (end-str)); } + void Field_decimal::sql_type(String &res) const { uint tmp=field_length; @@ -709,11 +903,11 @@ void Field_decimal::sql_type(String &res) const ** tiny int ****************************************************************************/ -int 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; + int error= 0; if (unsigned_flag) { @@ -721,18 +915,18 @@ int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs) { tmp=0; /* purecov: inspected */ current_thd->cuted_fields++; /* purecov: inspected */ - error = 1; + error= 1; } else if (tmp > 255) { tmp= 255; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len)) { current_thd->cuted_fields++; - error = 1; + error= 1; } } else @@ -741,18 +935,18 @@ int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs) { tmp= -128; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (tmp >= 128) { tmp= 127; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len)) { current_thd->cuted_fields++; - error = 1; + error= 1; } } ptr[0]= (char) tmp; @@ -760,9 +954,9 @@ int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs) } -int Field_tiny::store(double nr) +int Field_tiny::store(double nr) { - int error=0; + int error= 0; nr=rint(nr); if (unsigned_flag) { @@ -770,13 +964,13 @@ int Field_tiny::store(double nr) { *ptr=0; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr > 255.0) { *ptr=(char) 255; current_thd->cuted_fields++; - error = 1; + error= 1; } else *ptr=(char) nr; @@ -787,13 +981,13 @@ int Field_tiny::store(double nr) { *ptr= (char) -128; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr > 127.0) { *ptr=127; current_thd->cuted_fields++; - error = 1; + error= 1; } else *ptr=(char) nr; @@ -801,22 +995,22 @@ int Field_tiny::store(double nr) return error; } -int Field_tiny::store(longlong nr) +int Field_tiny::store(longlong nr) { - int error=0; + int error= 0; if (unsigned_flag) { if (nr < 0L) { *ptr=0; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr > 255L) { *ptr= (char) 255; current_thd->cuted_fields++; - error = 1; + error= 1; } else *ptr=(char) nr; @@ -827,13 +1021,13 @@ int Field_tiny::store(longlong nr) { *ptr= (char) -128; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr > 127L) { *ptr=127; current_thd->cuted_fields++; - error = 1; + error= 1; } else *ptr=(char) nr; @@ -904,29 +1098,29 @@ 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. -int 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; + int error= 0; if (unsigned_flag) { if (tmp < 0) { tmp=0; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (tmp > (uint16) ~0) { tmp=(uint16) ~0; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len)) { current_thd->cuted_fields++; - error = 1; + error= 1; } } else @@ -935,18 +1129,18 @@ int Field_short::store(const char *from,uint len,CHARSET_INFO *cs) { tmp= INT_MIN16; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (tmp > INT_MAX16) { tmp=INT_MAX16; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len)) { current_thd->cuted_fields++; - error = 1; + error= 1; } } #ifdef WORDS_BIGENDIAN @@ -961,9 +1155,9 @@ int Field_short::store(const char *from,uint len,CHARSET_INFO *cs) } -int Field_short::store(double nr) +int Field_short::store(double nr) { - int error=0; + int error= 0; int16 res; nr=rint(nr); if (unsigned_flag) @@ -972,13 +1166,13 @@ int Field_short::store(double nr) { res=0; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr > (double) (uint16) ~0) { res=(int16) (uint16) ~0; current_thd->cuted_fields++; - error = 1; + error= 1; } else res=(int16) (uint16) nr; @@ -989,13 +1183,13 @@ int Field_short::store(double nr) { res=INT_MIN16; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr > (double) INT_MAX16) { res=INT_MAX16; current_thd->cuted_fields++; - error = 1; + error= 1; } else res=(int16) nr; @@ -1011,9 +1205,9 @@ int Field_short::store(double nr) return error; } -int Field_short::store(longlong nr) +int Field_short::store(longlong nr) { - int error=0; + int error= 0; int16 res; if (unsigned_flag) { @@ -1021,13 +1215,13 @@ int Field_short::store(longlong nr) { res=0; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr > (longlong) (uint16) ~0) { res=(int16) (uint16) ~0; current_thd->cuted_fields++; - error = 1; + error= 1; } else res=(int16) (uint16) nr; @@ -1038,13 +1232,13 @@ int Field_short::store(longlong nr) { res=INT_MIN16; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr > INT_MAX16) { res=INT_MAX16; current_thd->cuted_fields++; - error = 1; + error= 1; } else res=(int16) nr; @@ -1168,11 +1362,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. -int 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; + int error= 0; if (unsigned_flag) { @@ -1180,18 +1374,18 @@ int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs) { tmp=0; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (tmp >= (long) (1L << 24)) { tmp=(long) (1L << 24)-1L; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len)) { current_thd->cuted_fields++; - error = 1; + error= 1; } } else @@ -1200,18 +1394,18 @@ int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs) { tmp= INT_MIN24; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (tmp > INT_MAX24) { tmp=INT_MAX24; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (current_thd->count_cuted_fields && !test_if_int(from,len)) { current_thd->cuted_fields++; - error = 1; + error= 1; } } @@ -1220,9 +1414,9 @@ int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs) } -int Field_medium::store(double nr) +int Field_medium::store(double nr) { - int error=0; + int error= 0; nr=rint(nr); if (unsigned_flag) { @@ -1230,14 +1424,14 @@ int Field_medium::store(double nr) { int3store(ptr,0); current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr >= (double) (long) (1L << 24)) { uint32 tmp=(uint32) (1L << 24)-1L; int3store(ptr,tmp); current_thd->cuted_fields++; - error = 1; + error= 1; } else int3store(ptr,(uint32) nr); @@ -1249,14 +1443,14 @@ int Field_medium::store(double nr) long tmp=(long) INT_MIN24; int3store(ptr,tmp); current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr > (double) INT_MAX24) { long tmp=(long) INT_MAX24; int3store(ptr,tmp); current_thd->cuted_fields++; - error = 1; + error= 1; } else int3store(ptr,(long) nr); @@ -1264,23 +1458,23 @@ int Field_medium::store(double nr) return error; } -int Field_medium::store(longlong nr) +int Field_medium::store(longlong nr) { - int error=0; + int error= 0; if (unsigned_flag) { if (nr < 0L) { int3store(ptr,0); current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr >= (longlong) (long) (1L << 24)) { long tmp=(long) (1L << 24)-1L;; int3store(ptr,tmp); current_thd->cuted_fields++; - error = 1; + error= 1; } else int3store(ptr,(uint32) nr); @@ -1292,14 +1486,14 @@ int Field_medium::store(longlong nr) long tmp=(long) INT_MIN24; int3store(ptr,tmp); current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr > (longlong) INT_MAX24) { long tmp=(long) INT_MAX24; int3store(ptr,tmp); current_thd->cuted_fields++; - error = 1; + error= 1; } else int3store(ptr,(long) nr); @@ -1377,14 +1571,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. -int 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; + int error= 0; String tmp_str(from,len,default_charset_info); errno=0; if (unsigned_flag) @@ -1393,7 +1587,7 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs) { tmp=0; // Set negative to 0 errno=ERANGE; - error = 1; + error= 1; } else tmp=(long) strtoul(tmp_str.c_ptr(),NULL,10); @@ -1403,7 +1597,7 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs) if (errno || current_thd->count_cuted_fields && !test_if_int(from,len)) { current_thd->cuted_fields++; - error = 1; + error= 1; } #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) @@ -1417,9 +1611,9 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs) } -int Field_long::store(double nr) +int Field_long::store(double nr) { - int error=0; + int error= 0; int32 res; nr=rint(nr); if (unsigned_flag) @@ -1428,13 +1622,13 @@ int Field_long::store(double nr) { res=0; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr > (double) (ulong) ~0L) { res=(int32) (uint32) ~0L; current_thd->cuted_fields++; - error = 1; + error= 1; } else res=(int32) (ulong) nr; @@ -1445,13 +1639,13 @@ int Field_long::store(double nr) { res=(int32) INT_MIN32; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr > (double) INT_MAX32) { res=(int32) INT_MAX32; current_thd->cuted_fields++; - error = 1; + error= 1; } else res=(int32) nr; @@ -1468,9 +1662,9 @@ int Field_long::store(double nr) } -int Field_long::store(longlong nr) +int Field_long::store(longlong nr) { - int error=0; + int error= 0; int32 res; if (unsigned_flag) { @@ -1478,13 +1672,13 @@ int Field_long::store(longlong nr) { res=0; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr >= (LL(1) << 32)) { res=(int32) (uint32) ~0L; current_thd->cuted_fields++; - error = 1; + error= 1; } else res=(int32) (uint32) nr; @@ -1495,13 +1689,13 @@ int Field_long::store(longlong nr) { res=(int32) INT_MIN32; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr > (longlong) INT_MAX32) { res=(int32) INT_MAX32; current_thd->cuted_fields++; - error = 1; + error= 1; } else res=(int32) nr; @@ -1623,7 +1817,7 @@ void Field_long::sql_type(String &res) const ** longlong int ****************************************************************************/ -int 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 @@ -1631,7 +1825,7 @@ int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs) } longlong tmp; String tmp_str(from,len,default_charset_info); - int error=0; + int error= 0; errno=0; if (unsigned_flag) { @@ -1639,7 +1833,7 @@ int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs) { tmp=0; // Set negative to 0 errno=ERANGE; - error = 1; + error= 1; } else tmp=(longlong) strtoull(tmp_str.c_ptr(),NULL,10); @@ -1649,7 +1843,7 @@ int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs) if (errno || current_thd->count_cuted_fields && !test_if_int(from,len)) { current_thd->cuted_fields++; - error = 1; + error= 1; } #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) @@ -1663,9 +1857,9 @@ int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs) } -int Field_longlong::store(double nr) +int Field_longlong::store(double nr) { - int error=0; + int error= 0; longlong res; nr=rint(nr); if (unsigned_flag) @@ -1674,13 +1868,13 @@ int Field_longlong::store(double nr) { res=0; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr >= (double) ~ (ulonglong) 0) { res= ~(longlong) 0; current_thd->cuted_fields++; - error = 1; + error= 1; } else res=(longlong) (ulonglong) nr; @@ -1691,13 +1885,13 @@ int Field_longlong::store(double nr) { res=(longlong) LONGLONG_MIN; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr >= (double) LONGLONG_MAX) { res=(longlong) LONGLONG_MAX; current_thd->cuted_fields++; - error = 1; + error= 1; } else res=(longlong) nr; @@ -1714,7 +1908,7 @@ int Field_longlong::store(double nr) } -int Field_longlong::store(longlong nr) +int Field_longlong::store(longlong nr) { #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) @@ -1843,7 +2037,7 @@ void Field_longlong::sql_type(String &res) const ** single precision float ****************************************************************************/ -int 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; @@ -1857,29 +2051,29 @@ int Field_float::store(const char *from,uint len,CHARSET_INFO *cs) } -int Field_float::store(double nr) +int Field_float::store(double nr) { float j; - int error=0; + 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; + error= 1; } if (nr < -FLT_MAX) { j= -FLT_MAX; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr > FLT_MAX) { j=FLT_MAX; current_thd->cuted_fields++; - error = 1; + error= 1; } else j= (float) nr; @@ -1895,15 +2089,15 @@ int Field_float::store(double nr) } -int Field_float::store(longlong nr) +int Field_float::store(longlong nr) { - int error=0; + int error= 0; float j= (float) nr; if (unsigned_flag && j < 0) { current_thd->cuted_fields++; j=0; - error = 1; + error= 1; } #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) @@ -2105,22 +2299,22 @@ void Field_float::sql_type(String &res) const ** double precision floating point numbers ****************************************************************************/ -int 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; + 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; + error= 1; } if (unsigned_flag && j < 0) { current_thd->cuted_fields++; j=0; - error = 1; + error= 1; } #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) @@ -2134,16 +2328,16 @@ int Field_double::store(const char *from,uint len,CHARSET_INFO *cs) } -int Field_double::store(double nr) +int Field_double::store(double nr) { - int error=0; + 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; + error= 1; } #ifdef WORDS_BIGENDIAN if (table->db_low_byte_first) @@ -2157,14 +2351,14 @@ int Field_double::store(double nr) } -int Field_double::store(longlong nr) +int Field_double::store(longlong nr) { double j= (double) nr; - int error=0; + int error= 0; if (unsigned_flag && j < 0) { current_thd->cuted_fields++; - error = 1; + error= 1; j=0; } #ifdef WORDS_BIGENDIAN @@ -2373,7 +2567,7 @@ Field_timestamp::Field_timestamp(char *ptr_arg, uint32 len_arg, } -int 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 @@ -2387,7 +2581,7 @@ int Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs) 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) @@ -2416,16 +2610,16 @@ void Field_timestamp::fill_and_store(char *from,uint len) } -int Field_timestamp::store(double nr) +int Field_timestamp::store(double nr) { - int error=0; + int error= 0; if (nr < 0 || nr > 99991231235959.0) { - nr=0; // Avoid overflow on buff + nr= 0; // Avoid overflow on buff current_thd->cuted_fields++; - error = 1; + error= 1; } - error |= Field_timestamp::store((longlong) rint(nr)); + error|= Field_timestamp::store((longlong) rint(nr)); return error; } @@ -2467,7 +2661,7 @@ static longlong fix_datetime(longlong nr) } -int Field_timestamp::store(longlong nr) +int Field_timestamp::store(longlong nr) { TIME l_time; time_t timestamp; @@ -2717,15 +2911,15 @@ void Field_timestamp::set_time() ** Stored as a 3 byte unsigned int ****************************************************************************/ -int 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; + int error= 0; if (str_to_time(from,len,<ime)) { tmp=0L; - error = 1; + error= 1; } else { @@ -2736,7 +2930,7 @@ int Field_time::store(const char *from,uint len,CHARSET_INFO *cs) { tmp=8385959; current_thd->cuted_fields++; - error = 1; + error= 1; } } if (ltime.neg) @@ -2746,21 +2940,21 @@ int Field_time::store(const char *from,uint len,CHARSET_INFO *cs) } -int Field_time::store(double nr) +int Field_time::store(double nr) { long tmp; - int error=0; + int error= 0; if (nr > 8385959.0) { tmp=8385959L; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr < -8385959.0) { tmp= -8385959L; current_thd->cuted_fields++; - error = 1; + error= 1; } else { @@ -2771,7 +2965,7 @@ int Field_time::store(double nr) { tmp=0; current_thd->cuted_fields++; - error = 1; + error= 1; } } int3store(ptr,tmp); @@ -2779,21 +2973,21 @@ int Field_time::store(double nr) } -int Field_time::store(longlong nr) +int Field_time::store(longlong nr) { long tmp; - int error=0; + int error= 0; if (nr > (longlong) 8385959L) { tmp=8385959L; current_thd->cuted_fields++; - error = 1; + error= 1; } else if (nr < (longlong) -8385959L) { tmp= -8385959L; current_thd->cuted_fields++; - error = 1; + error= 1; } else { @@ -2802,7 +2996,7 @@ int Field_time::store(longlong nr) { tmp=0; current_thd->cuted_fields++; - error = 1; + error= 1; } } int3store(ptr,tmp); @@ -2882,7 +3076,7 @@ void Field_time::sql_type(String &res) const ** Can handle 2 byte or 4 byte years! ****************************************************************************/ -int 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); @@ -2906,7 +3100,7 @@ int Field_year::store(const char *from, uint len,CHARSET_INFO *cs) return 0; } -int Field_year::store(double nr) +int Field_year::store(double nr) { if (nr < 0.0 || nr >= 2155.0) { @@ -2917,7 +3111,7 @@ int Field_year::store(double nr) return Field_year::store((longlong) nr); } -int Field_year::store(longlong nr) +int Field_year::store(longlong nr) { if (nr < 0 || nr >= 100 && nr <= 1900 || nr > 2155) { @@ -2976,15 +3170,15 @@ void Field_year::sql_type(String &res) const ** Stored as a 4 byte unsigned int ****************************************************************************/ -int 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; + int error= 0; if (str_to_TIME(from,len,&l_time,1) == TIMESTAMP_NONE) { tmp=0; - error = 1; + error= 1; } else tmp=(uint32) l_time.year*10000L + (uint32) (l_time.month*100+l_time.day); @@ -3000,17 +3194,17 @@ int Field_date::store(const char *from, uint len,CHARSET_INFO *cs) } -int Field_date::store(double nr) +int Field_date::store(double nr) { long tmp; - int error=0; + 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; + error= 1; } else tmp=(long) rint(nr); @@ -3026,17 +3220,17 @@ int Field_date::store(double nr) } -int Field_date::store(longlong nr) +int Field_date::store(longlong nr) { long tmp; - int error=0; + 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; + error= 1; } else tmp=(long) nr; @@ -3144,15 +3338,15 @@ void Field_date::sql_type(String &res) const ** In number context: YYYYMMDD ****************************************************************************/ -int 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; + int error= 0; if (str_to_TIME(from,len,&l_time,1) == TIMESTAMP_NONE) { tmp=0L; - error = 1; + error= 1; } else tmp= l_time.day + l_time.month*32 + l_time.year*16*32; @@ -3160,7 +3354,7 @@ int Field_newdate::store(const char *from,uint len,CHARSET_INFO *cs) return error; } -int Field_newdate::store(double nr) +int Field_newdate::store(double nr) { if (nr < 0.0 || nr > 99991231235959.0) { @@ -3172,17 +3366,17 @@ int Field_newdate::store(double nr) } -int Field_newdate::store(longlong nr) +int Field_newdate::store(longlong nr) { int32 tmp; - int error=0; + 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; + error= 1; } else { @@ -3200,7 +3394,7 @@ int Field_newdate::store(longlong nr) { tmp=0L; // Don't allow date to change current_thd->cuted_fields++; - error = 1; + error= 1; } else tmp= day + month*32 + (tmp/10000)*16*32; @@ -3309,7 +3503,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. ****************************************************************************/ -int 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 @@ -3324,28 +3518,28 @@ int Field_datetime::store(const char *from,uint len,CHARSET_INFO *cs) } -int Field_datetime::store(double nr) +int Field_datetime::store(double nr) { - int error=0; + int error= 0; if (nr < 0.0 || nr > 99991231235959.0) { nr=0.0; current_thd->cuted_fields++; - error = 1; + error= 1; } error |= Field_datetime::store((longlong) rint(nr)); return error; } -int Field_datetime::store(longlong nr) +int Field_datetime::store(longlong nr) { - int error=0; + int error= 0; if (nr < 0 || nr > LL(99991231235959)) { nr=0; current_thd->cuted_fields++; - error = 1; + error= 1; } else nr=fix_datetime(nr); @@ -3532,14 +3726,14 @@ void Field_datetime::sql_type(String &res) const /* Copy a string and fill with space */ -int 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; + int error= 0; #ifdef USE_TIS620 - if(!binary_flag) { + if (!binary_flag) { ThNormalize((uchar *)ptr, field_length, (uchar *)from, length); - if(length < field_length) { + if (length < field_length) { bfill(ptr + length, field_length - length, ' '); } } @@ -3572,7 +3766,7 @@ int Field_string::store(const char *from,uint length,CHARSET_INFO *cs) } -int 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); @@ -3582,7 +3776,7 @@ int Field_string::store(double nr) } -int Field_string::store(longlong nr) +int Field_string::store(longlong nr) { char buff[22]; char *end=longlong10_to_str(nr,buff,-10); @@ -3745,12 +3939,12 @@ uint Field_string::max_packed_col_length(uint max_length) ****************************************************************************/ -int 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; + int error= 0; field_charset=cs; #ifdef USE_TIS620 - if(!binary_flag) + if (!binary_flag) { ThNormalize((uchar *) ptr+2, field_length, (uchar *) from, length); } @@ -3764,7 +3958,7 @@ int 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; + error= 1; } #endif /* USE_TIS620 */ int2store(ptr,length); @@ -3772,7 +3966,7 @@ int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs) } -int 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); @@ -3782,7 +3976,7 @@ int Field_varstring::store(double nr) } -int Field_varstring::store(longlong nr) +int Field_varstring::store(longlong nr) { char buff[22]; char *end=longlong10_to_str(nr,buff,-10); @@ -4071,7 +4265,7 @@ uint32 Field_blob::get_length(const char *pos) } -int 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) @@ -4087,7 +4281,7 @@ int Field_blob::store(const char *from,uint len,CHARSET_INFO *cs) if (table->copy_blobs || len <= MAX_FIELD_WIDTH) { // Must make a copy #ifdef USE_TIS620 - if(!binary_flag) + if (!binary_flag) { /* If there isn't enough memory, use original string */ if ((th_ptr=(char * ) my_malloc(sizeof(char) * len,MYF(0)))) @@ -4109,17 +4303,19 @@ int Field_blob::store(const char *from,uint len,CHARSET_INFO *cs) } -int Field_blob::store(double nr) +int Field_blob::store(double nr) { value.set(nr); - return Field_blob::store(value.ptr(),(uint) value.length(), default_charset_info); + return Field_blob::store(value.ptr(),(uint) value.length(), + default_charset_info); } -int Field_blob::store(longlong nr) +int Field_blob::store(longlong nr) { value.set(nr); - return Field_blob::store(value.ptr(), (uint) value.length(), default_charset_info); + return Field_blob::store(value.ptr(), (uint) value.length(), + default_charset_info); } @@ -4226,16 +4422,15 @@ int Field_blob::cmp_binary(const char *a_ptr, const char *b_ptr, void Field_blob::get_key_image(char *buff,uint length, imagetype type) { - if(type == itMBR) + length-= HA_KEY_BLOB_LENGTH; + uint32 blob_length= get_length(ptr); + char *blob; + + if (type == itMBR) { - length-=HA_KEY_BLOB_LENGTH; - ulong blob_length=get_length(ptr); - char *blob; - get_ptr(&blob); - if(!blob_length) - { + if (!blob_length) return; - } + get_ptr(&blob); MBR mbr; Geometry gobj; @@ -4249,8 +4444,6 @@ void Field_blob::get_key_image(char *buff,uint length, imagetype type) } length-=HA_KEY_BLOB_LENGTH; - uint32 blob_length=get_length(ptr); - char *blob; if ((uint32) length > blob_length) { #ifdef HAVE_purify @@ -4269,6 +4462,7 @@ void Field_blob::set_key_image(char *buff,uint length) (void) Field_blob::store(buff+2,length, default_charset_info); } + void Field_geom::get_key_image(char *buff,uint length, imagetype type) { length-=HA_KEY_BLOB_LENGTH; @@ -4293,7 +4487,6 @@ void Field_geom::set_key_image(char *buff,uint length) } - int Field_blob::key_cmp(const byte *key_ptr, uint max_key_length) { char *blob1; @@ -4587,9 +4780,9 @@ uint find_enum(TYPELIB *lib,const char *x, uint length) ** (if there isn't a empty value in the enum) */ -int 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; + int error= 0; uint tmp=find_enum(typelib,from,length); if (!tmp) { @@ -4620,15 +4813,15 @@ int Field_enum::store(const char *from,uint length,CHARSET_INFO *cs) } -int Field_enum::store(double nr) +int Field_enum::store(double nr) { return Field_enum::store((longlong) nr); } -int Field_enum::store(longlong nr) +int Field_enum::store(longlong nr) { - int error=0; + int error= 0; if ((uint) nr > typelib->count || nr == 0) { current_thd->cuted_fields++; @@ -4763,11 +4956,11 @@ ulonglong find_set(TYPELIB *lib,const char *x,uint length) if (x != end) { const char *start=x; - bool error=0; + bool error= 0; for (;;) { const char *pos=start; - for ( ; pos != end && *pos != field_separator ; pos++) ; + for (; pos != end && *pos != field_separator ; pos++) ; uint find=find_enum(lib,start,(uint) (pos-start)); if (!find) error=1; @@ -4784,9 +4977,9 @@ ulonglong find_set(TYPELIB *lib,const char *x,uint length) } -int 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; + int error= 0; ulonglong tmp=find_set(typelib,from,length); if (!tmp && length && length < 22) { @@ -4814,9 +5007,9 @@ int Field_set::store(const char *from,uint length,CHARSET_INFO *cs) } -int Field_set::store(longlong nr) +int Field_set::store(longlong nr) { - int error=0; + int error= 0; if ((ulonglong) nr > (ulonglong) (((longlong) 1 << typelib->count) - (longlong) 1)) { @@ -4914,7 +5107,7 @@ bool Field_num::eq_def(Field *field) *****************************************************************************/ /* -** Make a field from the .frm file info + Make a field from the .frm file info */ uint32 calc_pack_length(enum_field_types type,uint32 length) @@ -5116,7 +5309,8 @@ create_field::create_field(Field *old_field,Field *orig_field) orig_field) { char buff[MAX_FIELD_WIDTH],*pos; - String tmp(buff,sizeof(buff),default_charset_info); + CHARSET_INFO *field_charset= charset ? charset : default_charset_info; + String tmp(buff,sizeof(buff),field_charset); /* Get the value from record[2] (the default value row) */ my_ptrdiff_t diff= (my_ptrdiff_t) (orig_field->table->rec_buff_length*2); @@ -5128,7 +5322,7 @@ create_field::create_field(Field *old_field,Field *orig_field) { pos= (char*) sql_memdup(tmp.ptr(),tmp.length()+1); pos[tmp.length()]=0; - def=new Item_string(pos,tmp.length(),default_charset_info); + def=new Item_string(pos,tmp.length(),field_charset); } } } |