~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.cc

  • Committer: Monty Taylor
  • Date: 2010-12-24 02:13:05 UTC
  • mto: This revision was merged to the branch mainline in revision 2038.
  • Revision ID: mordred@inaugust.com-20101224021305-e3slv1cyjczqorij
Changed the bzrignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
21
 
#include <drizzled/sql_select.h>
22
 
#include <drizzled/error.h>
23
 
#include <drizzled/show.h>
24
 
#include <drizzled/item/cmpfunc.h>
25
 
#include <drizzled/item/cache_row.h>
26
 
#include <drizzled/item/type_holder.h>
27
 
#include <drizzled/item/sum.h>
28
 
#include <drizzled/item/copy_string.h>
29
 
#include <drizzled/function/str/conv_charset.h>
30
 
#include <drizzled/sql_base.h>
31
 
#include <drizzled/util/convert.h>
32
 
#include <drizzled/plugin/client.h>
33
 
#include <drizzled/time_functions.h>
34
 
 
35
 
#include <drizzled/field/str.h>
36
 
#include <drizzled/field/num.h>
37
 
 
38
 
#include <drizzled/field/blob.h>
39
 
#include <drizzled/field/date.h>
40
 
#include <drizzled/field/datetime.h>
41
 
#include <drizzled/field/decimal.h>
42
 
#include <drizzled/field/double.h>
43
 
#include <drizzled/field/enum.h>
44
 
#include <drizzled/field/epoch.h>
45
 
#include <drizzled/field/int32.h>
46
 
#include <drizzled/field/int64.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>
52
 
#include <drizzled/field/varstring.h>
53
 
 
54
 
#include <drizzled/current_session.h>
55
 
#include <drizzled/session.h>
56
 
 
57
 
#include <drizzled/internal/m_string.h>
 
20
#include "config.h"
 
21
#include "drizzled/sql_select.h"
 
22
#include "drizzled/error.h"
 
23
#include "drizzled/show.h"
 
24
#include "drizzled/item/cmpfunc.h"
 
25
#include "drizzled/item/cache_row.h"
 
26
#include "drizzled/item/type_holder.h"
 
27
#include "drizzled/item/sum.h"
 
28
#include "drizzled/item/copy_string.h"
 
29
#include "drizzled/function/str/conv_charset.h"
 
30
#include "drizzled/sql_base.h"
 
31
#include "drizzled/util/convert.h"
 
32
#include "drizzled/plugin/client.h"
 
33
#include "drizzled/time_functions.h"
 
34
 
 
35
#include "drizzled/field/str.h"
 
36
#include "drizzled/field/num.h"
 
37
 
 
38
#include "drizzled/field/blob.h"
 
39
#include "drizzled/field/date.h"
 
40
#include "drizzled/field/datetime.h"
 
41
#include "drizzled/field/decimal.h"
 
42
#include "drizzled/field/double.h"
 
43
#include "drizzled/field/enum.h"
 
44
#include "drizzled/field/epoch.h"
 
45
#include "drizzled/field/int32.h"
 
46
#include "drizzled/field/int64.h"
 
47
#include "drizzled/field/null.h"
 
48
#include "drizzled/field/real.h"
 
49
#include "drizzled/field/size.h"
 
50
#include "drizzled/field/time.h"
 
51
#include "drizzled/field/varstring.h"
 
52
 
 
53
#include "drizzled/internal/m_string.h"
58
54
 
59
55
#include <cstdio>
60
56
#include <math.h>
102
98
 
103
99
    case DECIMAL_RESULT:
104
100
    {
105
 
      type::Decimal decimal_value;
106
 
      type::Decimal *val= val_decimal(&decimal_value);
 
101
      my_decimal decimal_value;
 
102
      my_decimal *val= val_decimal(&decimal_value);
107
103
      if (val)
108
 
        return not val->isZero();
 
104
        return !my_decimal_is_zero(val);
109
105
      return false;
110
106
    }
111
107
 
144
140
 
145
141
String *Item::val_string_from_decimal(String *str)
146
142
{
147
 
  type::Decimal dec_buf, *dec= val_decimal(&dec_buf);
 
143
  my_decimal dec_buf, *dec= val_decimal(&dec_buf);
148
144
  if (null_value)
149
145
    return NULL;
150
146
 
151
 
  class_decimal_round(E_DEC_FATAL_ERROR, dec, decimals, false, &dec_buf);
152
 
  class_decimal2string(&dec_buf, 0, str);
 
147
  my_decimal_round(E_DEC_FATAL_ERROR, dec, decimals, false, &dec_buf);
 
148
  my_decimal2string(E_DEC_FATAL_ERROR, &dec_buf, 0, 0, 0, str);
153
149
  return str;
154
150
}
155
151
 
156
 
type::Decimal *Item::val_decimal_from_real(type::Decimal *decimal_value)
 
152
my_decimal *Item::val_decimal_from_real(my_decimal *decimal_value)
157
153
{
158
154
  double nr= val_real();
159
155
  if (null_value)
160
156
    return NULL;
161
157
 
162
 
  double2_class_decimal(E_DEC_FATAL_ERROR, nr, decimal_value);
 
158
  double2my_decimal(E_DEC_FATAL_ERROR, nr, decimal_value);
163
159
  return (decimal_value);
164
160
}
165
161
 
166
 
type::Decimal *Item::val_decimal_from_int(type::Decimal *decimal_value)
 
162
my_decimal *Item::val_decimal_from_int(my_decimal *decimal_value)
167
163
{
168
164
  int64_t nr= val_int();
169
165
  if (null_value)
170
166
    return NULL;
171
167
 
172
 
  int2_class_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
 
168
  int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
173
169
  return decimal_value;
174
170
}
175
171
 
176
 
type::Decimal *Item::val_decimal_from_string(type::Decimal *decimal_value)
 
172
my_decimal *Item::val_decimal_from_string(my_decimal *decimal_value)
177
173
{
178
174
  String *res;
179
175
  char *end_ptr;
181
177
    return NULL;
182
178
 
183
179
  end_ptr= (char*) res->ptr()+ res->length();
184
 
  if (decimal_value->store(E_DEC_FATAL_ERROR & ~E_DEC_BAD_NUM,
 
180
  if (str2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_BAD_NUM,
185
181
                     res->ptr(), 
186
182
                     res->length(), 
187
 
                     res->charset()) & E_DEC_BAD_NUM)
 
183
                     res->charset(),
 
184
                     decimal_value) & E_DEC_BAD_NUM)
188
185
  {
189
 
    push_warning_printf(&getSession(), 
 
186
    push_warning_printf(current_session, 
190
187
                        DRIZZLE_ERROR::WARN_LEVEL_WARN,
191
188
                        ER_TRUNCATED_WRONG_VALUE,
192
189
                        ER(ER_TRUNCATED_WRONG_VALUE), "DECIMAL",
195
192
  return decimal_value;
196
193
}
197
194
 
198
 
type::Decimal *Item::val_decimal_from_date(type::Decimal *decimal_value)
 
195
my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value)
199
196
{
200
197
  assert(fixed);
201
 
  type::Time ltime;
202
 
  if (get_date(ltime, TIME_FUZZY_DATE))
 
198
  DRIZZLE_TIME ltime;
 
199
  if (get_date(&ltime, TIME_FUZZY_DATE))
203
200
  {
204
 
    decimal_value->set_zero();
 
201
    my_decimal_set_zero(decimal_value);
205
202
    null_value= 1;                               // set NULL, stop processing
206
203
    return NULL;
207
204
  }
208
 
  return date2_class_decimal(&ltime, decimal_value);
 
205
  return date2my_decimal(&ltime, decimal_value);
209
206
}
210
207
 
211
 
type::Decimal *Item::val_decimal_from_time(type::Decimal *decimal_value)
 
208
my_decimal *Item::val_decimal_from_time(my_decimal *decimal_value)
212
209
{
213
210
  assert(fixed);
214
 
  type::Time ltime;
215
 
  if (get_time(ltime))
 
211
  DRIZZLE_TIME ltime;
 
212
  if (get_time(&ltime))
216
213
  {
217
 
    decimal_value->set_zero();
 
214
    my_decimal_set_zero(decimal_value);
218
215
    return NULL;
219
216
  }
220
 
  return date2_class_decimal(&ltime, decimal_value);
 
217
  return date2my_decimal(&ltime, decimal_value);
221
218
}
222
219
 
223
220
double Item::val_real_from_decimal()
224
221
{
225
222
  /* Note that fix_fields may not be called for Item_avg_field items */
226
223
  double result;
227
 
  type::Decimal value_buff, *dec_val= val_decimal(&value_buff);
 
224
  my_decimal value_buff, *dec_val= val_decimal(&value_buff);
228
225
  if (null_value)
229
226
    return 0.0;
230
 
  class_decimal2double(E_DEC_FATAL_ERROR, dec_val, &result);
 
227
  my_decimal2double(E_DEC_FATAL_ERROR, dec_val, &result);
231
228
  return result;
232
229
}
233
230
 
235
232
{
236
233
  /* Note that fix_fields may not be called for Item_avg_field items */
237
234
  int64_t result;
238
 
  type::Decimal value, *dec_val= val_decimal(&value);
239
 
 
 
235
  my_decimal value, *dec_val= val_decimal(&value);
240
236
  if (null_value)
241
237
    return 0;
242
 
  dec_val->val_int32(E_DEC_FATAL_ERROR, unsigned_flag, &result);
243
 
 
 
238
  my_decimal2int(E_DEC_FATAL_ERROR, dec_val, unsigned_flag, &result);
244
239
  return result;
245
240
}
246
241
 
247
 
bool Item::save_time_in_field(Field *field)
 
242
int Item::save_time_in_field(Field *field)
248
243
{
249
 
  type::Time ltime;
250
 
 
251
 
  if (get_time(ltime))
 
244
  DRIZZLE_TIME ltime;
 
245
  if (get_time(&ltime))
252
246
    return set_field_to_null(field);
253
 
 
254
247
  field->set_notnull();
255
 
 
256
 
  return field->store_time(ltime, type::DRIZZLE_TIMESTAMP_TIME);
 
248
  return field->store_time(&ltime, DRIZZLE_TIMESTAMP_TIME);
257
249
}
258
250
 
259
 
bool Item::save_date_in_field(Field *field)
 
251
int Item::save_date_in_field(Field *field)
260
252
{
261
 
  type::Time ltime;
262
 
 
263
 
  if (get_date(ltime, TIME_FUZZY_DATE))
 
253
  DRIZZLE_TIME ltime;
 
254
  if (get_date(&ltime, TIME_FUZZY_DATE))
264
255
    return set_field_to_null(field);
265
 
 
266
256
  field->set_notnull();
267
 
 
268
 
  return field->store_time(ltime, type::DRIZZLE_TIMESTAMP_DATETIME);
 
257
  return field->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
269
258
}
270
259
 
271
260
/**
276
265
{
277
266
  if (null_value)
278
267
    return set_field_to_null(field);
279
 
 
280
268
  field->set_notnull();
281
 
 
282
269
  return field->store(result->ptr(), result->length(), collation.collation);
283
270
}
284
271
 
297
284
  with_sum_func(false),
298
285
  is_autogenerated_name(true),
299
286
  with_subselect(false),
300
 
  collation(&my_charset_bin, DERIVATION_COERCIBLE),
301
 
  _session(*current_session)
 
287
  collation(&my_charset_bin, DERIVATION_COERCIBLE)
302
288
{
303
289
  cmp_context= (Item_result)-1;
304
290
 
305
291
  /* Put item in free list so that we can free all items at end */
306
 
  next= getSession().free_list;
307
 
  getSession().free_list= this;
 
292
  Session *session= current_session;
 
293
  next= session->free_list;
 
294
  session->free_list= this;
308
295
 
309
296
  /*
310
297
    Item constructor can be called during execution other then SQL_COM
311
 
    command => we should check session->getLex()->current_select on zero (session->lex
 
298
    command => we should check session->lex->current_select on zero (session->lex
312
299
    can be uninitialised)
313
300
  */
314
 
  if (getSession().getLex()->current_select)
 
301
  if (session->lex->current_select)
315
302
  {
316
 
    enum_parsing_place place= getSession().getLex()->current_select->parsing_place;
 
303
    enum_parsing_place place= session->lex->current_select->parsing_place;
317
304
    if (place == SELECT_LIST || place == IN_HAVING)
318
 
      getSession().getLex()->current_select->select_n_having_items++;
 
305
      session->lex->current_select->select_n_having_items++;
319
306
  }
320
307
}
321
308
 
336
323
  is_autogenerated_name(item->is_autogenerated_name),
337
324
  with_subselect(item->with_subselect),
338
325
  collation(item->collation),
339
 
  cmp_context(item->cmp_context),
340
 
  _session(*session)
 
326
  cmp_context(item->cmp_context)
341
327
{
342
328
  /* Put this item in the session's free list */
343
 
  next= getSession().free_list;
344
 
  getSession().free_list= this;
 
329
  next= session->free_list;
 
330
  session->free_list= this;
345
331
}
346
332
 
347
333
uint32_t Item::float_length(uint32_t decimals_par) const
354
340
  Item_result restype= result_type();
355
341
 
356
342
  if ((restype == DECIMAL_RESULT) || (restype == INT_RESULT))
357
 
    return min(class_decimal_length_to_precision(max_length, decimals, unsigned_flag),
 
343
    return min(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
358
344
               (uint32_t) DECIMAL_MAX_PRECISION);
359
345
  return min(max_length, (uint32_t) DECIMAL_MAX_PRECISION);
360
346
}
361
347
 
362
348
int Item::decimal_int_part() const
363
349
{
364
 
  return class_decimal_int_part(decimal_precision(), decimals);
 
350
  return my_decimal_int_part(decimal_precision(), decimals);
365
351
}
366
352
 
367
353
void Item::print(String *str, enum_query_type)
439
425
    if (orig_len != length && ! is_autogenerated_name)
440
426
    {
441
427
      if (length == 0)
442
 
        push_warning_printf(&getSession(), 
 
428
        push_warning_printf(current_session, 
443
429
                            DRIZZLE_ERROR::WARN_LEVEL_WARN,
444
430
                            ER_NAME_BECOMES_EMPTY, 
445
431
                            ER(ER_NAME_BECOMES_EMPTY),
446
432
                            str + length - orig_len);
447
433
      else
448
 
        push_warning_printf(&getSession(),
 
434
        push_warning_printf(current_session, 
449
435
                            DRIZZLE_ERROR::WARN_LEVEL_WARN,
450
436
                            ER_REMOVED_SPACES, 
451
437
                            ER(ER_REMOVED_SPACES),
474
460
  return conv->safe ? conv : NULL;
475
461
}
476
462
 
477
 
bool Item::get_date(type::Time &ltime,uint32_t fuzzydate)
 
463
bool Item::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
478
464
{
479
 
  do
480
 
  {
481
 
    if (is_null())
482
 
    {
483
 
      break;
484
 
    }
485
 
    else if (result_type() == STRING_RESULT)
486
 
    {
487
 
      char buff[type::Time::MAX_STRING_LENGTH];
488
 
      String tmp(buff,sizeof(buff), &my_charset_bin),*res;
489
 
      if (!(res=val_str(&tmp)) ||
490
 
          str_to_datetime_with_warn(&getSession(), res->ptr(), res->length(),
491
 
                                    &ltime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR)
492
 
      {
493
 
        break;
494
 
      }
495
 
    }
496
 
    else
497
 
    {
498
 
      int64_t value= val_int();
499
 
      type::datetime_t date_value;
500
 
 
501
 
      ltime.convert(date_value, value, fuzzydate);
502
 
 
503
 
      if (not type::is_valid(date_value))
504
 
      {
505
 
        char buff[DECIMAL_LONGLONG_DIGITS], *end;
506
 
        end= internal::int64_t10_to_str(value, buff, -10);
507
 
        make_truncated_value_warning(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN,
508
 
                                     buff, (int) (end-buff), type::DRIZZLE_TIMESTAMP_NONE, NULL);
509
 
        break;
510
 
      }
511
 
    }
512
 
 
513
 
    return false;
514
 
  } while (0);
515
 
 
516
 
  ltime.reset();
517
 
 
 
465
  if (result_type() == STRING_RESULT)
 
466
  {
 
467
    char buff[40];
 
468
    String tmp(buff,sizeof(buff), &my_charset_bin),*res;
 
469
    if (!(res=val_str(&tmp)) ||
 
470
        str_to_datetime_with_warn(res->ptr(), res->length(),
 
471
                                  ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
 
472
      goto err;
 
473
  }
 
474
  else
 
475
  {
 
476
    int64_t value= val_int();
 
477
    int was_cut;
 
478
    if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1L)
 
479
    {
 
480
      char buff[22], *end;
 
481
      end= internal::int64_t10_to_str(value, buff, -10);
 
482
      make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
483
                                   buff, (int) (end-buff), DRIZZLE_TIMESTAMP_NONE,
 
484
                                   NULL);
 
485
      goto err;
 
486
    }
 
487
  }
 
488
  return false;
 
489
 
 
490
err:
 
491
  memset(ltime, 0, sizeof(*ltime));
518
492
  return true;
519
493
}
520
494
 
521
 
bool Item::get_time(type::Time &ltime)
 
495
bool Item::get_time(DRIZZLE_TIME *ltime)
522
496
{
523
 
  char buff[type::Time::MAX_STRING_LENGTH];
 
497
  char buff[40];
524
498
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
525
 
  if (!(res=val_str(&tmp)) or
526
 
      str_to_time_with_warn(&getSession(), res->ptr(), res->length(), &ltime))
 
499
  if (!(res=val_str(&tmp)) ||
 
500
      str_to_time_with_warn(res->ptr(), res->length(), ltime))
527
501
  {
528
 
    ltime.reset();
529
 
 
 
502
    memset(ltime, 0, sizeof(*ltime));
530
503
    return true;
531
504
  }
532
 
 
533
505
  return false;
534
506
}
535
507
 
536
 
bool Item::get_date_result(type::Time &ltime,uint32_t fuzzydate)
 
508
bool Item::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
537
509
{
538
 
  return get_date(ltime, fuzzydate);
 
510
  return get_date(ltime,fuzzydate);
539
511
}
540
512
 
541
513
bool Item::is_null()
788
760
    Item *real_itm= real_item();
789
761
 
790
762
    ref_pointer_array[el]= real_itm;
791
 
    if (!(item_ref= new Item_aggregate_ref(&session->getLex()->current_select->context,
 
763
    if (!(item_ref= new Item_aggregate_ref(&session->lex->current_select->context,
792
764
                                           ref_pointer_array + el, 0, name)))
793
765
      return; /* fatal_error is set */
794
766
    if (type() == SUM_FUNC_ITEM)
821
793
  if (mark_item)
822
794
    mark_item->depended_from= last;
823
795
  current->mark_as_dependent(last);
824
 
  if (session->getLex()->describe & DESCRIBE_EXTENDED)
 
796
  if (session->lex->describe & DESCRIBE_EXTENDED)
825
797
  {
826
798
    char warn_buff[DRIZZLE_ERRMSG_SIZE];
827
799
    snprintf(warn_buff, sizeof(warn_buff), ER(ER_WARN_FIELD_RESOLVED),
852
824
  {
853
825
    Item_subselect *prev_subselect_item= previous_select->master_unit()->item;
854
826
    prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
855
 
    prev_subselect_item->const_item_cache= false;
 
827
    prev_subselect_item->const_item_cache= 0;
856
828
  }
857
829
  {
858
830
    Item_subselect *prev_subselect_item= previous_select->master_unit()->item;
867
839
    }
868
840
    else
869
841
      prev_subselect_item->used_tables_cache|= found_field->getTable()->map;
870
 
    prev_subselect_item->const_item_cache= false;
 
842
    prev_subselect_item->const_item_cache= 0;
871
843
    mark_as_dependent(session, last_select, current_sel, resolved_item,
872
844
                      dependent);
873
845
  }
887
859
    - the found item on success
888
860
    - NULL if find_item is not in group_list
889
861
*/
890
 
static Item** find_field_in_group_list(Session *session, Item *find_item, Order *group_list)
 
862
static Item** find_field_in_group_list(Item *find_item, Order *group_list)
891
863
{
892
864
  const char *db_name;
893
865
  const char *table_name;
943
915
        if (cur_field->db_name && db_name)
944
916
        {
945
917
          /* If field_name is also qualified by a database name. */
946
 
          if (my_strcasecmp(system_charset_info, cur_field->db_name, db_name))
947
 
          {
 
918
          if (strcasecmp(cur_field->db_name, db_name))
948
919
            /* Same field names, different databases. */
949
920
            return NULL;
950
 
          }
951
921
          ++cur_match_degree;
952
922
        }
953
923
      }
966
936
          best match, they must reference the same column, otherwise the field
967
937
          is ambiguous.
968
938
        */
969
 
        my_error(ER_NON_UNIQ_ERROR, MYF(0), find_item->full_name(), session->where());
 
939
        my_error(ER_NON_UNIQ_ERROR, MYF(0), find_item->full_name(), current_session->where);
970
940
        return NULL;
971
941
      }
972
942
    }
974
944
 
975
945
  if (found_group)
976
946
    return found_group->item;
977
 
 
978
 
  return NULL;
 
947
  else
 
948
    return NULL;
979
949
}
980
950
 
981
951
Item** resolve_ref_in_select_and_group(Session *session, Item_ident *ref, Select_Lex *select)
1002
972
  /* If this is a non-aggregated field inside HAVING, search in GROUP BY. */
1003
973
  if (select->having_fix_field && !ref->with_sum_func && group_list)
1004
974
  {
1005
 
    group_by_ref= find_field_in_group_list(session, ref, group_list);
 
975
    group_by_ref= find_field_in_group_list(ref, group_list);
1006
976
 
1007
977
    /* Check if the fields found in SELECT and GROUP BY are the same field. */
1008
978
    if (group_by_ref && (select_ref != not_found_item) &&
1011
981
      ambiguous_fields= true;
1012
982
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
1013
983
                          ER(ER_NON_UNIQ_ERROR), ref->full_name(),
1014
 
                          session->where());
 
984
                          current_session->where);
1015
985
 
1016
986
    }
1017
987
  }
1090
1060
 
1091
1061
bool Item::is_datetime()
1092
1062
{
1093
 
  return field::isDateTime(field_type());
 
1063
  switch (field_type())
 
1064
  {
 
1065
    case DRIZZLE_TYPE_TIME:
 
1066
    case DRIZZLE_TYPE_DATE:
 
1067
    case DRIZZLE_TYPE_DATETIME:
 
1068
    case DRIZZLE_TYPE_TIMESTAMP:
 
1069
      return true;
 
1070
    case DRIZZLE_TYPE_BLOB:
 
1071
    case DRIZZLE_TYPE_VARCHAR:
 
1072
    case DRIZZLE_TYPE_DOUBLE:
 
1073
    case DRIZZLE_TYPE_DECIMAL:
 
1074
    case DRIZZLE_TYPE_ENUM:
 
1075
    case DRIZZLE_TYPE_LONG:
 
1076
    case DRIZZLE_TYPE_LONGLONG:
 
1077
    case DRIZZLE_TYPE_NULL:
 
1078
    case DRIZZLE_TYPE_UUID:
 
1079
      return false;
 
1080
  }
 
1081
 
 
1082
  assert(0);
 
1083
  abort();
1094
1084
}
1095
1085
 
1096
1086
String *Item::check_well_formed_result(String *str, bool send_error)
1103
1093
                                       str->length(), &well_formed_error);
1104
1094
  if (wlen < str->length())
1105
1095
  {
 
1096
    Session *session= current_session;
1106
1097
    char hexbuf[7];
1107
1098
    enum DRIZZLE_ERROR::enum_warning_level level;
1108
1099
    uint32_t diff= str->length() - wlen;
1119
1110
      null_value= 1;
1120
1111
      str= 0;
1121
1112
    }
1122
 
    push_warning_printf(&getSession(), level, ER_INVALID_CHARACTER_STRING,
 
1113
    push_warning_printf(session, level, ER_INVALID_CHARACTER_STRING,
1123
1114
                        ER(ER_INVALID_CHARACTER_STRING), cs->csname, hexbuf);
1124
1115
  }
1125
1116
  return str;
1184
1175
                                 0,
1185
1176
                                 Field::NONE,
1186
1177
                                 name,
1187
 
                                 decimals);
 
1178
                                 decimals,
 
1179
                                 0,
 
1180
                                 unsigned_flag);
1188
1181
    break;
1189
1182
  case DRIZZLE_TYPE_LONG:
1190
1183
    field= new field::Int32((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE, name);
1197
1190
                            name, decimals, 0, unsigned_flag);
1198
1191
    break;
1199
1192
  case DRIZZLE_TYPE_NULL:
1200
 
    field= new Field_null((unsigned char*) 0, max_length, name);
 
1193
    field= new Field_null((unsigned char*) 0, max_length, name, &my_charset_bin);
1201
1194
    break;
1202
1195
  case DRIZZLE_TYPE_DATE:
1203
 
    field= new Field_date(maybe_null, name);
1204
 
    break;
1205
 
 
1206
 
  case DRIZZLE_TYPE_MICROTIME:
1207
 
    field= new field::Microtime(maybe_null, name);
1208
 
    break;
1209
 
 
 
1196
    field= new Field_date(maybe_null, name, &my_charset_bin);
 
1197
    break;
1210
1198
  case DRIZZLE_TYPE_TIMESTAMP:
1211
 
    field= new field::Epoch(maybe_null, name);
 
1199
    field= new field::Epoch(maybe_null, name, &my_charset_bin);
1212
1200
    break;
1213
1201
  case DRIZZLE_TYPE_DATETIME:
1214
 
    field= new Field_datetime(maybe_null, name);
 
1202
    field= new Field_datetime(maybe_null, name, &my_charset_bin);
1215
1203
    break;
1216
1204
  case DRIZZLE_TYPE_TIME:
1217
 
    field= new field::Time(maybe_null, name);
 
1205
    field= new field::Time(maybe_null, name, &my_charset_bin);
1218
1206
    break;
1219
 
  case DRIZZLE_TYPE_BOOLEAN:
1220
1207
  case DRIZZLE_TYPE_UUID:
1221
1208
  case DRIZZLE_TYPE_ENUM:
1222
1209
  case DRIZZLE_TYPE_VARCHAR:
1278
1265
  }
1279
1266
  else if (result_type() == DECIMAL_RESULT)
1280
1267
  {
1281
 
    type::Decimal decimal_value;
1282
 
    type::Decimal *value= val_decimal(&decimal_value);
 
1268
    my_decimal decimal_value;
 
1269
    my_decimal *value= val_decimal(&decimal_value);
1283
1270
    if (null_value)
1284
1271
      return set_field_to_null_with_conversions(field, no_conversions);
1285
1272
    field->set_notnull();
1366
1353
  case DRIZZLE_TYPE_ENUM:
1367
1354
  case DRIZZLE_TYPE_BLOB:
1368
1355
  case DRIZZLE_TYPE_VARCHAR:
1369
 
  case DRIZZLE_TYPE_BOOLEAN:
1370
1356
  case DRIZZLE_TYPE_UUID:
1371
1357
  case DRIZZLE_TYPE_DECIMAL:
1372
1358
    {
1405
1391
    }
1406
1392
  case DRIZZLE_TYPE_TIME:
1407
1393
    {
1408
 
      type::Time tm;
1409
 
      get_time(tm);
 
1394
      DRIZZLE_TIME tm;
 
1395
      get_time(&tm);
1410
1396
      if (not null_value)
1411
1397
        result= client->store(&tm);
1412
1398
      break;
1413
1399
    }
1414
1400
  case DRIZZLE_TYPE_DATETIME:
1415
 
  case DRIZZLE_TYPE_MICROTIME:
1416
1401
  case DRIZZLE_TYPE_TIMESTAMP:
1417
1402
    {
1418
 
      type::Time tm;
1419
 
      get_date(tm, TIME_FUZZY_DATE);
 
1403
      DRIZZLE_TIME tm;
 
1404
      get_date(&tm, TIME_FUZZY_DATE);
1420
1405
      if (!null_value)
1421
1406
        result= client->store(&tm);
1422
1407
      break;
1428
1413
  return result;
1429
1414
}
1430
1415
 
1431
 
uint32_t Item::max_char_length() const
1432
 
{
1433
 
  return max_length / collation.collation->mbmaxlen;
1434
 
}
1435
 
 
1436
 
void Item::fix_length_and_charset(uint32_t max_char_length_arg, CHARSET_INFO *cs)
1437
 
1438
 
  max_length= char_to_byte_length_safe(max_char_length_arg, cs->mbmaxlen);
1439
 
  collation.collation= cs;
1440
 
}
1441
 
 
1442
 
void Item::fix_char_length(uint32_t max_char_length_arg)
1443
 
1444
 
  max_length= char_to_byte_length_safe(max_char_length_arg, collation.collation->mbmaxlen);
1445
 
}
1446
 
 
1447
 
void Item::fix_char_length_uint64_t(uint64_t max_char_length_arg)
1448
 
1449
 
  uint64_t max_result_length= max_char_length_arg *
1450
 
    collation.collation->mbmaxlen;
1451
 
 
1452
 
  if (max_result_length >= MAX_BLOB_WIDTH)
1453
 
  { 
1454
 
    max_length= MAX_BLOB_WIDTH;
1455
 
    maybe_null= false;
1456
 
  }
1457
 
  else
1458
 
  {
1459
 
    max_length= max_result_length;
1460
 
  }
1461
 
}
1462
 
 
1463
 
void Item::fix_length_and_charset_datetime(uint32_t max_char_length_arg)
1464
 
1465
 
  collation.set(&my_charset_bin);
1466
 
  fix_char_length(max_char_length_arg);
1467
 
}
1468
 
 
1469
1416
Item_result item_cmp_type(Item_result a,Item_result b)
1470
1417
{
1471
1418
  if (a == STRING_RESULT && b == STRING_RESULT)
1559
1506
    }
1560
1507
  case DECIMAL_RESULT:
1561
1508
    {
1562
 
      type::Decimal decimal_value;
1563
 
      type::Decimal *result= item->val_decimal(&decimal_value);
 
1509
      my_decimal decimal_value;
 
1510
      my_decimal *result= item->val_decimal(&decimal_value);
1564
1511
      uint32_t length= item->max_length, decimals= item->decimals;
1565
1512
      bool null_value= item->null_value;
1566
1513
      new_item= (null_value ?
1597
1544
 
1598
1545
  if (res_type == DECIMAL_RESULT)
1599
1546
  {
1600
 
    type::Decimal item_buf, *item_val,
 
1547
    my_decimal item_buf, *item_val,
1601
1548
               field_buf, *field_val;
1602
1549
    item_val= item->val_decimal(&item_buf);
1603
1550
    if (item->null_value)
1604
1551
      return 1;                                 // This must be true
1605
1552
    field_val= field->val_decimal(&field_buf);
1606
 
    return !class_decimal_cmp(item_val, field_val);
 
1553
    return !my_decimal_cmp(item_val, field_val);
1607
1554
  }
1608
1555
 
1609
1556
  double result= item->val_real();
1681
1628
  case STRING_RESULT:
1682
1629
    assert(item->collation.collation);
1683
1630
 
 
1631
    enum enum_field_types type;
1684
1632
    /*
1685
1633
      DATE/TIME fields have STRING_RESULT result type.
1686
1634
      To preserve type they needed to be handled separately.
1687
1635
    */
1688
 
    if (field::isDateTime(item->field_type()))
 
1636
    if ((type= item->field_type()) == DRIZZLE_TYPE_DATETIME ||
 
1637
        type == DRIZZLE_TYPE_TIME ||
 
1638
        type == DRIZZLE_TYPE_DATE ||
 
1639
        type == DRIZZLE_TYPE_TIMESTAMP)
1689
1640
    {
1690
1641
      new_field= item->tmp_table_field_from_field_type(table, 1);
1691
1642
      /*
1733
1684
          +1: for decimal point
1734
1685
        */
1735
1686
 
1736
 
        overflow= class_decimal_precision_to_length(intg + dec, dec,
 
1687
        overflow= my_decimal_precision_to_length(intg + dec, dec,
1737
1688
                                                 item->unsigned_flag) - len;
1738
1689
 
1739
1690
        if (overflow > 0)
1874
1825
 
1875
1826
std::ostream& operator<<(std::ostream& output, const Item &item)
1876
1827
{
1877
 
  switch (item.type())
1878
 
  {
1879
 
  case drizzled::Item::SUBSELECT_ITEM :
1880
 
  case drizzled::Item::FIELD_ITEM :
1881
 
  case drizzled::Item::SUM_FUNC_ITEM :
1882
 
  case drizzled::Item::STRING_ITEM :
1883
 
  case drizzled::Item::INT_ITEM :
1884
 
  case drizzled::Item::REAL_ITEM :
1885
 
  case drizzled::Item::NULL_ITEM :
1886
 
  case drizzled::Item::VARBIN_ITEM :
1887
 
  case drizzled::Item::COPY_STR_ITEM :
1888
 
  case drizzled::Item::FIELD_AVG_ITEM :
1889
 
  case drizzled::Item::DEFAULT_VALUE_ITEM :
1890
 
  case drizzled::Item::PROC_ITEM :
1891
 
  case drizzled::Item::COND_ITEM :
1892
 
  case drizzled::Item::REF_ITEM :
1893
 
  case drizzled::Item::FIELD_STD_ITEM :
1894
 
  case drizzled::Item::FIELD_VARIANCE_ITEM :
1895
 
  case drizzled::Item::INSERT_VALUE_ITEM :
1896
 
  case drizzled::Item::ROW_ITEM:
1897
 
  case drizzled::Item::CACHE_ITEM :
1898
 
  case drizzled::Item::TYPE_HOLDER :
1899
 
  case drizzled::Item::PARAM_ITEM :
1900
 
  case drizzled::Item::DECIMAL_ITEM :
1901
 
  case drizzled::Item::FUNC_ITEM :
1902
 
  case drizzled::Item::BOOLEAN_ITEM :
1903
 
    {
1904
 
      output << "Item:(";
1905
 
      output <<  item.full_name();
1906
 
      output << ", ";
1907
 
      output << drizzled::display::type(item.type());
1908
 
      output << ")";
1909
 
    }
1910
 
    break;
1911
 
  }
 
1828
  output << "Item:(";
 
1829
  output <<  item.name;
 
1830
  output << ", ";
 
1831
  output << drizzled::display::type(item.type());
 
1832
  output << ")";
1912
1833
 
1913
1834
  return output;  // for multiple << operators.
1914
1835
}