26
26
#include <drizzled/cached_item.h>
27
27
#include <drizzled/check_stack_overrun.h>
28
28
#include <drizzled/current_session.h>
29
#include <drizzled/display.h>
29
30
#include <drizzled/error.h>
30
31
#include <drizzled/internal/my_sys.h>
31
32
#include <drizzled/item/cache_int.h>
33
34
#include <drizzled/item/int_with_ref.h>
34
35
#include <drizzled/item/subselect.h>
35
36
#include <drizzled/session.h>
37
#include <drizzled/sql_lex.h>
36
38
#include <drizzled/sql_select.h>
39
#include <drizzled/system_variables.h>
37
40
#include <drizzled/temporal.h>
38
41
#include <drizzled/time_functions.h>
39
#include <drizzled/sql_lex.h>
40
#include <drizzled/system_variables.h>
43
44
#include <algorithm>
2375
Item_func_if::fix_length_and_dec()
2377
void Item_func_if::fix_length_and_dec()
2377
2379
maybe_null= args[1]->maybe_null || args[2]->maybe_null;
2378
2380
decimals= max(args[1]->decimals, args[2]->decimals);
2400
agg_result_type(&cached_result_type, args+1, 2);
2402
agg_result_type(&cached_result_type, args +1, 2);
2401
2403
if (cached_result_type == STRING_RESULT)
2403
if (agg_arg_charsets(collation, args+1, 2, MY_COLL_ALLOW_CONV, 1))
2405
if (agg_arg_charsets(collation, args +1, 2, MY_COLL_ALLOW_CONV, 1))
2408
2410
collation.set(&my_charset_bin); // Number
2410
cached_field_type= agg_field_type(args + 1, 2);
2412
cached_field_type= agg_field_type(args +1, 2);
2413
if ((cached_result_type == DECIMAL_RESULT )
2414
|| (cached_result_type == INT_RESULT))
2415
switch (cached_result_type)
2416
int len1= args[1]->max_length - args[1]->decimals
2417
- (args[1]->unsigned_flag ? 0 : 1);
2419
int len2= args[2]->max_length - args[2]->decimals
2420
- (args[2]->unsigned_flag ? 0 : 1);
2422
max_length= max(len1, len2) + decimals + (unsigned_flag ? 0 : 1);
2417
case DECIMAL_RESULT:
2420
int len1= args[1]->max_length -args[1]->decimals -(args[1]->unsigned_flag ? 0 : 1);
2421
int len2= args[2]->max_length -args[2]->decimals -(args[2]->unsigned_flag ? 0 : 1);
2422
max_length= max(len1, len2) + decimals + (unsigned_flag ? 0 : 1);
2425
2427
max_length= max(args[1]->max_length, args[2]->max_length);
2450
2458
assert(fixed == 1);
2451
2459
Item *arg= args[0]->val_bool() ? args[1] : args[2];
2452
int64_t value=arg->val_int();
2453
null_value=arg->null_value;
2460
int64_t value= arg->val_int();
2461
null_value= arg->null_value;
2460
2468
assert(fixed == 1);
2461
2469
Item *arg= args[0]->val_bool() ? args[1] : args[2];
2462
String *res=arg->val_str(str);
2470
String *res= arg->val_str(str);
2464
2473
res->set_charset(collation.collation);
2465
null_value=arg->null_value;
2475
null_value= arg->null_value;