mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
MDEV-11330 Split Item_func_hybrid_field_type::val_xxx() into methods in Type_handler
This commit is contained in:
395
sql/item_func.cc
395
sql/item_func.cc
@ -828,237 +828,196 @@ void Item_func_num1::fix_length_and_dec()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String *Item_func_hybrid_field_type::val_str(String *str)
|
String *Item_func_hybrid_field_type::val_str_from_decimal_op(String *str)
|
||||||
{
|
{
|
||||||
DBUG_ASSERT(fixed == 1);
|
my_decimal decimal_value, *val;
|
||||||
switch (Item_func_hybrid_field_type::cmp_type()) {
|
if (!(val= decimal_op_with_null_check(&decimal_value)))
|
||||||
case DECIMAL_RESULT:
|
return 0; // null is set
|
||||||
{
|
DBUG_ASSERT(!null_value);
|
||||||
my_decimal decimal_value, *val;
|
my_decimal_round(E_DEC_FATAL_ERROR, val, decimals, FALSE, val);
|
||||||
if (!(val= decimal_op_with_null_check(&decimal_value)))
|
str->set_charset(collation.collation);
|
||||||
return 0; // null is set
|
my_decimal2string(E_DEC_FATAL_ERROR, val, 0, 0, 0, str);
|
||||||
my_decimal_round(E_DEC_FATAL_ERROR, val, decimals, FALSE, val);
|
|
||||||
str->set_charset(collation.collation);
|
|
||||||
my_decimal2string(E_DEC_FATAL_ERROR, val, 0, 0, 0, str);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case INT_RESULT:
|
|
||||||
{
|
|
||||||
longlong nr= int_op();
|
|
||||||
if (null_value)
|
|
||||||
return 0; /* purecov: inspected */
|
|
||||||
str->set_int(nr, unsigned_flag, collation.collation);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case REAL_RESULT:
|
|
||||||
{
|
|
||||||
double nr= real_op();
|
|
||||||
if (null_value)
|
|
||||||
return 0; /* purecov: inspected */
|
|
||||||
str->set_real(nr, decimals, collation.collation);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TIME_RESULT:
|
|
||||||
{
|
|
||||||
MYSQL_TIME ltime;
|
|
||||||
if (date_op_with_null_check(<ime) ||
|
|
||||||
(null_value= str->alloc(MAX_DATE_STRING_REP_LENGTH)))
|
|
||||||
return (String *) 0;
|
|
||||||
ltime.time_type= mysql_type_to_time_type(field_type());
|
|
||||||
str->length(my_TIME_to_str(<ime, const_cast<char*>(str->ptr()), decimals));
|
|
||||||
str->set_charset(&my_charset_bin);
|
|
||||||
DBUG_ASSERT(!null_value);
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
case STRING_RESULT:
|
|
||||||
return str_op_with_null_check(&str_value);
|
|
||||||
case ROW_RESULT:
|
|
||||||
DBUG_ASSERT(0);
|
|
||||||
}
|
|
||||||
DBUG_ASSERT(!null_value || (str == NULL));
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double Item_func_hybrid_field_type::val_real_from_decimal_op()
|
||||||
double Item_func_hybrid_field_type::val_real()
|
|
||||||
{
|
{
|
||||||
DBUG_ASSERT(fixed == 1);
|
my_decimal decimal_value, *val;
|
||||||
switch (Item_func_hybrid_field_type::cmp_type()) {
|
if (!(val= decimal_op_with_null_check(&decimal_value)))
|
||||||
case DECIMAL_RESULT:
|
return 0.0; // null is set
|
||||||
{
|
double result;
|
||||||
my_decimal decimal_value, *val;
|
my_decimal2double(E_DEC_FATAL_ERROR, val, &result);
|
||||||
double result;
|
return result;
|
||||||
if (!(val= decimal_op_with_null_check(&decimal_value)))
|
|
||||||
return 0.0; // null is set
|
|
||||||
my_decimal2double(E_DEC_FATAL_ERROR, val, &result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
case INT_RESULT:
|
|
||||||
{
|
|
||||||
longlong result= int_op();
|
|
||||||
return unsigned_flag ? (double) ((ulonglong) result) : (double) result;
|
|
||||||
}
|
|
||||||
case REAL_RESULT:
|
|
||||||
return real_op();
|
|
||||||
case TIME_RESULT:
|
|
||||||
{
|
|
||||||
MYSQL_TIME ltime;
|
|
||||||
if (date_op_with_null_check(<ime))
|
|
||||||
return 0;
|
|
||||||
ltime.time_type= mysql_type_to_time_type(field_type());
|
|
||||||
return TIME_to_double(<ime);
|
|
||||||
}
|
|
||||||
case STRING_RESULT:
|
|
||||||
{
|
|
||||||
String *res= str_op_with_null_check(&str_value);
|
|
||||||
return res ? double_from_string_with_check(res) : 0.0;
|
|
||||||
}
|
|
||||||
case ROW_RESULT:
|
|
||||||
DBUG_ASSERT(0);
|
|
||||||
}
|
|
||||||
return 0.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
longlong Item_func_hybrid_field_type::val_int_from_decimal_op()
|
||||||
longlong Item_func_hybrid_field_type::val_int()
|
|
||||||
{
|
{
|
||||||
DBUG_ASSERT(fixed == 1);
|
my_decimal decimal_value, *val;
|
||||||
switch (Item_func_hybrid_field_type::cmp_type()) {
|
if (!(val= decimal_op_with_null_check(&decimal_value)))
|
||||||
case DECIMAL_RESULT:
|
return 0; // null is set
|
||||||
{
|
longlong result;
|
||||||
my_decimal decimal_value, *val;
|
my_decimal2int(E_DEC_FATAL_ERROR, val, unsigned_flag, &result);
|
||||||
if (!(val= decimal_op_with_null_check(&decimal_value)))
|
return result;
|
||||||
return 0; // null is set
|
|
||||||
longlong result;
|
|
||||||
my_decimal2int(E_DEC_FATAL_ERROR, val, unsigned_flag, &result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
case INT_RESULT:
|
|
||||||
return int_op();
|
|
||||||
case REAL_RESULT:
|
|
||||||
return (longlong) rint(real_op());
|
|
||||||
case TIME_RESULT:
|
|
||||||
{
|
|
||||||
MYSQL_TIME ltime;
|
|
||||||
if (date_op_with_null_check(<ime))
|
|
||||||
return 0;
|
|
||||||
ltime.time_type= mysql_type_to_time_type(field_type());
|
|
||||||
return TIME_to_ulonglong(<ime);
|
|
||||||
}
|
|
||||||
case STRING_RESULT:
|
|
||||||
{
|
|
||||||
String *res= str_op_with_null_check(&str_value);
|
|
||||||
return res ? longlong_from_string_with_check(res) : 0;
|
|
||||||
}
|
|
||||||
case ROW_RESULT:
|
|
||||||
DBUG_ASSERT(0);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Item_func_hybrid_field_type::get_date_from_decimal_op(MYSQL_TIME *ltime,
|
||||||
my_decimal *Item_func_hybrid_field_type::val_decimal(my_decimal *decimal_value)
|
ulonglong fuzzydate)
|
||||||
{
|
{
|
||||||
my_decimal *val= decimal_value;
|
my_decimal value, *res;
|
||||||
DBUG_ASSERT(fixed == 1);
|
if (!(res= decimal_op_with_null_check(&value)) ||
|
||||||
switch (Item_func_hybrid_field_type::cmp_type()) {
|
decimal_to_datetime_with_warn(res, ltime, fuzzydate,
|
||||||
case DECIMAL_RESULT:
|
field_name_or_null()))
|
||||||
val= decimal_op_with_null_check(decimal_value);
|
return make_zero_mysql_time(ltime, fuzzydate);
|
||||||
break;
|
|
||||||
case INT_RESULT:
|
|
||||||
{
|
|
||||||
longlong result= int_op();
|
|
||||||
if (null_value)
|
|
||||||
return NULL;
|
|
||||||
int2my_decimal(E_DEC_FATAL_ERROR, result, unsigned_flag, decimal_value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case REAL_RESULT:
|
|
||||||
{
|
|
||||||
double result= (double)real_op();
|
|
||||||
if (null_value)
|
|
||||||
return NULL;
|
|
||||||
double2my_decimal(E_DEC_FATAL_ERROR, result, decimal_value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TIME_RESULT:
|
|
||||||
{
|
|
||||||
MYSQL_TIME ltime;
|
|
||||||
if (date_op_with_null_check(<ime))
|
|
||||||
{
|
|
||||||
my_decimal_set_zero(decimal_value);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
ltime.time_type= mysql_type_to_time_type(field_type());
|
|
||||||
return date2my_decimal(<ime, decimal_value);
|
|
||||||
}
|
|
||||||
case STRING_RESULT:
|
|
||||||
{
|
|
||||||
String *res= str_op_with_null_check(&str_value);
|
|
||||||
return res ? decimal_from_string_with_check(decimal_value, res) : 0;
|
|
||||||
}
|
|
||||||
case ROW_RESULT:
|
|
||||||
DBUG_ASSERT(0);
|
|
||||||
}
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Item_func_hybrid_field_type::get_date(MYSQL_TIME *ltime,
|
|
||||||
ulonglong fuzzydate)
|
|
||||||
{
|
|
||||||
DBUG_ASSERT(fixed == 1);
|
|
||||||
switch (Item_func_hybrid_field_type::cmp_type()) {
|
|
||||||
case DECIMAL_RESULT:
|
|
||||||
{
|
|
||||||
my_decimal value, *res;
|
|
||||||
if (!(res= decimal_op_with_null_check(&value)) ||
|
|
||||||
decimal_to_datetime_with_warn(res, ltime, fuzzydate,
|
|
||||||
field_name_or_null()))
|
|
||||||
goto err;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case INT_RESULT:
|
|
||||||
{
|
|
||||||
longlong value= int_op();
|
|
||||||
bool neg= !unsigned_flag && value < 0;
|
|
||||||
if (null_value || int_to_datetime_with_warn(neg, neg ? -value : value,
|
|
||||||
ltime, fuzzydate,
|
|
||||||
field_name_or_null()))
|
|
||||||
goto err;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case REAL_RESULT:
|
|
||||||
{
|
|
||||||
double value= real_op();
|
|
||||||
if (null_value || double_to_datetime_with_warn(value, ltime, fuzzydate,
|
|
||||||
field_name_or_null()))
|
|
||||||
goto err;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TIME_RESULT:
|
|
||||||
return date_op(ltime,
|
|
||||||
fuzzydate |
|
|
||||||
(field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0));
|
|
||||||
case STRING_RESULT:
|
|
||||||
{
|
|
||||||
char buff[40];
|
|
||||||
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
|
|
||||||
if (!(res= str_op_with_null_check(&tmp)) ||
|
|
||||||
str_to_datetime_with_warn(res->charset(), res->ptr(), res->length(),
|
|
||||||
ltime, fuzzydate))
|
|
||||||
goto err;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ROW_RESULT:
|
|
||||||
DBUG_ASSERT(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (null_value= 0);
|
return (null_value= 0);
|
||||||
|
}
|
||||||
|
|
||||||
err:
|
|
||||||
bzero(ltime, sizeof(*ltime));
|
String *Item_func_hybrid_field_type::val_str_from_int_op(String *str)
|
||||||
return null_value|= !(fuzzydate & TIME_FUZZY_DATES);
|
{
|
||||||
|
longlong nr= int_op();
|
||||||
|
if (null_value)
|
||||||
|
return 0; /* purecov: inspected */
|
||||||
|
str->set_int(nr, unsigned_flag, collation.collation);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Item_func_hybrid_field_type::val_real_from_int_op()
|
||||||
|
{
|
||||||
|
longlong result= int_op();
|
||||||
|
return unsigned_flag ? (double) ((ulonglong) result) : (double) result;
|
||||||
|
}
|
||||||
|
|
||||||
|
my_decimal *
|
||||||
|
Item_func_hybrid_field_type::val_decimal_from_int_op(my_decimal *dec)
|
||||||
|
{
|
||||||
|
longlong result= int_op();
|
||||||
|
if (null_value)
|
||||||
|
return NULL;
|
||||||
|
int2my_decimal(E_DEC_FATAL_ERROR, result, unsigned_flag, dec);
|
||||||
|
return dec;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Item_func_hybrid_field_type::get_date_from_int_op(MYSQL_TIME *ltime,
|
||||||
|
ulonglong fuzzydate)
|
||||||
|
{
|
||||||
|
longlong value= int_op();
|
||||||
|
bool neg= !unsigned_flag && value < 0;
|
||||||
|
if (null_value || int_to_datetime_with_warn(neg, neg ? -value : value,
|
||||||
|
ltime, fuzzydate,
|
||||||
|
field_name_or_null()))
|
||||||
|
return make_zero_mysql_time(ltime, fuzzydate);
|
||||||
|
return (null_value= 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String *Item_func_hybrid_field_type::val_str_from_real_op(String *str)
|
||||||
|
{
|
||||||
|
double nr= real_op();
|
||||||
|
if (null_value)
|
||||||
|
return 0; /* purecov: inspected */
|
||||||
|
str->set_real(nr, decimals, collation.collation);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
longlong Item_func_hybrid_field_type::val_int_from_real_op()
|
||||||
|
{
|
||||||
|
return (longlong) rint(real_op());
|
||||||
|
}
|
||||||
|
|
||||||
|
my_decimal *
|
||||||
|
Item_func_hybrid_field_type::val_decimal_from_real_op(my_decimal *dec)
|
||||||
|
{
|
||||||
|
double result= (double) real_op();
|
||||||
|
if (null_value)
|
||||||
|
return NULL;
|
||||||
|
double2my_decimal(E_DEC_FATAL_ERROR, result, dec);
|
||||||
|
return dec;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Item_func_hybrid_field_type::get_date_from_real_op(MYSQL_TIME *ltime,
|
||||||
|
ulonglong fuzzydate)
|
||||||
|
{
|
||||||
|
double value= real_op();
|
||||||
|
if (null_value || double_to_datetime_with_warn(value, ltime, fuzzydate,
|
||||||
|
field_name_or_null()))
|
||||||
|
return make_zero_mysql_time(ltime, fuzzydate);
|
||||||
|
return (null_value= 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String *Item_func_hybrid_field_type::val_str_from_date_op(String *str)
|
||||||
|
{
|
||||||
|
MYSQL_TIME ltime;
|
||||||
|
if (date_op_with_null_check(<ime) ||
|
||||||
|
(null_value= str->alloc(MAX_DATE_STRING_REP_LENGTH)))
|
||||||
|
return (String *) 0;
|
||||||
|
ltime.time_type= mysql_type_to_time_type(field_type());
|
||||||
|
str->length(my_TIME_to_str(<ime, const_cast<char*>(str->ptr()), decimals));
|
||||||
|
str->set_charset(&my_charset_bin);
|
||||||
|
DBUG_ASSERT(!null_value);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Item_func_hybrid_field_type::val_real_from_date_op()
|
||||||
|
{
|
||||||
|
MYSQL_TIME ltime;
|
||||||
|
if (date_op_with_null_check(<ime))
|
||||||
|
return 0;
|
||||||
|
ltime.time_type= mysql_type_to_time_type(field_type());
|
||||||
|
return TIME_to_double(<ime);
|
||||||
|
}
|
||||||
|
longlong Item_func_hybrid_field_type::val_int_from_date_op()
|
||||||
|
{
|
||||||
|
MYSQL_TIME ltime;
|
||||||
|
if (date_op_with_null_check(<ime))
|
||||||
|
return 0;
|
||||||
|
ltime.time_type= mysql_type_to_time_type(field_type());
|
||||||
|
return TIME_to_ulonglong(<ime);
|
||||||
|
}
|
||||||
|
|
||||||
|
my_decimal *
|
||||||
|
Item_func_hybrid_field_type::val_decimal_from_date_op(my_decimal *dec)
|
||||||
|
{
|
||||||
|
MYSQL_TIME ltime;
|
||||||
|
if (date_op_with_null_check(<ime))
|
||||||
|
{
|
||||||
|
my_decimal_set_zero(dec);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ltime.time_type= mysql_type_to_time_type(field_type());
|
||||||
|
return date2my_decimal(<ime, dec);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double Item_func_hybrid_field_type::val_real_from_str_op()
|
||||||
|
{
|
||||||
|
String *res= str_op_with_null_check(&str_value);
|
||||||
|
return res ? double_from_string_with_check(res) : 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
longlong Item_func_hybrid_field_type::val_int_from_str_op()
|
||||||
|
{
|
||||||
|
String *res= str_op_with_null_check(&str_value);
|
||||||
|
return res ? longlong_from_string_with_check(res) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
my_decimal *
|
||||||
|
Item_func_hybrid_field_type::val_decimal_from_str_op(my_decimal *decimal_value)
|
||||||
|
{
|
||||||
|
String *res= str_op_with_null_check(&str_value);
|
||||||
|
return res ? decimal_from_string_with_check(decimal_value, res) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Item_func_hybrid_field_type::get_date_from_str_op(MYSQL_TIME *ltime,
|
||||||
|
ulonglong fuzzydate)
|
||||||
|
{
|
||||||
|
StringBuffer<40> tmp;
|
||||||
|
String *res;
|
||||||
|
if (!(res= str_op_with_null_check(&tmp)) ||
|
||||||
|
str_to_datetime_with_warn(res->charset(), res->ptr(), res->length(),
|
||||||
|
ltime, fuzzydate))
|
||||||
|
return make_zero_mysql_time(ltime, fuzzydate);
|
||||||
|
return (null_value= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -451,6 +451,62 @@ class Item_func_hybrid_field_type: public Item_hybrid_func
|
|||||||
DBUG_ASSERT((res != NULL) ^ null_value);
|
DBUG_ASSERT((res != NULL) ^ null_value);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
bool make_zero_mysql_time(MYSQL_TIME *ltime, ulonglong fuzzydate)
|
||||||
|
{
|
||||||
|
bzero(ltime, sizeof(*ltime));
|
||||||
|
return null_value|= !(fuzzydate & TIME_FUZZY_DATES);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Value methods that involve no conversion
|
||||||
|
String *val_str_from_str_op(String *str)
|
||||||
|
{
|
||||||
|
return str_op_with_null_check(&str_value);
|
||||||
|
}
|
||||||
|
my_decimal *val_decimal_from_decimal_op(my_decimal *dec)
|
||||||
|
{
|
||||||
|
return decimal_op_with_null_check(dec);
|
||||||
|
}
|
||||||
|
longlong val_int_from_int_op()
|
||||||
|
{
|
||||||
|
return int_op();
|
||||||
|
}
|
||||||
|
double val_real_from_real_op()
|
||||||
|
{
|
||||||
|
return real_op();
|
||||||
|
}
|
||||||
|
bool get_date_from_date_op(MYSQL_TIME *ltime, ulonglong fuzzydate)
|
||||||
|
{
|
||||||
|
return date_op(ltime,
|
||||||
|
fuzzydate |
|
||||||
|
(field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value methods that involve conversion
|
||||||
|
String *val_str_from_decimal_op(String *str);
|
||||||
|
String *val_str_from_real_op(String *str);
|
||||||
|
String *val_str_from_int_op(String *str);
|
||||||
|
String *val_str_from_date_op(String *str);
|
||||||
|
|
||||||
|
my_decimal *val_decimal_from_str_op(my_decimal *dec);
|
||||||
|
my_decimal *val_decimal_from_real_op(my_decimal *dec);
|
||||||
|
my_decimal *val_decimal_from_int_op(my_decimal *dec);
|
||||||
|
my_decimal *val_decimal_from_date_op(my_decimal *dec);
|
||||||
|
|
||||||
|
longlong val_int_from_str_op();
|
||||||
|
longlong val_int_from_real_op();
|
||||||
|
longlong val_int_from_decimal_op();
|
||||||
|
longlong val_int_from_date_op();
|
||||||
|
|
||||||
|
double val_real_from_str_op();
|
||||||
|
double val_real_from_decimal_op();
|
||||||
|
double val_real_from_date_op();
|
||||||
|
double val_real_from_int_op();
|
||||||
|
|
||||||
|
bool get_date_from_str_op(MYSQL_TIME *ltime, ulonglong fuzzydate);
|
||||||
|
bool get_date_from_real_op(MYSQL_TIME *ltime, ulonglong fuzzydate);
|
||||||
|
bool get_date_from_decimal_op(MYSQL_TIME *ltime, ulonglong fuzzydate);
|
||||||
|
bool get_date_from_int_op(MYSQL_TIME *ltime, ulonglong fuzzydate);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Item_func_hybrid_field_type(THD *thd):
|
Item_func_hybrid_field_type(THD *thd):
|
||||||
@ -469,11 +525,38 @@ public:
|
|||||||
Item_hybrid_func(thd, list)
|
Item_hybrid_func(thd, list)
|
||||||
{ collation.set_numeric(); }
|
{ collation.set_numeric(); }
|
||||||
|
|
||||||
double val_real();
|
double val_real()
|
||||||
longlong val_int();
|
{
|
||||||
my_decimal *val_decimal(my_decimal *);
|
DBUG_ASSERT(fixed);
|
||||||
String *val_str(String*str);
|
return Item_func_hybrid_field_type::type_handler()->
|
||||||
bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date);
|
Item_func_hybrid_field_type_val_real(this);
|
||||||
|
}
|
||||||
|
longlong val_int()
|
||||||
|
{
|
||||||
|
DBUG_ASSERT(fixed);
|
||||||
|
return Item_func_hybrid_field_type::type_handler()->
|
||||||
|
Item_func_hybrid_field_type_val_int(this);
|
||||||
|
}
|
||||||
|
my_decimal *val_decimal(my_decimal *dec)
|
||||||
|
{
|
||||||
|
DBUG_ASSERT(fixed);
|
||||||
|
return Item_func_hybrid_field_type::type_handler()->
|
||||||
|
Item_func_hybrid_field_type_val_decimal(this, dec);
|
||||||
|
}
|
||||||
|
String *val_str(String*str)
|
||||||
|
{
|
||||||
|
DBUG_ASSERT(fixed);
|
||||||
|
String *res= Item_func_hybrid_field_type::type_handler()->
|
||||||
|
Item_func_hybrid_field_type_val_str(this, str);
|
||||||
|
DBUG_ASSERT(null_value == (res == NULL));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date)
|
||||||
|
{
|
||||||
|
DBUG_ASSERT(fixed);
|
||||||
|
return Item_func_hybrid_field_type::type_handler()->
|
||||||
|
Item_func_hybrid_field_type_get_date(this, res, fuzzy_date);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Performs the operation that this functions implements when the
|
@brief Performs the operation that this functions implements when the
|
||||||
|
243
sql/sql_type.cc
243
sql/sql_type.cc
@ -899,4 +899,245 @@ Type_handler_string_result::Item_func_hex_val_str_ascii(Item_func_hex *item,
|
|||||||
return item->val_str_ascii_from_val_str(str);
|
return item->val_str_ascii_from_val_str(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************/
|
/***************************************************************************/
|
||||||
|
|
||||||
|
String *
|
||||||
|
Type_handler_decimal_result::Item_func_hybrid_field_type_val_str(
|
||||||
|
Item_func_hybrid_field_type *item,
|
||||||
|
String *str) const
|
||||||
|
{
|
||||||
|
return item->val_str_from_decimal_op(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double
|
||||||
|
Type_handler_decimal_result::Item_func_hybrid_field_type_val_real(
|
||||||
|
Item_func_hybrid_field_type *item)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return item->val_real_from_decimal_op();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
longlong
|
||||||
|
Type_handler_decimal_result::Item_func_hybrid_field_type_val_int(
|
||||||
|
Item_func_hybrid_field_type *item)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return item->val_int_from_decimal_op();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
my_decimal *
|
||||||
|
Type_handler_decimal_result::Item_func_hybrid_field_type_val_decimal(
|
||||||
|
Item_func_hybrid_field_type *item,
|
||||||
|
my_decimal *dec) const
|
||||||
|
{
|
||||||
|
return item->val_decimal_from_decimal_op(dec);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
Type_handler_decimal_result::Item_func_hybrid_field_type_get_date(
|
||||||
|
Item_func_hybrid_field_type *item,
|
||||||
|
MYSQL_TIME *ltime,
|
||||||
|
ulonglong fuzzydate) const
|
||||||
|
{
|
||||||
|
return item->get_date_from_decimal_op(ltime, fuzzydate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
String *
|
||||||
|
Type_handler_int_result::Item_func_hybrid_field_type_val_str(
|
||||||
|
Item_func_hybrid_field_type *item,
|
||||||
|
String *str) const
|
||||||
|
{
|
||||||
|
return item->val_str_from_int_op(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double
|
||||||
|
Type_handler_int_result::Item_func_hybrid_field_type_val_real(
|
||||||
|
Item_func_hybrid_field_type *item)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return item->val_real_from_int_op();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
longlong
|
||||||
|
Type_handler_int_result::Item_func_hybrid_field_type_val_int(
|
||||||
|
Item_func_hybrid_field_type *item)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return item->val_int_from_int_op();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
my_decimal *
|
||||||
|
Type_handler_int_result::Item_func_hybrid_field_type_val_decimal(
|
||||||
|
Item_func_hybrid_field_type *item,
|
||||||
|
my_decimal *dec) const
|
||||||
|
{
|
||||||
|
return item->val_decimal_from_int_op(dec);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
Type_handler_int_result::Item_func_hybrid_field_type_get_date(
|
||||||
|
Item_func_hybrid_field_type *item,
|
||||||
|
MYSQL_TIME *ltime,
|
||||||
|
ulonglong fuzzydate) const
|
||||||
|
{
|
||||||
|
return item->get_date_from_int_op(ltime, fuzzydate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
String *
|
||||||
|
Type_handler_real_result::Item_func_hybrid_field_type_val_str(
|
||||||
|
Item_func_hybrid_field_type *item,
|
||||||
|
String *str) const
|
||||||
|
{
|
||||||
|
return item->val_str_from_real_op(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double
|
||||||
|
Type_handler_real_result::Item_func_hybrid_field_type_val_real(
|
||||||
|
Item_func_hybrid_field_type *item)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return item->val_real_from_real_op();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
longlong
|
||||||
|
Type_handler_real_result::Item_func_hybrid_field_type_val_int(
|
||||||
|
Item_func_hybrid_field_type *item)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return item->val_int_from_real_op();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
my_decimal *
|
||||||
|
Type_handler_real_result::Item_func_hybrid_field_type_val_decimal(
|
||||||
|
Item_func_hybrid_field_type *item,
|
||||||
|
my_decimal *dec) const
|
||||||
|
{
|
||||||
|
return item->val_decimal_from_real_op(dec);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
Type_handler_real_result::Item_func_hybrid_field_type_get_date(
|
||||||
|
Item_func_hybrid_field_type *item,
|
||||||
|
MYSQL_TIME *ltime,
|
||||||
|
ulonglong fuzzydate) const
|
||||||
|
{
|
||||||
|
return item->get_date_from_real_op(ltime, fuzzydate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
String *
|
||||||
|
Type_handler_temporal_result::Item_func_hybrid_field_type_val_str(
|
||||||
|
Item_func_hybrid_field_type *item,
|
||||||
|
String *str) const
|
||||||
|
{
|
||||||
|
return item->val_str_from_date_op(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double
|
||||||
|
Type_handler_temporal_result::Item_func_hybrid_field_type_val_real(
|
||||||
|
Item_func_hybrid_field_type *item)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return item->val_real_from_date_op();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
longlong
|
||||||
|
Type_handler_temporal_result::Item_func_hybrid_field_type_val_int(
|
||||||
|
Item_func_hybrid_field_type *item)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return item->val_int_from_date_op();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
my_decimal *
|
||||||
|
Type_handler_temporal_result::Item_func_hybrid_field_type_val_decimal(
|
||||||
|
Item_func_hybrid_field_type *item,
|
||||||
|
my_decimal *dec) const
|
||||||
|
{
|
||||||
|
return item->val_decimal_from_date_op(dec);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
Type_handler_temporal_result::Item_func_hybrid_field_type_get_date(
|
||||||
|
Item_func_hybrid_field_type *item,
|
||||||
|
MYSQL_TIME *ltime,
|
||||||
|
ulonglong fuzzydate) const
|
||||||
|
{
|
||||||
|
return item->get_date_from_date_op(ltime, fuzzydate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
String *
|
||||||
|
Type_handler_string_result::Item_func_hybrid_field_type_val_str(
|
||||||
|
Item_func_hybrid_field_type *item,
|
||||||
|
String *str) const
|
||||||
|
{
|
||||||
|
return item->val_str_from_str_op(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double
|
||||||
|
Type_handler_string_result::Item_func_hybrid_field_type_val_real(
|
||||||
|
Item_func_hybrid_field_type *item)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return item->val_real_from_str_op();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
longlong
|
||||||
|
Type_handler_string_result::Item_func_hybrid_field_type_val_int(
|
||||||
|
Item_func_hybrid_field_type *item)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return item->val_int_from_str_op();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
my_decimal *
|
||||||
|
Type_handler_string_result::Item_func_hybrid_field_type_val_decimal(
|
||||||
|
Item_func_hybrid_field_type *item,
|
||||||
|
my_decimal *dec) const
|
||||||
|
{
|
||||||
|
return item->val_decimal_from_str_op(dec);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
Type_handler_string_result::Item_func_hybrid_field_type_get_date(
|
||||||
|
Item_func_hybrid_field_type *item,
|
||||||
|
MYSQL_TIME *ltime,
|
||||||
|
ulonglong fuzzydate) const
|
||||||
|
{
|
||||||
|
return item->get_date_from_str_op(ltime, fuzzydate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
113
sql/sql_type.h
113
sql/sql_type.h
@ -28,6 +28,7 @@ class Item;
|
|||||||
class Item_cache;
|
class Item_cache;
|
||||||
class Item_sum_hybrid;
|
class Item_sum_hybrid;
|
||||||
class Item_func_hex;
|
class Item_func_hex;
|
||||||
|
class Item_func_hybrid_field_type;
|
||||||
class Type_std_attributes;
|
class Type_std_attributes;
|
||||||
class Sort_param;
|
class Sort_param;
|
||||||
class Arg_comparator;
|
class Arg_comparator;
|
||||||
@ -294,6 +295,25 @@ public:
|
|||||||
virtual bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *) const= 0;
|
virtual bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *) const= 0;
|
||||||
virtual String *Item_func_hex_val_str_ascii(Item_func_hex *item,
|
virtual String *Item_func_hex_val_str_ascii(Item_func_hex *item,
|
||||||
String *str) const= 0;
|
String *str) const= 0;
|
||||||
|
|
||||||
|
virtual
|
||||||
|
String *Item_func_hybrid_field_type_val_str(Item_func_hybrid_field_type *,
|
||||||
|
String *) const= 0;
|
||||||
|
virtual
|
||||||
|
double Item_func_hybrid_field_type_val_real(Item_func_hybrid_field_type *)
|
||||||
|
const= 0;
|
||||||
|
virtual
|
||||||
|
longlong Item_func_hybrid_field_type_val_int(Item_func_hybrid_field_type *)
|
||||||
|
const= 0;
|
||||||
|
virtual
|
||||||
|
my_decimal *Item_func_hybrid_field_type_val_decimal(
|
||||||
|
Item_func_hybrid_field_type *,
|
||||||
|
my_decimal *) const= 0;
|
||||||
|
virtual
|
||||||
|
bool Item_func_hybrid_field_type_get_date(Item_func_hybrid_field_type *,
|
||||||
|
MYSQL_TIME *,
|
||||||
|
ulonglong fuzzydate) const= 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -357,6 +377,39 @@ public:
|
|||||||
DBUG_ASSERT(0);
|
DBUG_ASSERT(0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
String *Item_func_hybrid_field_type_val_str(Item_func_hybrid_field_type *,
|
||||||
|
String *) const
|
||||||
|
{
|
||||||
|
DBUG_ASSERT(0);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
double Item_func_hybrid_field_type_val_real(Item_func_hybrid_field_type *)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
DBUG_ASSERT(0);
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
longlong Item_func_hybrid_field_type_val_int(Item_func_hybrid_field_type *)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
DBUG_ASSERT(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
my_decimal *Item_func_hybrid_field_type_val_decimal(
|
||||||
|
Item_func_hybrid_field_type *,
|
||||||
|
my_decimal *) const
|
||||||
|
{
|
||||||
|
DBUG_ASSERT(0);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
bool Item_func_hybrid_field_type_get_date(Item_func_hybrid_field_type *,
|
||||||
|
MYSQL_TIME *,
|
||||||
|
ulonglong fuzzydate) const
|
||||||
|
{
|
||||||
|
DBUG_ASSERT(0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -392,6 +445,18 @@ public:
|
|||||||
bool set_comparator_func(Arg_comparator *cmp) const;
|
bool set_comparator_func(Arg_comparator *cmp) const;
|
||||||
bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const;
|
bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const;
|
||||||
String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const;
|
String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const;
|
||||||
|
String *Item_func_hybrid_field_type_val_str(Item_func_hybrid_field_type *,
|
||||||
|
String *) const;
|
||||||
|
double Item_func_hybrid_field_type_val_real(Item_func_hybrid_field_type *)
|
||||||
|
const;
|
||||||
|
longlong Item_func_hybrid_field_type_val_int(Item_func_hybrid_field_type *)
|
||||||
|
const;
|
||||||
|
my_decimal *Item_func_hybrid_field_type_val_decimal(
|
||||||
|
Item_func_hybrid_field_type *,
|
||||||
|
my_decimal *) const;
|
||||||
|
bool Item_func_hybrid_field_type_get_date(Item_func_hybrid_field_type *,
|
||||||
|
MYSQL_TIME *,
|
||||||
|
ulonglong fuzzydate) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -412,6 +477,18 @@ public:
|
|||||||
bool set_comparator_func(Arg_comparator *cmp) const;
|
bool set_comparator_func(Arg_comparator *cmp) const;
|
||||||
bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const;
|
bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const;
|
||||||
String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const;
|
String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const;
|
||||||
|
String *Item_func_hybrid_field_type_val_str(Item_func_hybrid_field_type *,
|
||||||
|
String *) const;
|
||||||
|
double Item_func_hybrid_field_type_val_real(Item_func_hybrid_field_type *)
|
||||||
|
const;
|
||||||
|
longlong Item_func_hybrid_field_type_val_int(Item_func_hybrid_field_type *)
|
||||||
|
const;
|
||||||
|
my_decimal *Item_func_hybrid_field_type_val_decimal(
|
||||||
|
Item_func_hybrid_field_type *,
|
||||||
|
my_decimal *) const;
|
||||||
|
bool Item_func_hybrid_field_type_get_date(Item_func_hybrid_field_type *,
|
||||||
|
MYSQL_TIME *,
|
||||||
|
ulonglong fuzzydate) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -432,6 +509,18 @@ public:
|
|||||||
bool set_comparator_func(Arg_comparator *cmp) const;
|
bool set_comparator_func(Arg_comparator *cmp) const;
|
||||||
bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const;
|
bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const;
|
||||||
String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const;
|
String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const;
|
||||||
|
String *Item_func_hybrid_field_type_val_str(Item_func_hybrid_field_type *,
|
||||||
|
String *) const;
|
||||||
|
double Item_func_hybrid_field_type_val_real(Item_func_hybrid_field_type *)
|
||||||
|
const;
|
||||||
|
longlong Item_func_hybrid_field_type_val_int(Item_func_hybrid_field_type *)
|
||||||
|
const;
|
||||||
|
my_decimal *Item_func_hybrid_field_type_val_decimal(
|
||||||
|
Item_func_hybrid_field_type *,
|
||||||
|
my_decimal *) const;
|
||||||
|
bool Item_func_hybrid_field_type_get_date(Item_func_hybrid_field_type *,
|
||||||
|
MYSQL_TIME *,
|
||||||
|
ulonglong fuzzydate) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -450,6 +539,18 @@ public:
|
|||||||
bool set_comparator_func(Arg_comparator *cmp) const;
|
bool set_comparator_func(Arg_comparator *cmp) const;
|
||||||
bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const;
|
bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const;
|
||||||
String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const;
|
String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const;
|
||||||
|
String *Item_func_hybrid_field_type_val_str(Item_func_hybrid_field_type *,
|
||||||
|
String *) const;
|
||||||
|
double Item_func_hybrid_field_type_val_real(Item_func_hybrid_field_type *)
|
||||||
|
const;
|
||||||
|
longlong Item_func_hybrid_field_type_val_int(Item_func_hybrid_field_type *)
|
||||||
|
const;
|
||||||
|
my_decimal *Item_func_hybrid_field_type_val_decimal(
|
||||||
|
Item_func_hybrid_field_type *,
|
||||||
|
my_decimal *) const;
|
||||||
|
bool Item_func_hybrid_field_type_get_date(Item_func_hybrid_field_type *,
|
||||||
|
MYSQL_TIME *,
|
||||||
|
ulonglong fuzzydate) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -472,6 +573,18 @@ public:
|
|||||||
bool set_comparator_func(Arg_comparator *cmp) const;
|
bool set_comparator_func(Arg_comparator *cmp) const;
|
||||||
bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const;
|
bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const;
|
||||||
String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const;
|
String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const;
|
||||||
|
String *Item_func_hybrid_field_type_val_str(Item_func_hybrid_field_type *,
|
||||||
|
String *) const;
|
||||||
|
double Item_func_hybrid_field_type_val_real(Item_func_hybrid_field_type *)
|
||||||
|
const;
|
||||||
|
longlong Item_func_hybrid_field_type_val_int(Item_func_hybrid_field_type *)
|
||||||
|
const;
|
||||||
|
my_decimal *Item_func_hybrid_field_type_val_decimal(
|
||||||
|
Item_func_hybrid_field_type *,
|
||||||
|
my_decimal *) const;
|
||||||
|
bool Item_func_hybrid_field_type_get_date(Item_func_hybrid_field_type *,
|
||||||
|
MYSQL_TIME *,
|
||||||
|
ulonglong fuzzydate) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user