~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_func.cc

Merged changes from codestyle.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
  if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") ||
40
40
      !my_strcasecmp(system_charset_info, name->str, "LOCAL") ||
41
41
      !my_strcasecmp(system_charset_info, name->str, "SESSION"))
42
 
    return TRUE;
43
 
  return FALSE;
 
42
    return true;
 
43
  return false;
44
44
}
45
45
 
46
46
 
47
47
/**
48
48
  @return
49
 
    TRUE if item is a constant
 
49
    true if item is a constant
50
50
*/
51
51
 
52
52
bool
53
53
eval_const_cond(COND *cond)
54
54
{
55
 
  return ((Item_func*) cond)->val_int() ? TRUE : FALSE;
 
55
  return ((Item_func*) cond)->val_int() ? true : false;
56
56
}
57
57
 
58
58
 
133
133
   item.
134
134
 
135
135
  RETURN VALUES
136
 
  FALSE ok
137
 
  TRUE  Got error.  Stored with my_error().
 
136
  false ok
 
137
  true  Got error.  Stored with my_error().
138
138
*/
139
139
 
140
140
bool
141
 
Item_func::fix_fields(THD *thd, Item **ref)
 
141
Item_func::fix_fields(THD *thd, Item **ref __attribute__((__unused__)))
142
142
{
143
143
  DBUG_ASSERT(fixed == 0);
144
144
  Item **arg,**arg_end;
149
149
  const_item_cache=1;
150
150
 
151
151
  if (check_stack_overrun(thd, STACK_MIN_SIZE, buff))
152
 
    return TRUE;                                // Fatal error if flag is set!
 
152
    return true;                                // Fatal error if flag is set!
153
153
  if (arg_count)
154
154
  {                                             // Print purify happy
155
155
    for (arg=args, arg_end=args+arg_count; arg != arg_end ; arg++)
160
160
        We shouldn't call fix_fields() twice, so check 'fixed' field first
161
161
      */
162
162
      if ((!(*arg)->fixed && (*arg)->fix_fields(thd, arg)))
163
 
        return TRUE;                            /* purecov: inspected */
 
163
        return true;                            /* purecov: inspected */
164
164
      item= *arg;
165
165
 
166
166
      if (allowed_arg_cols)
188
188
  }
189
189
  fix_length_and_dec();
190
190
  if (thd->is_error()) // An error inside fix_length_and_dec occured
191
 
    return TRUE;
 
191
    return true;
192
192
  fixed= 1;
193
193
  thd->thd_marker= save_thd_marker;
194
 
  return FALSE;
 
194
  return false;
195
195
}
196
196
 
197
197
 
198
 
void Item_func::fix_after_pullout(st_select_lex *new_parent, Item **ref)
 
198
void Item_func::fix_after_pullout(st_select_lex *new_parent,
 
199
                                  Item **ref __attribute__((__unused__)))
199
200
{
200
201
  Item **arg,**arg_end;
201
202
 
307
308
  callback functions.
308
309
 
309
310
    First the function applies the analyzer to the root node of
310
 
    the Item_func object. Then if the analizer succeeeds (returns TRUE)
 
311
    the Item_func object. Then if the analizer succeeeds (returns true)
311
312
    the function recursively applies the compile method to each argument
312
313
    of the Item_func node.
313
314
    If the call of the method for an argument item returns a new item
358
359
{
359
360
  Item **arg, **arg_end;
360
361
  for (arg= args, arg_end= args+arg_count; arg != arg_end ; arg++)
361
 
    (*arg)->split_sum_func2(thd, ref_pointer_array, fields, arg, TRUE);
 
362
    (*arg)->split_sum_func2(thd, ref_pointer_array, fields, arg, true);
362
363
}
363
364
 
364
365
 
649
650
bool Item_func_connection_id::fix_fields(THD *thd, Item **ref)
650
651
{
651
652
  if (Item_int_func::fix_fields(thd, ref))
652
 
    return TRUE;
653
 
  thd->thread_specific_used= TRUE;
 
653
    return true;
 
654
  thd->thread_specific_used= true;
654
655
  value= thd->variables.pseudo_thread_id;
655
 
  return FALSE;
 
656
  return false;
656
657
}
657
658
 
658
659
 
753
754
    my_decimal decimal_value, *val;
754
755
    if (!(val= decimal_op(&decimal_value)))
755
756
      return 0;                                 // null is set
756
 
    my_decimal_round(E_DEC_FATAL_ERROR, val, decimals, FALSE, val);
 
757
    my_decimal_round(E_DEC_FATAL_ERROR, val, decimals, false, val);
757
758
    my_decimal2string(E_DEC_FATAL_ERROR, val, 0, 0, 0, str);
758
759
    break;
759
760
  }
1041
1042
 
1042
1043
  if ((null_value= args[0]->null_value))
1043
1044
    return NULL;
1044
 
  my_decimal_round(E_DEC_FATAL_ERROR, tmp, decimals, FALSE, dec);
 
1045
  my_decimal_round(E_DEC_FATAL_ERROR, tmp, decimals, false, dec);
1045
1046
  sign= dec->sign();
1046
1047
  if (unsigned_flag)
1047
1048
  {
1752
1753
    return 0;
1753
1754
  }
1754
1755
  null_value=0;
1755
 
  return (shift < sizeof(longlong)*8 ? (longlong) res : LL(0));
 
1756
  return (shift < sizeof(longlong)*8 ? (longlong) res : 0LL);
1756
1757
}
1757
1758
 
1758
1759
longlong Item_func_shift_right::val_int()
1767
1768
    return 0;
1768
1769
  }
1769
1770
  null_value=0;
1770
 
  return (shift < sizeof(longlong)*8 ? (longlong) res : LL(0));
 
1771
  return (shift < sizeof(longlong)*8 ? (longlong) res : 0LL);
1771
1772
}
1772
1773
 
1773
1774
 
2130
2131
bool Item_func_rand::fix_fields(THD *thd,Item **ref)
2131
2132
{
2132
2133
  if (Item_real_func::fix_fields(thd, ref))
2133
 
    return TRUE;
 
2134
    return true;
2134
2135
  used_tables_cache|= RAND_TABLE_BIT;
2135
2136
  if (arg_count)
2136
2137
  {                                     // Only use argument once in query
2144
2145
    */
2145
2146
    if (!rand && !(rand= (struct rand_struct*)
2146
2147
                   thd->stmt_arena->alloc(sizeof(*rand))))
2147
 
      return TRUE;
 
2148
      return true;
2148
2149
 
2149
2150
    if (args[0]->const_item())
2150
2151
      seed_random (args[0]);
2164
2165
    }
2165
2166
    rand= &thd->rand;
2166
2167
  }
2167
 
  return FALSE;
 
2168
  return false;
2168
2169
}
2169
2170
 
2170
2171
void Item_func_rand::update_used_tables()
2204
2205
void Item_func_min_max::fix_length_and_dec()
2205
2206
{
2206
2207
  int max_int_part=0;
2207
 
  bool datetime_found= FALSE;
 
2208
  bool datetime_found= false;
2208
2209
  decimals=0;
2209
2210
  max_length=0;
2210
2211
  maybe_null=0;
2220
2221
    cmp_type=item_cmp_type(cmp_type,args[i]->result_type());
2221
2222
    if (args[i]->result_type() != ROW_RESULT && args[i]->is_datetime())
2222
2223
    {
2223
 
      datetime_found= TRUE;
 
2224
      datetime_found= true;
2224
2225
      if (!datetime_item || args[i]->field_type() == MYSQL_TYPE_DATETIME)
2225
2226
        datetime_item= args[i];
2226
2227
    }
2231
2232
    if (datetime_found)
2232
2233
    {
2233
2234
      thd= current_thd;
2234
 
      compare_as_dates= TRUE;
 
2235
      compare_as_dates= true;
2235
2236
    }
2236
2237
  }
2237
2238
  else if ((cmp_type == DECIMAL_RESULT) || (cmp_type == INT_RESULT))
2681
2682
                              find->length(), 0);
2682
2683
        enum_bit=0;
2683
2684
        if (enum_value)
2684
 
          enum_bit=LL(1) << (enum_value-1);
 
2685
          enum_bit=1LL << (enum_value-1);
2685
2686
      }
2686
2687
    }
2687
2688
  }
2752
2753
               wc == (my_wc_t) separator)
2753
2754
        return (longlong) ++position;
2754
2755
      else
2755
 
        return LL(0);
 
2756
        return 0LL;
2756
2757
    }
2757
2758
  }
2758
2759
  return 0;
2788
2789
        (*deinit)(&initid);
2789
2790
      }
2790
2791
      free_udf(u_d);
2791
 
      initialized= FALSE;
 
2792
      initialized= false;
2792
2793
    }
2793
2794
    if (buffers)                                // Because of bug in ecc
2794
2795
      delete [] buffers;
2805
2806
  DBUG_ENTER("Item_udf_func::fix_fields");
2806
2807
 
2807
2808
  if (check_stack_overrun(thd, STACK_MIN_SIZE, buff))
2808
 
    DBUG_RETURN(TRUE);                          // Fatal error flag is set!
 
2809
    DBUG_RETURN(true);                          // Fatal error flag is set!
2809
2810
 
2810
2811
  udf_func *tmp_udf=find_udf(u_d->name.str,(uint) u_d->name.length,1);
2811
2812
 
2812
2813
  if (!tmp_udf)
2813
2814
  {
2814
2815
    my_error(ER_CANT_FIND_UDF, MYF(0), u_d->name.str, errno);
2815
 
    DBUG_RETURN(TRUE);
 
2816
    DBUG_RETURN(true);
2816
2817
  }
2817
2818
  u_d=tmp_udf;
2818
2819
  args=arguments;
2829
2830
 
2830
2831
    {
2831
2832
      free_udf(u_d);
2832
 
      DBUG_RETURN(TRUE);
 
2833
      DBUG_RETURN(true);
2833
2834
    }
2834
2835
    uint i;
2835
2836
    Item **arg,**arg_end;
2843
2844
      // we can't assign 'item' before, because fix_fields() can change arg
2844
2845
      Item *item= *arg;
2845
2846
      if (item->check_cols(1))
2846
 
        DBUG_RETURN(TRUE);
 
2847
        DBUG_RETURN(true);
2847
2848
      /*
2848
2849
        TODO: We should think about this. It is not always
2849
2850
        right way just to set an UDF result to return my_charset_bin
2876
2877
                                                       sizeof(long))))
2877
2878
    {
2878
2879
      free_udf(u_d);
2879
 
      DBUG_RETURN(TRUE);
 
2880
      DBUG_RETURN(true);
2880
2881
    }
2881
2882
  }
2882
2883
  func->fix_length_and_dec();
2945
2946
      my_error(ER_CANT_INITIALIZE_UDF, MYF(0),
2946
2947
               u_d->name.str, init_msg_buff);
2947
2948
      free_udf(u_d);
2948
 
      DBUG_RETURN(TRUE);
 
2949
      DBUG_RETURN(true);
2949
2950
    }
2950
2951
    func->max_length=min(initid.max_length,MAX_BLOB_WIDTH);
2951
2952
    func->maybe_null=initid.maybe_null;
2963
2964
  {
2964
2965
    my_error(ER_CANT_INITIALIZE_UDF, MYF(0),
2965
2966
             u_d->name.str, ER(ER_UNKNOWN_ERROR));
2966
 
    DBUG_RETURN(TRUE);
 
2967
    DBUG_RETURN(true);
2967
2968
  }
2968
 
  DBUG_RETURN(FALSE);
 
2969
  DBUG_RETURN(false);
2969
2970
}
2970
2971
 
2971
2972
 
3191
3192
    return 0;
3192
3193
  if (str->length() < DECIMAL_MAX_STR_LENGTH)
3193
3194
    str->length(DECIMAL_MAX_STR_LENGTH);
3194
 
  my_decimal_round(E_DEC_FATAL_ERROR, dec, decimals, FALSE, &dec_buf);
 
3195
  my_decimal_round(E_DEC_FATAL_ERROR, dec, decimals, false, &dec_buf);
3195
3196
  my_decimal2string(E_DEC_FATAL_ERROR, &dec_buf, 0, 0, '0', str);
3196
3197
  return str;
3197
3198
}
3378
3379
      LAST_INSERT_ID(X) take precedence over an generated auto_increment
3379
3380
      value for this row.
3380
3381
    */
3381
 
    thd->arg_of_last_insert_id_function= TRUE;
 
3382
    thd->arg_of_last_insert_id_function= true;
3382
3383
    thd->first_successful_insert_id_in_prev_stmt= value;
3383
3384
    return value;
3384
3385
  }
3514
3515
  /* fix_fields will call Item_func_set_user_var::fix_length_and_dec */
3515
3516
  if (Item_func::fix_fields(thd, ref) ||
3516
3517
      !(entry= get_variable(&thd->user_vars, name, 1)))
3517
 
    return TRUE;
 
3518
    return true;
3518
3519
  /* 
3519
3520
     Remember the last query which updated it, this way a query can later know
3520
3521
     if this variable is a constant item in the query (it is if update_query_id
3541
3542
    entry->collation.set(args[0]->collation.collation, DERIVATION_IMPLICIT);
3542
3543
  collation.set(entry->collation.collation, DERIVATION_IMPLICIT);
3543
3544
  cached_result_type= args[0]->result_type();
3544
 
  return FALSE;
 
3545
  return false;
3545
3546
}
3546
3547
 
3547
3548
 
3710
3711
longlong user_var_entry::val_int(my_bool *null_value) const
3711
3712
{
3712
3713
  if ((*null_value= (value == 0)))
3713
 
    return LL(0);
 
3714
    return 0LL;
3714
3715
 
3715
3716
  switch (type) {
3716
3717
  case REAL_RESULT:
3732
3733
    DBUG_ASSERT(1);                             // Impossible
3733
3734
    break;
3734
3735
  }
3735
 
  return LL(0);                                 // Impossible
 
3736
  return 0LL;                                   // Impossible
3736
3737
}
3737
3738
 
3738
3739
 
3805
3806
    will be caught by thd->is_error() check in sql_set_variables().
3806
3807
 
3807
3808
  @retval
3808
 
    FALSE OK.
 
3809
    false OK.
3809
3810
*/
3810
3811
 
3811
3812
bool
3813
3814
{
3814
3815
  DBUG_ENTER("Item_func_set_user_var::check");
3815
3816
  if (use_result_field && !result_field)
3816
 
    use_result_field= FALSE;
 
3817
    use_result_field= false;
3817
3818
 
3818
3819
  switch (cached_result_type) {
3819
3820
  case REAL_RESULT:
3849
3850
    DBUG_ASSERT(0);
3850
3851
    break;
3851
3852
  }
3852
 
  DBUG_RETURN(FALSE);
 
3853
  DBUG_RETURN(false);
3853
3854
}
3854
3855
 
3855
3856
 
3958
3959
double Item_func_set_user_var::val_result()
3959
3960
{
3960
3961
  DBUG_ASSERT(fixed == 1);
3961
 
  check(TRUE);
 
3962
  check(true);
3962
3963
  update();                                     // Store expression
3963
3964
  return entry->val_real(&null_value);
3964
3965
}
3966
3967
longlong Item_func_set_user_var::val_int_result()
3967
3968
{
3968
3969
  DBUG_ASSERT(fixed == 1);
3969
 
  check(TRUE);
 
3970
  check(true);
3970
3971
  update();                                     // Store expression
3971
3972
  return entry->val_int(&null_value);
3972
3973
}
3974
3975
String *Item_func_set_user_var::str_result(String *str)
3975
3976
{
3976
3977
  DBUG_ASSERT(fixed == 1);
3977
 
  check(TRUE);
 
3978
  check(true);
3978
3979
  update();                                     // Store expression
3979
3980
  return entry->val_str(&null_value, str, decimals);
3980
3981
}
3983
3984
my_decimal *Item_func_set_user_var::val_decimal_result(my_decimal *val)
3984
3985
{
3985
3986
  DBUG_ASSERT(fixed == 1);
3986
 
  check(TRUE);
 
3987
  check(true);
3987
3988
  update();                                     // Store expression
3988
3989
  return entry->val_decimal(&null_value, val);
3989
3990
}
4068
4069
    in the Item_func_set_user_var::send() function.
4069
4070
 
4070
4071
  RETURN VALUES
4071
 
    FALSE       Ok
4072
 
    TRUE        Error
 
4072
    false       Ok
 
4073
    true        Error
4073
4074
*/
4074
4075
 
4075
4076
int Item_func_set_user_var::save_in_field(Field *field, bool no_conversions,
4098
4099
      return set_field_to_null_with_conversions(field, no_conversions);
4099
4100
    }
4100
4101
 
4101
 
    /* NOTE: If null_value == FALSE, "result" must be not NULL.  */
 
4102
    /* NOTE: If null_value == false, "result" must be not NULL.  */
4102
4103
 
4103
4104
    field->set_notnull();
4104
4105
    error=field->store(result->ptr(),result->length(),cs);
4166
4167
{
4167
4168
  DBUG_ASSERT(fixed == 1);
4168
4169
  if (!var_entry)
4169
 
    return LL(0);                               // No such variable
 
4170
    return 0LL;                         // No such variable
4170
4171
  return (var_entry->val_int(&null_value));
4171
4172
}
4172
4173
 
4372
4373
}
4373
4374
 
4374
4375
 
4375
 
void Item_func_get_user_var::print(String *str, enum_query_type query_type)
 
4376
void Item_func_get_user_var::print(String *str,
 
4377
                                   enum_query_type query_type __attribute__((__unused__)))
4376
4378
{
4377
4379
  str->append(STRING_WITH_LEN("(@"));
4378
4380
  str->append(name.str,name.length);
4380
4382
}
4381
4383
 
4382
4384
 
4383
 
bool Item_func_get_user_var::eq(const Item *item, bool binary_cmp) const
 
4385
bool Item_func_get_user_var::eq(const Item *item,
 
4386
                                bool binary_cmp __attribute__((__unused__))) const
4384
4387
{
4385
4388
  /* Assume we don't have rtti */
4386
4389
  if (this == item)
4400
4403
  DBUG_ASSERT(fixed == 0);
4401
4404
  if (Item::fix_fields(thd, ref) ||
4402
4405
      !(entry= get_variable(&thd->user_vars, name, 1)))
4403
 
    return TRUE;
 
4406
    return true;
4404
4407
  entry->type= STRING_RESULT;
4405
4408
  /*
4406
4409
    Let us set the same collation which is used for loading
4409
4412
  */
4410
4413
  entry->collation.set(thd->variables.collation_database);
4411
4414
  entry->update_query_id= thd->query_id;
4412
 
  return FALSE;
 
4415
  return false;
4413
4416
}
4414
4417
 
4415
4418
 
4416
4419
void Item_user_var_as_out_param::set_null_value(CHARSET_INFO* cs)
4417
4420
{
4418
 
  ::update_hash(entry, TRUE, 0, 0, STRING_RESULT, cs,
 
4421
  ::update_hash(entry, true, 0, 0, STRING_RESULT, cs,
4419
4422
                DERIVATION_IMPLICIT, 0 /* unsigned_arg */);
4420
4423
}
4421
4424
 
4423
4426
void Item_user_var_as_out_param::set_value(const char *str, uint length,
4424
4427
                                           CHARSET_INFO* cs)
4425
4428
{
4426
 
  ::update_hash(entry, FALSE, (void*)str, length, STRING_RESULT, cs,
 
4429
  ::update_hash(entry, false, (void*)str, length, STRING_RESULT, cs,
4427
4430
                DERIVATION_IMPLICIT, 0 /* unsigned_arg */);
4428
4431
}
4429
4432
 
4442
4445
}
4443
4446
 
4444
4447
 
4445
 
String* Item_user_var_as_out_param::val_str(String *str)
4446
 
{
4447
 
  DBUG_ASSERT(0);
4448
 
  return 0;
4449
 
}
4450
 
 
4451
 
 
4452
 
my_decimal* Item_user_var_as_out_param::val_decimal(my_decimal *decimal_buffer)
4453
 
{
4454
 
  DBUG_ASSERT(0);
4455
 
  return 0;
4456
 
}
4457
 
 
4458
 
 
4459
 
void Item_user_var_as_out_param::print(String *str, enum_query_type query_type)
 
4448
String* Item_user_var_as_out_param::val_str(String *str __attribute__((__unused__)))
 
4449
{
 
4450
  DBUG_ASSERT(0);
 
4451
  return 0;
 
4452
}
 
4453
 
 
4454
 
 
4455
my_decimal* Item_user_var_as_out_param::val_decimal(my_decimal *decimal_buffer __attribute__((__unused__)))
 
4456
{
 
4457
  DBUG_ASSERT(0);
 
4458
  return 0;
 
4459
}
 
4460
 
 
4461
 
 
4462
void Item_user_var_as_out_param::print(String *str,
 
4463
                                       enum_query_type query_type __attribute__((__unused__)))
4460
4464
{
4461
4465
  str->append('@');
4462
4466
  str->append(name.str,name.length);
4569
4573
/**
4570
4574
  Check a user level lock.
4571
4575
 
4572
 
  Sets null_value=TRUE on error.
 
4576
  Sets null_value=true on error.
4573
4577
 
4574
4578
  @retval
4575
4579
    1           Available