diff options
-rw-r--r-- | include/ma_dyncol.h | 12 | ||||
-rw-r--r-- | mysys/ma_dyncol.c | 120 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 144 | ||||
-rw-r--r-- | unittest/mysys/ma_dyncol-t.c | 240 |
4 files changed, 258 insertions, 258 deletions
diff --git a/include/ma_dyncol.h b/include/ma_dyncol.h index 687823a4e73..6174328d62a 100644 --- a/include/ma_dyncol.h +++ b/include/ma_dyncol.h @@ -79,15 +79,15 @@ struct st_dynamic_column_value unsigned long long ulong_value; double double_value; struct { - LEX_STRING string_value; + LEX_STRING value; CHARSET_INFO *charset; - }; + } string; struct { - decimal_digit_t decimal_buffer[DECIMAL_BUFF_LENGTH]; - decimal_t decimal_value; - }; + decimal_digit_t buffer[DECIMAL_BUFF_LENGTH]; + decimal_t value; + } decimal; MYSQL_TIME time_value; - }; + } x; }; typedef struct st_dynamic_column_value DYNAMIC_COLUMN_VALUE; diff --git a/mysys/ma_dyncol.c b/mysys/ma_dyncol.c index dcb03d7f073..91198293541 100644 --- a/mysys/ma_dyncol.c +++ b/mysys/ma_dyncol.c @@ -238,7 +238,7 @@ dynamic_column_uint_read(DYNAMIC_COLUMN_VALUE *store_it_here, for (i= 0; i < length; i++) value+= ((ulonglong)data[i]) << (i*8); - store_it_here->ulong_value= value; + store_it_here->x.ulong_value= value; return ER_DYNCOL_OK; } @@ -297,12 +297,12 @@ dynamic_column_sint_read(DYNAMIC_COLUMN_VALUE *store_it_here, { ulonglong val; dynamic_column_uint_read(store_it_here, data, length); - val= store_it_here->ulong_value; + val= store_it_here->x.ulong_value; if (val & 1) val= (val >> 1) ^ ULL(0xffffffffffffffff); else val>>= 1; - store_it_here->long_value= (longlong) val; + store_it_here->x.long_value= (longlong) val; return ER_DYNCOL_OK; } @@ -324,30 +324,30 @@ dynamic_column_value_len(DYNAMIC_COLUMN_VALUE *value) case DYN_COL_NULL: return 0; case DYN_COL_INT: - return dynamic_column_sint_bytes(value->long_value); + return dynamic_column_sint_bytes(value->x.long_value); case DYN_COL_UINT: - return dynamic_column_uint_bytes(value->ulong_value); + return dynamic_column_uint_bytes(value->x.ulong_value); case DYN_COL_DOUBLE: return 8; case DYN_COL_STRING: - return (dynamic_column_var_uint_bytes(value->charset->number) + - value->string_value.length); + return (dynamic_column_var_uint_bytes(value->x.string.charset->number) + + value->x.string.value.length); case DYN_COL_DECIMAL: { - int precision= value->decimal_value.intg + value->decimal_value.frac; - int scale= value->decimal_value.frac; + int precision= value->x.decimal.value.intg + value->x.decimal.value.frac; + int scale= value->x.decimal.value.frac; - if (precision == 0 || decimal_is_zero(&value->decimal_value)) + if (precision == 0 || decimal_is_zero(&value->x.decimal.value)) { /* This is here to simplify dynamic_column_decimal_store() */ - value->decimal_value.intg= value->decimal_value.frac= 0; + value->x.decimal.value.intg= value->x.decimal.value.frac= 0; return 0; } /* Check if legal decimal; This is needed to not get an assert in decimal_bin_size(). However this should be impossible as all decimals entered here should be valid and we have the special check - above to handle the unlikely but possible case that decimal_value.intg + above to handle the unlikely but possible case that decimal.value.intg and decimal.frac is 0. */ if (scale < 0 || precision <= 0) @@ -355,8 +355,8 @@ dynamic_column_value_len(DYNAMIC_COLUMN_VALUE *value) DBUG_ASSERT(0); /* Impossible */ return (size_t) ~0; } - return (dynamic_column_var_uint_bytes(value->decimal_value.intg) + - dynamic_column_var_uint_bytes(value->decimal_value.frac) + + return (dynamic_column_var_uint_bytes(value->x.decimal.value.intg) + + dynamic_column_var_uint_bytes(value->x.decimal.value.frac) + decimal_bin_size(precision, scale)); } case DYN_COL_DATETIME: @@ -410,7 +410,7 @@ dynamic_column_double_read(DYNAMIC_COLUMN_VALUE *store_it_here, { if (length != 8) return ER_DYNCOL_FORMAT; - float8get(store_it_here->double_value, data); + float8get(store_it_here->x.double_value, data); return ER_DYNCOL_OK; } @@ -455,12 +455,12 @@ dynamic_column_string_read(DYNAMIC_COLUMN_VALUE *store_it_here, uint charset_nr= (uint)dynamic_column_var_uint_get(data, length, &len); if (len == 0) /* Wrong packed number */ return ER_DYNCOL_FORMAT; - store_it_here->charset= get_charset(charset_nr, MYF(MY_WME)); - if (store_it_here->charset == NULL) + store_it_here->x.string.charset= get_charset(charset_nr, MYF(MY_WME)); + if (store_it_here->x.string.charset == NULL) return ER_DYNCOL_UNKNOWN_CHARSET; data+= len; - store_it_here->string_value.length= (length-= len); - store_it_here->string_value.str= (char*) data; + store_it_here->x.string.value.length= (length-= len); + store_it_here->x.string.value.str= (char*) data; return ER_DYNCOL_OK; } @@ -508,11 +508,11 @@ dynamic_column_decimal_store(DYNAMIC_COLUMN *str, void dynamic_column_prepare_decimal(DYNAMIC_COLUMN_VALUE *value) { - value->decimal_value.buf= value->decimal_buffer; - value->decimal_value.len= DECIMAL_BUFF_LENGTH; + value->x.decimal.value.buf= value->x.decimal.buffer; + value->x.decimal.value.len= DECIMAL_BUFF_LENGTH; /* just to be safe */ value->type= DYN_COL_DECIMAL; - decimal_make_zero(&value->decimal_value); + decimal_make_zero(&value->x.decimal.value); } @@ -553,7 +553,7 @@ dynamic_column_decimal_read(DYNAMIC_COLUMN_VALUE *store_it_here, (int) (length - intg_len - frac_len)) return ER_DYNCOL_FORMAT; - if (bin2decimal(data, &store_it_here->decimal_value, precision, scale) != + if (bin2decimal(data, &store_it_here->x.decimal.value, precision, scale) != E_DEC_OK) return ER_DYNCOL_FORMAT; return ER_DYNCOL_OK; @@ -607,14 +607,14 @@ dynamic_column_date_time_read(DYNAMIC_COLUMN_VALUE *store_it_here, */ if (length != 9) goto err; - store_it_here->time_value.time_type= MYSQL_TIMESTAMP_DATETIME; + store_it_here->x.time_value.time_type= MYSQL_TIMESTAMP_DATETIME; if ((rc= dynamic_column_date_read_internal(store_it_here, data, 3)) || (rc= dynamic_column_time_read_internal(store_it_here, data + 3, 6))) goto err; return ER_DYNCOL_OK; err: - store_it_here->time_value.time_type= MYSQL_TIMESTAMP_ERROR; + store_it_here->x.time_value.time_type= MYSQL_TIMESTAMP_ERROR; return rc; } @@ -682,9 +682,9 @@ static enum enum_dyncol_func_result dynamic_column_time_read(DYNAMIC_COLUMN_VALUE *store_it_here, uchar *data, size_t length) { - store_it_here->time_value.year= store_it_here->time_value.month= - store_it_here->time_value.day= 0; - store_it_here->time_value.time_type= MYSQL_TIMESTAMP_TIME; + store_it_here->x.time_value.year= store_it_here->x.time_value.month= + store_it_here->x.time_value.day= 0; + store_it_here->x.time_value.time_type= MYSQL_TIMESTAMP_TIME; return dynamic_column_time_read_internal(store_it_here, data, length); } @@ -709,23 +709,23 @@ dynamic_column_time_read_internal(DYNAMIC_COLUMN_VALUE *store_it_here, 1123456789012345612345612345678901234567890 <123456><123456><123456><123456><123456><123456> */ - store_it_here->time_value.second_part= (data[0] | + store_it_here->x.time_value.second_part= (data[0] | (data[1] << 8) | ((data[2] & 0xf) << 16)); - store_it_here->time_value.second= ((data[2] >> 4) | + store_it_here->x.time_value.second= ((data[2] >> 4) | ((data[3] & 0x3) << 4)); - store_it_here->time_value.minute= (data[3] >> 2); - store_it_here->time_value.hour= (((((uint)data[5]) & 0x3 ) << 8) | data[4]); - store_it_here->time_value.neg= ((data[5] & 0x4) ? 1 : 0); - if (store_it_here->time_value.second > 59 || - store_it_here->time_value.minute > 59 || - store_it_here->time_value.hour > 838 || - store_it_here->time_value.second_part > 999999) + store_it_here->x.time_value.minute= (data[3] >> 2); + store_it_here->x.time_value.hour= (((((uint)data[5]) & 0x3 ) << 8) | data[4]); + store_it_here->x.time_value.neg= ((data[5] & 0x4) ? 1 : 0); + if (store_it_here->x.time_value.second > 59 || + store_it_here->x.time_value.minute > 59 || + store_it_here->x.time_value.hour > 838 || + store_it_here->x.time_value.second_part > 999999) goto err; return ER_DYNCOL_OK; err: - store_it_here->time_value.time_type= MYSQL_TIMESTAMP_ERROR; + store_it_here->x.time_value.time_type= MYSQL_TIMESTAMP_ERROR; return ER_DYNCOL_FORMAT; } @@ -783,12 +783,12 @@ static enum enum_dyncol_func_result dynamic_column_date_read(DYNAMIC_COLUMN_VALUE *store_it_here, uchar *data, size_t length) { - store_it_here->time_value.neg= 0; - store_it_here->time_value.second_part= 0; - store_it_here->time_value.hour= 0; - store_it_here->time_value.minute= 0; - store_it_here->time_value.second= 0; - store_it_here->time_value.time_type= MYSQL_TIMESTAMP_DATE; + store_it_here->x.time_value.neg= 0; + store_it_here->x.time_value.second_part= 0; + store_it_here->x.time_value.hour= 0; + store_it_here->x.time_value.minute= 0; + store_it_here->x.time_value.second= 0; + store_it_here->x.time_value.time_type= MYSQL_TIMESTAMP_DATE; return dynamic_column_date_read_internal(store_it_here, data, length); } @@ -814,19 +814,19 @@ dynamic_column_date_read_internal(DYNAMIC_COLUMN_VALUE *store_it_here, 12345678901234123412345 <123456><123456><123456> */ - store_it_here->time_value.day= (data[0] & 0x1f); - store_it_here->time_value.month= (((data[1] & 0x1) << 3) | + store_it_here->x.time_value.day= (data[0] & 0x1f); + store_it_here->x.time_value.month= (((data[1] & 0x1) << 3) | (data[0] >> 5)); - store_it_here->time_value.year= ((((uint)data[2]) << 7) | + store_it_here->x.time_value.year= ((((uint)data[2]) << 7) | (data[1] >> 1)); - if (store_it_here->time_value.day > 31 || - store_it_here->time_value.month > 12 || - store_it_here->time_value.year > 9999) + if (store_it_here->x.time_value.day > 31 || + store_it_here->x.time_value.month > 12 || + store_it_here->x.time_value.year > 9999) goto err; return ER_DYNCOL_OK; err: - store_it_here->time_value.time_type= MYSQL_TIMESTAMP_ERROR; + store_it_here->x.time_value.time_type= MYSQL_TIMESTAMP_ERROR; return ER_DYNCOL_FORMAT; } @@ -845,25 +845,25 @@ data_store(DYNAMIC_COLUMN *str, DYNAMIC_COLUMN_VALUE *value) { switch (value->type) { case DYN_COL_INT: - return dynamic_column_sint_store(str, value->long_value); + return dynamic_column_sint_store(str, value->x.long_value); case DYN_COL_UINT: - return dynamic_column_uint_store(str, value->ulong_value); + return dynamic_column_uint_store(str, value->x.ulong_value); case DYN_COL_DOUBLE: - return dynamic_column_double_store(str, value->double_value); + return dynamic_column_double_store(str, value->x.double_value); case DYN_COL_STRING: - return dynamic_column_string_store(str, &value->string_value, - value->charset); + return dynamic_column_string_store(str, &value->x.string.value, + value->x.string.charset); case DYN_COL_DECIMAL: - return dynamic_column_decimal_store(str, &value->decimal_value); + return dynamic_column_decimal_store(str, &value->x.decimal.value); case DYN_COL_DATETIME: /* date+time in bits: 14 + 4 + 5 + 5 + 6 + 6 40bits = 5 bytes */ - return dynamic_column_date_time_store(str, &value->time_value); + return dynamic_column_date_time_store(str, &value->x.time_value); case DYN_COL_DATE: /* date in dits: 14 + 4 + 5 = 23bits ~= 3bytes*/ - return dynamic_column_date_store(str, &value->time_value); + return dynamic_column_date_store(str, &value->x.time_value); case DYN_COL_TIME: /* time in bits: 5 + 6 + 6 = 17bits ~= 3bytes*/ - return dynamic_column_time_store(str, &value->time_value); + return dynamic_column_time_store(str, &value->x.time_value); case DYN_COL_NULL: break; /* Impossible */ } diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index a2f600d8473..9abbdfcec4f 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -3606,40 +3606,40 @@ void Item_func_dyncol_create::prepare_arguments() DBUG_ASSERT(args[valpos]->field_type() == MYSQL_TYPE_NULL); break; case DYN_COL_INT: - vals[i].long_value= args[valpos]->val_int(); + vals[i].x.long_value= args[valpos]->val_int(); break; case DYN_COL_UINT: - vals[i].ulong_value= args[valpos]->val_int(); + vals[i].x.ulong_value= args[valpos]->val_int(); break; case DYN_COL_DOUBLE: - vals[i].double_value= args[valpos]->val_real(); + vals[i].x.double_value= args[valpos]->val_real(); break; case DYN_COL_STRING: res= args[valpos]->val_str(&tmp); if (res && - (vals[i].string_value.str= my_strndup(res->ptr(), res->length(), + (vals[i].x.string.value.str= my_strndup(res->ptr(), res->length(), MYF(MY_WME)))) { - vals[i].string_value.length= res->length(); - vals[i].charset= res->charset(); + vals[i].x.string.value.length= res->length(); + vals[i].x.string.charset= res->charset(); } else { args[valpos]->null_value= 1; // In case of out of memory - vals[i].string_value.str= NULL; - vals[i].string_value.length= 0; // just to be safe + vals[i].x.string.value.str= NULL; + vals[i].x.string.value.length= 0; // just to be safe } break; case DYN_COL_DECIMAL: if ((dres= args[valpos]->val_decimal(&dtmp))) { dynamic_column_prepare_decimal(&vals[i]); - DBUG_ASSERT(vals[i].decimal_value.len == dres->len); - vals[i].decimal_value.intg= dres->intg; - vals[i].decimal_value.frac= dres->frac; - vals[i].decimal_value.sign= dres->sign(); - memcpy(vals[i].decimal_buffer, dres->buf, - sizeof(vals[i].decimal_buffer)); + DBUG_ASSERT(vals[i].x.decimal.value.len == dres->len); + vals[i].x.decimal.value.intg= dres->intg; + vals[i].x.decimal.value.frac= dres->frac; + vals[i].x.decimal.value.sign= dres->sign(); + memcpy(vals[i].x.decimal.buffer, dres->buf, + sizeof(vals[i].x.decimal.buffer)); } else { @@ -3648,13 +3648,13 @@ void Item_func_dyncol_create::prepare_arguments() } break; case DYN_COL_DATETIME: - args[valpos]->get_date(&vals[i].time_value, TIME_FUZZY_DATE); + args[valpos]->get_date(&vals[i].x.time_value, TIME_FUZZY_DATE); break; case DYN_COL_DATE: - args[valpos]->get_date(&vals[i].time_value, TIME_FUZZY_DATE); + args[valpos]->get_date(&vals[i].x.time_value, TIME_FUZZY_DATE); break; case DYN_COL_TIME: - args[valpos]->get_time(&vals[i].time_value); + args[valpos]->get_time(&vals[i].x.time_value); break; default: DBUG_ASSERT(0); @@ -3663,7 +3663,7 @@ void Item_func_dyncol_create::prepare_arguments() if (vals[i].type != DYN_COL_NULL && args[valpos]->null_value) { if (vals[i].type == DYN_COL_STRING) - my_free(vals[i].string_value.str, MYF(MY_ALLOW_ZERO_PTR)); + my_free(vals[i].x.string.value.str, MYF(MY_ALLOW_ZERO_PTR)); vals[i].type= DYN_COL_NULL; } } @@ -3677,7 +3677,7 @@ void Item_func_dyncol_create::cleanup_arguments() for (i= 0; i < column_count; i++) { if (vals[i].type == DYN_COL_STRING) - my_free(vals[i].string_value.str, MYF(MY_ALLOW_ZERO_PTR)); + my_free(vals[i].x.string.value.str, MYF(MY_ALLOW_ZERO_PTR)); } } @@ -3894,19 +3894,19 @@ String *Item_dyncol_get::val_str(String *str_result) goto null; case DYN_COL_INT: case DYN_COL_UINT: - str_result->set_int(val.long_value, test(val.type == DYN_COL_UINT), + str_result->set_int(val.x.long_value, test(val.type == DYN_COL_UINT), &my_charset_latin1); break; case DYN_COL_DOUBLE: - str_result->set_real(val.double_value, NOT_FIXED_DEC, &my_charset_latin1); + str_result->set_real(val.x.double_value, NOT_FIXED_DEC, &my_charset_latin1); break; case DYN_COL_STRING: - if ((char*) tmp.ptr() <= val.string_value.str && - (char*) tmp.ptr() + tmp.length() >= val.string_value.str) + if ((char*) tmp.ptr() <= val.x.string.value.str && + (char*) tmp.ptr() + tmp.length() >= val.x.string.value.str) { /* value is allocated in tmp buffer; We have to make a copy */ - str_result->copy(val.string_value.str, val.string_value.length, - val.charset); + str_result->copy(val.x.string.value.str, val.x.string.value.length, + val.x.string.charset); } else { @@ -3915,24 +3915,24 @@ String *Item_dyncol_get::val_str(String *str_result) into a field or in a buffer for another item and this buffer is not going to be deleted during expression evaluation */ - str_result->set(val.string_value.str, val.string_value.length, - val.charset); + str_result->set(val.x.string.value.str, val.x.string.value.length, + val.x.string.charset); } break; case DYN_COL_DECIMAL: { int res; int length= - my_decimal_string_length((const my_decimal*)&val.decimal_value); + my_decimal_string_length((const my_decimal*)&val.x.decimal.value); if (str_result->alloc(length)) goto null; - if ((res= decimal2string(&val.decimal_value, (char*) str_result->ptr(), + if ((res= decimal2string(&val.x.decimal.value, (char*) str_result->ptr(), &length, 0, 0, ' ')) != E_DEC_OK) { char buff[40]; int len= sizeof(buff); DBUG_ASSERT(length < (int)sizeof(buff)); - decimal2string(&val.decimal_value, buff, &len, 0, 0, ' '); + decimal2string(&val.x.decimal.value, buff, &len, 0, 0, ' '); decimal_operation_results(res, buff, "CHAR"); } str_result->set_charset(&my_charset_latin1); @@ -3950,7 +3950,7 @@ String *Item_dyncol_get::val_str(String *str_result) asked to return the time argument as a string. */ if (str_result->alloc(MAX_DATE_STRING_REP_LENGTH) || - !(length= my_TIME_to_str(&val.time_value, (char*) str_result->ptr(), + !(length= my_TIME_to_str(&val.x.time_value, (char*) str_result->ptr(), AUTO_SEC_PART_DIGITS))) goto null; str_result->set_charset(&my_charset_latin1); @@ -3980,20 +3980,20 @@ longlong Item_dyncol_get::val_int() goto null; case DYN_COL_UINT: unsigned_flag= 1; // Make it possible for caller to detect sign - return val.long_value; + return val.x.long_value; case DYN_COL_INT: unsigned_flag= 0; // Make it possible for caller to detect sign - return val.long_value; + return val.x.long_value; case DYN_COL_DOUBLE: { bool error; longlong num; - num= double_to_longlong(val.double_value, unsigned_flag, &error); + num= double_to_longlong(val.x.double_value, unsigned_flag, &error); if (error) { char buff[30]; - sprintf(buff, "%lg", val.double_value); + sprintf(buff, "%lg", val.x.double_value); push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_DATA_OVERFLOW, ER(ER_DATA_OVERFLOW), @@ -4006,14 +4006,14 @@ longlong Item_dyncol_get::val_int() { int error; longlong num; - char *end= val.string_value.str + val.string_value.length, *org_end= end; + char *end= val.x.string.value.str + val.x.string.value.length, *org_end= end; - num= my_strtoll10(val.string_value.str, &end, &error); + num= my_strtoll10(val.x.string.value.str, &end, &error); if (end != org_end || error > 0) { char buff[80]; - strmake(buff, val.string_value.str, min(sizeof(buff)-1, - val.string_value.length)); + strmake(buff, val.x.string.value.str, min(sizeof(buff)-1, + val.x.string.value.length)); push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_BAD_DATA, ER(ER_BAD_DATA), @@ -4026,18 +4026,18 @@ longlong Item_dyncol_get::val_int() case DYN_COL_DECIMAL: { longlong num; - my_decimal2int(E_DEC_FATAL_ERROR, &val.decimal_value, unsigned_flag, + my_decimal2int(E_DEC_FATAL_ERROR, &val.x.decimal.value, unsigned_flag, &num); return num; } case DYN_COL_DATETIME: case DYN_COL_DATE: case DYN_COL_TIME: - unsigned_flag= !val.time_value.neg; + unsigned_flag= !val.x.time_value.neg; if (unsigned_flag) - return TIME_to_ulonglong(&val.time_value); + return TIME_to_ulonglong(&val.x.time_value); else - return -(longlong)TIME_to_ulonglong(&val.time_value); + return -(longlong)TIME_to_ulonglong(&val.x.time_value); } null: @@ -4059,24 +4059,24 @@ double Item_dyncol_get::val_real() case DYN_COL_NULL: goto null; case DYN_COL_UINT: - return ulonglong2double(val.ulong_value); + return ulonglong2double(val.x.ulong_value); case DYN_COL_INT: - return (double) val.long_value; + return (double) val.x.long_value; case DYN_COL_DOUBLE: - return (double) val.double_value; + return (double) val.x.double_value; case DYN_COL_STRING: { int error; char *end; - double res= my_strntod(val.charset, (char*) val.string_value.str, - val.string_value.length, &end, &error); + double res= my_strntod(val.x.string.charset, (char*) val.x.string.value.str, + val.x.string.value.length, &end, &error); - if (end != (char*) val.string_value.str + val.string_value.length || + if (end != (char*) val.x.string.value.str + val.x.string.value.length || error) { char buff[80]; - strmake(buff, val.string_value.str, min(sizeof(buff)-1, - val.string_value.length)); + strmake(buff, val.x.string.value.str, min(sizeof(buff)-1, + val.x.string.value.length)); push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_BAD_DATA, ER(ER_BAD_DATA), @@ -4088,13 +4088,13 @@ double Item_dyncol_get::val_real() { double res; /* This will always succeed */ - decimal2double(&val.decimal_value, &res); + decimal2double(&val.x.decimal.value, &res); return res; } case DYN_COL_DATETIME: case DYN_COL_DATE: case DYN_COL_TIME: - return TIME_to_double(&val.time_value); + return TIME_to_double(&val.x.time_value); } null: @@ -4116,22 +4116,22 @@ my_decimal *Item_dyncol_get::val_decimal(my_decimal *decimal_value) case DYN_COL_NULL: goto null; case DYN_COL_UINT: - int2my_decimal(E_DEC_FATAL_ERROR, val.long_value, TRUE, decimal_value); + int2my_decimal(E_DEC_FATAL_ERROR, val.x.long_value, TRUE, decimal_value); break; case DYN_COL_INT: - int2my_decimal(E_DEC_FATAL_ERROR, val.long_value, FALSE, decimal_value); + int2my_decimal(E_DEC_FATAL_ERROR, val.x.long_value, FALSE, decimal_value); break; case DYN_COL_DOUBLE: - double2my_decimal(E_DEC_FATAL_ERROR, val.double_value, decimal_value); + double2my_decimal(E_DEC_FATAL_ERROR, val.x.double_value, decimal_value); break; case DYN_COL_STRING: { int rc; - rc= str2my_decimal(0, val.string_value.str, val.string_value.length, - val.charset, decimal_value); + rc= str2my_decimal(0, val.x.string.value.str, val.x.string.value.length, + val.x.string.charset, decimal_value); char buff[80]; - strmake(buff, val.string_value.str, min(sizeof(buff)-1, - val.string_value.length)); + strmake(buff, val.x.string.value.str, min(sizeof(buff)-1, + val.x.string.value.length)); if (rc != E_DEC_OK) { push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, @@ -4142,14 +4142,14 @@ my_decimal *Item_dyncol_get::val_decimal(my_decimal *decimal_value) break; } case DYN_COL_DECIMAL: - decimal2my_decimal(&val.decimal_value, decimal_value); + decimal2my_decimal(&val.x.decimal.value, decimal_value); break; case DYN_COL_DATETIME: case DYN_COL_DATE: case DYN_COL_TIME: - decimal_value= seconds2my_decimal(val.time_value.neg, - TIME_to_ulonglong(&val.time_value), - val.time_value.second_part, + decimal_value= seconds2my_decimal(val.x.time_value.neg, + TIME_to_ulonglong(&val.x.time_value), + val.x.time_value.second_part, decimal_value); break; } @@ -4178,36 +4178,36 @@ bool Item_dyncol_get::get_date(MYSQL_TIME *ltime, uint fuzzy_date) signed_value= 1; // For error message /* fall_trough */ case DYN_COL_UINT: - if (signed_value || val.ulong_value <= LONGLONG_MAX) + if (signed_value || val.x.ulong_value <= LONGLONG_MAX) { - if (int_to_datetime_with_warn(val.ulong_value, ltime, fuzzy_date, + if (int_to_datetime_with_warn(val.x.ulong_value, ltime, fuzzy_date, 0 /* TODO */)) goto null; return 0; } /* let double_to_datetime_with_warn() issue the warning message */ - val.double_value= static_cast<double>(ULONGLONG_MAX); + val.x.double_value= static_cast<double>(ULONGLONG_MAX); /* fall_trough */ case DYN_COL_DOUBLE: - if (double_to_datetime_with_warn(val.double_value, ltime, fuzzy_date, + if (double_to_datetime_with_warn(val.x.double_value, ltime, fuzzy_date, 0 /* TODO */)) goto null; return 0; case DYN_COL_DECIMAL: - if (decimal_to_datetime_with_warn((my_decimal*)&val.decimal_value, ltime, + if (decimal_to_datetime_with_warn((my_decimal*)&val.x.decimal.value, ltime, fuzzy_date, 0 /* TODO */)) goto null; return 0; case DYN_COL_STRING: - if (str_to_datetime_with_warn(val.string_value.str, - val.string_value.length, + if (str_to_datetime_with_warn(val.x.string.value.str, + val.x.string.value.length, ltime, fuzzy_date) <= MYSQL_TIMESTAMP_ERROR) goto null; return 0; case DYN_COL_DATETIME: case DYN_COL_DATE: case DYN_COL_TIME: - *ltime= val.time_value; + *ltime= val.x.time_value; return 0; } diff --git a/unittest/mysys/ma_dyncol-t.c b/unittest/mysys/ma_dyncol-t.c index 0e973b20747..11731ae81d4 100644 --- a/unittest/mysys/ma_dyncol-t.c +++ b/unittest/mysys/ma_dyncol-t.c @@ -61,7 +61,7 @@ void test_value_single_uint(ulonglong num, const char *name) DYNAMIC_COLUMN str; /* init values */ val.type= DYN_COL_UINT; - val.ulong_value= num; + val.x.ulong_value= num; dynamic_column_value_init(&res); /* create column */ if (dynamic_column_create(&str, 1, &val)) @@ -70,8 +70,8 @@ void test_value_single_uint(ulonglong num, const char *name) /* read column */ if (dynamic_column_get(&str, 1, &res)) goto err; - rc= (res.type == DYN_COL_UINT) && (res.ulong_value == num); - num= res.ulong_value; + rc= (res.type == DYN_COL_UINT) && (res.x.ulong_value == num); + num= res.x.ulong_value; err: ok(rc, "%s - %llu", name, num); /* cleanup */ @@ -85,7 +85,7 @@ void test_value_single_sint(longlong num, const char *name) DYNAMIC_COLUMN str; /* init values */ val.type= DYN_COL_INT; - val.long_value= num; + val.x.long_value= num; dynamic_column_value_init(&res); /* create column */ if (dynamic_column_create(&str, 1, &val)) @@ -94,8 +94,8 @@ void test_value_single_sint(longlong num, const char *name) /* read column */ if (dynamic_column_get(&str, 1, &res)) goto err; - rc= (res.type == DYN_COL_INT) && (res.long_value == num); - num= res.ulong_value; + rc= (res.type == DYN_COL_INT) && (res.x.long_value == num); + num= res.x.ulong_value; err: ok(rc, "%s - %lld", name, num); /* cleanup */ @@ -110,7 +110,7 @@ void test_value_single_double(double num, const char *name) DYNAMIC_COLUMN str; /* init values */ val.type= DYN_COL_DOUBLE; - val.double_value= num; + val.x.double_value= num; dynamic_column_value_init(&res); /* create column */ if (dynamic_column_create(&str, 1, &val)) @@ -119,8 +119,8 @@ void test_value_single_double(double num, const char *name) /* read column */ if (dynamic_column_get(&str, 1, &res)) goto err; - rc= (res.type == DYN_COL_DOUBLE) && (res.double_value == num); - num= res.ulong_value; + rc= (res.type == DYN_COL_DOUBLE) && (res.x.double_value == num); + num= res.x.ulong_value; err: ok(rc, "%s - %lf", name, num); /* cleanup */ @@ -138,7 +138,7 @@ void test_value_single_decimal(const char *num) /* init values */ dynamic_column_prepare_decimal(&val); // special procedure for decimal!!! - if (string2decimal(num, &val.decimal_value, &end) != E_DEC_OK) + if (string2decimal(num, &val.x.decimal.value, &end) != E_DEC_OK) goto err; dynamic_column_value_init(&res); @@ -150,8 +150,8 @@ void test_value_single_decimal(const char *num) if (dynamic_column_get(&str, 1, &res)) goto err; rc= ((res.type == DYN_COL_DECIMAL) && - (decimal_cmp(&res.decimal_value, &val.decimal_value) == 0)); - decimal2string(&res.decimal_value, buff, &length, 0, 0, ' '); + (decimal_cmp(&res.x.decimal.value, &val.x.decimal.value) == 0)); + decimal2string(&res.x.decimal.value, buff, &length, 0, 0, ' '); err: ok(rc, "%s - %s", num, buff); /* cleanup */ @@ -211,9 +211,9 @@ void test_value_single_string(const char *string, size_t len, /* init values */ val.type= DYN_COL_STRING; - val.string_value.str= (char*)string; - val.string_value.length= len; - val.charset= cs; + val.x.string.value.str= (char*)string; + val.x.string.value.length= len; + val.x.string.charset= cs; dynamic_column_value_init(&res); /* create column */ @@ -224,15 +224,15 @@ void test_value_single_string(const char *string, size_t len, if (dynamic_column_get(&str, 1, &res)) goto err; rc= ((res.type == DYN_COL_STRING) && - (res.string_value.length == len) && - (memcmp(res.string_value.str, string, len) == 0) && - (res.charset->number == cs->number)); + (res.x.string.value.length == len) && + (memcmp(res.x.string.value.str, string, len) == 0) && + (res.x.string.charset->number == cs->number)); err: ok(rc, "'%s' - '%s' %u %u-%s", string, - res.string_value.str, (uint)res.string_value.length, - (uint)res.charset->number, res.charset->name); + res.x.string.value.str, (uint)res.x.string.value.length, + (uint)res.x.string.charset->number, res.x.string.charset->name); /* cleanup */ - val.string_value.str= NULL; // we did not allocated it + val.x.string.value.str= NULL; // we did not allocated it dynamic_column_column_free(&str); } @@ -243,10 +243,10 @@ void test_value_single_date(uint year, uint month, uint day, const char *name) DYNAMIC_COLUMN str; /* init values */ val.type= DYN_COL_DATE; - val.time_value.time_type= MYSQL_TIMESTAMP_DATE; - val.time_value.year= year; - val.time_value.month= month; - val.time_value.day= day; + val.x.time_value.time_type= MYSQL_TIMESTAMP_DATE; + val.x.time_value.year= year; + val.x.time_value.month= month; + val.x.time_value.day= day; dynamic_column_value_init(&res); /* create column */ if (dynamic_column_create(&str, 1, &val)) @@ -256,10 +256,10 @@ void test_value_single_date(uint year, uint month, uint day, const char *name) if (dynamic_column_get(&str, 1, &res)) goto err; rc= ((res.type == DYN_COL_DATE) && - (res.time_value.time_type == MYSQL_TIMESTAMP_DATE) && - (res.time_value.year == year) && - (res.time_value.month == month) && - (res.time_value.day == day)); + (res.x.time_value.time_type == MYSQL_TIMESTAMP_DATE) && + (res.x.time_value.year == year) && + (res.x.time_value.month == month) && + (res.x.time_value.day == day)); err: ok(rc, "%s - %04u-%02u-%02u", name, year, month, day); /* cleanup */ @@ -274,12 +274,12 @@ void test_value_single_time(uint neg, uint hour, uint minute, uint second, DYNAMIC_COLUMN str; /* init values */ val.type= DYN_COL_TIME; - val.time_value.time_type= MYSQL_TIMESTAMP_TIME; - val.time_value.neg= neg; - val.time_value.hour= hour; - val.time_value.minute= minute; - val.time_value.second= second; - val.time_value.second_part= mic; + val.x.time_value.time_type= MYSQL_TIMESTAMP_TIME; + val.x.time_value.neg= neg; + val.x.time_value.hour= hour; + val.x.time_value.minute= minute; + val.x.time_value.second= second; + val.x.time_value.second_part= mic; dynamic_column_value_init(&res); /* create column */ if (dynamic_column_create(&str, 1, &val)) @@ -289,12 +289,12 @@ void test_value_single_time(uint neg, uint hour, uint minute, uint second, if (dynamic_column_get(&str, 1, &res)) goto err; rc= ((res.type == DYN_COL_TIME) && - (res.time_value.time_type == MYSQL_TIMESTAMP_TIME) && - (res.time_value.neg == (int)neg) && - (res.time_value.hour == hour) && - (res.time_value.minute == minute) && - (res.time_value.second == second) && - (res.time_value.second_part == mic)); + (res.x.time_value.time_type == MYSQL_TIMESTAMP_TIME) && + (res.x.time_value.neg == (int)neg) && + (res.x.time_value.hour == hour) && + (res.x.time_value.minute == minute) && + (res.x.time_value.second == second) && + (res.x.time_value.second_part == mic)); err: ok(rc, "%s - %c%02u:%02u:%02u.%06u", name, (neg ? '-' : '+'), hour, minute, second, mic); @@ -312,15 +312,15 @@ void test_value_single_datetime(uint neg, uint year, uint month, uint day, DYNAMIC_COLUMN str; /* init values */ val.type= DYN_COL_DATETIME; - val.time_value.time_type= MYSQL_TIMESTAMP_DATETIME; - val.time_value.neg= neg; - val.time_value.year= year; - val.time_value.month= month; - val.time_value.day= day; - val.time_value.hour= hour; - val.time_value.minute= minute; - val.time_value.second= second; - val.time_value.second_part= mic; + val.x.time_value.time_type= MYSQL_TIMESTAMP_DATETIME; + val.x.time_value.neg= neg; + val.x.time_value.year= year; + val.x.time_value.month= month; + val.x.time_value.day= day; + val.x.time_value.hour= hour; + val.x.time_value.minute= minute; + val.x.time_value.second= second; + val.x.time_value.second_part= mic; dynamic_column_value_init(&res); /* create column */ if (dynamic_column_create(&str, 1, &val)) @@ -330,15 +330,15 @@ void test_value_single_datetime(uint neg, uint year, uint month, uint day, if (dynamic_column_get(&str, 1, &res)) goto err; rc= ((res.type == DYN_COL_DATETIME) && - (res.time_value.time_type == MYSQL_TIMESTAMP_DATETIME) && - (res.time_value.neg == (int)neg) && - (res.time_value.year == year) && - (res.time_value.month == month) && - (res.time_value.day == day) && - (res.time_value.hour == hour) && - (res.time_value.minute == minute) && - (res.time_value.second == second) && - (res.time_value.second_part == mic)); + (res.x.time_value.time_type == MYSQL_TIMESTAMP_DATETIME) && + (res.x.time_value.neg == (int)neg) && + (res.x.time_value.year == year) && + (res.x.time_value.month == month) && + (res.x.time_value.day == day) && + (res.x.time_value.hour == hour) && + (res.x.time_value.minute == minute) && + (res.x.time_value.second == second) && + (res.x.time_value.second_part == mic)); err: ok(rc, "%s - %c %04u-%02u-%02u %02u:%02u:%02u.%06u", name, (neg ? '-' : '+'), year, month, day, hour, minute, second, mic); @@ -368,40 +368,40 @@ void test_value_multi(ulonglong num0, DYNAMIC_COLUMN str; /* init values */ val[0].type= DYN_COL_UINT; - val[0].ulong_value= num0; + val[0].x.ulong_value= num0; val[1].type= DYN_COL_INT; - val[1].long_value= num1; + val[1].x.long_value= num1; val[2].type= DYN_COL_DOUBLE; - val[2].double_value= num2; + val[2].x.double_value= num2; dynamic_column_prepare_decimal(val + 3); // special procedure for decimal!!! - if (string2decimal(num3, &val[3].decimal_value, &end3) != E_DEC_OK) + if (string2decimal(num3, &val[3].x.decimal.value, &end3) != E_DEC_OK) goto err; val[4].type= DYN_COL_STRING; - val[4].string_value.str= (char*)string4; - val[4].string_value.length= len4; - val[4].charset= cs4; + val[4].x.string.value.str= (char*)string4; + val[4].x.string.value.length= len4; + val[4].x.string.charset= cs4; val[5].type= DYN_COL_DATE; - val[5].time_value.time_type= MYSQL_TIMESTAMP_DATE; - val[5].time_value.year= year5; - val[5].time_value.month= month5; - val[5].time_value.day= day5; + val[5].x.time_value.time_type= MYSQL_TIMESTAMP_DATE; + val[5].x.time_value.year= year5; + val[5].x.time_value.month= month5; + val[5].x.time_value.day= day5; val[6].type= DYN_COL_TIME; - val[6].time_value.time_type= MYSQL_TIMESTAMP_TIME; - val[6].time_value.neg= neg6; - val[6].time_value.hour= hour6; - val[6].time_value.minute= minute6; - val[6].time_value.second= second6; - val[6].time_value.second_part= mic6; + val[6].x.time_value.time_type= MYSQL_TIMESTAMP_TIME; + val[6].x.time_value.neg= neg6; + val[6].x.time_value.hour= hour6; + val[6].x.time_value.minute= minute6; + val[6].x.time_value.second= second6; + val[6].x.time_value.second_part= mic6; val[7].type= DYN_COL_DATETIME; - val[7].time_value.time_type= MYSQL_TIMESTAMP_DATETIME; - val[7].time_value.neg= neg7; - val[7].time_value.year= year7; - val[7].time_value.month= month7; - val[7].time_value.day= day7; - val[7].time_value.hour= hour7; - val[7].time_value.minute= minute7; - val[7].time_value.second= second7; - val[7].time_value.second_part= mic7; + val[7].x.time_value.time_type= MYSQL_TIMESTAMP_DATETIME; + val[7].x.time_value.neg= neg7; + val[7].x.time_value.year= year7; + val[7].x.time_value.month= month7; + val[7].x.time_value.day= day7; + val[7].x.time_value.hour= hour7; + val[7].x.time_value.minute= minute7; + val[7].x.time_value.second= second7; + val[7].x.time_value.second_part= mic7; val[8].type= DYN_COL_NULL; for (i= 0; i < 9; i++) dynamic_column_value_init(res + i); @@ -414,44 +414,44 @@ void test_value_multi(ulonglong num0, if (dynamic_column_get(&str, column_numbers[i], res + i)) goto err; rc= ((res[0].type == DYN_COL_UINT) && - (res[0].ulong_value == num0) && + (res[0].x.ulong_value == num0) && (res[1].type == DYN_COL_INT) && - (res[1].long_value == num1) && + (res[1].x.long_value == num1) && (res[2].type == DYN_COL_DOUBLE) && - (res[2].double_value == num2) && + (res[2].x.double_value == num2) && (res[3].type == DYN_COL_DECIMAL) && - (decimal_cmp(&res[3].decimal_value, &val[3].decimal_value) == 0) && + (decimal_cmp(&res[3].x.decimal.value, &val[3].x.decimal.value) == 0) && (res[4].type == DYN_COL_STRING) && - (res[4].string_value.length == len4) && - (memcmp(res[4].string_value.str, string4, len4) == 0) && - (res[4].charset->number == cs4->number) && + (res[4].x.string.value.length == len4) && + (memcmp(res[4].x.string.value.str, string4, len4) == 0) && + (res[4].x.string.charset->number == cs4->number) && (res[5].type == DYN_COL_DATE) && - (res[5].time_value.time_type == MYSQL_TIMESTAMP_DATE) && - (res[5].time_value.year == year5) && - (res[5].time_value.month == month5) && - (res[5].time_value.day == day5) && + (res[5].x.time_value.time_type == MYSQL_TIMESTAMP_DATE) && + (res[5].x.time_value.year == year5) && + (res[5].x.time_value.month == month5) && + (res[5].x.time_value.day == day5) && (res[6].type == DYN_COL_TIME) && - (res[6].time_value.time_type == MYSQL_TIMESTAMP_TIME) && - (res[6].time_value.neg == (int)neg6) && - (res[6].time_value.hour == hour6) && - (res[6].time_value.minute == minute6) && - (res[6].time_value.second == second6) && - (res[6].time_value.second_part == mic6) && + (res[6].x.time_value.time_type == MYSQL_TIMESTAMP_TIME) && + (res[6].x.time_value.neg == (int)neg6) && + (res[6].x.time_value.hour == hour6) && + (res[6].x.time_value.minute == minute6) && + (res[6].x.time_value.second == second6) && + (res[6].x.time_value.second_part == mic6) && (res[7].type == DYN_COL_DATETIME) && - (res[7].time_value.time_type == MYSQL_TIMESTAMP_DATETIME) && - (res[7].time_value.neg == (int)neg7) && - (res[7].time_value.year == year7) && - (res[7].time_value.month == month7) && - (res[7].time_value.day == day7) && - (res[7].time_value.hour == hour7) && - (res[7].time_value.minute == minute7) && - (res[7].time_value.second == second7) && - (res[7].time_value.second_part == mic7) && + (res[7].x.time_value.time_type == MYSQL_TIMESTAMP_DATETIME) && + (res[7].x.time_value.neg == (int)neg7) && + (res[7].x.time_value.year == year7) && + (res[7].x.time_value.month == month7) && + (res[7].x.time_value.day == day7) && + (res[7].x.time_value.hour == hour7) && + (res[7].x.time_value.minute == minute7) && + (res[7].x.time_value.second == second7) && + (res[7].x.time_value.second_part == mic7) && (res[8].type == DYN_COL_NULL)); err: ok(rc, "%s", name); /* cleanup */ - val[4].string_value.str= NULL; // we did not allocated it + val[4].x.string.value.str= NULL; // we did not allocated it dynamic_column_column_free(&str); } @@ -486,13 +486,13 @@ void test_update_multi(uint *column_numbers, uint *column_values, DYNAMIC_COLUMN_VALUE val; val.type= DYN_COL_UINT; - val.ulong_value= column_values[0]; + val.x.ulong_value= column_values[0]; if (dynamic_column_create(&str, column_numbers[0], &val)) goto err; for (i= 1; i < all; i++) { val.type= (null_values[i] ? DYN_COL_NULL : DYN_COL_UINT); - val.ulong_value= column_values[i]; + val.x.ulong_value= column_values[i]; if (dynamic_column_update(&str, column_numbers[i], &val)) goto err; @@ -510,7 +510,7 @@ void test_update_multi(uint *column_numbers, uint *column_values, else { if (val.type != DYN_COL_UINT || - val.ulong_value != column_values[j] || + val.x.ulong_value != column_values[j] || dynamic_column_exists(&str, column_numbers[j]) == ER_DYNCOL_NO) goto err; } @@ -582,12 +582,12 @@ void test_empty_string() "%s", "empty list"); val.type= DYN_COL_UINT; - val.ulong_value= 1212; + val.x.ulong_value= 1212; rc= dynamic_column_update(&str, 1, &val); if (rc == ER_DYNCOL_OK) rc= dynamic_column_get(&str, 1, &res); ok( (rc == ER_DYNCOL_OK) && - (res.type == DYN_COL_UINT) && (res.ulong_value == val.ulong_value), + (res.type == DYN_COL_UINT) && (res.x.ulong_value == val.x.ulong_value), "%s", "empty update"); } @@ -616,7 +616,7 @@ void test_update_many(uint *column_numbers, uint *column_values, for (i= 0; i < column_count; i++) { val[i].type= DYN_COL_UINT; - val[i].ulong_value= column_values[i]; + val[i].x.ulong_value= column_values[i]; } for (i= 0; i < update_count; i++) { @@ -625,13 +625,13 @@ void test_update_many(uint *column_numbers, uint *column_values, else { upd[i].type= DYN_COL_UINT; - upd[i].ulong_value= update_values[i]; + upd[i].x.ulong_value= update_values[i]; } } for (i= 0; i < result_count; i++) { res[i].type= DYN_COL_UINT; - res[i].ulong_value= result_values[i]; + res[i].x.ulong_value= result_values[i]; } if (dynamic_column_create_many(&str1, column_count, column_numbers, val)) goto err; |