~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.cc

  • Committer: Brian Aker
  • Date: 2011-02-12 06:56:00 UTC
  • mto: This revision was merged to the branch mainline in revision 2161.
  • Revision ID: brian@tangent.org-20110212065600-m6c68fybw51rflhj
Further strip out includes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
#include "drizzled/field/str.h"
36
36
#include "drizzled/field/num.h"
 
37
 
37
38
#include "drizzled/field/blob.h"
38
 
#include "drizzled/field/enum.h"
39
 
#include "drizzled/field/null.h"
40
39
#include "drizzled/field/date.h"
 
40
#include "drizzled/field/datetime.h"
41
41
#include "drizzled/field/decimal.h"
42
 
#include "drizzled/field/real.h"
43
42
#include "drizzled/field/double.h"
 
43
#include "drizzled/field/enum.h"
 
44
#include "drizzled/field/epoch.h"
44
45
#include "drizzled/field/int32.h"
45
46
#include "drizzled/field/int64.h"
46
 
#include "drizzled/field/num.h"
47
 
#include "drizzled/field/timestamp.h"
48
 
#include "drizzled/field/datetime.h"
 
47
#include "drizzled/field/microtime.h"
 
48
#include "drizzled/field/null.h"
 
49
#include "drizzled/field/real.h"
 
50
#include "drizzled/field/size.h"
 
51
#include "drizzled/field/time.h"
49
52
#include "drizzled/field/varstring.h"
 
53
 
50
54
#include "drizzled/internal/m_string.h"
51
55
 
52
56
#include <cstdio>
95
99
 
96
100
    case DECIMAL_RESULT:
97
101
    {
98
 
      my_decimal decimal_value;
99
 
      my_decimal *val= val_decimal(&decimal_value);
 
102
      type::Decimal decimal_value;
 
103
      type::Decimal *val= val_decimal(&decimal_value);
100
104
      if (val)
101
 
        return !my_decimal_is_zero(val);
 
105
        return not val->isZero();
102
106
      return false;
103
107
    }
104
108
 
137
141
 
138
142
String *Item::val_string_from_decimal(String *str)
139
143
{
140
 
  my_decimal dec_buf, *dec= val_decimal(&dec_buf);
 
144
  type::Decimal dec_buf, *dec= val_decimal(&dec_buf);
141
145
  if (null_value)
142
146
    return NULL;
143
147
 
144
 
  my_decimal_round(E_DEC_FATAL_ERROR, dec, decimals, false, &dec_buf);
145
 
  my_decimal2string(E_DEC_FATAL_ERROR, &dec_buf, 0, 0, 0, str);
 
148
  class_decimal_round(E_DEC_FATAL_ERROR, dec, decimals, false, &dec_buf);
 
149
  class_decimal2string(&dec_buf, 0, str);
146
150
  return str;
147
151
}
148
152
 
149
 
my_decimal *Item::val_decimal_from_real(my_decimal *decimal_value)
 
153
type::Decimal *Item::val_decimal_from_real(type::Decimal *decimal_value)
150
154
{
151
155
  double nr= val_real();
152
156
  if (null_value)
153
157
    return NULL;
154
158
 
155
 
  double2my_decimal(E_DEC_FATAL_ERROR, nr, decimal_value);
 
159
  double2_class_decimal(E_DEC_FATAL_ERROR, nr, decimal_value);
156
160
  return (decimal_value);
157
161
}
158
162
 
159
 
my_decimal *Item::val_decimal_from_int(my_decimal *decimal_value)
 
163
type::Decimal *Item::val_decimal_from_int(type::Decimal *decimal_value)
160
164
{
161
165
  int64_t nr= val_int();
162
166
  if (null_value)
163
167
    return NULL;
164
168
 
165
 
  int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
 
169
  int2_class_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
166
170
  return decimal_value;
167
171
}
168
172
 
169
 
my_decimal *Item::val_decimal_from_string(my_decimal *decimal_value)
 
173
type::Decimal *Item::val_decimal_from_string(type::Decimal *decimal_value)
170
174
{
171
175
  String *res;
172
176
  char *end_ptr;
174
178
    return NULL;
175
179
 
176
180
  end_ptr= (char*) res->ptr()+ res->length();
177
 
  if (str2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_BAD_NUM,
 
181
  if (decimal_value->store(E_DEC_FATAL_ERROR & ~E_DEC_BAD_NUM,
178
182
                     res->ptr(), 
179
183
                     res->length(), 
180
 
                     res->charset(),
181
 
                     decimal_value) & E_DEC_BAD_NUM)
 
184
                     res->charset()) & E_DEC_BAD_NUM)
182
185
  {
183
 
    push_warning_printf(current_session, 
 
186
    push_warning_printf(&getSession(), 
184
187
                        DRIZZLE_ERROR::WARN_LEVEL_WARN,
185
188
                        ER_TRUNCATED_WRONG_VALUE,
186
189
                        ER(ER_TRUNCATED_WRONG_VALUE), "DECIMAL",
189
192
  return decimal_value;
190
193
}
191
194
 
192
 
my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value)
 
195
type::Decimal *Item::val_decimal_from_date(type::Decimal *decimal_value)
193
196
{
194
197
  assert(fixed);
195
 
  DRIZZLE_TIME ltime;
196
 
  if (get_date(&ltime, TIME_FUZZY_DATE))
 
198
  type::Time ltime;
 
199
  if (get_date(ltime, TIME_FUZZY_DATE))
197
200
  {
198
 
    my_decimal_set_zero(decimal_value);
 
201
    decimal_value->set_zero();
199
202
    null_value= 1;                               // set NULL, stop processing
200
203
    return NULL;
201
204
  }
202
 
  return date2my_decimal(&ltime, decimal_value);
 
205
  return date2_class_decimal(&ltime, decimal_value);
203
206
}
204
207
 
205
 
my_decimal *Item::val_decimal_from_time(my_decimal *decimal_value)
 
208
type::Decimal *Item::val_decimal_from_time(type::Decimal *decimal_value)
206
209
{
207
210
  assert(fixed);
208
 
  DRIZZLE_TIME ltime;
209
 
  if (get_time(&ltime))
 
211
  type::Time ltime;
 
212
  if (get_time(ltime))
210
213
  {
211
 
    my_decimal_set_zero(decimal_value);
 
214
    decimal_value->set_zero();
212
215
    return NULL;
213
216
  }
214
 
  return date2my_decimal(&ltime, decimal_value);
 
217
  return date2_class_decimal(&ltime, decimal_value);
215
218
}
216
219
 
217
220
double Item::val_real_from_decimal()
218
221
{
219
222
  /* Note that fix_fields may not be called for Item_avg_field items */
220
223
  double result;
221
 
  my_decimal value_buff, *dec_val= val_decimal(&value_buff);
 
224
  type::Decimal value_buff, *dec_val= val_decimal(&value_buff);
222
225
  if (null_value)
223
226
    return 0.0;
224
 
  my_decimal2double(E_DEC_FATAL_ERROR, dec_val, &result);
 
227
  class_decimal2double(E_DEC_FATAL_ERROR, dec_val, &result);
225
228
  return result;
226
229
}
227
230
 
229
232
{
230
233
  /* Note that fix_fields may not be called for Item_avg_field items */
231
234
  int64_t result;
232
 
  my_decimal value, *dec_val= val_decimal(&value);
 
235
  type::Decimal value, *dec_val= val_decimal(&value);
 
236
 
233
237
  if (null_value)
234
238
    return 0;
235
 
  my_decimal2int(E_DEC_FATAL_ERROR, dec_val, unsigned_flag, &result);
 
239
  dec_val->val_int32(E_DEC_FATAL_ERROR, unsigned_flag, &result);
 
240
 
236
241
  return result;
237
242
}
238
243
 
239
 
int Item::save_time_in_field(Field *field)
 
244
bool Item::save_time_in_field(Field *field)
240
245
{
241
 
  DRIZZLE_TIME ltime;
242
 
  if (get_time(&ltime))
 
246
  type::Time ltime;
 
247
 
 
248
  if (get_time(ltime))
243
249
    return set_field_to_null(field);
 
250
 
244
251
  field->set_notnull();
245
 
  return field->store_time(&ltime, DRIZZLE_TIMESTAMP_TIME);
 
252
 
 
253
  return field->store_time(ltime, type::DRIZZLE_TIMESTAMP_TIME);
246
254
}
247
255
 
248
 
int Item::save_date_in_field(Field *field)
 
256
bool Item::save_date_in_field(Field *field)
249
257
{
250
 
  DRIZZLE_TIME ltime;
251
 
  if (get_date(&ltime, TIME_FUZZY_DATE))
 
258
  type::Time ltime;
 
259
 
 
260
  if (get_date(ltime, TIME_FUZZY_DATE))
252
261
    return set_field_to_null(field);
 
262
 
253
263
  field->set_notnull();
254
 
  return field->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
 
264
 
 
265
  return field->store_time(ltime, type::DRIZZLE_TIMESTAMP_DATETIME);
255
266
}
256
267
 
257
268
/**
262
273
{
263
274
  if (null_value)
264
275
    return set_field_to_null(field);
 
276
 
265
277
  field->set_notnull();
 
278
 
266
279
  return field->store(result->ptr(), result->length(), collation.collation);
267
280
}
268
281
 
281
294
  with_sum_func(false),
282
295
  is_autogenerated_name(true),
283
296
  with_subselect(false),
284
 
  collation(&my_charset_bin, DERIVATION_COERCIBLE)
 
297
  collation(&my_charset_bin, DERIVATION_COERCIBLE),
 
298
  _session(*current_session)
285
299
{
286
300
  cmp_context= (Item_result)-1;
287
301
 
288
302
  /* Put item in free list so that we can free all items at end */
289
 
  Session *session= current_session;
290
 
  next= session->free_list;
291
 
  session->free_list= this;
 
303
  next= getSession().free_list;
 
304
  getSession().free_list= this;
292
305
 
293
306
  /*
294
307
    Item constructor can be called during execution other then SQL_COM
295
308
    command => we should check session->lex->current_select on zero (session->lex
296
309
    can be uninitialised)
297
310
  */
298
 
  if (session->lex->current_select)
 
311
  if (getSession().lex->current_select)
299
312
  {
300
 
    enum_parsing_place place= session->lex->current_select->parsing_place;
 
313
    enum_parsing_place place= getSession().getLex()->current_select->parsing_place;
301
314
    if (place == SELECT_LIST || place == IN_HAVING)
302
 
      session->lex->current_select->select_n_having_items++;
 
315
      getSession().getLex()->current_select->select_n_having_items++;
303
316
  }
304
317
}
305
318
 
320
333
  is_autogenerated_name(item->is_autogenerated_name),
321
334
  with_subselect(item->with_subselect),
322
335
  collation(item->collation),
323
 
  cmp_context(item->cmp_context)
 
336
  cmp_context(item->cmp_context),
 
337
  _session(*session)
324
338
{
325
339
  /* Put this item in the session's free list */
326
 
  next= session->free_list;
327
 
  session->free_list= this;
 
340
  next= getSession().free_list;
 
341
  getSession().free_list= this;
328
342
}
329
343
 
330
344
uint32_t Item::float_length(uint32_t decimals_par) const
337
351
  Item_result restype= result_type();
338
352
 
339
353
  if ((restype == DECIMAL_RESULT) || (restype == INT_RESULT))
340
 
    return min(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
 
354
    return min(class_decimal_length_to_precision(max_length, decimals, unsigned_flag),
341
355
               (uint32_t) DECIMAL_MAX_PRECISION);
342
356
  return min(max_length, (uint32_t) DECIMAL_MAX_PRECISION);
343
357
}
344
358
 
345
359
int Item::decimal_int_part() const
346
360
{
347
 
  return my_decimal_int_part(decimal_precision(), decimals);
 
361
  return class_decimal_int_part(decimal_precision(), decimals);
348
362
}
349
363
 
350
364
void Item::print(String *str, enum_query_type)
422
436
    if (orig_len != length && ! is_autogenerated_name)
423
437
    {
424
438
      if (length == 0)
425
 
        push_warning_printf(current_session, 
 
439
        push_warning_printf(&getSession(), 
426
440
                            DRIZZLE_ERROR::WARN_LEVEL_WARN,
427
441
                            ER_NAME_BECOMES_EMPTY, 
428
442
                            ER(ER_NAME_BECOMES_EMPTY),
429
443
                            str + length - orig_len);
430
444
      else
431
 
        push_warning_printf(current_session, 
 
445
        push_warning_printf(&getSession(),
432
446
                            DRIZZLE_ERROR::WARN_LEVEL_WARN,
433
447
                            ER_REMOVED_SPACES, 
434
448
                            ER(ER_REMOVED_SPACES),
457
471
  return conv->safe ? conv : NULL;
458
472
}
459
473
 
460
 
bool Item::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
474
bool Item::get_date(type::Time &ltime,uint32_t fuzzydate)
461
475
{
462
 
  if (result_type() == STRING_RESULT)
463
 
  {
464
 
    char buff[40];
465
 
    String tmp(buff,sizeof(buff), &my_charset_bin),*res;
466
 
    if (!(res=val_str(&tmp)) ||
467
 
        str_to_datetime_with_warn(res->ptr(), res->length(),
468
 
                                  ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
469
 
      goto err;
470
 
  }
471
 
  else
472
 
  {
473
 
    int64_t value= val_int();
474
 
    int was_cut;
475
 
    if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1L)
476
 
    {
477
 
      char buff[22], *end;
478
 
      end= internal::int64_t10_to_str(value, buff, -10);
479
 
      make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
480
 
                                   buff, (int) (end-buff), DRIZZLE_TIMESTAMP_NONE,
481
 
                                   NULL);
482
 
      goto err;
483
 
    }
484
 
  }
485
 
  return false;
486
 
 
487
 
err:
488
 
  memset(ltime, 0, sizeof(*ltime));
 
476
  do
 
477
  {
 
478
    if (is_null())
 
479
    {
 
480
      break;
 
481
    }
 
482
    else if (result_type() == STRING_RESULT)
 
483
    {
 
484
      char buff[type::Time::MAX_STRING_LENGTH];
 
485
      String tmp(buff,sizeof(buff), &my_charset_bin),*res;
 
486
      if (!(res=val_str(&tmp)) ||
 
487
          str_to_datetime_with_warn(&getSession(), res->ptr(), res->length(),
 
488
                                    &ltime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR)
 
489
      {
 
490
        break;
 
491
      }
 
492
    }
 
493
    else
 
494
    {
 
495
      int64_t value= val_int();
 
496
      type::datetime_t date_value;
 
497
 
 
498
      ltime.convert(date_value, value, fuzzydate);
 
499
 
 
500
      if (not type::is_valid(date_value))
 
501
      {
 
502
        char buff[DECIMAL_LONGLONG_DIGITS], *end;
 
503
        end= internal::int64_t10_to_str(value, buff, -10);
 
504
        make_truncated_value_warning(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
505
                                     buff, (int) (end-buff), type::DRIZZLE_TIMESTAMP_NONE, NULL);
 
506
        break;
 
507
      }
 
508
    }
 
509
 
 
510
    return false;
 
511
  } while (0);
 
512
 
 
513
  ltime.reset();
 
514
 
489
515
  return true;
490
516
}
491
517
 
492
 
bool Item::get_time(DRIZZLE_TIME *ltime)
 
518
bool Item::get_time(type::Time &ltime)
493
519
{
494
 
  char buff[40];
 
520
  char buff[type::Time::MAX_STRING_LENGTH];
495
521
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
496
 
  if (!(res=val_str(&tmp)) ||
497
 
      str_to_time_with_warn(res->ptr(), res->length(), ltime))
 
522
  if (!(res=val_str(&tmp)) or
 
523
      str_to_time_with_warn(&getSession(), res->ptr(), res->length(), &ltime))
498
524
  {
499
 
    memset(ltime, 0, sizeof(*ltime));
 
525
    ltime.reset();
 
526
 
500
527
    return true;
501
528
  }
 
529
 
502
530
  return false;
503
531
}
504
532
 
505
 
bool Item::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
533
bool Item::get_date_result(type::Time &ltime,uint32_t fuzzydate)
506
534
{
507
 
  return get_date(ltime,fuzzydate);
 
535
  return get_date(ltime, fuzzydate);
508
536
}
509
537
 
510
538
bool Item::is_null()
821
849
  {
822
850
    Item_subselect *prev_subselect_item= previous_select->master_unit()->item;
823
851
    prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
824
 
    prev_subselect_item->const_item_cache= 0;
 
852
    prev_subselect_item->const_item_cache= false;
825
853
  }
826
854
  {
827
855
    Item_subselect *prev_subselect_item= previous_select->master_unit()->item;
836
864
    }
837
865
    else
838
866
      prev_subselect_item->used_tables_cache|= found_field->getTable()->map;
839
 
    prev_subselect_item->const_item_cache= 0;
 
867
    prev_subselect_item->const_item_cache= false;
840
868
    mark_as_dependent(session, last_select, current_sel, resolved_item,
841
869
                      dependent);
842
870
  }
856
884
    - the found item on success
857
885
    - NULL if find_item is not in group_list
858
886
*/
859
 
static Item** find_field_in_group_list(Item *find_item, Order *group_list)
 
887
static Item** find_field_in_group_list(Session *session, Item *find_item, Order *group_list)
860
888
{
861
889
  const char *db_name;
862
890
  const char *table_name;
912
940
        if (cur_field->db_name && db_name)
913
941
        {
914
942
          /* If field_name is also qualified by a database name. */
915
 
          if (strcasecmp(cur_field->db_name, db_name))
 
943
          if (my_strcasecmp(system_charset_info, cur_field->db_name, db_name))
 
944
          {
916
945
            /* Same field names, different databases. */
917
946
            return NULL;
 
947
          }
918
948
          ++cur_match_degree;
919
949
        }
920
950
      }
933
963
          best match, they must reference the same column, otherwise the field
934
964
          is ambiguous.
935
965
        */
936
 
        my_error(ER_NON_UNIQ_ERROR, MYF(0), find_item->full_name(), current_session->where);
 
966
        my_error(ER_NON_UNIQ_ERROR, MYF(0), find_item->full_name(), session->where());
937
967
        return NULL;
938
968
      }
939
969
    }
941
971
 
942
972
  if (found_group)
943
973
    return found_group->item;
944
 
  else
945
 
    return NULL;
 
974
 
 
975
  return NULL;
946
976
}
947
977
 
948
978
Item** resolve_ref_in_select_and_group(Session *session, Item_ident *ref, Select_Lex *select)
969
999
  /* If this is a non-aggregated field inside HAVING, search in GROUP BY. */
970
1000
  if (select->having_fix_field && !ref->with_sum_func && group_list)
971
1001
  {
972
 
    group_by_ref= find_field_in_group_list(ref, group_list);
 
1002
    group_by_ref= find_field_in_group_list(session, ref, group_list);
973
1003
 
974
1004
    /* Check if the fields found in SELECT and GROUP BY are the same field. */
975
1005
    if (group_by_ref && (select_ref != not_found_item) &&
978
1008
      ambiguous_fields= true;
979
1009
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
980
1010
                          ER(ER_NON_UNIQ_ERROR), ref->full_name(),
981
 
                          current_session->where);
 
1011
                          session->where());
982
1012
 
983
1013
    }
984
1014
  }
1007
1037
}
1008
1038
 
1009
1039
void Item::init_make_field(SendField *tmp_field,
1010
 
                           enum enum_field_types field_type_arg)
 
1040
                           enum enum_field_types field_type_arg)
1011
1041
{
1012
1042
  char *empty_name= (char*) "";
1013
1043
  tmp_field->db_name=   empty_name;
1059
1089
{
1060
1090
  switch (field_type())
1061
1091
  {
 
1092
    case DRIZZLE_TYPE_TIME:
1062
1093
    case DRIZZLE_TYPE_DATE:
1063
1094
    case DRIZZLE_TYPE_DATETIME:
1064
1095
    case DRIZZLE_TYPE_TIMESTAMP:
 
1096
    case DRIZZLE_TYPE_MICROTIME:
1065
1097
      return true;
1066
1098
    case DRIZZLE_TYPE_BLOB:
1067
1099
    case DRIZZLE_TYPE_VARCHAR:
1072
1104
    case DRIZZLE_TYPE_LONGLONG:
1073
1105
    case DRIZZLE_TYPE_NULL:
1074
1106
    case DRIZZLE_TYPE_UUID:
 
1107
    case DRIZZLE_TYPE_BOOLEAN:
1075
1108
      return false;
1076
1109
  }
1077
1110
 
1089
1122
                                       str->length(), &well_formed_error);
1090
1123
  if (wlen < str->length())
1091
1124
  {
1092
 
    Session *session= current_session;
1093
1125
    char hexbuf[7];
1094
1126
    enum DRIZZLE_ERROR::enum_warning_level level;
1095
1127
    uint32_t diff= str->length() - wlen;
1106
1138
      null_value= 1;
1107
1139
      str= 0;
1108
1140
    }
1109
 
    push_warning_printf(session, level, ER_INVALID_CHARACTER_STRING,
 
1141
    push_warning_printf(&getSession(), level, ER_INVALID_CHARACTER_STRING,
1110
1142
                        ER(ER_INVALID_CHARACTER_STRING), cs->csname, hexbuf);
1111
1143
  }
1112
1144
  return str;
1171
1203
                                 0,
1172
1204
                                 Field::NONE,
1173
1205
                                 name,
1174
 
                                 decimals,
1175
 
                                 0,
1176
 
                                 unsigned_flag);
 
1206
                                 decimals);
1177
1207
    break;
1178
1208
  case DRIZZLE_TYPE_LONG:
1179
1209
    field= new field::Int32((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE, name);
1191
1221
  case DRIZZLE_TYPE_DATE:
1192
1222
    field= new Field_date(maybe_null, name, &my_charset_bin);
1193
1223
    break;
 
1224
 
 
1225
  case DRIZZLE_TYPE_MICROTIME:
 
1226
    field= new field::Microtime(maybe_null, name);
 
1227
    break;
 
1228
 
1194
1229
  case DRIZZLE_TYPE_TIMESTAMP:
1195
 
    field= new Field_timestamp(maybe_null, name, &my_charset_bin);
 
1230
    field= new field::Epoch(maybe_null, name);
1196
1231
    break;
1197
1232
  case DRIZZLE_TYPE_DATETIME:
1198
1233
    field= new Field_datetime(maybe_null, name, &my_charset_bin);
1199
1234
    break;
 
1235
  case DRIZZLE_TYPE_TIME:
 
1236
    field= new field::Time(maybe_null, name, &my_charset_bin);
 
1237
    break;
 
1238
  case DRIZZLE_TYPE_BOOLEAN:
1200
1239
  case DRIZZLE_TYPE_UUID:
1201
1240
  case DRIZZLE_TYPE_ENUM:
1202
1241
  case DRIZZLE_TYPE_VARCHAR:
1258
1297
  }
1259
1298
  else if (result_type() == DECIMAL_RESULT)
1260
1299
  {
1261
 
    my_decimal decimal_value;
1262
 
    my_decimal *value= val_decimal(&decimal_value);
 
1300
    type::Decimal decimal_value;
 
1301
    type::Decimal *value= val_decimal(&decimal_value);
1263
1302
    if (null_value)
1264
1303
      return set_field_to_null_with_conversions(field, no_conversions);
1265
1304
    field->set_notnull();
1346
1385
  case DRIZZLE_TYPE_ENUM:
1347
1386
  case DRIZZLE_TYPE_BLOB:
1348
1387
  case DRIZZLE_TYPE_VARCHAR:
 
1388
  case DRIZZLE_TYPE_BOOLEAN:
1349
1389
  case DRIZZLE_TYPE_UUID:
1350
1390
  case DRIZZLE_TYPE_DECIMAL:
1351
1391
    {
1382
1422
        result= client->store(nr, decimals, buffer);
1383
1423
      break;
1384
1424
    }
 
1425
  case DRIZZLE_TYPE_TIME:
 
1426
    {
 
1427
      type::Time tm;
 
1428
      get_time(tm);
 
1429
      if (not null_value)
 
1430
        result= client->store(&tm);
 
1431
      break;
 
1432
    }
1385
1433
  case DRIZZLE_TYPE_DATETIME:
 
1434
  case DRIZZLE_TYPE_MICROTIME:
1386
1435
  case DRIZZLE_TYPE_TIMESTAMP:
1387
1436
    {
1388
 
      DRIZZLE_TIME tm;
1389
 
      get_date(&tm, TIME_FUZZY_DATE);
 
1437
      type::Time tm;
 
1438
      get_date(tm, TIME_FUZZY_DATE);
1390
1439
      if (!null_value)
1391
1440
        result= client->store(&tm);
1392
1441
      break;
1398
1447
  return result;
1399
1448
}
1400
1449
 
 
1450
uint32_t Item::max_char_length() const
 
1451
{
 
1452
  return max_length / collation.collation->mbmaxlen;
 
1453
}
 
1454
 
 
1455
void Item::fix_length_and_charset(uint32_t max_char_length_arg, CHARSET_INFO *cs)
 
1456
 
1457
  max_length= char_to_byte_length_safe(max_char_length_arg, cs->mbmaxlen);
 
1458
  collation.collation= cs;
 
1459
}
 
1460
 
 
1461
void Item::fix_char_length(uint32_t max_char_length_arg)
 
1462
 
1463
  max_length= char_to_byte_length_safe(max_char_length_arg, collation.collation->mbmaxlen);
 
1464
}
 
1465
 
 
1466
void Item::fix_char_length_uint64_t(uint64_t max_char_length_arg)
 
1467
 
1468
  uint64_t max_result_length= max_char_length_arg *
 
1469
    collation.collation->mbmaxlen;
 
1470
 
 
1471
  if (max_result_length >= MAX_BLOB_WIDTH)
 
1472
  { 
 
1473
    max_length= MAX_BLOB_WIDTH;
 
1474
    maybe_null= false;
 
1475
  }
 
1476
  else
 
1477
  {
 
1478
    max_length= max_result_length;
 
1479
  }
 
1480
}
 
1481
 
 
1482
void Item::fix_length_and_charset_datetime(uint32_t max_char_length_arg)
 
1483
 
1484
  collation.set(&my_charset_bin);
 
1485
  fix_char_length(max_char_length_arg);
 
1486
}
 
1487
 
1401
1488
Item_result item_cmp_type(Item_result a,Item_result b)
1402
1489
{
1403
1490
  if (a == STRING_RESULT && b == STRING_RESULT)
1491
1578
    }
1492
1579
  case DECIMAL_RESULT:
1493
1580
    {
1494
 
      my_decimal decimal_value;
1495
 
      my_decimal *result= item->val_decimal(&decimal_value);
 
1581
      type::Decimal decimal_value;
 
1582
      type::Decimal *result= item->val_decimal(&decimal_value);
1496
1583
      uint32_t length= item->max_length, decimals= item->decimals;
1497
1584
      bool null_value= item->null_value;
1498
1585
      new_item= (null_value ?
1529
1616
 
1530
1617
  if (res_type == DECIMAL_RESULT)
1531
1618
  {
1532
 
    my_decimal item_buf, *item_val,
 
1619
    type::Decimal item_buf, *item_val,
1533
1620
               field_buf, *field_val;
1534
1621
    item_val= item->val_decimal(&item_buf);
1535
1622
    if (item->null_value)
1536
1623
      return 1;                                 // This must be true
1537
1624
    field_val= field->val_decimal(&field_buf);
1538
 
    return !my_decimal_cmp(item_val, field_val);
 
1625
    return !class_decimal_cmp(item_val, field_val);
1539
1626
  }
1540
1627
 
1541
1628
  double result= item->val_real();
1592
1679
      Values with MY_INT32_NUM_DECIMAL_DIGITS digits may or may not fit into
1593
1680
      Int32 -> make them field::Int64.
1594
1681
    */
1595
 
    if (item->max_length >= (MY_INT32_NUM_DECIMAL_DIGITS - 1))
1596
 
      new_field=new field::Int64(item->max_length, maybe_null,
1597
 
                                 item->name, item->unsigned_flag);
 
1682
    if (item->unsigned_flag)
 
1683
    {
 
1684
      new_field= new field::Size(item->max_length, maybe_null,
 
1685
                                  item->name, item->unsigned_flag);
 
1686
    }
 
1687
    else if (item->max_length >= (MY_INT32_NUM_DECIMAL_DIGITS - 1))
 
1688
    {
 
1689
      new_field= new field::Int64(item->max_length, maybe_null,
 
1690
                                  item->name, item->unsigned_flag);
 
1691
    }
1598
1692
    else
1599
 
      new_field=new field::Int32(item->max_length, maybe_null,
1600
 
                                 item->name, item->unsigned_flag);
 
1693
    {
 
1694
      new_field= new field::Int32(item->max_length, maybe_null,
 
1695
                                  item->name, item->unsigned_flag);
 
1696
    }
 
1697
 
1601
1698
    break;
1602
1699
 
1603
1700
  case STRING_RESULT:
1609
1706
      To preserve type they needed to be handled separately.
1610
1707
    */
1611
1708
    if ((type= item->field_type()) == DRIZZLE_TYPE_DATETIME ||
 
1709
        type == DRIZZLE_TYPE_TIME ||
 
1710
        type == DRIZZLE_TYPE_MICROTIME ||
1612
1711
        type == DRIZZLE_TYPE_DATE ||
1613
1712
        type == DRIZZLE_TYPE_TIMESTAMP)
1614
1713
    {
1658
1757
          +1: for decimal point
1659
1758
        */
1660
1759
 
1661
 
        overflow= my_decimal_precision_to_length(intg + dec, dec,
 
1760
        overflow= class_decimal_precision_to_length(intg + dec, dec,
1662
1761
                                                 item->unsigned_flag) - len;
1663
1762
 
1664
1763
        if (overflow > 0)
1799
1898
 
1800
1899
std::ostream& operator<<(std::ostream& output, const Item &item)
1801
1900
{
1802
 
  output << "Item:(";
1803
 
  output <<  item.name;
1804
 
  output << ", ";
1805
 
  output << drizzled::display::type(item.type());
1806
 
  output << ")";
 
1901
  switch (item.type())
 
1902
  {
 
1903
  case drizzled::Item::SUBSELECT_ITEM :
 
1904
  case drizzled::Item::FIELD_ITEM :
 
1905
  case drizzled::Item::SUM_FUNC_ITEM :
 
1906
  case drizzled::Item::STRING_ITEM :
 
1907
  case drizzled::Item::INT_ITEM :
 
1908
  case drizzled::Item::REAL_ITEM :
 
1909
  case drizzled::Item::NULL_ITEM :
 
1910
  case drizzled::Item::VARBIN_ITEM :
 
1911
  case drizzled::Item::COPY_STR_ITEM :
 
1912
  case drizzled::Item::FIELD_AVG_ITEM :
 
1913
  case drizzled::Item::DEFAULT_VALUE_ITEM :
 
1914
  case drizzled::Item::PROC_ITEM :
 
1915
  case drizzled::Item::COND_ITEM :
 
1916
  case drizzled::Item::REF_ITEM :
 
1917
  case drizzled::Item::FIELD_STD_ITEM :
 
1918
  case drizzled::Item::FIELD_VARIANCE_ITEM :
 
1919
  case drizzled::Item::INSERT_VALUE_ITEM :
 
1920
  case drizzled::Item::ROW_ITEM:
 
1921
  case drizzled::Item::CACHE_ITEM :
 
1922
  case drizzled::Item::TYPE_HOLDER :
 
1923
  case drizzled::Item::PARAM_ITEM :
 
1924
  case drizzled::Item::DECIMAL_ITEM :
 
1925
  case drizzled::Item::FUNC_ITEM :
 
1926
  case drizzled::Item::BOOLEAN_ITEM :
 
1927
    {
 
1928
      output << "Item:(";
 
1929
      output <<  item.full_name();
 
1930
      output << ", ";
 
1931
      output << drizzled::display::type(item.type());
 
1932
      output << ")";
 
1933
    }
 
1934
    break;
 
1935
  }
1807
1936
 
1808
1937
  return output;  // for multiple << operators.
1809
1938
}