mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-13526 Add Type_handler::Item_val_bool()
This commit is contained in:
30
sql/item.cc
30
sql/item.cc
@ -109,36 +109,6 @@ void Item::push_note_converted_to_positive_complement(THD *thd)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@todo
|
||||
Make this functions class dependent
|
||||
*/
|
||||
|
||||
bool Item::val_bool()
|
||||
{
|
||||
switch(result_type()) {
|
||||
case INT_RESULT:
|
||||
return val_int() != 0;
|
||||
case DECIMAL_RESULT:
|
||||
{
|
||||
my_decimal decimal_value;
|
||||
my_decimal *val= val_decimal(&decimal_value);
|
||||
if (val)
|
||||
return !my_decimal_is_zero(val);
|
||||
return 0;
|
||||
}
|
||||
case REAL_RESULT:
|
||||
case STRING_RESULT:
|
||||
return val_real() != 0.0;
|
||||
case ROW_RESULT:
|
||||
case TIME_RESULT:
|
||||
DBUG_ASSERT(0);
|
||||
return 0; // Wrong (but safe)
|
||||
}
|
||||
return 0; // Wrong (but safe)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Get date/time/datetime.
|
||||
Optionally extend TIME result to DATETIME.
|
||||
|
@ -1047,7 +1047,10 @@ public:
|
||||
FALSE value is false or NULL
|
||||
TRUE value is true (not equal to 0)
|
||||
*/
|
||||
virtual bool val_bool();
|
||||
virtual bool val_bool()
|
||||
{
|
||||
return type_handler()->Item_val_bool(this);
|
||||
}
|
||||
virtual String *val_nodeset(String*) { return 0; }
|
||||
|
||||
/*
|
||||
|
@ -3077,6 +3077,38 @@ bool Type_handler_geometry::
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
bool Type_handler_real_result::Item_val_bool(Item *item) const
|
||||
{
|
||||
return item->val_real() != 0.0;
|
||||
}
|
||||
|
||||
bool Type_handler_int_result::Item_val_bool(Item *item) const
|
||||
{
|
||||
return item->val_int() != 0;
|
||||
}
|
||||
|
||||
bool Type_handler_decimal_result::Item_val_bool(Item *item) const
|
||||
{
|
||||
my_decimal decimal_value;
|
||||
my_decimal *val= item->val_decimal(&decimal_value);
|
||||
if (val)
|
||||
return !my_decimal_is_zero(val);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Type_handler_temporal_result::Item_val_bool(Item *item) const
|
||||
{
|
||||
return item->val_real() != 0.0;
|
||||
}
|
||||
|
||||
bool Type_handler_string_result::Item_val_bool(Item *item) const
|
||||
{
|
||||
return item->val_real() != 0.0;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
longlong Type_handler_real_result::
|
||||
|
@ -891,6 +891,7 @@ public:
|
||||
virtual
|
||||
bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const= 0;
|
||||
|
||||
virtual bool Item_val_bool(Item *item) const= 0;
|
||||
virtual longlong Item_val_int_signed_typecast(Item *item) const= 0;
|
||||
virtual longlong Item_val_int_unsigned_typecast(Item *item) const= 0;
|
||||
|
||||
@ -1147,6 +1148,11 @@ public:
|
||||
DBUG_ASSERT(0);
|
||||
return true;
|
||||
}
|
||||
bool Item_val_bool(Item *item) const
|
||||
{
|
||||
DBUG_ASSERT(0);
|
||||
return false;
|
||||
}
|
||||
longlong Item_val_int_signed_typecast(Item *item) const
|
||||
{
|
||||
DBUG_ASSERT(0);
|
||||
@ -1352,6 +1358,7 @@ public:
|
||||
bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const;
|
||||
bool Item_func_signed_fix_length_and_dec(Item_func_signed *item) const;
|
||||
bool Item_func_unsigned_fix_length_and_dec(Item_func_unsigned *item) const;
|
||||
bool Item_val_bool(Item *item) const;
|
||||
longlong Item_val_int_signed_typecast(Item *item) const;
|
||||
longlong Item_val_int_unsigned_typecast(Item *item) const;
|
||||
String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const;
|
||||
@ -1427,6 +1434,7 @@ public:
|
||||
bool Item_sum_sum_fix_length_and_dec(Item_sum_sum *) const;
|
||||
bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const;
|
||||
bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const;
|
||||
bool Item_val_bool(Item *item) const;
|
||||
longlong Item_val_int_signed_typecast(Item *item) const;
|
||||
longlong Item_val_int_unsigned_typecast(Item *item) const;
|
||||
String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const;
|
||||
@ -1494,6 +1502,7 @@ public:
|
||||
bool Item_sum_sum_fix_length_and_dec(Item_sum_sum *) const;
|
||||
bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const;
|
||||
bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const;
|
||||
bool Item_val_bool(Item *item) const;
|
||||
longlong Item_val_int_signed_typecast(Item *item) const;
|
||||
longlong Item_val_int_unsigned_typecast(Item *item) const;
|
||||
String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const;
|
||||
@ -1564,6 +1573,7 @@ public:
|
||||
bool Item_sum_sum_fix_length_and_dec(Item_sum_sum *) const;
|
||||
bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const;
|
||||
bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const;
|
||||
bool Item_val_bool(Item *item) const;
|
||||
longlong Item_val_int_signed_typecast(Item *item) const;
|
||||
longlong Item_val_int_unsigned_typecast(Item *item) const;
|
||||
String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const;
|
||||
@ -1673,6 +1683,7 @@ public:
|
||||
bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const;
|
||||
bool Item_func_signed_fix_length_and_dec(Item_func_signed *item) const;
|
||||
bool Item_func_unsigned_fix_length_and_dec(Item_func_unsigned *item) const;
|
||||
bool Item_val_bool(Item *item) const;
|
||||
longlong Item_val_int_signed_typecast(Item *item) const;
|
||||
longlong Item_val_int_unsigned_typecast(Item *item) const;
|
||||
String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) const;
|
||||
|
Reference in New Issue
Block a user