~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_func.cc

  • Committer: Mark Atwood
  • Date: 2008-07-01 21:25:46 UTC
  • mto: This revision was merged to the branch mainline in revision 45.
  • Revision ID: mark@localhost.localdomain-20080701212546-jzs7ljtwcp2dcmgd
Remove all OpenSSL and all YaSSL code

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
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
 
307
307
  callback functions.
308
308
 
309
309
    First the function applies the analyzer to the root node of
310
 
    the Item_func object. Then if the analizer succeeeds (returns true)
 
310
    the Item_func object. Then if the analizer succeeeds (returns TRUE)
311
311
    the function recursively applies the compile method to each argument
312
312
    of the Item_func node.
313
313
    If the call of the method for an argument item returns a new item
358
358
{
359
359
  Item **arg, **arg_end;
360
360
  for (arg= args, arg_end= args+arg_count; arg != arg_end ; arg++)
361
 
    (*arg)->split_sum_func2(thd, ref_pointer_array, fields, arg, true);
 
361
    (*arg)->split_sum_func2(thd, ref_pointer_array, fields, arg, TRUE);
362
362
}
363
363
 
364
364
 
649
649
bool Item_func_connection_id::fix_fields(THD *thd, Item **ref)
650
650
{
651
651
  if (Item_int_func::fix_fields(thd, ref))
652
 
    return true;
653
 
  thd->thread_specific_used= true;
 
652
    return TRUE;
 
653
  thd->thread_specific_used= TRUE;
654
654
  value= thd->variables.pseudo_thread_id;
655
 
  return false;
 
655
  return FALSE;
656
656
}
657
657
 
658
658
 
753
753
    my_decimal decimal_value, *val;
754
754
    if (!(val= decimal_op(&decimal_value)))
755
755
      return 0;                                 // null is set
756
 
    my_decimal_round(E_DEC_FATAL_ERROR, val, decimals, false, val);
 
756
    my_decimal_round(E_DEC_FATAL_ERROR, val, decimals, FALSE, val);
757
757
    my_decimal2string(E_DEC_FATAL_ERROR, val, 0, 0, 0, str);
758
758
    break;
759
759
  }
1041
1041
 
1042
1042
  if ((null_value= args[0]->null_value))
1043
1043
    return NULL;
1044
 
  my_decimal_round(E_DEC_FATAL_ERROR, tmp, decimals, false, dec);
 
1044
  my_decimal_round(E_DEC_FATAL_ERROR, tmp, decimals, FALSE, dec);
1045
1045
  sign= dec->sign();
1046
1046
  if (unsigned_flag)
1047
1047
  {
2130
2130
bool Item_func_rand::fix_fields(THD *thd,Item **ref)
2131
2131
{
2132
2132
  if (Item_real_func::fix_fields(thd, ref))
2133
 
    return true;
 
2133
    return TRUE;
2134
2134
  used_tables_cache|= RAND_TABLE_BIT;
2135
2135
  if (arg_count)
2136
2136
  {                                     // Only use argument once in query
2144
2144
    */
2145
2145
    if (!rand && !(rand= (struct rand_struct*)
2146
2146
                   thd->stmt_arena->alloc(sizeof(*rand))))
2147
 
      return true;
 
2147
      return TRUE;
2148
2148
 
2149
2149
    if (args[0]->const_item())
2150
2150
      seed_random (args[0]);
2164
2164
    }
2165
2165
    rand= &thd->rand;
2166
2166
  }
2167
 
  return false;
 
2167
  return FALSE;
2168
2168
}
2169
2169
 
2170
2170
void Item_func_rand::update_used_tables()
2204
2204
void Item_func_min_max::fix_length_and_dec()
2205
2205
{
2206
2206
  int max_int_part=0;
2207
 
  bool datetime_found= false;
 
2207
  bool datetime_found= FALSE;
2208
2208
  decimals=0;
2209
2209
  max_length=0;
2210
2210
  maybe_null=0;
2220
2220
    cmp_type=item_cmp_type(cmp_type,args[i]->result_type());
2221
2221
    if (args[i]->result_type() != ROW_RESULT && args[i]->is_datetime())
2222
2222
    {
2223
 
      datetime_found= true;
 
2223
      datetime_found= TRUE;
2224
2224
      if (!datetime_item || args[i]->field_type() == MYSQL_TYPE_DATETIME)
2225
2225
        datetime_item= args[i];
2226
2226
    }
2231
2231
    if (datetime_found)
2232
2232
    {
2233
2233
      thd= current_thd;
2234
 
      compare_as_dates= true;
 
2234
      compare_as_dates= TRUE;
2235
2235
    }
2236
2236
  }
2237
2237
  else if ((cmp_type == DECIMAL_RESULT) || (cmp_type == INT_RESULT))
2788
2788
        (*deinit)(&initid);
2789
2789
      }
2790
2790
      free_udf(u_d);
2791
 
      initialized= false;
 
2791
      initialized= FALSE;
2792
2792
    }
2793
2793
    if (buffers)                                // Because of bug in ecc
2794
2794
      delete [] buffers;
2805
2805
  DBUG_ENTER("Item_udf_func::fix_fields");
2806
2806
 
2807
2807
  if (check_stack_overrun(thd, STACK_MIN_SIZE, buff))
2808
 
    DBUG_RETURN(true);                          // Fatal error flag is set!
 
2808
    DBUG_RETURN(TRUE);                          // Fatal error flag is set!
2809
2809
 
2810
2810
  udf_func *tmp_udf=find_udf(u_d->name.str,(uint) u_d->name.length,1);
2811
2811
 
2812
2812
  if (!tmp_udf)
2813
2813
  {
2814
2814
    my_error(ER_CANT_FIND_UDF, MYF(0), u_d->name.str, errno);
2815
 
    DBUG_RETURN(true);
 
2815
    DBUG_RETURN(TRUE);
2816
2816
  }
2817
2817
  u_d=tmp_udf;
2818
2818
  args=arguments;
2829
2829
 
2830
2830
    {
2831
2831
      free_udf(u_d);
2832
 
      DBUG_RETURN(true);
 
2832
      DBUG_RETURN(TRUE);
2833
2833
    }
2834
2834
    uint i;
2835
2835
    Item **arg,**arg_end;
2843
2843
      // we can't assign 'item' before, because fix_fields() can change arg
2844
2844
      Item *item= *arg;
2845
2845
      if (item->check_cols(1))
2846
 
        DBUG_RETURN(true);
 
2846
        DBUG_RETURN(TRUE);
2847
2847
      /*
2848
2848
        TODO: We should think about this. It is not always
2849
2849
        right way just to set an UDF result to return my_charset_bin
2876
2876
                                                       sizeof(long))))
2877
2877
    {
2878
2878
      free_udf(u_d);
2879
 
      DBUG_RETURN(true);
 
2879
      DBUG_RETURN(TRUE);
2880
2880
    }
2881
2881
  }
2882
2882
  func->fix_length_and_dec();
2945
2945
      my_error(ER_CANT_INITIALIZE_UDF, MYF(0),
2946
2946
               u_d->name.str, init_msg_buff);
2947
2947
      free_udf(u_d);
2948
 
      DBUG_RETURN(true);
 
2948
      DBUG_RETURN(TRUE);
2949
2949
    }
2950
2950
    func->max_length=min(initid.max_length,MAX_BLOB_WIDTH);
2951
2951
    func->maybe_null=initid.maybe_null;
2963
2963
  {
2964
2964
    my_error(ER_CANT_INITIALIZE_UDF, MYF(0),
2965
2965
             u_d->name.str, ER(ER_UNKNOWN_ERROR));
2966
 
    DBUG_RETURN(true);
 
2966
    DBUG_RETURN(TRUE);
2967
2967
  }
2968
 
  DBUG_RETURN(false);
 
2968
  DBUG_RETURN(FALSE);
2969
2969
}
2970
2970
 
2971
2971
 
3191
3191
    return 0;
3192
3192
  if (str->length() < DECIMAL_MAX_STR_LENGTH)
3193
3193
    str->length(DECIMAL_MAX_STR_LENGTH);
3194
 
  my_decimal_round(E_DEC_FATAL_ERROR, dec, decimals, false, &dec_buf);
 
3194
  my_decimal_round(E_DEC_FATAL_ERROR, dec, decimals, FALSE, &dec_buf);
3195
3195
  my_decimal2string(E_DEC_FATAL_ERROR, &dec_buf, 0, 0, '0', str);
3196
3196
  return str;
3197
3197
}
3378
3378
      LAST_INSERT_ID(X) take precedence over an generated auto_increment
3379
3379
      value for this row.
3380
3380
    */
3381
 
    thd->arg_of_last_insert_id_function= true;
 
3381
    thd->arg_of_last_insert_id_function= TRUE;
3382
3382
    thd->first_successful_insert_id_in_prev_stmt= value;
3383
3383
    return value;
3384
3384
  }
3514
3514
  /* fix_fields will call Item_func_set_user_var::fix_length_and_dec */
3515
3515
  if (Item_func::fix_fields(thd, ref) ||
3516
3516
      !(entry= get_variable(&thd->user_vars, name, 1)))
3517
 
    return true;
 
3517
    return TRUE;
3518
3518
  /* 
3519
3519
     Remember the last query which updated it, this way a query can later know
3520
3520
     if this variable is a constant item in the query (it is if update_query_id
3541
3541
    entry->collation.set(args[0]->collation.collation, DERIVATION_IMPLICIT);
3542
3542
  collation.set(entry->collation.collation, DERIVATION_IMPLICIT);
3543
3543
  cached_result_type= args[0]->result_type();
3544
 
  return false;
 
3544
  return FALSE;
3545
3545
}
3546
3546
 
3547
3547
 
3805
3805
    will be caught by thd->is_error() check in sql_set_variables().
3806
3806
 
3807
3807
  @retval
3808
 
    false OK.
 
3808
    FALSE OK.
3809
3809
*/
3810
3810
 
3811
3811
bool
3813
3813
{
3814
3814
  DBUG_ENTER("Item_func_set_user_var::check");
3815
3815
  if (use_result_field && !result_field)
3816
 
    use_result_field= false;
 
3816
    use_result_field= FALSE;
3817
3817
 
3818
3818
  switch (cached_result_type) {
3819
3819
  case REAL_RESULT:
3849
3849
    DBUG_ASSERT(0);
3850
3850
    break;
3851
3851
  }
3852
 
  DBUG_RETURN(false);
 
3852
  DBUG_RETURN(FALSE);
3853
3853
}
3854
3854
 
3855
3855
 
3958
3958
double Item_func_set_user_var::val_result()
3959
3959
{
3960
3960
  DBUG_ASSERT(fixed == 1);
3961
 
  check(true);
 
3961
  check(TRUE);
3962
3962
  update();                                     // Store expression
3963
3963
  return entry->val_real(&null_value);
3964
3964
}
3966
3966
longlong Item_func_set_user_var::val_int_result()
3967
3967
{
3968
3968
  DBUG_ASSERT(fixed == 1);
3969
 
  check(true);
 
3969
  check(TRUE);
3970
3970
  update();                                     // Store expression
3971
3971
  return entry->val_int(&null_value);
3972
3972
}
3974
3974
String *Item_func_set_user_var::str_result(String *str)
3975
3975
{
3976
3976
  DBUG_ASSERT(fixed == 1);
3977
 
  check(true);
 
3977
  check(TRUE);
3978
3978
  update();                                     // Store expression
3979
3979
  return entry->val_str(&null_value, str, decimals);
3980
3980
}
3983
3983
my_decimal *Item_func_set_user_var::val_decimal_result(my_decimal *val)
3984
3984
{
3985
3985
  DBUG_ASSERT(fixed == 1);
3986
 
  check(true);
 
3986
  check(TRUE);
3987
3987
  update();                                     // Store expression
3988
3988
  return entry->val_decimal(&null_value, val);
3989
3989
}
4068
4068
    in the Item_func_set_user_var::send() function.
4069
4069
 
4070
4070
  RETURN VALUES
4071
 
    false       Ok
4072
 
    true        Error
 
4071
    FALSE       Ok
 
4072
    TRUE        Error
4073
4073
*/
4074
4074
 
4075
4075
int Item_func_set_user_var::save_in_field(Field *field, bool no_conversions,
4098
4098
      return set_field_to_null_with_conversions(field, no_conversions);
4099
4099
    }
4100
4100
 
4101
 
    /* NOTE: If null_value == false, "result" must be not NULL.  */
 
4101
    /* NOTE: If null_value == FALSE, "result" must be not NULL.  */
4102
4102
 
4103
4103
    field->set_notnull();
4104
4104
    error=field->store(result->ptr(),result->length(),cs);
4400
4400
  DBUG_ASSERT(fixed == 0);
4401
4401
  if (Item::fix_fields(thd, ref) ||
4402
4402
      !(entry= get_variable(&thd->user_vars, name, 1)))
4403
 
    return true;
 
4403
    return TRUE;
4404
4404
  entry->type= STRING_RESULT;
4405
4405
  /*
4406
4406
    Let us set the same collation which is used for loading
4409
4409
  */
4410
4410
  entry->collation.set(thd->variables.collation_database);
4411
4411
  entry->update_query_id= thd->query_id;
4412
 
  return false;
 
4412
  return FALSE;
4413
4413
}
4414
4414
 
4415
4415
 
4416
4416
void Item_user_var_as_out_param::set_null_value(CHARSET_INFO* cs)
4417
4417
{
4418
 
  ::update_hash(entry, true, 0, 0, STRING_RESULT, cs,
 
4418
  ::update_hash(entry, TRUE, 0, 0, STRING_RESULT, cs,
4419
4419
                DERIVATION_IMPLICIT, 0 /* unsigned_arg */);
4420
4420
}
4421
4421
 
4423
4423
void Item_user_var_as_out_param::set_value(const char *str, uint length,
4424
4424
                                           CHARSET_INFO* cs)
4425
4425
{
4426
 
  ::update_hash(entry, false, (void*)str, length, STRING_RESULT, cs,
 
4426
  ::update_hash(entry, FALSE, (void*)str, length, STRING_RESULT, cs,
4427
4427
                DERIVATION_IMPLICIT, 0 /* unsigned_arg */);
4428
4428
}
4429
4429
 
4569
4569
/**
4570
4570
  Check a user level lock.
4571
4571
 
4572
 
  Sets null_value=true on error.
 
4572
  Sets null_value=TRUE on error.
4573
4573
 
4574
4574
  @retval
4575
4575
    1           Available