diff options
author | unknown <bell@sanja.is.com.ua> | 2004-03-18 15:21:06 +0200 |
---|---|---|
committer | unknown <bell@sanja.is.com.ua> | 2004-03-18 15:21:06 +0200 |
commit | 85dddd908a70bcbcd992b2f24525ff3f96476569 (patch) | |
tree | 55a6329f97a0caf55caa7c27ba9a689a9859565e /sql/item_func.cc | |
parent | bffc3339c5dd71fa810ef44c78d3577a7908c6f2 (diff) | |
parent | 1a81e0414515cef6275b5d2f3f27b950aa1ff91f (diff) | |
download | mariadb-git-85dddd908a70bcbcd992b2f24525ff3f96476569.tar.gz |
merge
sql/field.cc:
Auto merged
sql/item.cc:
Auto merged
sql/item_cmpfunc.cc:
Auto merged
sql/item_func.h:
Auto merged
sql/sql_base.cc:
Auto merged
sql/sql_parse.cc:
Auto merged
sql/sql_select.cc:
Auto merged
sql/sql_show.cc:
Auto merged
sql/sql_update.cc:
Auto merged
sql/sql_yacc.yy:
Auto merged
Diffstat (limited to 'sql/item_func.cc')
-rw-r--r-- | sql/item_func.cc | 86 |
1 files changed, 83 insertions, 3 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc index 04e3452c1f7..be9367ec381 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -199,6 +199,7 @@ Item_func::Item_func(THD *thd, Item_func *item) bool Item_func::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) { + DBUG_ASSERT(fixed == 0); Item **arg,**arg_end; #ifndef EMBEDDED_LIBRARY // Avoid compiler warning char buff[STACK_BUFF_ALLOC]; // Max argument in function @@ -214,8 +215,10 @@ Item_func::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) for (arg=args, arg_end=args+arg_count; arg != arg_end ; arg++) { Item *item; - /* We can't yet set item to *arg as fix_fields may change *arg */ - /* We shouldn't call fix_fields() twice, so check 'fixed' field first */ + /* + We can't yet set item to *arg as fix_fields may change *arg + We shouldn't call fix_fields() twice, so check 'fixed' field first + */ if ((!(*arg)->fixed && (*arg)->fix_fields(thd, tables, arg)) || (*arg)->check_cols(allowed_arg_cols)) return 1; /* purecov: inspected */ @@ -381,6 +384,7 @@ Field *Item_func::tmp_table_field(TABLE *t_arg) String *Item_real_func::val_str(String *str) { + DBUG_ASSERT(fixed == 1); double nr=val(); if (null_value) return 0; /* purecov: inspected */ @@ -391,6 +395,7 @@ String *Item_real_func::val_str(String *str) String *Item_num_func::val_str(String *str) { + DBUG_ASSERT(fixed == 1); if (hybrid_type == INT_RESULT) { longlong nr=val_int(); @@ -423,12 +428,13 @@ void Item_func::fix_num_length_and_dec() Item *Item_func::get_tmp_table_item(THD *thd) { if (!with_sum_func && !const_item()) - return new Item_field(result_field); + return new Item_field(result_field, 1); return copy_or_same(thd); } String *Item_int_func::val_str(String *str) { + DBUG_ASSERT(fixed == 1); longlong nr=val_int(); if (null_value) return 0; @@ -456,6 +462,7 @@ void Item_num_op::find_num_type(void) String *Item_num_op::val_str(String *str) { + DBUG_ASSERT(fixed == 1); if (hybrid_type == INT_RESULT) { longlong nr=val_int(); @@ -497,6 +504,7 @@ void Item_func_unsigned::print(String *str) double Item_func_plus::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val()+args[1]->val(); if ((null_value=args[0]->null_value || args[1]->null_value)) return 0.0; @@ -505,6 +513,7 @@ double Item_func_plus::val() longlong Item_func_plus::val_int() { + DBUG_ASSERT(fixed == 1); if (hybrid_type == INT_RESULT) { longlong value=args[0]->val_int()+args[1]->val_int(); @@ -532,6 +541,7 @@ void Item_func_minus::fix_length_and_dec() double Item_func_minus::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val() - args[1]->val(); if ((null_value=args[0]->null_value || args[1]->null_value)) return 0.0; @@ -540,6 +550,7 @@ double Item_func_minus::val() longlong Item_func_minus::val_int() { + DBUG_ASSERT(fixed == 1); if (hybrid_type == INT_RESULT) { longlong value=args[0]->val_int() - args[1]->val_int(); @@ -553,6 +564,7 @@ longlong Item_func_minus::val_int() double Item_func_mul::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val()*args[1]->val(); if ((null_value=args[0]->null_value || args[1]->null_value)) return 0.0; /* purecov: inspected */ @@ -561,6 +573,7 @@ double Item_func_mul::val() longlong Item_func_mul::val_int() { + DBUG_ASSERT(fixed == 1); if (hybrid_type == INT_RESULT) { longlong value=args[0]->val_int()*args[1]->val_int(); @@ -574,6 +587,7 @@ longlong Item_func_mul::val_int() double Item_func_div::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val(); double val2=args[1]->val(); if ((null_value= val2 == 0.0 || args[0]->null_value || args[1]->null_value)) @@ -583,6 +597,7 @@ double Item_func_div::val() longlong Item_func_div::val_int() { + DBUG_ASSERT(fixed == 1); if (hybrid_type == INT_RESULT) { longlong value=args[0]->val_int(); @@ -607,6 +622,7 @@ void Item_func_div::fix_length_and_dec() /* Integer division */ longlong Item_func_int_div::val_int() { + DBUG_ASSERT(fixed == 1); longlong value=args[0]->val_int(); longlong val2=args[1]->val_int(); if ((null_value= val2 == 0 || args[0]->null_value || args[1]->null_value)) @@ -627,6 +643,7 @@ void Item_func_int_div::fix_length_and_dec() double Item_func_mod::val() { + DBUG_ASSERT(fixed == 1); double value= floor(args[0]->val()+0.5); double val2=floor(args[1]->val()+0.5); if ((null_value=val2 == 0.0 || args[0]->null_value || args[1]->null_value)) @@ -636,6 +653,7 @@ double Item_func_mod::val() longlong Item_func_mod::val_int() { + DBUG_ASSERT(fixed == 1); longlong value= args[0]->val_int(); longlong val2= args[1]->val_int(); if ((null_value=val2 == 0 || args[0]->null_value || args[1]->null_value)) @@ -654,6 +672,7 @@ void Item_func_mod::fix_length_and_dec() double Item_func_neg::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val(); null_value=args[0]->null_value; return -value; @@ -662,6 +681,7 @@ double Item_func_neg::val() longlong Item_func_neg::val_int() { + DBUG_ASSERT(fixed == 1); longlong value=args[0]->val_int(); null_value=args[0]->null_value; return -value; @@ -695,6 +715,7 @@ void Item_func_neg::fix_length_and_dec() double Item_func_abs::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val(); null_value=args[0]->null_value; return fabs(value); @@ -703,6 +724,7 @@ double Item_func_abs::val() longlong Item_func_abs::val_int() { + DBUG_ASSERT(fixed == 1); longlong value=args[0]->val_int(); null_value=args[0]->null_value; return value >= 0 ? value : -value; @@ -725,6 +747,7 @@ void Item_func_abs::fix_length_and_dec() /* Gateway to natural LOG function */ double Item_func_ln::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val(); if ((null_value=(args[0]->null_value || value <= 0.0))) return 0.0; @@ -738,6 +761,7 @@ double Item_func_ln::val() */ double Item_func_log::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val(); if ((null_value=(args[0]->null_value || value <= 0.0))) return 0.0; @@ -753,6 +777,7 @@ double Item_func_log::val() double Item_func_log2::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val(); if ((null_value=(args[0]->null_value || value <= 0.0))) return 0.0; @@ -761,6 +786,7 @@ double Item_func_log2::val() double Item_func_log10::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val(); if ((null_value=(args[0]->null_value || value <= 0.0))) return 0.0; /* purecov: inspected */ @@ -769,6 +795,7 @@ double Item_func_log10::val() double Item_func_exp::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val(); if ((null_value=args[0]->null_value)) return 0.0; /* purecov: inspected */ @@ -777,6 +804,7 @@ double Item_func_exp::val() double Item_func_sqrt::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val(); if ((null_value=(args[0]->null_value || value < 0))) return 0.0; /* purecov: inspected */ @@ -785,6 +813,7 @@ double Item_func_sqrt::val() double Item_func_pow::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val(); double val2=args[1]->val(); if ((null_value=(args[0]->null_value || args[1]->null_value))) @@ -796,6 +825,7 @@ double Item_func_pow::val() double Item_func_acos::val() { + DBUG_ASSERT(fixed == 1); // the volatile's for BUG #2338 to calm optimizer down (because of gcc's bug) volatile double value=args[0]->val(); if ((null_value=(args[0]->null_value || (value < -1.0 || value > 1.0)))) @@ -805,6 +835,7 @@ double Item_func_acos::val() double Item_func_asin::val() { + DBUG_ASSERT(fixed == 1); // the volatile's for BUG #2338 to calm optimizer down (because of gcc's bug) volatile double value=args[0]->val(); if ((null_value=(args[0]->null_value || (value < -1.0 || value > 1.0)))) @@ -814,6 +845,7 @@ double Item_func_asin::val() double Item_func_atan::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val(); if ((null_value=args[0]->null_value)) return 0.0; @@ -829,6 +861,7 @@ double Item_func_atan::val() double Item_func_cos::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val(); if ((null_value=args[0]->null_value)) return 0.0; @@ -837,6 +870,7 @@ double Item_func_cos::val() double Item_func_sin::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val(); if ((null_value=args[0]->null_value)) return 0.0; @@ -845,6 +879,7 @@ double Item_func_sin::val() double Item_func_tan::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val(); if ((null_value=args[0]->null_value)) return 0.0; @@ -857,6 +892,7 @@ double Item_func_tan::val() longlong Item_func_shift_left::val_int() { + DBUG_ASSERT(fixed == 1); uint shift; ulonglong res= ((ulonglong) args[0]->val_int() << (shift=(uint) args[1]->val_int())); @@ -871,6 +907,7 @@ longlong Item_func_shift_left::val_int() longlong Item_func_shift_right::val_int() { + DBUG_ASSERT(fixed == 1); uint shift; ulonglong res= (ulonglong) args[0]->val_int() >> (shift=(uint) args[1]->val_int()); @@ -886,6 +923,7 @@ longlong Item_func_shift_right::val_int() longlong Item_func_bit_neg::val_int() { + DBUG_ASSERT(fixed == 1); ulonglong res= (ulonglong) args[0]->val_int(); if ((null_value=args[0]->null_value)) return 0; @@ -905,6 +943,7 @@ void Item_func_integer::fix_length_and_dec() longlong Item_func_ceiling::val_int() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val(); null_value=args[0]->null_value; return (longlong) ceil(value); @@ -912,6 +951,7 @@ longlong Item_func_ceiling::val_int() longlong Item_func_floor::val_int() { + DBUG_ASSERT(fixed == 1); // the volatile's for BUG #3051 to calm optimizer down (because of gcc's bug) volatile double value=args[0]->val(); null_value=args[0]->null_value; @@ -934,6 +974,7 @@ void Item_func_round::fix_length_and_dec() double Item_func_round::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val(); int dec=(int) args[1]->val_int(); uint abs_dec=abs(dec); @@ -1001,11 +1042,13 @@ void Item_func_rand::update_used_tables() double Item_func_rand::val() { + DBUG_ASSERT(fixed == 1); return my_rnd(rand); } longlong Item_func_sign::val_int() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val(); null_value=args[0]->null_value; return value < 0.0 ? -1 : (value > 0 ? 1 : 0); @@ -1014,6 +1057,7 @@ longlong Item_func_sign::val_int() double Item_func_units::val() { + DBUG_ASSERT(fixed == 1); double value=args[0]->val(); if ((null_value=args[0]->null_value)) return 0; @@ -1045,6 +1089,7 @@ void Item_func_min_max::fix_length_and_dec() String *Item_func_min_max::val_str(String *str) { + DBUG_ASSERT(fixed == 1); switch (cmp_type) { case INT_RESULT: { @@ -1106,6 +1151,7 @@ String *Item_func_min_max::val_str(String *str) double Item_func_min_max::val() { + DBUG_ASSERT(fixed == 1); double value=0.0; null_value=1; for (uint i=0; i < arg_count ; i++) @@ -1128,6 +1174,7 @@ double Item_func_min_max::val() longlong Item_func_min_max::val_int() { + DBUG_ASSERT(fixed == 1); longlong value=0; null_value=1; for (uint i=0; i < arg_count ; i++) @@ -1149,6 +1196,7 @@ longlong Item_func_min_max::val_int() longlong Item_func_length::val_int() { + DBUG_ASSERT(fixed == 1); String *res=args[0]->val_str(&value); if (!res) { @@ -1162,6 +1210,7 @@ longlong Item_func_length::val_int() longlong Item_func_char_length::val_int() { + DBUG_ASSERT(fixed == 1); String *res=args[0]->val_str(&value); if (!res) { @@ -1175,6 +1224,7 @@ longlong Item_func_char_length::val_int() longlong Item_func_coercibility::val_int() { + DBUG_ASSERT(fixed == 1); if (args[0]->null_value) { null_value= 1; @@ -1194,6 +1244,7 @@ void Item_func_locate::fix_length_and_dec() longlong Item_func_locate::val_int() { + DBUG_ASSERT(fixed == 1); String *a=args[0]->val_str(&value1); String *b=args[1]->val_str(&value2); if (!a || !b) @@ -1244,6 +1295,7 @@ void Item_func_locate::print(String *str) longlong Item_func_field::val_int() { + DBUG_ASSERT(fixed == 1); if (cmp_type == STRING_RESULT) { String *field; @@ -1291,6 +1343,7 @@ void Item_func_field::fix_length_and_dec() longlong Item_func_ascii::val_int() { + DBUG_ASSERT(fixed == 1); String *res=args[0]->val_str(&value); if (!res) { @@ -1303,6 +1356,7 @@ longlong Item_func_ascii::val_int() longlong Item_func_ord::val_int() { + DBUG_ASSERT(fixed == 1); String *res=args[0]->val_str(&value); if (!res) { @@ -1357,6 +1411,7 @@ static const char separator=','; longlong Item_func_find_in_set::val_int() { + DBUG_ASSERT(fixed == 1); if (enum_value) { ulonglong tmp=(ulonglong) args[1]->val_int(); @@ -1410,6 +1465,7 @@ longlong Item_func_find_in_set::val_int() longlong Item_func_bit_count::val_int() { + DBUG_ASSERT(fixed == 1); ulonglong value= (ulonglong) args[0]->val_int(); if (args[0]->null_value) { @@ -1682,6 +1738,7 @@ String *udf_handler::val_str(String *str,String *save_str) double Item_func_udf_float::val() { + DBUG_ASSERT(fixed == 1); DBUG_ENTER("Item_func_udf_float::val"); DBUG_PRINT("info",("result_type: %d arg_count: %d", args[0]->result_type(), arg_count)); @@ -1691,6 +1748,7 @@ double Item_func_udf_float::val() String *Item_func_udf_float::val_str(String *str) { + DBUG_ASSERT(fixed == 1); double nr=val(); if (null_value) return 0; /* purecov: inspected */ @@ -1701,6 +1759,7 @@ String *Item_func_udf_float::val_str(String *str) longlong Item_func_udf_int::val_int() { + DBUG_ASSERT(fixed == 1); DBUG_ENTER("Item_func_udf_int::val_int"); DBUG_PRINT("info",("result_type: %d arg_count: %d", args[0]->result_type(), arg_count)); @@ -1711,6 +1770,7 @@ longlong Item_func_udf_int::val_int() String *Item_func_udf_int::val_str(String *str) { + DBUG_ASSERT(fixed == 1); longlong nr=val_int(); if (null_value) return 0; @@ -1734,6 +1794,7 @@ void Item_func_udf_str::fix_length_and_dec() String *Item_func_udf_str::val_str(String *str) { + DBUG_ASSERT(fixed == 1); String *res=udf.val_str(str,&str_value); null_value = !res; return res; @@ -1847,6 +1908,7 @@ void item_user_lock_release(User_level_lock *ull) longlong Item_master_pos_wait::val_int() { + DBUG_ASSERT(fixed == 1); THD* thd = current_thd; String *log_name = args[0]->val_str(&value); int event_count= 0; @@ -1948,6 +2010,7 @@ void debug_sync_point(const char* lock_name, uint lock_timeout) longlong Item_func_get_lock::val_int() { + DBUG_ASSERT(fixed == 1); String *res=args[0]->val_str(&value); longlong timeout=args[1]->val_int(); struct timespec abstime; @@ -2043,6 +2106,7 @@ longlong Item_func_get_lock::val_int() longlong Item_func_release_lock::val_int() { + DBUG_ASSERT(fixed == 1); String *res=args[0]->val_str(&value); User_level_lock *ull; longlong result; @@ -2077,6 +2141,7 @@ longlong Item_func_release_lock::val_int() longlong Item_func_set_last_insert_id::val_int() { + DBUG_ASSERT(fixed == 1); longlong value=args[0]->val_int(); current_thd->insert_id(value); null_value=args[0]->null_value; @@ -2087,6 +2152,7 @@ longlong Item_func_set_last_insert_id::val_int() longlong Item_func_benchmark::val_int() { + DBUG_ASSERT(fixed == 1); char buff[MAX_FIELD_WIDTH]; String tmp(buff,sizeof(buff), &my_charset_bin); THD *thd=current_thd; @@ -2179,6 +2245,7 @@ static user_var_entry *get_variable(HASH *hash, LEX_STRING &name, bool Item_func_set_user_var::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) { + DBUG_ASSERT(fixed == 0); /* fix_fields will call Item_func_set_user_var::fix_length_and_dec */ if (Item_func::fix_fields(thd, tables, ref) || !(entry= get_variable(&thd->user_vars, name, 1))) @@ -2443,6 +2510,7 @@ Item_func_set_user_var::update() double Item_func_set_user_var::val() { + DBUG_ASSERT(fixed == 1); check(); update(); // Store expression return entry->val(&null_value); @@ -2450,6 +2518,7 @@ double Item_func_set_user_var::val() longlong Item_func_set_user_var::val_int() { + DBUG_ASSERT(fixed == 1); check(); update(); // Store expression return entry->val_int(&null_value); @@ -2457,6 +2526,7 @@ longlong Item_func_set_user_var::val_int() String *Item_func_set_user_var::val_str(String *str) { + DBUG_ASSERT(fixed == 1); check(); update(); // Store expression return entry->val_str(&null_value, str, decimals); @@ -2476,6 +2546,7 @@ void Item_func_set_user_var::print(String *str) String * Item_func_get_user_var::val_str(String *str) { + DBUG_ASSERT(fixed == 1); DBUG_ENTER("Item_func_get_user_var::val_str"); if (!var_entry) DBUG_RETURN((String*) 0); // No such variable @@ -2485,6 +2556,7 @@ Item_func_get_user_var::val_str(String *str) double Item_func_get_user_var::val() { + DBUG_ASSERT(fixed == 1); if (!var_entry) return 0.0; // No such variable return (var_entry->val(&null_value)); @@ -2493,6 +2565,7 @@ double Item_func_get_user_var::val() longlong Item_func_get_user_var::val_int() { + DBUG_ASSERT(fixed == 1); if (!var_entry) return LL(0); // No such variable return (var_entry->val_int(&null_value)); @@ -2639,6 +2712,7 @@ bool Item_func_get_user_var::eq(const Item *item, bool binary_cmp) const longlong Item_func_inet_aton::val_int() { + DBUG_ASSERT(fixed == 1); uint byte_result = 0; ulonglong result = 0; // We are ready for 64 bit addresses const char *p,* end; @@ -2706,6 +2780,7 @@ void Item_func_match::init_search(bool no_order) fields.push_back(args[i]); concat=new Item_func_concat_ws(new Item_string(" ",1, cmp_collation.collation), fields); + concat->fix_fields(current_thd, 0, &concat); } if (master) @@ -2748,6 +2823,7 @@ void Item_func_match::init_search(bool no_order) bool Item_func_match::fix_fields(THD *thd, TABLE_LIST *tlist, Item **ref) { + DBUG_ASSERT(fixed == 0); Item *item; LINT_INIT(item); // Safe as arg_count is > 1 @@ -2892,6 +2968,7 @@ bool Item_func_match::eq(const Item *item, bool binary_cmp) const double Item_func_match::val() { + DBUG_ASSERT(fixed == 1); DBUG_ENTER("Item_func_match::val"); if (ft_handler == NULL) DBUG_RETURN(-1.0); @@ -2934,6 +3011,7 @@ void Item_func_match::print(String *str) longlong Item_func_bit_xor::val_int() { + DBUG_ASSERT(fixed == 1); ulonglong arg1= (ulonglong) args[0]->val_int(); ulonglong arg2= (ulonglong) args[1]->val_int(); if ((null_value= (args[0]->null_value || args[1]->null_value))) @@ -3062,6 +3140,7 @@ Item *get_system_var(THD *thd, enum_var_type var_type, const char *var_name, longlong Item_func_is_free_lock::val_int() { + DBUG_ASSERT(fixed == 1); String *res=args[0]->val_str(&value); THD *thd=current_thd; User_level_lock *ull; @@ -3084,6 +3163,7 @@ longlong Item_func_is_free_lock::val_int() longlong Item_func_is_used_lock::val_int() { + DBUG_ASSERT(fixed == 1); String *res=args[0]->val_str(&value); THD *thd=current_thd; User_level_lock *ull; |