~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item.cc

  • Committer: Brian Aker
  • Date: 2008-07-07 14:25:25 UTC
  • mto: (77.1.25 codestyle)
  • mto: This revision was merged to the branch mainline in revision 82.
  • Revision ID: brian@tangent.org-20080707142525-xzy2nl3ie2ebwfln
LL() cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
 
17
 
#include <drizzled/server_includes.h>
18
 
#include <drizzled/sql_select.h>
19
 
#include <drizzled/drizzled_error_messages.h>
 
17
#ifdef USE_PRAGMA_IMPLEMENTATION
 
18
#pragma implementation                          // gcc: Class implementation
 
19
#endif
 
20
#include "mysql_priv.h"
 
21
#include <mysql.h>
 
22
#include <m_ctype.h>
 
23
#include "my_dir.h"
 
24
#include "sql_select.h"
20
25
 
21
26
const String my_null_string("NULL", 4, default_charset_info);
22
27
 
39
44
 
40
45
 
41
46
my_decimal *
42
 
Hybrid_type_traits::val_decimal(Hybrid_type *val,
43
 
                                my_decimal *to __attribute__((unused))) const
 
47
Hybrid_type_traits::val_decimal(Hybrid_type *val, my_decimal *to) const
44
48
{
45
49
  double2my_decimal(E_DEC_FATAL_ERROR, val->real, val->dec_buf);
46
50
  return val->dec_buf;
48
52
 
49
53
 
50
54
String *
51
 
Hybrid_type_traits::val_str(Hybrid_type *val, String *to, uint8_t decimals) const
 
55
Hybrid_type_traits::val_str(Hybrid_type *val, String *to, uint8 decimals) const
52
56
{
53
57
  to->set_real(val->real, decimals, &my_charset_bin);
54
58
  return to;
67
71
Hybrid_type_traits_decimal::fix_length_and_dec(Item *item, Item *arg) const
68
72
{
69
73
  item->decimals= arg->decimals;
70
 
  item->max_length= cmin(arg->max_length + DECIMAL_LONGLONG_DIGITS,
71
 
                        (unsigned int)DECIMAL_MAX_STR_LENGTH);
 
74
  item->max_length= min(arg->max_length + DECIMAL_LONGLONG_DIGITS,
 
75
                        DECIMAL_MAX_STR_LENGTH);
72
76
}
73
77
 
74
78
 
93
97
  @todo
94
98
  what is '4' for scale?
95
99
*/
96
 
void Hybrid_type_traits_decimal::div(Hybrid_type *val, uint64_t u) const
 
100
void Hybrid_type_traits_decimal::div(Hybrid_type *val, ulonglong u) const
97
101
{
98
102
  int2my_decimal(E_DEC_FATAL_ERROR, u, true, &val->dec_buf[2]);
99
103
  /* XXX: what is '4' for scale? */
105
109
}
106
110
 
107
111
 
108
 
int64_t
 
112
longlong
109
113
Hybrid_type_traits_decimal::val_int(Hybrid_type *val, bool unsigned_flag) const
110
114
{
111
 
  int64_t result;
 
115
  longlong result;
112
116
  my_decimal2int(E_DEC_FATAL_ERROR, &val->dec_buf[val->used_dec_buf_no],
113
117
                 unsigned_flag, &result);
114
118
  return result;
126
130
 
127
131
String *
128
132
Hybrid_type_traits_decimal::val_str(Hybrid_type *val, String *to,
129
 
                                    uint8_t decimals) const
 
133
                                    uint8 decimals) const
130
134
{
131
135
  my_decimal_round(E_DEC_FATAL_ERROR, &val->dec_buf[val->used_dec_buf_no],
132
136
                   decimals, false, &val->dec_buf[2]);
143
147
}
144
148
 
145
149
void
146
 
Hybrid_type_traits_integer::fix_length_and_dec(Item *item,
147
 
                                               Item *arg __attribute__((unused))) const
 
150
Hybrid_type_traits_integer::fix_length_and_dec(Item *item, Item *arg) const
148
151
{
149
152
  item->decimals= 0;
150
153
  item->max_length= MY_INT64_NUM_DECIMAL_DIGITS;
161
164
 
162
165
void item_init(void)
163
166
{
 
167
  uuid_short_init();
164
168
}
165
169
 
166
170
 
187
191
    return val_real() != 0.0;
188
192
  case ROW_RESULT:
189
193
  default:
190
 
    assert(0);
 
194
    DBUG_ASSERT(0);
191
195
    return 0;                                   // Wrong (but safe)
192
196
  }
193
197
}
205
209
 
206
210
String *Item::val_string_from_int(String *str)
207
211
{
208
 
  int64_t nr= val_int();
 
212
  longlong nr= val_int();
209
213
  if (null_value)
210
214
    return 0;
211
215
  str->set_int(nr, unsigned_flag, &my_charset_bin);
236
240
 
237
241
my_decimal *Item::val_decimal_from_int(my_decimal *decimal_value)
238
242
{
239
 
  int64_t nr= val_int();
 
243
  longlong nr= val_int();
240
244
  if (null_value)
241
245
    return 0;
242
246
  int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
256
260
                     res->ptr(), res->length(), res->charset(),
257
261
                     decimal_value) & E_DEC_BAD_NUM)
258
262
  {
259
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
263
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
260
264
                        ER_TRUNCATED_WRONG_VALUE,
261
265
                        ER(ER_TRUNCATED_WRONG_VALUE), "DECIMAL",
262
266
                        str_value.c_ptr());
267
271
 
268
272
my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value)
269
273
{
270
 
  assert(fixed == 1);
271
 
  DRIZZLE_TIME ltime;
 
274
  DBUG_ASSERT(fixed == 1);
 
275
  MYSQL_TIME ltime;
272
276
  if (get_date(&ltime, TIME_FUZZY_DATE))
273
277
  {
274
278
    my_decimal_set_zero(decimal_value);
281
285
 
282
286
my_decimal *Item::val_decimal_from_time(my_decimal *decimal_value)
283
287
{
284
 
  assert(fixed == 1);
285
 
  DRIZZLE_TIME ltime;
 
288
  DBUG_ASSERT(fixed == 1);
 
289
  MYSQL_TIME ltime;
286
290
  if (get_time(&ltime))
287
291
  {
288
292
    my_decimal_set_zero(decimal_value);
304
308
}
305
309
 
306
310
 
307
 
int64_t Item::val_int_from_decimal()
 
311
longlong Item::val_int_from_decimal()
308
312
{
309
313
  /* Note that fix_fields may not be called for Item_avg_field items */
310
 
  int64_t result;
 
314
  longlong result;
311
315
  my_decimal value, *dec_val= val_decimal(&value);
312
316
  if (null_value)
313
317
    return 0;
317
321
 
318
322
int Item::save_time_in_field(Field *field)
319
323
{
320
 
  DRIZZLE_TIME ltime;
 
324
  MYSQL_TIME ltime;
321
325
  if (get_time(&ltime))
322
326
    return set_field_to_null(field);
323
327
  field->set_notnull();
324
 
  return field->store_time(&ltime, DRIZZLE_TIMESTAMP_TIME);
 
328
  return field->store_time(&ltime, MYSQL_TIMESTAMP_TIME);
325
329
}
326
330
 
327
331
 
328
332
int Item::save_date_in_field(Field *field)
329
333
{
330
 
  DRIZZLE_TIME ltime;
 
334
  MYSQL_TIME ltime;
331
335
  if (get_date(&ltime, TIME_FUZZY_DATE))
332
336
    return set_field_to_null(field);
333
337
  field->set_notnull();
334
 
  return field->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
 
338
  return field->store_time(&ltime, MYSQL_TIMESTAMP_DATETIME);
335
339
}
336
340
 
337
341
 
372
376
  collation(&my_charset_bin, DERIVATION_COERCIBLE)
373
377
{
374
378
  marker= 0;
375
 
  maybe_null= false;
376
 
  null_value= false;
377
 
  with_sum_func= false;
378
 
  unsigned_flag= false;
379
 
  decimals= 0; 
380
 
  max_length= 0;
 
379
  maybe_null=null_value=with_sum_func=unsigned_flag=0;
 
380
  decimals= 0; max_length= 0;
381
381
  with_subselect= 0;
382
382
  cmp_context= (Item_result)-1;
383
383
 
429
429
}
430
430
 
431
431
 
432
 
uint32_t Item::decimal_precision() const
 
432
uint Item::decimal_precision() const
433
433
{
434
434
  Item_result restype= result_type();
435
435
 
436
436
  if ((restype == DECIMAL_RESULT) || (restype == INT_RESULT))
437
 
    return cmin(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
438
 
               (unsigned int)DECIMAL_MAX_PRECISION);
439
 
  return cmin(max_length, (uint32_t)DECIMAL_MAX_PRECISION);
 
437
    return min(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
 
438
               DECIMAL_MAX_PRECISION);
 
439
  return min(max_length, DECIMAL_MAX_PRECISION);
440
440
}
441
441
 
442
442
 
455
455
 
456
456
void Item::cleanup()
457
457
{
 
458
  DBUG_ENTER("Item::cleanup");
458
459
  fixed=0;
459
460
  marker= 0;
460
461
  if (orig_name)
461
462
    name= orig_name;
462
 
  return;
 
463
  DBUG_VOID_RETURN;
463
464
}
464
465
 
465
466
 
469
470
  @param arg   a dummy parameter, is not used here
470
471
*/
471
472
 
472
 
bool Item::cleanup_processor(unsigned char *arg __attribute__((unused)))
 
473
bool Item::cleanup_processor(uchar *arg)
473
474
{
474
475
  if (fixed)
475
476
    cleanup();
524
525
    pointer to newly allocated item is returned.
525
526
*/
526
527
 
527
 
Item* Item::transform(Item_transformer transformer, unsigned char *arg)
 
528
Item* Item::transform(Item_transformer transformer, uchar *arg)
528
529
{
529
530
  return (this->*transformer)(arg);
530
531
}
565
566
 
566
567
void Item_ident::cleanup()
567
568
{
 
569
  DBUG_ENTER("Item_ident::cleanup");
568
570
#ifdef CANT_BE_USED_AS_MEMORY_IS_FREED
569
571
                       db_name ? db_name : "(null)",
570
572
                       orig_db_name ? orig_db_name : "(null)",
578
580
  table_name= orig_table_name;
579
581
  field_name= orig_field_name;
580
582
  depended_from= 0;
581
 
  return;
 
583
  DBUG_VOID_RETURN;
582
584
}
583
585
 
584
 
bool Item_ident::remove_dependence_processor(unsigned char * arg)
 
586
bool Item_ident::remove_dependence_processor(uchar * arg)
585
587
{
 
588
  DBUG_ENTER("Item_ident::remove_dependence_processor");
586
589
  if (depended_from == (st_select_lex *) arg)
587
590
    depended_from= 0;
588
 
  return(0);
 
591
  DBUG_RETURN(0);
589
592
}
590
593
 
591
594
 
607
610
    for the subsequent items.
608
611
*/
609
612
 
610
 
bool Item_field::collect_item_field_processor(unsigned char *arg)
 
613
bool Item_field::collect_item_field_processor(uchar *arg)
611
614
{
 
615
  DBUG_ENTER("Item_field::collect_item_field_processor");
 
616
  DBUG_PRINT("info", ("%s", field->field_name ? field->field_name : "noname"));
612
617
  List<Item_field> *item_list= (List<Item_field>*) arg;
613
618
  List_iterator<Item_field> item_list_it(*item_list);
614
619
  Item_field *curr_item;
615
620
  while ((curr_item= item_list_it++))
616
621
  {
617
622
    if (curr_item->eq(this, 1))
618
 
      return(false); /* Already in the set. */
 
623
      DBUG_RETURN(false); /* Already in the set. */
619
624
  }
620
625
  item_list->push_back(this);
621
 
  return(false);
 
626
  DBUG_RETURN(false);
622
627
}
623
628
 
624
629
 
638
643
    false otherwise
639
644
*/
640
645
 
641
 
bool Item_field::find_item_in_field_list_processor(unsigned char *arg)
 
646
bool Item_field::find_item_in_field_list_processor(uchar *arg)
642
647
{
643
648
  KEY_PART_INFO *first_non_group_part= *((KEY_PART_INFO **) arg);
644
649
  KEY_PART_INFO *last_part= *(((KEY_PART_INFO **) arg) + 1);
661
666
    column read set or to register used fields in a view
662
667
*/
663
668
 
664
 
bool Item_field::register_field_in_read_map(unsigned char *arg)
 
669
bool Item_field::register_field_in_read_map(uchar *arg)
665
670
{
666
 
  Table *table= (Table *) arg;
 
671
  TABLE *table= (TABLE *) arg;
667
672
  if (field->table == table || !table)
668
673
    bitmap_set_bit(field->table->read_set, field->field_index);
669
 
  if (field->vcol_info && field->vcol_info->expr_item)
670
 
    return field->vcol_info->expr_item->walk(&Item::register_field_in_read_map, 
671
 
                                             1, arg);
672
674
  return 0;
673
675
}
674
676
 
675
 
/*
676
 
  Mark field in bitmap supplied as *arg
677
 
 
678
 
*/
679
 
 
680
 
bool Item_field::register_field_in_bitmap(unsigned char *arg)
681
 
{
682
 
  MY_BITMAP *bitmap= (MY_BITMAP *) arg;
683
 
  assert(bitmap);
684
 
  bitmap_set_bit(bitmap, field->field_index);
685
 
  return false;
686
 
}
687
 
 
688
 
 
689
 
bool Item::check_cols(uint32_t c)
 
677
 
 
678
bool Item::check_cols(uint c)
690
679
{
691
680
  if (c != 1)
692
681
  {
697
686
}
698
687
 
699
688
 
700
 
void Item::set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs)
 
689
void Item::set_name(const char *str, uint length, CHARSET_INFO *cs)
701
690
{
702
691
  if (!length)
703
692
  {
708
697
  }
709
698
  if (cs->ctype)
710
699
  {
711
 
    uint32_t orig_len= length;
 
700
    uint orig_len= length;
712
701
    /*
713
702
      This will probably need a better implementation in the future:
714
703
      a function in CHARSET_INFO structure.
721
710
    if (orig_len != length && !is_autogenerated_name)
722
711
    {
723
712
      if (length == 0)
724
 
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
713
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
725
714
                            ER_NAME_BECOMES_EMPTY, ER(ER_NAME_BECOMES_EMPTY),
726
715
                            str + length - orig_len);
727
716
      else
728
 
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
717
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
729
718
                            ER_REMOVED_SPACES, ER(ER_REMOVED_SPACES),
730
719
                            str + length - orig_len);
731
720
    }
738
727
                                   &res_length);
739
728
  }
740
729
  else
741
 
    name= sql_strmake(str, (name_length= cmin(length,(unsigned int)MAX_ALIAS_NAME)));
 
730
    name= sql_strmake(str, (name_length= min(length,MAX_ALIAS_NAME)));
742
731
}
743
732
 
744
733
 
746
735
  @details
747
736
  This function is called when:
748
737
  - Comparing items in the WHERE clause (when doing where optimization)
749
 
  - When trying to find an order_st BY/GROUP BY item in the SELECT part
 
738
  - When trying to find an ORDER BY/GROUP BY item in the SELECT part
750
739
*/
751
740
 
752
 
bool Item::eq(const Item *item, bool binary_cmp __attribute__((unused))) const
 
741
bool Item::eq(const Item *item, bool binary_cmp) const
753
742
{
754
743
  /*
755
744
    Note, that this is never true if item is a Item_param:
761
750
}
762
751
 
763
752
 
764
 
Item *Item::safe_charset_converter(const CHARSET_INFO * const tocs)
 
753
Item *Item::safe_charset_converter(CHARSET_INFO *tocs)
765
754
{
766
755
  Item_func_conv_charset *conv= new Item_func_conv_charset(this, tocs, 1);
767
756
  return conv->safe ? conv : NULL;
779
768
  the latter returns a non-fixed Item, so val_str() crashes afterwards.
780
769
  Override Item_num method, to return a fixed item.
781
770
*/
782
 
Item *Item_num::safe_charset_converter(const CHARSET_INFO * const tocs __attribute__((unused)))
 
771
Item *Item_num::safe_charset_converter(CHARSET_INFO *tocs)
783
772
{
784
773
  Item_string *conv;
785
774
  char buf[64];
794
783
}
795
784
 
796
785
 
797
 
Item *Item_static_float_func::safe_charset_converter(const CHARSET_INFO * const tocs __attribute__((unused)))
 
786
Item *Item_static_float_func::safe_charset_converter(CHARSET_INFO *tocs)
798
787
{
799
788
  Item_string *conv;
800
789
  char buf[64];
810
799
}
811
800
 
812
801
 
813
 
Item *Item_string::safe_charset_converter(const CHARSET_INFO * const tocs)
 
802
Item *Item_string::safe_charset_converter(CHARSET_INFO *tocs)
814
803
{
815
804
  Item_string *conv;
816
 
  uint32_t conv_errors;
 
805
  uint conv_errors;
817
806
  char *ptr;
818
807
  String tmp, cstr, *ostr= val_str(&tmp);
819
808
  cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
838
827
}
839
828
 
840
829
 
841
 
Item *Item_param::safe_charset_converter(const CHARSET_INFO * const tocs)
 
830
Item *Item_param::safe_charset_converter(CHARSET_INFO *tocs)
842
831
{
843
832
  if (const_item())
844
833
  {
845
 
    uint32_t cnv_errors;
 
834
    uint cnv_errors;
846
835
    String *ostr= val_str(&cnvstr);
847
836
    cnvitem->str_value.copy(ostr->ptr(), ostr->length(),
848
837
                            ostr->charset(), tocs, &cnv_errors);
856
845
}
857
846
 
858
847
 
859
 
Item *Item_static_string_func::safe_charset_converter(const CHARSET_INFO * const tocs)
 
848
Item *Item_static_string_func::safe_charset_converter(CHARSET_INFO *tocs)
860
849
{
861
850
  Item_string *conv;
862
 
  uint32_t conv_errors;
 
851
  uint conv_errors;
863
852
  String tmp, cstr, *ostr= val_str(&tmp);
864
853
  cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
865
854
  if (conv_errors ||
897
886
 
898
887
 
899
888
/**
900
 
  Get the value of the function as a DRIZZLE_TIME structure.
 
889
  Get the value of the function as a MYSQL_TIME structure.
901
890
  As a extra convenience the time structure is reset on error!
902
891
*/
903
892
 
904
 
bool Item::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
893
bool Item::get_date(MYSQL_TIME *ltime,uint fuzzydate)
905
894
{
906
895
  if (result_type() == STRING_RESULT)
907
896
  {
909
898
    String tmp(buff,sizeof(buff), &my_charset_bin),*res;
910
899
    if (!(res=val_str(&tmp)) ||
911
900
        str_to_datetime_with_warn(res->ptr(), res->length(),
912
 
                                  ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
 
901
                                  ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR)
913
902
      goto err;
914
903
  }
915
904
  else
916
905
  {
917
 
    int64_t value= val_int();
 
906
    longlong value= val_int();
918
907
    int was_cut;
919
 
    if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1L)
 
908
    if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1LL)
920
909
    {
921
910
      char buff[22], *end;
922
 
      end= int64_t10_to_str(value, buff, -10);
923
 
      make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
924
 
                                   buff, (int) (end-buff), DRIZZLE_TIMESTAMP_NONE,
925
 
                                   NULL);
 
911
      end= longlong10_to_str(value, buff, -10);
 
912
      make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
913
                                   buff, (int) (end-buff), MYSQL_TIMESTAMP_NONE,
 
914
                                   NullS);
926
915
      goto err;
927
916
    }
928
917
  }
929
918
  return 0;
930
919
 
931
920
err:
932
 
  memset(ltime, 0, sizeof(*ltime));
 
921
  bzero((char*) ltime,sizeof(*ltime));
933
922
  return 1;
934
923
}
935
924
 
939
928
  As a extra convenience the time structure is reset on error!
940
929
*/
941
930
 
942
 
bool Item::get_time(DRIZZLE_TIME *ltime)
 
931
bool Item::get_time(MYSQL_TIME *ltime)
943
932
{
944
933
  char buff[40];
945
934
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
946
935
  if (!(res=val_str(&tmp)) ||
947
936
      str_to_time_with_warn(res->ptr(), res->length(), ltime))
948
937
  {
949
 
    memset(ltime, 0, sizeof(*ltime));
 
938
    bzero((char*) ltime,sizeof(*ltime));
950
939
    return 1;
951
940
  }
952
941
  return 0;
953
942
}
954
943
 
955
 
const CHARSET_INFO *Item::default_charset()
 
944
CHARSET_INFO *Item::default_charset()
956
945
{
957
946
  return current_thd->variables.collation_connection;
958
947
}
969
958
int Item::save_in_field_no_warnings(Field *field, bool no_conversions)
970
959
{
971
960
  int res;
972
 
  Table *table= field->table;
 
961
  TABLE *table= field->table;
973
962
  THD *thd= table->in_use;
974
963
  enum_check_fields tmp= thd->count_cuted_fields;
 
964
  my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
975
965
  ulong sql_mode= thd->variables.sql_mode;
976
 
  thd->variables.sql_mode&= ~(MODE_NO_ZERO_DATE);
 
966
  thd->variables.sql_mode&= ~(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE);
977
967
  thd->count_cuted_fields= CHECK_FIELD_IGNORE;
978
968
  res= save_in_field(field, no_conversions);
979
969
  thd->count_cuted_fields= tmp;
 
970
  dbug_tmp_restore_column_map(table->write_set, old_map);
980
971
  thd->variables.sql_mode= sql_mode;
981
972
  return res;
982
973
}
1055
1046
      Item_ref to allow fields from view being stored in tmp table.
1056
1047
    */
1057
1048
    Item_aggregate_ref *item_ref;
1058
 
    uint32_t el= fields.elements;
 
1049
    uint el= fields.elements;
1059
1050
    Item *real_itm= real_item();
1060
1051
 
1061
1052
    ref_pointer_array[el]= real_itm;
1125
1116
  @endcode
1126
1117
*/
1127
1118
 
1128
 
bool DTCollation::aggregate(DTCollation &dt, uint32_t flags)
 
1119
bool DTCollation::aggregate(DTCollation &dt, uint flags)
1129
1120
{
1130
1121
  if (!my_charset_same(collation, dt.collation))
1131
1122
  {
1212
1203
        set(dt);
1213
1204
        return 0;
1214
1205
      }
1215
 
      const CHARSET_INFO * const bin= get_charset_by_csname(collation->csname, 
1216
 
                                                            MY_CS_BINSORT,MYF(0));
 
1206
      CHARSET_INFO *bin= get_charset_by_csname(collation->csname, 
 
1207
                                               MY_CS_BINSORT,MYF(0));
1217
1208
      set(bin, DERIVATION_NONE);
1218
1209
    }
1219
1210
  }
1245
1236
 
1246
1237
 
1247
1238
static
1248
 
void my_coll_agg_error(Item** args, uint32_t count, const char *fname,
 
1239
void my_coll_agg_error(Item** args, uint count, const char *fname,
1249
1240
                       int item_sep)
1250
1241
{
1251
1242
  if (count == 2)
1259
1250
 
1260
1251
 
1261
1252
bool agg_item_collations(DTCollation &c, const char *fname,
1262
 
                         Item **av, uint32_t count, uint32_t flags, int item_sep)
 
1253
                         Item **av, uint count, uint flags, int item_sep)
1263
1254
{
1264
 
  uint32_t i;
 
1255
  uint i;
1265
1256
  Item **arg;
1266
1257
  c.set(av[0]->collation);
1267
1258
  for (i= 1, arg= &av[item_sep]; i < count; i++, arg++)
1283
1274
 
1284
1275
 
1285
1276
bool agg_item_collations_for_comparison(DTCollation &c, const char *fname,
1286
 
                                        Item **av, uint32_t count, uint32_t flags)
 
1277
                                        Item **av, uint count, uint flags)
1287
1278
{
1288
1279
  return (agg_item_collations(c, fname, av, count,
1289
1280
                              flags | MY_COLL_DISALLOW_NONE, 1));
1322
1313
*/
1323
1314
 
1324
1315
bool agg_item_charsets(DTCollation &coll, const char *fname,
1325
 
                       Item **args, uint32_t nargs, uint32_t flags, int item_sep)
 
1316
                       Item **args, uint nargs, uint flags, int item_sep)
1326
1317
{
1327
1318
  Item **arg, *safe_args[2];
1328
1319
 
1345
1336
  }
1346
1337
 
1347
1338
  THD *thd= current_thd;
 
1339
  Query_arena *arena, backup;
1348
1340
  bool res= false;
1349
 
  uint32_t i;
 
1341
  uint i;
 
1342
  /*
 
1343
    In case we're in statement prepare, create conversion item
 
1344
    in its memory: it will be reused on each execute.
 
1345
  */
 
1346
  arena= NULL;
1350
1347
 
1351
1348
  for (i= 0, arg= args; i < nargs; i++, arg+= item_sep)
1352
1349
  {
1353
1350
    Item* conv;
1354
 
    uint32_t dummy_offset;
 
1351
    uint32 dummy_offset;
1355
1352
    if (!String::needs_conversion(0, (*arg)->collation.collation,
1356
1353
                                  coll.collation,
1357
1354
                                  &dummy_offset))
1392
1389
    */
1393
1390
    conv->fix_fields(thd, arg);
1394
1391
  }
1395
 
 
 
1392
  if (arena)
 
1393
    thd->restore_active_arena(arena, &backup);
1396
1394
  return res;
1397
1395
}
1398
1396
 
1413
1411
/**********************************************/
1414
1412
 
1415
1413
Item_field::Item_field(Field *f)
1416
 
  :Item_ident(0, NULL, *f->table_name, f->field_name),
 
1414
  :Item_ident(0, NullS, *f->table_name, f->field_name),
1417
1415
   item_equal(0), no_const_subst(0),
1418
1416
   have_privileges(0), any_privileges(0)
1419
1417
{
1433
1431
  Item_field (this is important in prepared statements).
1434
1432
*/
1435
1433
 
1436
 
Item_field::Item_field(THD *thd __attribute__((unused)),
1437
 
                       Name_resolution_context *context_arg,
 
1434
Item_field::Item_field(THD *thd, Name_resolution_context *context_arg,
1438
1435
                       Field *f)
1439
1436
  :Item_ident(context_arg, f->table->s->db.str, *f->table_name, f->field_name),
1440
1437
   item_equal(0), no_const_subst(0),
1513
1510
  {
1514
1511
    tmp=(char*) sql_alloc((uint) strlen(db_name)+(uint) strlen(table_name)+
1515
1512
                          (uint) strlen(field_name)+3);
1516
 
    strxmov(tmp,db_name,".",table_name,".",field_name,NULL);
 
1513
    strxmov(tmp,db_name,".",table_name,".",field_name,NullS);
1517
1514
  }
1518
1515
  else
1519
1516
  {
1521
1518
    {
1522
1519
      tmp= (char*) sql_alloc((uint) strlen(table_name) +
1523
1520
                             (uint) strlen(field_name) + 2);
1524
 
      strxmov(tmp, table_name, ".", field_name, NULL);
 
1521
      strxmov(tmp, table_name, ".", field_name, NullS);
1525
1522
    }
1526
1523
    else
1527
1524
      tmp= (char*) field_name;
1529
1526
  return tmp;
1530
1527
}
1531
1528
 
1532
 
void Item_ident::print(String *str,
1533
 
                       enum_query_type query_type __attribute__((unused)))
 
1529
void Item_ident::print(String *str, enum_query_type query_type)
1534
1530
{
1535
1531
  THD *thd= current_thd;
1536
1532
  char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
1540
1536
  {
1541
1537
    if (table_name && table_name[0])
1542
1538
    {
1543
 
      my_stpcpy(t_name_buff, table_name);
 
1539
      strmov(t_name_buff, table_name);
1544
1540
      my_casedn_str(files_charset_info, t_name_buff);
1545
1541
      t_name= t_name_buff;
1546
1542
    }
1547
1543
    if (db_name && db_name[0])
1548
1544
    {
1549
 
      my_stpcpy(d_name_buff, db_name);
 
1545
      strmov(d_name_buff, db_name);
1550
1546
      my_casedn_str(files_charset_info, d_name_buff);
1551
1547
      d_name= d_name_buff;
1552
1548
    }
1585
1581
/* ARGSUSED */
1586
1582
String *Item_field::val_str(String *str)
1587
1583
{
1588
 
  assert(fixed == 1);
 
1584
  DBUG_ASSERT(fixed == 1);
1589
1585
  if ((null_value=field->is_null()))
1590
1586
    return 0;
1591
1587
  str->set_charset(str_value.charset());
1595
1591
 
1596
1592
double Item_field::val_real()
1597
1593
{
1598
 
  assert(fixed == 1);
 
1594
  DBUG_ASSERT(fixed == 1);
1599
1595
  if ((null_value=field->is_null()))
1600
1596
    return 0.0;
1601
1597
  return field->val_real();
1602
1598
}
1603
1599
 
1604
1600
 
1605
 
int64_t Item_field::val_int()
 
1601
longlong Item_field::val_int()
1606
1602
{
1607
 
  assert(fixed == 1);
 
1603
  DBUG_ASSERT(fixed == 1);
1608
1604
  if ((null_value=field->is_null()))
1609
1605
    return 0;
1610
1606
  return field->val_int();
1627
1623
  return result_field->val_str(str,&str_value);
1628
1624
}
1629
1625
 
1630
 
bool Item_field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
1626
bool Item_field::get_date(MYSQL_TIME *ltime,uint fuzzydate)
1631
1627
{
1632
1628
  if ((null_value=field->is_null()) || field->get_date(ltime,fuzzydate))
1633
1629
  {
1634
 
    memset(ltime, 0, sizeof(*ltime));
 
1630
    bzero((char*) ltime,sizeof(*ltime));
1635
1631
    return 1;
1636
1632
  }
1637
1633
  return 0;
1638
1634
}
1639
1635
 
1640
 
bool Item_field::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
1636
bool Item_field::get_date_result(MYSQL_TIME *ltime,uint fuzzydate)
1641
1637
{
1642
1638
  if ((null_value=result_field->is_null()) ||
1643
1639
      result_field->get_date(ltime,fuzzydate))
1644
1640
  {
1645
 
    memset(ltime, 0, sizeof(*ltime));
 
1641
    bzero((char*) ltime,sizeof(*ltime));
1646
1642
    return 1;
1647
1643
  }
1648
1644
  return 0;
1649
1645
}
1650
1646
 
1651
 
bool Item_field::get_time(DRIZZLE_TIME *ltime)
 
1647
bool Item_field::get_time(MYSQL_TIME *ltime)
1652
1648
{
1653
1649
  if ((null_value=field->is_null()) || field->get_time(ltime))
1654
1650
  {
1655
 
    memset(ltime, 0, sizeof(*ltime));
 
1651
    bzero((char*) ltime,sizeof(*ltime));
1656
1652
    return 1;
1657
1653
  }
1658
1654
  return 0;
1665
1661
  return result_field->val_real();
1666
1662
}
1667
1663
 
1668
 
int64_t Item_field::val_int_result()
 
1664
longlong Item_field::val_int_result()
1669
1665
{
1670
1666
  if ((null_value=result_field->is_null()))
1671
1667
    return 0;
1701
1697
    return result_field->val_real() != 0.0;
1702
1698
  case ROW_RESULT:
1703
1699
  default:
1704
 
    assert(0);
 
1700
    DBUG_ASSERT(0);
1705
1701
    return 0;                                   // Shut up compiler
1706
1702
  }
1707
1703
}
1708
1704
 
1709
1705
 
1710
 
bool Item_field::eq(const Item *item,
1711
 
                    bool binary_cmp __attribute__((unused))) const
 
1706
bool Item_field::eq(const Item *item, bool binary_cmp) const
1712
1707
{
1713
1708
  Item *real_item= ((Item *) item)->real_item();
1714
1709
  if (real_item->type() != FIELD_ITEM)
1715
1710
    return 0;
1716
 
 
 
1711
  
1717
1712
  Item_field *item_field= (Item_field*) real_item;
1718
1713
  if (item_field->field && field)
1719
1714
    return item_field->field == field;
1746
1741
}
1747
1742
 
1748
1743
 
1749
 
void Item_field::fix_after_pullout(st_select_lex *new_parent,
1750
 
                                   Item **ref __attribute__((unused)))
 
1744
void Item_field::fix_after_pullout(st_select_lex *new_parent, Item **ref)
1751
1745
{
1752
1746
  if (new_parent == depended_from)
1753
1747
    depended_from= NULL;
1768
1762
  return new_item;
1769
1763
}
1770
1764
 
1771
 
int64_t Item_field::val_int_endpoint(bool left_endp __attribute__((unused)),
1772
 
                                      bool *incl_endp __attribute__((unused)))
 
1765
longlong Item_field::val_int_endpoint(bool left_endp, bool *incl_endp)
1773
1766
{
1774
 
  int64_t res= val_int();
1775
 
  return null_value? INT64_MIN : res;
 
1767
  longlong res= val_int();
 
1768
  return null_value? LONGLONG_MIN : res;
1776
1769
}
1777
1770
 
1778
1771
/**
1779
 
  Create an item from a string we KNOW points to a valid int64_t
 
1772
  Create an item from a string we KNOW points to a valid longlong
1780
1773
  end \\0 terminated number string.
1781
1774
  This is always 'signed'. Unsigned values are created with Item_uint()
1782
1775
*/
1783
1776
 
1784
 
Item_int::Item_int(const char *str_arg, uint32_t length)
 
1777
Item_int::Item_int(const char *str_arg, uint length)
1785
1778
{
1786
1779
  char *end_ptr= (char*) str_arg + length;
1787
1780
  int error;
1801
1794
String *Item_int::val_str(String *str)
1802
1795
{
1803
1796
  // following assert is redundant, because fixed=1 assigned in constructor
1804
 
  assert(fixed == 1);
 
1797
  DBUG_ASSERT(fixed == 1);
1805
1798
  str->set(value, &my_charset_bin);
1806
1799
  return str;
1807
1800
}
1808
1801
 
1809
 
void Item_int::print(String *str,
1810
 
                     enum_query_type query_type __attribute__((unused)))
 
1802
void Item_int::print(String *str, enum_query_type query_type)
1811
1803
{
1812
1804
  // my_charset_bin is good enough for numbers
1813
1805
  str_value.set(value, &my_charset_bin);
1815
1807
}
1816
1808
 
1817
1809
 
1818
 
Item_uint::Item_uint(const char *str_arg, uint32_t length):
 
1810
Item_uint::Item_uint(const char *str_arg, uint length):
1819
1811
  Item_int(str_arg, length)
1820
1812
{
1821
1813
  unsigned_flag= 1;
1822
1814
}
1823
1815
 
1824
1816
 
1825
 
Item_uint::Item_uint(const char *str_arg, int64_t i, uint32_t length):
 
1817
Item_uint::Item_uint(const char *str_arg, longlong i, uint length):
1826
1818
  Item_int(str_arg, i, length)
1827
1819
{
1828
1820
  unsigned_flag= 1;
1832
1824
String *Item_uint::val_str(String *str)
1833
1825
{
1834
1826
  // following assert is redundant, because fixed=1 assigned in constructor
1835
 
  assert(fixed == 1);
1836
 
  str->set((uint64_t) value, &my_charset_bin);
 
1827
  DBUG_ASSERT(fixed == 1);
 
1828
  str->set((ulonglong) value, &my_charset_bin);
1837
1829
  return str;
1838
1830
}
1839
1831
 
1840
1832
 
1841
 
void Item_uint::print(String *str,
1842
 
                      enum_query_type query_type __attribute__((unused)))
 
1833
void Item_uint::print(String *str, enum_query_type query_type)
1843
1834
{
1844
1835
  // latin1 is good enough for numbers
1845
 
  str_value.set((uint64_t) value, default_charset());
 
1836
  str_value.set((ulonglong) value, default_charset());
1846
1837
  str->append(str_value);
1847
1838
}
1848
1839
 
1849
1840
 
1850
 
Item_decimal::Item_decimal(const char *str_arg, uint32_t length,
1851
 
                           const CHARSET_INFO * const charset)
 
1841
Item_decimal::Item_decimal(const char *str_arg, uint length,
 
1842
                           CHARSET_INFO *charset)
1852
1843
{
1853
1844
  str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
1854
1845
  name= (char*) str_arg;
1855
 
  decimals= (uint8_t) decimal_value.frac;
 
1846
  decimals= (uint8) decimal_value.frac;
1856
1847
  fixed= 1;
1857
1848
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1858
1849
                                             decimals, unsigned_flag);
1859
1850
}
1860
1851
 
1861
 
Item_decimal::Item_decimal(int64_t val, bool unsig)
 
1852
Item_decimal::Item_decimal(longlong val, bool unsig)
1862
1853
{
1863
1854
  int2my_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
1864
 
  decimals= (uint8_t) decimal_value.frac;
 
1855
  decimals= (uint8) decimal_value.frac;
1865
1856
  fixed= 1;
1866
1857
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1867
1858
                                             decimals, unsigned_flag);
1868
1859
}
1869
1860
 
1870
1861
 
1871
 
Item_decimal::Item_decimal(double val,
1872
 
                           int precision __attribute__((unused)),
1873
 
                           int scale __attribute__((unused)))
 
1862
Item_decimal::Item_decimal(double val, int precision, int scale)
1874
1863
{
1875
1864
  double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
1876
 
  decimals= (uint8_t) decimal_value.frac;
 
1865
  decimals= (uint8) decimal_value.frac;
1877
1866
  fixed= 1;
1878
1867
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1879
1868
                                             decimals, unsigned_flag);
1881
1870
 
1882
1871
 
1883
1872
Item_decimal::Item_decimal(const char *str, const my_decimal *val_arg,
1884
 
                           uint32_t decimal_par, uint32_t length)
 
1873
                           uint decimal_par, uint length)
1885
1874
{
1886
1875
  my_decimal2decimal(val_arg, &decimal_value);
1887
1876
  name= (char*) str;
1888
 
  decimals= (uint8_t) decimal_par;
 
1877
  decimals= (uint8) decimal_par;
1889
1878
  max_length= length;
1890
1879
  fixed= 1;
1891
1880
}
1894
1883
Item_decimal::Item_decimal(my_decimal *value_par)
1895
1884
{
1896
1885
  my_decimal2decimal(value_par, &decimal_value);
1897
 
  decimals= (uint8_t) decimal_value.frac;
 
1886
  decimals= (uint8) decimal_value.frac;
1898
1887
  fixed= 1;
1899
1888
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1900
1889
                                             decimals, unsigned_flag);
1901
1890
}
1902
1891
 
1903
1892
 
1904
 
Item_decimal::Item_decimal(const unsigned char *bin, int precision, int scale)
 
1893
Item_decimal::Item_decimal(const uchar *bin, int precision, int scale)
1905
1894
{
1906
1895
  binary2my_decimal(E_DEC_FATAL_ERROR, bin,
1907
1896
                    &decimal_value, precision, scale);
1908
 
  decimals= (uint8_t) decimal_value.frac;
 
1897
  decimals= (uint8) decimal_value.frac;
1909
1898
  fixed= 1;
1910
1899
  max_length= my_decimal_precision_to_length(precision, decimals,
1911
1900
                                             unsigned_flag);
1912
1901
}
1913
1902
 
1914
1903
 
1915
 
int64_t Item_decimal::val_int()
 
1904
longlong Item_decimal::val_int()
1916
1905
{
1917
 
  int64_t result;
 
1906
  longlong result;
1918
1907
  my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &result);
1919
1908
  return result;
1920
1909
}
1933
1922
  return result;
1934
1923
}
1935
1924
 
1936
 
void Item_decimal::print(String *str,
1937
 
                         enum_query_type query_type __attribute__((unused)))
 
1925
void Item_decimal::print(String *str, enum_query_type query_type)
1938
1926
{
1939
1927
  my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, &str_value);
1940
1928
  str->append(str_value);
1941
1929
}
1942
1930
 
1943
1931
 
1944
 
bool Item_decimal::eq(const Item *item,
1945
 
                      bool binary_cmp __attribute__((unused))) const
 
1932
bool Item_decimal::eq(const Item *item, bool binary_cmp) const
1946
1933
{
1947
1934
  if (type() == item->type() && item->basic_const_item())
1948
1935
  {
1963
1950
void Item_decimal::set_decimal_value(my_decimal *value_par)
1964
1951
{
1965
1952
  my_decimal2decimal(value_par, &decimal_value);
1966
 
  decimals= (uint8_t) decimal_value.frac;
 
1953
  decimals= (uint8) decimal_value.frac;
1967
1954
  unsigned_flag= !decimal_value.sign();
1968
1955
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1969
1956
                                             decimals, unsigned_flag);
1973
1960
String *Item_float::val_str(String *str)
1974
1961
{
1975
1962
  // following assert is redundant, because fixed=1 assigned in constructor
1976
 
  assert(fixed == 1);
 
1963
  DBUG_ASSERT(fixed == 1);
1977
1964
  str->set_real(value,decimals,&my_charset_bin);
1978
1965
  return str;
1979
1966
}
1982
1969
my_decimal *Item_float::val_decimal(my_decimal *decimal_value)
1983
1970
{
1984
1971
  // following assert is redundant, because fixed=1 assigned in constructor
1985
 
  assert(fixed == 1);
 
1972
  DBUG_ASSERT(fixed == 1);
1986
1973
  double2my_decimal(E_DEC_FATAL_ERROR, value, decimal_value);
1987
1974
  return (decimal_value);
1988
1975
}
2027
2014
 
2028
2015
double Item_string::val_real()
2029
2016
{
2030
 
  assert(fixed == 1);
 
2017
  DBUG_ASSERT(fixed == 1);
2031
2018
  int error;
2032
2019
  char *end, *org_end;
2033
2020
  double tmp;
2034
 
  const CHARSET_INFO * const cs= str_value.charset();
 
2021
  CHARSET_INFO *cs= str_value.charset();
2035
2022
 
2036
2023
  org_end= (char*) str_value.ptr() + str_value.length();
2037
2024
  tmp= my_strntod(cs, (char*) str_value.ptr(), str_value.length(), &end,
2042
2029
      We can use str_value.ptr() here as Item_string is gurantee to put an
2043
2030
      end \0 here.
2044
2031
    */
2045
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2032
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2046
2033
                        ER_TRUNCATED_WRONG_VALUE,
2047
2034
                        ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE",
2048
2035
                        str_value.ptr());
2055
2042
  @todo
2056
2043
  Give error if we wanted a signed integer and we got an unsigned one
2057
2044
*/
2058
 
int64_t Item_string::val_int()
 
2045
longlong Item_string::val_int()
2059
2046
{
2060
 
  assert(fixed == 1);
 
2047
  DBUG_ASSERT(fixed == 1);
2061
2048
  int err;
2062
 
  int64_t tmp;
 
2049
  longlong tmp;
2063
2050
  char *end= (char*) str_value.ptr()+ str_value.length();
2064
2051
  char *org_end= end;
2065
 
  const CHARSET_INFO * const cs= str_value.charset();
 
2052
  CHARSET_INFO *cs= str_value.charset();
2066
2053
 
2067
2054
  tmp= (*(cs->cset->strtoll10))(cs, str_value.ptr(), &end, &err);
2068
2055
  /*
2072
2059
  if (err > 0 ||
2073
2060
      (end != org_end && !check_if_only_end_space(cs, end, org_end)))
2074
2061
  {
2075
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2062
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2076
2063
                        ER_TRUNCATED_WRONG_VALUE,
2077
2064
                        ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
2078
2065
                        str_value.ptr());
2087
2074
}
2088
2075
 
2089
2076
 
2090
 
bool Item_null::eq(const Item *item,
2091
 
                   bool binary_cmp __attribute__((unused))) const
 
2077
bool Item_null::eq(const Item *item, bool binary_cmp) const
2092
2078
{ return item->type() == type(); }
2093
2079
 
2094
2080
 
2095
2081
double Item_null::val_real()
2096
2082
{
2097
2083
  // following assert is redundant, because fixed=1 assigned in constructor
2098
 
  assert(fixed == 1);
 
2084
  DBUG_ASSERT(fixed == 1);
2099
2085
  null_value=1;
2100
2086
  return 0.0;
2101
2087
}
2102
 
int64_t Item_null::val_int()
 
2088
longlong Item_null::val_int()
2103
2089
{
2104
2090
  // following assert is redundant, because fixed=1 assigned in constructor
2105
 
  assert(fixed == 1);
 
2091
  DBUG_ASSERT(fixed == 1);
2106
2092
  null_value=1;
2107
2093
  return 0;
2108
2094
}
2109
2095
/* ARGSUSED */
2110
 
String *Item_null::val_str(String *str __attribute__((unused)))
 
2096
String *Item_null::val_str(String *str)
2111
2097
{
2112
2098
  // following assert is redundant, because fixed=1 assigned in constructor
2113
 
  assert(fixed == 1);
 
2099
  DBUG_ASSERT(fixed == 1);
2114
2100
  null_value=1;
2115
2101
  return 0;
2116
2102
}
2117
2103
 
2118
 
my_decimal *Item_null::val_decimal(my_decimal *decimal_value __attribute__((unused)))
 
2104
my_decimal *Item_null::val_decimal(my_decimal *decimal_value)
2119
2105
{
2120
2106
  return 0;
2121
2107
}
2122
2108
 
2123
2109
 
2124
 
Item *Item_null::safe_charset_converter(const CHARSET_INFO * const tocs)
 
2110
Item *Item_null::safe_charset_converter(CHARSET_INFO *tocs)
2125
2111
{
2126
2112
  collation.set(tocs);
2127
2113
  return this;
2136
2122
 
2137
2123
static void
2138
2124
default_set_param_func(Item_param *param,
2139
 
                       unsigned char **pos __attribute__((unused)),
 
2125
                       uchar **pos __attribute__((unused)),
2140
2126
                       ulong len __attribute__((unused)))
2141
2127
{
2142
2128
  param->set_null();
2143
2129
}
2144
2130
 
2145
2131
 
2146
 
Item_param::Item_param(uint32_t pos_in_query_arg) :
 
2132
Item_param::Item_param(uint pos_in_query_arg) :
2147
2133
  state(NO_VALUE),
2148
2134
  item_result_type(STRING_RESULT),
2149
2135
  /* Don't pretend to be a literal unless value for this item is set. */
2150
2136
  item_type(PARAM_ITEM),
2151
 
  param_type(DRIZZLE_TYPE_VARCHAR),
 
2137
  param_type(MYSQL_TYPE_VARCHAR),
2152
2138
  pos_in_query(pos_in_query_arg),
2153
2139
  set_param_func(default_set_param_func),
2154
2140
  limit_clause_param(false)
2167
2153
 
2168
2154
void Item_param::set_null()
2169
2155
{
 
2156
  DBUG_ENTER("Item_param::set_null");
2170
2157
  /* These are cleared after each execution by reset() method */
2171
2158
  null_value= 1;
2172
2159
  /* 
2178
2165
  decimals= 0;
2179
2166
  state= NULL_VALUE;
2180
2167
  item_type= Item::NULL_ITEM;
2181
 
  return;
 
2168
  DBUG_VOID_RETURN;
2182
2169
}
2183
2170
 
2184
 
void Item_param::set_int(int64_t i, uint32_t max_length_arg)
 
2171
void Item_param::set_int(longlong i, uint32 max_length_arg)
2185
2172
{
2186
 
  value.integer= (int64_t) i;
 
2173
  DBUG_ENTER("Item_param::set_int");
 
2174
  value.integer= (longlong) i;
2187
2175
  state= INT_VALUE;
2188
2176
  max_length= max_length_arg;
2189
2177
  decimals= 0;
2190
2178
  maybe_null= 0;
2191
 
  return;
 
2179
  DBUG_VOID_RETURN;
2192
2180
}
2193
2181
 
2194
2182
void Item_param::set_double(double d)
2195
2183
{
 
2184
  DBUG_ENTER("Item_param::set_double");
2196
2185
  value.real= d;
2197
2186
  state= REAL_VALUE;
2198
2187
  max_length= DBL_DIG + 8;
2199
2188
  decimals= NOT_FIXED_DEC;
2200
2189
  maybe_null= 0;
2201
 
  return;
 
2190
  DBUG_VOID_RETURN;
2202
2191
}
2203
2192
 
2204
2193
 
2214
2203
    internal decimal value.
2215
2204
*/
2216
2205
 
2217
 
void Item_param::set_decimal(char *str, ulong length)
 
2206
void Item_param::set_decimal(const char *str, ulong length)
2218
2207
{
2219
2208
  char *end;
 
2209
  DBUG_ENTER("Item_param::set_decimal");
2220
2210
 
2221
 
  end= str+length;
2222
 
  str2my_decimal((uint)E_DEC_FATAL_ERROR, str, &decimal_value, &end);
 
2211
  end= (char*) str+length;
 
2212
  str2my_decimal(E_DEC_FATAL_ERROR, str, &decimal_value, &end);
2223
2213
  state= DECIMAL_VALUE;
2224
2214
  decimals= decimal_value.frac;
2225
2215
  max_length= my_decimal_precision_to_length(decimal_value.precision(),
2226
2216
                                             decimals, unsigned_flag);
2227
2217
  maybe_null= 0;
2228
 
  return;
 
2218
  DBUG_VOID_RETURN;
2229
2219
}
2230
2220
 
2231
2221
 
2232
2222
/**
2233
 
  Set parameter value from DRIZZLE_TIME value.
 
2223
  Set parameter value from MYSQL_TIME value.
2234
2224
 
2235
2225
  @param tm              datetime value to set (time_type is ignored)
2236
2226
  @param type            type of datetime value
2242
2232
    the fact that even wrong value sent over binary protocol fits into
2243
2233
    MAX_DATE_STRING_REP_LENGTH buffer.
2244
2234
*/
2245
 
void Item_param::set_time(DRIZZLE_TIME *tm,
2246
 
                          enum enum_drizzle_timestamp_type time_type,
2247
 
                          uint32_t max_length_arg)
 
2235
void Item_param::set_time(MYSQL_TIME *tm, timestamp_type time_type,
 
2236
                          uint32 max_length_arg)
2248
2237
 
2238
  DBUG_ENTER("Item_param::set_time");
 
2239
 
2249
2240
  value.time= *tm;
2250
2241
  value.time.time_type= time_type;
2251
2242
 
2252
2243
  if (value.time.year > 9999 || value.time.month > 12 ||
2253
2244
      value.time.day > 31 ||
2254
 
      ((time_type != DRIZZLE_TIMESTAMP_TIME) && value.time.hour > 23) ||
 
2245
      ((time_type != MYSQL_TIMESTAMP_TIME) && value.time.hour > 23) ||
2255
2246
      value.time.minute > 59 || value.time.second > 59)
2256
2247
  {
2257
2248
    char buff[MAX_DATE_STRING_REP_LENGTH];
2258
 
    uint32_t length= my_TIME_to_str(&value.time, buff);
2259
 
    make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2249
    uint length= my_TIME_to_str(&value.time, buff);
 
2250
    make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2260
2251
                                 buff, length, time_type, 0);
2261
 
    set_zero_time(&value.time, DRIZZLE_TIMESTAMP_ERROR);
 
2252
    set_zero_time(&value.time, MYSQL_TIMESTAMP_ERROR);
2262
2253
  }
2263
2254
 
2264
2255
  state= TIME_VALUE;
2265
2256
  maybe_null= 0;
2266
2257
  max_length= max_length_arg;
2267
2258
  decimals= 0;
2268
 
  return;
 
2259
  DBUG_VOID_RETURN;
2269
2260
}
2270
2261
 
2271
2262
 
2272
2263
bool Item_param::set_str(const char *str, ulong length)
2273
2264
{
 
2265
  DBUG_ENTER("Item_param::set_str");
2274
2266
  /*
2275
2267
    Assign string with no conversion: data is converted only after it's
2276
2268
    been written to the binary log.
2277
2269
  */
2278
 
  uint32_t dummy_errors;
 
2270
  uint dummy_errors;
2279
2271
  if (str_value.copy(str, length, &my_charset_bin, &my_charset_bin,
2280
2272
                     &dummy_errors))
2281
 
    return(true);
 
2273
    DBUG_RETURN(true);
2282
2274
  state= STRING_VALUE;
2283
2275
  max_length= length;
2284
2276
  maybe_null= 0;
2285
2277
  /* max_length and decimals are set after charset conversion */
2286
 
  /* sic: str may be not null-terminated */
2287
 
  return(false);
 
2278
  /* sic: str may be not null-terminated, don't add DBUG_PRINT here */
 
2279
  DBUG_RETURN(false);
2288
2280
}
2289
2281
 
2290
2282
 
2291
2283
bool Item_param::set_longdata(const char *str, ulong length)
2292
2284
{
 
2285
  DBUG_ENTER("Item_param::set_longdata");
 
2286
 
2293
2287
  /*
2294
2288
    If client character set is multibyte, end of long data packet
2295
2289
    may hit at the middle of a multibyte character.  Additionally,
2300
2294
    write query to the binary log and only then perform conversion.
2301
2295
  */
2302
2296
  if (str_value.append(str, length, &my_charset_bin))
2303
 
    return(true);
 
2297
    DBUG_RETURN(true);
2304
2298
  state= LONG_DATA_VALUE;
2305
2299
  maybe_null= 0;
2306
2300
 
2307
 
  return(false);
 
2301
  DBUG_RETURN(false);
2308
2302
}
2309
2303
 
2310
2304
 
2322
2316
 
2323
2317
bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry)
2324
2318
{
 
2319
  DBUG_ENTER("Item_param::set_from_user_var");
2325
2320
  if (entry && entry->value)
2326
2321
  {
2327
2322
    item_result_type= entry->type;
2328
2323
    unsigned_flag= entry->unsigned_flag;
2329
2324
    if (limit_clause_param)
2330
2325
    {
2331
 
      bool unused;
 
2326
      my_bool unused;
2332
2327
      set_int(entry->val_int(&unused), MY_INT64_NUM_DECIMAL_DIGITS);
2333
2328
      item_type= Item::INT_ITEM;
2334
 
      return(!unsigned_flag && value.integer < 0 ? 1 : 0);
 
2329
      DBUG_RETURN(!unsigned_flag && value.integer < 0 ? 1 : 0);
2335
2330
    }
2336
2331
    switch (item_result_type) {
2337
2332
    case REAL_RESULT:
2339
2334
      item_type= Item::REAL_ITEM;
2340
2335
      break;
2341
2336
    case INT_RESULT:
2342
 
      set_int(*(int64_t*)entry->value, MY_INT64_NUM_DECIMAL_DIGITS);
 
2337
      set_int(*(longlong*)entry->value, MY_INT64_NUM_DECIMAL_DIGITS);
2343
2338
      item_type= Item::INT_ITEM;
2344
2339
      break;
2345
2340
    case STRING_RESULT:
2346
2341
    {
2347
 
      const CHARSET_INFO * const fromcs= entry->collation.collation;
2348
 
      const CHARSET_INFO * const tocs= thd->variables.collation_connection;
2349
 
      uint32_t dummy_offset;
 
2342
      CHARSET_INFO *fromcs= entry->collation.collation;
 
2343
      CHARSET_INFO *tocs= thd->variables.collation_connection;
 
2344
      uint32 dummy_offset;
2350
2345
 
2351
2346
      value.cs_info.character_set_of_placeholder= 
2352
2347
        value.cs_info.character_set_client= fromcs;
2365
2360
      item_type= Item::STRING_ITEM;
2366
2361
 
2367
2362
      if (set_str((const char *)entry->value, entry->length))
2368
 
        return(1);
 
2363
        DBUG_RETURN(1);
2369
2364
      break;
2370
2365
    }
2371
2366
    case DECIMAL_RESULT:
2380
2375
      break;
2381
2376
    }
2382
2377
    default:
2383
 
      assert(0);
 
2378
      DBUG_ASSERT(0);
2384
2379
      set_null();
2385
2380
    }
2386
2381
  }
2387
2382
  else
2388
2383
    set_null();
2389
2384
 
2390
 
  return(0);
 
2385
  DBUG_RETURN(0);
2391
2386
}
2392
2387
 
2393
2388
/**
2400
2395
 
2401
2396
void Item_param::reset()
2402
2397
{
 
2398
  DBUG_ENTER("Item_param::reset");
2403
2399
  /* Shrink string buffer if it's bigger than max possible CHAR column */
2404
2400
  if (str_value.alloced_length() > MAX_CHAR_WIDTH)
2405
2401
    str_value.free();
2421
2417
    contain a literal of some kind.
2422
2418
    In all other cases when this object is accessed its value is
2423
2419
    set (this assumption is guarded by 'state' and
2424
 
    assertS(state != NO_VALUE) in all Item_param::get_*
 
2420
    DBUG_ASSERTS(state != NO_VALUE) in all Item_param::get_*
2425
2421
    methods).
2426
2422
  */
2427
 
  return;
 
2423
  DBUG_VOID_RETURN;
2428
2424
}
2429
2425
 
2430
2426
 
2450
2446
    return set_field_to_null_with_conversions(field, no_conversions);
2451
2447
  case NO_VALUE:
2452
2448
  default:
2453
 
    assert(0);
 
2449
    DBUG_ASSERT(0);
2454
2450
  }
2455
2451
  return 1;
2456
2452
}
2457
2453
 
2458
2454
 
2459
 
bool Item_param::get_time(DRIZZLE_TIME *res)
 
2455
bool Item_param::get_time(MYSQL_TIME *res)
2460
2456
{
2461
2457
  if (state == TIME_VALUE)
2462
2458
  {
2471
2467
}
2472
2468
 
2473
2469
 
2474
 
bool Item_param::get_date(DRIZZLE_TIME *res, uint32_t fuzzydate)
 
2470
bool Item_param::get_date(MYSQL_TIME *res, uint fuzzydate)
2475
2471
{
2476
2472
  if (state == TIME_VALUE)
2477
2473
  {
2508
2504
      This works for example when user says SELECT ?+0.0 and supplies
2509
2505
      time value for the placeholder.
2510
2506
    */
2511
 
    return uint64_t2double(TIME_to_uint64_t(&value.time));
 
2507
    return ulonglong2double(TIME_to_ulonglong(&value.time));
2512
2508
  case NULL_VALUE:
2513
2509
    return 0.0;
2514
2510
  default:
2515
 
    assert(0);
 
2511
    DBUG_ASSERT(0);
2516
2512
  }
2517
2513
  return 0.0;
2518
2514
2519
2515
 
2520
2516
 
2521
 
int64_t Item_param::val_int() 
 
2517
longlong Item_param::val_int() 
2522
2518
2523
2519
  switch (state) {
2524
2520
  case REAL_VALUE:
2525
 
    return (int64_t) rint(value.real);
 
2521
    return (longlong) rint(value.real);
2526
2522
  case INT_VALUE:
2527
2523
    return value.integer;
2528
2524
  case DECIMAL_VALUE:
2529
2525
  {
2530
 
    int64_t i;
 
2526
    longlong i;
2531
2527
    my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &i);
2532
2528
    return i;
2533
2529
  }
2539
2535
                         str_value.length(), 10, (char**) 0, &dummy_err);
2540
2536
    }
2541
2537
  case TIME_VALUE:
2542
 
    return (int64_t) TIME_to_uint64_t(&value.time);
 
2538
    return (longlong) TIME_to_ulonglong(&value.time);
2543
2539
  case NULL_VALUE:
2544
2540
    return 0; 
2545
2541
  default:
2546
 
    assert(0);
 
2542
    DBUG_ASSERT(0);
2547
2543
  }
2548
2544
  return 0;
2549
2545
}
2566
2562
    return dec;
2567
2563
  case TIME_VALUE:
2568
2564
  {
2569
 
    int64_t i= (int64_t) TIME_to_uint64_t(&value.time);
 
2565
    longlong i= (longlong) TIME_to_ulonglong(&value.time);
2570
2566
    int2my_decimal(E_DEC_FATAL_ERROR, i, 0, dec);
2571
2567
    return dec;
2572
2568
  }
2573
2569
  case NULL_VALUE:
2574
2570
    return 0; 
2575
2571
  default:
2576
 
    assert(0);
 
2572
    DBUG_ASSERT(0);
2577
2573
  }
2578
2574
  return 0;
2579
2575
}
2607
2603
  case NULL_VALUE:
2608
2604
    return NULL; 
2609
2605
  default:
2610
 
    assert(0);
 
2606
    DBUG_ASSERT(0);
2611
2607
  }
2612
2608
  return str;
2613
2609
}
2654
2650
      *ptr++= '\'';
2655
2651
      ptr+= (uint) my_TIME_to_str(&value.time, ptr);
2656
2652
      *ptr++= '\'';
2657
 
      str->length((uint32_t) (ptr - buf));
 
2653
      str->length((uint32) (ptr - buf));
2658
2654
      break;
2659
2655
    }
2660
2656
  case STRING_VALUE:
2667
2663
  case NULL_VALUE:
2668
2664
    return &my_null_string;
2669
2665
  default:
2670
 
    assert(0);
 
2666
    DBUG_ASSERT(0);
2671
2667
  }
2672
2668
  return str;
2673
2669
}
2744
2740
    break;
2745
2741
  case NO_VALUE:
2746
2742
  default:
2747
 
    assert(0);
 
2743
    DBUG_ASSERT(0);
2748
2744
  };
2749
2745
  return 0;
2750
2746
}
2783
2779
 
2784
2780
/* End of Item_param related */
2785
2781
 
2786
 
void Item_param::print(String *str,
2787
 
                       enum_query_type query_type __attribute__((unused)))
 
2782
void Item_param::print(String *str, enum_query_type query_type)
2788
2783
{
2789
2784
  if (state == NO_VALUE)
2790
2785
  {
2814
2809
}
2815
2810
 
2816
2811
/* ARGSUSED */
2817
 
String *Item_copy_string::val_str(String *str __attribute__((unused)))
 
2812
String *Item_copy_string::val_str(String *str)
2818
2813
{
2819
2814
  // Item_copy_string is used without fix_fields call
2820
2815
  if (null_value)
2838
2833
*/
2839
2834
 
2840
2835
/* ARGSUSED */
2841
 
bool Item::fix_fields(THD *thd __attribute__((unused)),
2842
 
                      Item **ref __attribute__((unused)))
 
2836
bool Item::fix_fields(THD *thd, Item **ref)
2843
2837
{
2844
2838
 
2845
2839
  // We do not check fields which are fixed during construction
2846
 
  assert(fixed == 0 || basic_const_item());
 
2840
  DBUG_ASSERT(fixed == 0 || basic_const_item());
2847
2841
  fixed= 1;
2848
2842
  return false;
2849
2843
}
2850
2844
 
2851
2845
double Item_ref_null_helper::val_real()
2852
2846
{
2853
 
  assert(fixed == 1);
 
2847
  DBUG_ASSERT(fixed == 1);
2854
2848
  double tmp= (*ref)->val_result();
2855
2849
  owner->was_null|= null_value= (*ref)->null_value;
2856
2850
  return tmp;
2857
2851
}
2858
2852
 
2859
2853
 
2860
 
int64_t Item_ref_null_helper::val_int()
 
2854
longlong Item_ref_null_helper::val_int()
2861
2855
{
2862
 
  assert(fixed == 1);
2863
 
  int64_t tmp= (*ref)->val_int_result();
 
2856
  DBUG_ASSERT(fixed == 1);
 
2857
  longlong tmp= (*ref)->val_int_result();
2864
2858
  owner->was_null|= null_value= (*ref)->null_value;
2865
2859
  return tmp;
2866
2860
}
2868
2862
 
2869
2863
my_decimal *Item_ref_null_helper::val_decimal(my_decimal *decimal_value)
2870
2864
{
2871
 
  assert(fixed == 1);
 
2865
  DBUG_ASSERT(fixed == 1);
2872
2866
  my_decimal *val= (*ref)->val_decimal_result(decimal_value);
2873
2867
  owner->was_null|= null_value= (*ref)->null_value;
2874
2868
  return val;
2877
2871
 
2878
2872
bool Item_ref_null_helper::val_bool()
2879
2873
{
2880
 
  assert(fixed == 1);
 
2874
  DBUG_ASSERT(fixed == 1);
2881
2875
  bool val= (*ref)->val_bool_result();
2882
2876
  owner->was_null|= null_value= (*ref)->null_value;
2883
2877
  return val;
2886
2880
 
2887
2881
String* Item_ref_null_helper::val_str(String* s)
2888
2882
{
2889
 
  assert(fixed == 1);
 
2883
  DBUG_ASSERT(fixed == 1);
2890
2884
  String* tmp= (*ref)->str_result(s);
2891
2885
  owner->was_null|= null_value= (*ref)->null_value;
2892
2886
  return tmp;
2893
2887
}
2894
2888
 
2895
2889
 
2896
 
bool Item_ref_null_helper::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate)
 
2890
bool Item_ref_null_helper::get_date(MYSQL_TIME *ltime, uint fuzzydate)
2897
2891
{  
2898
2892
  return (owner->was_null|= null_value= (*ref)->get_date(ltime, fuzzydate));
2899
2893
}
2925
2919
  current->mark_as_dependent(last);
2926
2920
  if (thd->lex->describe & DESCRIBE_EXTENDED)
2927
2921
  {
2928
 
    char warn_buff[DRIZZLE_ERRMSG_SIZE];
 
2922
    char warn_buff[MYSQL_ERRMSG_SIZE];
2929
2923
    sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED),
2930
2924
            db_name, (db_name[0] ? "." : ""),
2931
2925
            table_name, (table_name [0] ? "." : ""),
2932
2926
            resolved_item->field_name,
2933
2927
            current->select_number, last->select_number);
2934
 
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
 
2928
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
2935
2929
                 ER_WARN_FIELD_RESOLVED, warn_buff);
2936
2930
  }
2937
2931
}
3016
3010
    - NULL if find_item is not in group_list
3017
3011
*/
3018
3012
 
3019
 
static Item** find_field_in_group_list(Item *find_item, order_st *group_list)
 
3013
static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
3020
3014
{
3021
3015
  const char *db_name;
3022
3016
  const char *table_name;
3023
3017
  const char *field_name;
3024
 
  order_st      *found_group= NULL;
 
3018
  ORDER      *found_group= NULL;
3025
3019
  int         found_match_degree= 0;
3026
3020
  Item_ident *cur_field;
3027
3021
  int         cur_match_degree= 0;
3045
3039
    db_name= name_buff;
3046
3040
  }
3047
3041
 
3048
 
  assert(field_name != 0);
 
3042
  DBUG_ASSERT(field_name != 0);
3049
3043
 
3050
 
  for (order_st *cur_group= group_list ; cur_group ; cur_group= cur_group->next)
 
3044
  for (ORDER *cur_group= group_list ; cur_group ; cur_group= cur_group->next)
3051
3045
  {
3052
3046
    if ((*(cur_group->item))->real_item()->type() == Item::FIELD_ITEM)
3053
3047
    {
3054
3048
      cur_field= (Item_ident*) *cur_group->item;
3055
3049
      cur_match_degree= 0;
3056
3050
      
3057
 
      assert(cur_field->field_name != 0);
 
3051
      DBUG_ASSERT(cur_field->field_name != 0);
3058
3052
 
3059
3053
      if (!my_strcasecmp(system_charset_info,
3060
3054
                         cur_field->field_name, field_name))
3148
3142
{
3149
3143
  Item **group_by_ref= NULL;
3150
3144
  Item **select_ref= NULL;
3151
 
  order_st *group_list= (order_st*) select->group_list.first;
 
3145
  ORDER *group_list= (ORDER*) select->group_list.first;
3152
3146
  bool ambiguous_fields= false;
3153
 
  uint32_t counter;
 
3147
  uint counter;
3154
3148
  enum_resolution_type resolution;
3155
3149
 
3156
3150
  /*
3174
3168
        !((*group_by_ref)->eq(*select_ref, 0)))
3175
3169
    {
3176
3170
      ambiguous_fields= true;
3177
 
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
 
3171
      push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
3178
3172
                          ER(ER_NON_UNIQ_ERROR), ref->full_name(),
3179
3173
                          current_thd->where);
3180
3174
 
3185
3179
  {
3186
3180
    if (select_ref != not_found_item && !ambiguous_fields)
3187
3181
    {
3188
 
      assert(*select_ref != 0);
 
3182
      DBUG_ASSERT(*select_ref != 0);
3189
3183
      if (!select->ref_pointer_array[counter])
3190
3184
      {
3191
3185
        my_error(ER_ILLEGAL_REFERENCE, MYF(0),
3192
3186
                 ref->name, "forward reference in item list");
3193
3187
        return NULL;
3194
3188
      }
3195
 
      assert((*select_ref)->fixed);
 
3189
      DBUG_ASSERT((*select_ref)->fixed);
3196
3190
      return (select->ref_pointer_array + counter);
3197
3191
    }
3198
3192
    if (group_by_ref)
3199
3193
      return group_by_ref;
3200
 
    assert(false);
 
3194
    DBUG_ASSERT(false);
3201
3195
    return NULL; /* So there is no compiler warning. */
3202
3196
  }
3203
3197
 
3382
3376
        return -1; /* Some error occurred (e.g. ambiguous names). */
3383
3377
      if (ref != not_found_item)
3384
3378
      {
3385
 
        assert(*ref && (*ref)->fixed);
 
3379
        DBUG_ASSERT(*ref && (*ref)->fixed);
3386
3380
        prev_subselect_item->used_tables_cache|= (*ref)->used_tables();
3387
3381
        prev_subselect_item->const_item_cache&= (*ref)->const_item();
3388
3382
        break;
3398
3392
    prev_subselect_item->const_item_cache= 0;
3399
3393
  }
3400
3394
 
3401
 
  assert(ref != 0);
 
3395
  DBUG_ASSERT(ref != 0);
3402
3396
  if (!*from_field)
3403
3397
    return -1;
3404
3398
  if (ref == not_found_item && *from_field == not_found_field)
3426
3420
    Item_ref *rf;
3427
3421
 
3428
3422
    /* Should have been checked in resolve_ref_in_select_and_group(). */
3429
 
    assert(*ref && (*ref)->fixed);
 
3423
    DBUG_ASSERT(*ref && (*ref)->fixed);
3430
3424
    /*
3431
3425
      Here, a subset of actions performed by Item_ref::set_properties
3432
3426
      is not enough. So we pass ptr to NULL into Item_[direct]_ref
3457
3451
      rf is Item_ref => never substitute other items (in this case)
3458
3452
      during fix_fields() => we can use rf after fix_fields()
3459
3453
    */
3460
 
    assert(!rf->fixed);                // Assured by Item_ref()
 
3454
    DBUG_ASSERT(!rf->fixed);                // Assured by Item_ref()
3461
3455
    if (rf->fix_fields(thd, reference) || rf->check_cols(1))
3462
3456
      return -1;
3463
3457
 
3484
3478
        rf is Item_ref => never substitute other items (in this case)
3485
3479
        during fix_fields() => we can use rf after fix_fields()
3486
3480
      */
3487
 
      assert(!rf->fixed);                // Assured by Item_ref()
 
3481
      DBUG_ASSERT(!rf->fixed);                // Assured by Item_ref()
3488
3482
      if (rf->fix_fields(thd, reference) || rf->check_cols(1))
3489
3483
        return -1;
3490
3484
      return 0;
3541
3535
 
3542
3536
bool Item_field::fix_fields(THD *thd, Item **reference)
3543
3537
{
3544
 
  assert(fixed == 0);
 
3538
  DBUG_ASSERT(fixed == 0);
3545
3539
  Field *from_field= (Field *)not_found_field;
3546
3540
  bool outer_fixed= false;
3547
3541
 
3567
3561
      /* Look up in current select's item_list to find aliased fields */
3568
3562
      if (thd->lex->current_select->is_item_list_lookup)
3569
3563
      {
3570
 
        uint32_t counter;
 
3564
        uint counter;
3571
3565
        enum_resolution_type resolution;
3572
3566
        Item** res= find_item_in_list(this, thd->lex->current_select->item_list,
3573
3567
                                      &counter, REPORT_EXCEPT_NOT_FOUND,
3665
3659
  }
3666
3660
  else if (thd->mark_used_columns != MARK_COLUMNS_NONE)
3667
3661
  {
3668
 
    Table *table= field->table;
 
3662
    TABLE *table= field->table;
3669
3663
    MY_BITMAP *current_bitmap, *other_bitmap;
3670
3664
    if (thd->mark_used_columns == MARK_COLUMNS_READ)
3671
3665
    {
3698
3692
  return true;
3699
3693
}
3700
3694
 
3701
 
Item *Item_field::safe_charset_converter(const CHARSET_INFO * const tocs)
 
3695
Item *Item_field::safe_charset_converter(CHARSET_INFO *tocs)
3702
3696
{
3703
3697
  no_const_subst= 1;
3704
3698
  return Item::safe_charset_converter(tocs);
3707
3701
 
3708
3702
void Item_field::cleanup()
3709
3703
{
 
3704
  DBUG_ENTER("Item_field::cleanup");
3710
3705
  Item_ident::cleanup();
3711
3706
  /*
3712
3707
    Even if this object was created by direct link to field in setup_wild()
3715
3710
   */
3716
3711
  field= result_field= 0;
3717
3712
  null_value= false;
3718
 
  return;
 
3713
  DBUG_VOID_RETURN;
3719
3714
}
3720
3715
 
3721
3716
/**
3787
3782
    false  otherwise
3788
3783
*/
3789
3784
 
3790
 
bool Item_field::subst_argument_checker(unsigned char **arg)
 
3785
bool Item_field::subst_argument_checker(uchar **arg)
3791
3786
{
3792
3787
  return (result_type() != STRING_RESULT) || (*arg);
3793
3788
}
3794
3789
 
3795
3790
 
3796
3791
/**
 
3792
  Convert a numeric value to a zero-filled string
 
3793
 
 
3794
  @param[in,out]  item   the item to operate on
 
3795
  @param          field  The field that this value is equated to
 
3796
 
 
3797
  This function converts a numeric value to a string. In this conversion
 
3798
  the zero-fill flag of the field is taken into account.
 
3799
  This is required so the resulting string value can be used instead of
 
3800
  the field reference when propagating equalities.
 
3801
*/
 
3802
 
 
3803
static void convert_zerofill_number_to_string(Item **item, Field_num *field)
 
3804
{
 
3805
  char buff[MAX_FIELD_WIDTH],*pos;
 
3806
  String tmp(buff,sizeof(buff), field->charset()), *res;
 
3807
 
 
3808
  res= (*item)->val_str(&tmp);
 
3809
  field->prepend_zeros(res);
 
3810
  pos= (char *) sql_strmake (res->ptr(), res->length());
 
3811
  *item= new Item_string(pos, res->length(), field->charset());
 
3812
}
 
3813
 
 
3814
 
 
3815
/**
3797
3816
  Set a pointer to the multiple equality the field reference belongs to
3798
3817
  (if any).
3799
3818
 
3817
3836
    - pointer to the field item, otherwise.
3818
3837
*/
3819
3838
 
3820
 
Item *Item_field::equal_fields_propagator(unsigned char *arg)
 
3839
Item *Item_field::equal_fields_propagator(uchar *arg)
3821
3840
{
3822
3841
  if (no_const_subst)
3823
3842
    return this;
3839
3858
  if (!item ||
3840
3859
      (cmp_context != (Item_result)-1 && item->cmp_context != cmp_context))
3841
3860
    item= this;
3842
 
 
 
3861
  else if (field && (field->flags & ZEROFILL_FLAG) && IS_NUM(field->type()))
 
3862
  {
 
3863
    if (item && cmp_context != INT_RESULT)
 
3864
      convert_zerofill_number_to_string(&item, (Field_num *)field);
 
3865
    else
 
3866
      item= this;
 
3867
  }
3843
3868
  return item;
3844
3869
}
3845
3870
 
3850
3875
  See comments in Arg_comparator::set_compare_func() for details.
3851
3876
*/
3852
3877
 
3853
 
bool Item_field::set_no_const_sub(unsigned char *arg __attribute__((unused)))
 
3878
bool Item_field::set_no_const_sub(uchar *arg)
3854
3879
{
3855
3880
  if (field->charset() != &my_charset_bin)
3856
3881
    no_const_subst=1;
3883
3908
    - this - otherwise.
3884
3909
*/
3885
3910
 
3886
 
Item *Item_field::replace_equal_field(unsigned char *arg __attribute__((unused)))
 
3911
Item *Item_field::replace_equal_field(uchar *arg)
3887
3912
{
3888
3913
  if (item_equal)
3889
3914
  {
3919
3944
  tmp_field->type=              field_type_arg;
3920
3945
  tmp_field->length=max_length;
3921
3946
  tmp_field->decimals=decimals;
 
3947
  if (unsigned_flag)
 
3948
    tmp_field->flags |= UNSIGNED_FLAG;
3922
3949
}
3923
3950
 
3924
3951
void Item::make_field(Send_field *tmp_field)
3929
3956
 
3930
3957
enum_field_types Item::string_field_type() const
3931
3958
{
3932
 
  enum_field_types f_type= DRIZZLE_TYPE_VARCHAR;
3933
 
  if (max_length >= 65536)
3934
 
    f_type= DRIZZLE_TYPE_BLOB;
 
3959
  enum_field_types f_type= MYSQL_TYPE_VAR_STRING;
 
3960
  if (max_length >= 16777216)
 
3961
    f_type= MYSQL_TYPE_LONG_BLOB;
 
3962
  else if (max_length >= 65536)
 
3963
    f_type= MYSQL_TYPE_MEDIUM_BLOB;
3935
3964
  return f_type;
3936
3965
}
3937
3966
 
3946
3975
{
3947
3976
  switch (result_type()) {
3948
3977
  case STRING_RESULT:  return string_field_type();
3949
 
  case INT_RESULT:     return DRIZZLE_TYPE_LONGLONG;
3950
 
  case DECIMAL_RESULT: return DRIZZLE_TYPE_NEWDECIMAL;
3951
 
  case REAL_RESULT:    return DRIZZLE_TYPE_DOUBLE;
 
3978
  case INT_RESULT:     return MYSQL_TYPE_LONGLONG;
 
3979
  case DECIMAL_RESULT: return MYSQL_TYPE_NEWDECIMAL;
 
3980
  case REAL_RESULT:    return MYSQL_TYPE_DOUBLE;
3952
3981
  case ROW_RESULT:
3953
3982
  default:
3954
 
    assert(0);
3955
 
    return DRIZZLE_TYPE_VARCHAR;
 
3983
    DBUG_ASSERT(0);
 
3984
    return MYSQL_TYPE_VARCHAR;
3956
3985
  }
3957
3986
}
3958
3987
 
3961
3990
{
3962
3991
  switch (field_type())
3963
3992
  {
3964
 
    case DRIZZLE_TYPE_NEWDATE:
3965
 
    case DRIZZLE_TYPE_DATETIME:
3966
 
    case DRIZZLE_TYPE_TIMESTAMP:
 
3993
    case MYSQL_TYPE_DATE:
 
3994
    case MYSQL_TYPE_DATETIME:
 
3995
    case MYSQL_TYPE_TIMESTAMP:
3967
3996
      return true;
3968
3997
    default:
3969
3998
      break;
3975
4004
String *Item::check_well_formed_result(String *str, bool send_error)
3976
4005
{
3977
4006
  /* Check whether we got a well-formed string */
3978
 
  const CHARSET_INFO * const cs= str->charset();
 
4007
  CHARSET_INFO *cs= str->charset();
3979
4008
  int well_formed_error;
3980
 
  uint32_t wlen= cs->cset->well_formed_len(cs,
 
4009
  uint wlen= cs->cset->well_formed_len(cs,
3981
4010
                                       str->ptr(), str->ptr() + str->length(),
3982
4011
                                       str->length(), &well_formed_error);
3983
4012
  if (wlen < str->length())
3984
4013
  {
3985
4014
    THD *thd= current_thd;
3986
4015
    char hexbuf[7];
3987
 
    enum DRIZZLE_ERROR::enum_warning_level level;
3988
 
    uint32_t diff= str->length() - wlen;
 
4016
    enum MYSQL_ERROR::enum_warning_level level;
 
4017
    uint diff= str->length() - wlen;
3989
4018
    set_if_smaller(diff, 3);
3990
4019
    octet2hex(hexbuf, str->ptr() + wlen, diff);
3991
4020
    if (send_error)
3995
4024
      return 0;
3996
4025
    }
3997
4026
    {
3998
 
      level= DRIZZLE_ERROR::WARN_LEVEL_ERROR;
 
4027
      level= MYSQL_ERROR::WARN_LEVEL_ERROR;
3999
4028
      null_value= 1;
4000
4029
      str= 0;
4001
4030
    }
4026
4055
    0    otherwise
4027
4056
*/
4028
4057
 
4029
 
bool Item::eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO * const cs)
 
4058
bool Item::eq_by_collation(Item *item, bool binary_cmp, CHARSET_INFO *cs)
4030
4059
{
4031
 
  const CHARSET_INFO *save_cs= 0;
4032
 
  const CHARSET_INFO *save_item_cs= 0;
 
4060
  CHARSET_INFO *save_cs= 0;
 
4061
  CHARSET_INFO *save_item_cs= 0;
4033
4062
  if (collation.collation != cs)
4034
4063
  {
4035
4064
    save_cs= collation.collation;
4059
4088
  @param table          Table for which the field is created
4060
4089
*/
4061
4090
 
4062
 
Field *Item::make_string_field(Table *table)
 
4091
Field *Item::make_string_field(TABLE *table)
4063
4092
{
4064
4093
  Field *field;
4065
 
  assert(collation.collation);
 
4094
  DBUG_ASSERT(collation.collation);
4066
4095
  if (max_length/collation.collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB)
4067
4096
    field= new Field_blob(max_length, maybe_null, name,
4068
4097
                          collation.collation);
4069
 
  else
 
4098
  /* Item_type_holder holds the exact type, do not change it */
 
4099
  else if (max_length > 0 &&
 
4100
      (type() != Item::TYPE_HOLDER || field_type() != MYSQL_TYPE_STRING))
4070
4101
    field= new Field_varstring(max_length, maybe_null, name, table->s,
4071
4102
                               collation.collation);
4072
 
 
 
4103
  else
 
4104
    field= new Field_string(max_length, maybe_null, name,
 
4105
                            collation.collation);
4073
4106
  if (field)
4074
4107
    field->init(table);
4075
4108
  return field;
4088
4121
    \#    Created field
4089
4122
*/
4090
4123
 
4091
 
Field *Item::tmp_table_field_from_field_type(Table *table, bool fixed_length __attribute__((unused)))
 
4124
Field *Item::tmp_table_field_from_field_type(TABLE *table, bool fixed_length)
4092
4125
{
4093
4126
  /*
4094
4127
    The field functions defines a field to be not null if null_ptr is not 0
4095
4128
  */
4096
 
  unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
 
4129
  uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
4097
4130
  Field *field;
4098
4131
 
4099
4132
  switch (field_type()) {
4100
 
  case DRIZZLE_TYPE_NEWDECIMAL:
4101
 
    field= new Field_new_decimal((unsigned char*) 0, max_length, null_ptr, 0,
 
4133
  case MYSQL_TYPE_NEWDECIMAL:
 
4134
    field= new Field_new_decimal((uchar*) 0, max_length, null_ptr, 0,
4102
4135
                                 Field::NONE, name, decimals, 0,
4103
4136
                                 unsigned_flag);
4104
4137
    break;
4105
 
  case DRIZZLE_TYPE_TINY:
4106
 
    field= new Field_tiny((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4107
 
                          name, 0, unsigned_flag);
4108
 
    break;
4109
 
  case DRIZZLE_TYPE_LONG:
4110
 
    field= new Field_long((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4111
 
                          name, 0, unsigned_flag);
4112
 
    break;
4113
 
  case DRIZZLE_TYPE_LONGLONG:
4114
 
    field= new Field_int64_t((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
 
4138
  case MYSQL_TYPE_TINY:
 
4139
    field= new Field_tiny((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4140
                          name, 0, unsigned_flag);
 
4141
    break;
 
4142
  case MYSQL_TYPE_SHORT:
 
4143
    field= new Field_short((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4144
                           name, 0, unsigned_flag);
 
4145
    break;
 
4146
  case MYSQL_TYPE_LONG:
 
4147
    field= new Field_long((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4148
                          name, 0, unsigned_flag);
 
4149
    break;
 
4150
  case MYSQL_TYPE_LONGLONG:
 
4151
    field= new Field_longlong((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4115
4152
                              name, 0, unsigned_flag);
4116
4153
    break;
4117
 
  case DRIZZLE_TYPE_DOUBLE:
4118
 
    field= new Field_double((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
 
4154
  case MYSQL_TYPE_FLOAT:
 
4155
    field= new Field_float((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4156
                           name, decimals, 0, unsigned_flag);
 
4157
    break;
 
4158
  case MYSQL_TYPE_DOUBLE:
 
4159
    field= new Field_double((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4119
4160
                            name, decimals, 0, unsigned_flag);
4120
4161
    break;
4121
 
  case DRIZZLE_TYPE_NULL:
4122
 
    field= new Field_null((unsigned char*) 0, max_length, Field::NONE,
 
4162
  case MYSQL_TYPE_NULL:
 
4163
    field= new Field_null((uchar*) 0, max_length, Field::NONE,
4123
4164
                          name, &my_charset_bin);
4124
4165
    break;
4125
 
  case DRIZZLE_TYPE_NEWDATE:
 
4166
  case MYSQL_TYPE_NEWDATE:
 
4167
  case MYSQL_TYPE_DATE:
4126
4168
    field= new Field_newdate(maybe_null, name, &my_charset_bin);
4127
4169
    break;
4128
 
  case DRIZZLE_TYPE_TIME:
 
4170
  case MYSQL_TYPE_TIME:
4129
4171
    field= new Field_time(maybe_null, name, &my_charset_bin);
4130
4172
    break;
4131
 
  case DRIZZLE_TYPE_TIMESTAMP:
 
4173
  case MYSQL_TYPE_TIMESTAMP:
4132
4174
    field= new Field_timestamp(maybe_null, name, &my_charset_bin);
4133
4175
    break;
4134
 
  case DRIZZLE_TYPE_DATETIME:
 
4176
  case MYSQL_TYPE_DATETIME:
4135
4177
    field= new Field_datetime(maybe_null, name, &my_charset_bin);
4136
4178
    break;
 
4179
  case MYSQL_TYPE_YEAR:
 
4180
    field= new Field_year((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4181
                          name);
 
4182
    break;
4137
4183
  default:
4138
4184
    /* This case should never be chosen */
4139
 
    assert(0);
 
4185
    DBUG_ASSERT(0);
 
4186
    /* If something goes awfully wrong, it's better to get a string than die */
 
4187
  case MYSQL_TYPE_STRING:
 
4188
    if (fixed_length && max_length < CONVERT_IF_BIGGER_TO_BLOB)
 
4189
    {
 
4190
      field= new Field_string(max_length, maybe_null, name,
 
4191
                              collation.collation);
 
4192
      break;
 
4193
    }
4140
4194
    /* Fall through to make_string_field() */
4141
 
  case DRIZZLE_TYPE_ENUM:
4142
 
  case DRIZZLE_TYPE_VARCHAR:
 
4195
  case MYSQL_TYPE_ENUM:
 
4196
  case MYSQL_TYPE_SET:
 
4197
  case MYSQL_TYPE_VAR_STRING:
 
4198
  case MYSQL_TYPE_VARCHAR:
4143
4199
    return make_string_field(table);
4144
 
  case DRIZZLE_TYPE_BLOB:
 
4200
  case MYSQL_TYPE_TINY_BLOB:
 
4201
  case MYSQL_TYPE_MEDIUM_BLOB:
 
4202
  case MYSQL_TYPE_LONG_BLOB:
 
4203
  case MYSQL_TYPE_BLOB:
4145
4204
    if (this->type() == Item::TYPE_HOLDER)
4146
4205
      field= new Field_blob(max_length, maybe_null, name, collation.collation,
4147
4206
                            1);
4159
4218
void Item_field::make_field(Send_field *tmp_field)
4160
4219
{
4161
4220
  field->make_field(tmp_field);
4162
 
  assert(tmp_field->table_name != 0);
 
4221
  DBUG_ASSERT(tmp_field->table_name != 0);
4163
4222
  if (name)
4164
4223
    tmp_field->col_name=name;                   // Use user supplied name
4165
4224
  if (table_name)
4191
4250
int Item_field::save_in_field(Field *to, bool no_conversions)
4192
4251
{
4193
4252
  int res;
 
4253
  DBUG_ENTER("Item_field::save_in_field");
4194
4254
  if (result_field->is_null())
4195
4255
  {
4196
4256
    null_value=1;
4199
4259
  else
4200
4260
  {
4201
4261
    to->set_notnull();
 
4262
    DBUG_EXECUTE("info", dbug_print(););
4202
4263
    res= field_conv(to,result_field);
4203
4264
    null_value=0;
4204
4265
  }
4205
 
  return(res);
 
4266
  DBUG_RETURN(res);
4206
4267
}
4207
4268
 
4208
4269
 
4255
4316
  if (result_type() == STRING_RESULT)
4256
4317
  {
4257
4318
    String *result;
4258
 
    const CHARSET_INFO * const cs= collation.collation;
 
4319
    CHARSET_INFO *cs= collation.collation;
4259
4320
    char buff[MAX_FIELD_WIDTH];         // Alloc buffer for small columns
4260
4321
    str_value.set_quick(buff, sizeof(buff), cs);
4261
4322
    result=val_str(&str_value);
4299
4360
  }
4300
4361
  else
4301
4362
  {
4302
 
    int64_t nr=val_int();
 
4363
    longlong nr=val_int();
4303
4364
    if (null_value)
4304
4365
      return set_field_to_null_with_conversions(field, no_conversions);
4305
4366
    field->set_notnull();
4309
4370
}
4310
4371
 
4311
4372
 
4312
 
int Item_string::save_in_field(Field *field,
4313
 
                               bool no_conversions __attribute__((unused)))
 
4373
int Item_string::save_in_field(Field *field, bool no_conversions)
4314
4374
{
4315
4375
  String *result;
4316
4376
  result=val_str(&str_value);
4325
4385
}
4326
4386
 
4327
4387
 
4328
 
int Item_int::save_in_field(Field *field,
4329
 
                            bool no_conversions __attribute__((unused)))
 
4388
int Item_int::save_in_field(Field *field, bool no_conversions)
4330
4389
{
4331
 
  int64_t nr=val_int();
 
4390
  longlong nr=val_int();
4332
4391
  if (null_value)
4333
4392
    return set_field_to_null(field);
4334
4393
  field->set_notnull();
4336
4395
}
4337
4396
 
4338
4397
 
4339
 
int Item_decimal::save_in_field(Field *field,
4340
 
                                bool no_conversions __attribute__((unused)))
 
4398
int Item_decimal::save_in_field(Field *field, bool no_conversions)
4341
4399
{
4342
4400
  field->set_notnull();
4343
4401
  return field->store_decimal(&decimal_value);
4344
4402
}
4345
4403
 
4346
4404
 
4347
 
bool Item_int::eq(const Item *arg,
4348
 
                  bool binary_cmp __attribute__((unused))) const
 
4405
bool Item_int::eq(const Item *arg, bool binary_cmp) const
4349
4406
{
4350
4407
  /* No need to check for null value as basic constant can't be NULL */
4351
4408
  if (arg->basic_const_item() && arg->type() == type())
4363
4420
 
4364
4421
Item *Item_int_with_ref::clone_item()
4365
4422
{
4366
 
  assert(ref->const_item());
 
4423
  DBUG_ASSERT(ref->const_item());
4367
4424
  /*
4368
4425
    We need to evaluate the constant to make sure it works with
4369
4426
    parameter markers.
4381
4438
}
4382
4439
 
4383
4440
 
4384
 
static uint32_t nr_of_decimals(const char *str, const char *end)
 
4441
static uint nr_of_decimals(const char *str, const char *end)
4385
4442
{
4386
4443
  const char *decimal_point;
4387
4444
 
4409
4466
  value is not a true double value (overflow)
4410
4467
*/
4411
4468
 
4412
 
Item_float::Item_float(const char *str_arg, uint32_t length)
 
4469
Item_float::Item_float(const char *str_arg, uint length)
4413
4470
{
4414
4471
  int error;
4415
4472
  char *end_not_used;
4421
4478
      Note that we depend on that str_arg is null terminated, which is true
4422
4479
      when we are in the parser
4423
4480
    */
4424
 
    assert(str_arg[length] == 0);
 
4481
    DBUG_ASSERT(str_arg[length] == 0);
4425
4482
    my_error(ER_ILLEGAL_VALUE_FOR_TYPE, MYF(0), "double", (char*) str_arg);
4426
4483
  }
4427
4484
  presentation= name=(char*) str_arg;
4428
 
  decimals=(uint8_t) nr_of_decimals(str_arg, str_arg+length);
 
4485
  decimals=(uint8) nr_of_decimals(str_arg, str_arg+length);
4429
4486
  max_length=length;
4430
4487
  fixed= 1;
4431
4488
}
4432
4489
 
4433
4490
 
4434
 
int Item_float::save_in_field(Field *field,
4435
 
                              bool no_conversions __attribute__((unused)))
 
4491
int Item_float::save_in_field(Field *field, bool no_conversions)
4436
4492
{
4437
4493
  double nr= val_real();
4438
4494
  if (null_value)
4442
4498
}
4443
4499
 
4444
4500
 
4445
 
void Item_float::print(String *str,
4446
 
                       enum_query_type query_type __attribute__((unused)))
 
4501
void Item_float::print(String *str, enum_query_type query_type)
4447
4502
{
4448
4503
  if (presentation)
4449
4504
  {
4460
4515
/*
4461
4516
  hex item
4462
4517
  In string context this is a binary string.
4463
 
  In number context this is a int64_t value.
 
4518
  In number context this is a longlong value.
4464
4519
*/
4465
4520
 
4466
 
bool Item_float::eq(const Item *arg,
4467
 
                    bool binary_cmp __attribute__((unused))) const
 
4521
bool Item_float::eq(const Item *arg, bool binary_cmp) const
4468
4522
{
4469
4523
  if (arg->basic_const_item() && arg->type() == type())
4470
4524
  {
4479
4533
}
4480
4534
 
4481
4535
 
4482
 
inline uint32_t char_val(char X)
 
4536
inline uint char_val(char X)
4483
4537
{
4484
4538
  return (uint) (X >= '0' && X <= '9' ? X-'0' :
4485
4539
                 X >= 'A' && X <= 'Z' ? X-'A'+10 :
4487
4541
}
4488
4542
 
4489
4543
 
4490
 
Item_hex_string::Item_hex_string(const char *str, uint32_t str_length)
 
4544
Item_hex_string::Item_hex_string(const char *str, uint str_length)
4491
4545
{
4492
4546
  max_length=(str_length+1)/2;
4493
4547
  char *ptr=(char*) sql_alloc(max_length+1);
4508
4562
  unsigned_flag= 1;
4509
4563
}
4510
4564
 
4511
 
int64_t Item_hex_string::val_int()
 
4565
longlong Item_hex_string::val_int()
4512
4566
{
4513
4567
  // following assert is redundant, because fixed=1 assigned in constructor
4514
 
  assert(fixed == 1);
 
4568
  DBUG_ASSERT(fixed == 1);
4515
4569
  char *end=(char*) str_value.ptr()+str_value.length(),
4516
 
       *ptr=end-cmin(str_value.length(),(uint32_t)sizeof(int64_t));
 
4570
       *ptr=end-min(str_value.length(),sizeof(longlong));
4517
4571
 
4518
 
  uint64_t value=0;
 
4572
  ulonglong value=0;
4519
4573
  for (; ptr != end ; ptr++)
4520
 
    value=(value << 8)+ (uint64_t) (unsigned char) *ptr;
4521
 
  return (int64_t) value;
 
4574
    value=(value << 8)+ (ulonglong) (uchar) *ptr;
 
4575
  return (longlong) value;
4522
4576
}
4523
4577
 
4524
4578
 
4525
4579
my_decimal *Item_hex_string::val_decimal(my_decimal *decimal_value)
4526
4580
{
4527
4581
  // following assert is redundant, because fixed=1 assigned in constructor
4528
 
  assert(fixed == 1);
4529
 
  uint64_t value= (uint64_t)val_int();
 
4582
  DBUG_ASSERT(fixed == 1);
 
4583
  ulonglong value= (ulonglong)val_int();
4530
4584
  int2my_decimal(E_DEC_FATAL_ERROR, value, true, decimal_value);
4531
4585
  return (decimal_value);
4532
4586
}
4533
4587
 
4534
4588
 
4535
 
int Item_hex_string::save_in_field(Field *field,
4536
 
                                   bool no_conversions __attribute__((unused)))
 
4589
int Item_hex_string::save_in_field(Field *field, bool no_conversions)
4537
4590
{
4538
4591
  field->set_notnull();
4539
4592
  if (field->result_type() == STRING_RESULT)
4540
4593
    return field->store(str_value.ptr(), str_value.length(), 
4541
4594
                        collation.collation);
4542
4595
 
4543
 
  uint64_t nr;
4544
 
  uint32_t length= str_value.length();
 
4596
  ulonglong nr;
 
4597
  uint32 length= str_value.length();
4545
4598
  if (length > 8)
4546
4599
  {
4547
 
    nr= field->flags & UNSIGNED_FLAG ? UINT64_MAX : INT64_MAX;
 
4600
    nr= field->flags & UNSIGNED_FLAG ? ULONGLONG_MAX : LONGLONG_MAX;
4548
4601
    goto warn;
4549
4602
  }
4550
 
  nr= (uint64_t) val_int();
4551
 
  if ((length == 8) && !(field->flags & UNSIGNED_FLAG) && (nr > INT64_MAX))
 
4603
  nr= (ulonglong) val_int();
 
4604
  if ((length == 8) && !(field->flags & UNSIGNED_FLAG) && (nr > LONGLONG_MAX))
4552
4605
  {
4553
 
    nr= INT64_MAX;
 
4606
    nr= LONGLONG_MAX;
4554
4607
    goto warn;
4555
4608
  }
4556
 
  return field->store((int64_t) nr, true);  // Assume hex numbers are unsigned
 
4609
  return field->store((longlong) nr, true);  // Assume hex numbers are unsigned
4557
4610
 
4558
4611
warn:
4559
 
  if (!field->store((int64_t) nr, true))
4560
 
    field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE,
 
4612
  if (!field->store((longlong) nr, true))
 
4613
    field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE,
4561
4614
                       1);
4562
4615
  return 1;
4563
4616
}
4564
4617
 
4565
4618
 
4566
 
void Item_hex_string::print(String *str,
4567
 
                            enum_query_type query_type __attribute__((unused)))
 
4619
void Item_hex_string::print(String *str, enum_query_type query_type)
4568
4620
{
4569
4621
  char *end= (char*) str_value.ptr() + str_value.length(),
4570
 
       *ptr= end - cmin(str_value.length(), (uint32_t)sizeof(int64_t));
 
4622
       *ptr= end - min(str_value.length(), sizeof(longlong));
4571
4623
  str->append("0x");
4572
4624
  for (; ptr != end ; ptr++)
4573
4625
  {
4574
 
    str->append(_dig_vec_lower[((unsigned char) *ptr) >> 4]);
4575
 
    str->append(_dig_vec_lower[((unsigned char) *ptr) & 0x0F]);
 
4626
    str->append(_dig_vec_lower[((uchar) *ptr) >> 4]);
 
4627
    str->append(_dig_vec_lower[((uchar) *ptr) & 0x0F]);
4576
4628
  }
4577
4629
}
4578
4630
 
4589
4641
}
4590
4642
 
4591
4643
 
4592
 
Item *Item_hex_string::safe_charset_converter(const CHARSET_INFO * const tocs)
 
4644
Item *Item_hex_string::safe_charset_converter(CHARSET_INFO *tocs)
4593
4645
{
4594
4646
  Item_string *conv;
4595
4647
  String tmp, *str= val_str(&tmp);
4605
4657
/*
4606
4658
  bin item.
4607
4659
  In string context this is a binary string.
4608
 
  In number context this is a int64_t value.
 
4660
  In number context this is a longlong value.
4609
4661
*/
4610
4662
  
4611
 
Item_bin_string::Item_bin_string(const char *str, uint32_t str_length)
 
4663
Item_bin_string::Item_bin_string(const char *str, uint str_length)
4612
4664
{
4613
4665
  const char *end= str + str_length - 1;
4614
 
  unsigned char bits= 0;
4615
 
  uint32_t power= 1;
 
4666
  uchar bits= 0;
 
4667
  uint power= 1;
4616
4668
 
4617
4669
  max_length= (str_length + 7) >> 3;
4618
4670
  char *ptr= (char*) sql_alloc(max_length + 1);
4643
4695
  Pack data in buffer for sending.
4644
4696
*/
4645
4697
 
4646
 
bool Item_null::send(Protocol *protocol,
4647
 
                     String *packet __attribute__((unused)))
 
4698
bool Item_null::send(Protocol *protocol, String *packet)
4648
4699
{
4649
4700
  return protocol->store_null();
4650
4701
}
4660
4711
 
4661
4712
  switch ((f_type=field_type())) {
4662
4713
  default:
4663
 
  case DRIZZLE_TYPE_NULL:
4664
 
  case DRIZZLE_TYPE_ENUM:
4665
 
  case DRIZZLE_TYPE_BLOB:
4666
 
  case DRIZZLE_TYPE_VARCHAR:
4667
 
  case DRIZZLE_TYPE_NEWDECIMAL:
 
4714
  case MYSQL_TYPE_NULL:
 
4715
  case MYSQL_TYPE_ENUM:
 
4716
  case MYSQL_TYPE_SET:
 
4717
  case MYSQL_TYPE_TINY_BLOB:
 
4718
  case MYSQL_TYPE_MEDIUM_BLOB:
 
4719
  case MYSQL_TYPE_LONG_BLOB:
 
4720
  case MYSQL_TYPE_BLOB:
 
4721
  case MYSQL_TYPE_STRING:
 
4722
  case MYSQL_TYPE_VAR_STRING:
 
4723
  case MYSQL_TYPE_VARCHAR:
 
4724
  case MYSQL_TYPE_NEWDECIMAL:
4668
4725
  {
4669
4726
    String *res;
4670
4727
    if ((res=val_str(buffer)))
4671
4728
      result= protocol->store(res->ptr(),res->length(),res->charset());
4672
4729
    break;
4673
4730
  }
4674
 
  case DRIZZLE_TYPE_TINY:
 
4731
  case MYSQL_TYPE_TINY:
4675
4732
  {
4676
 
    int64_t nr;
 
4733
    longlong nr;
4677
4734
    nr= val_int();
4678
4735
    if (!null_value)
4679
4736
      result= protocol->store_tiny(nr);
4680
4737
    break;
4681
4738
  }
4682
 
  case DRIZZLE_TYPE_LONG:
4683
 
  {
4684
 
    int64_t nr;
 
4739
  case MYSQL_TYPE_SHORT:
 
4740
  case MYSQL_TYPE_YEAR:
 
4741
  {
 
4742
    longlong nr;
 
4743
    nr= val_int();
 
4744
    if (!null_value)
 
4745
      result= protocol->store_short(nr);
 
4746
    break;
 
4747
  }
 
4748
  case MYSQL_TYPE_LONG:
 
4749
  {
 
4750
    longlong nr;
4685
4751
    nr= val_int();
4686
4752
    if (!null_value)
4687
4753
      result= protocol->store_long(nr);
4688
4754
    break;
4689
4755
  }
4690
 
  case DRIZZLE_TYPE_LONGLONG:
 
4756
  case MYSQL_TYPE_LONGLONG:
4691
4757
  {
4692
 
    int64_t nr;
 
4758
    longlong nr;
4693
4759
    nr= val_int();
4694
4760
    if (!null_value)
4695
 
      result= protocol->store_int64_t(nr, unsigned_flag);
4696
 
    break;
4697
 
  }
4698
 
  case DRIZZLE_TYPE_DOUBLE:
 
4761
      result= protocol->store_longlong(nr, unsigned_flag);
 
4762
    break;
 
4763
  }
 
4764
  case MYSQL_TYPE_FLOAT:
 
4765
  {
 
4766
    float nr;
 
4767
    nr= (float) val_real();
 
4768
    if (!null_value)
 
4769
      result= protocol->store(nr, decimals, buffer);
 
4770
    break;
 
4771
  }
 
4772
  case MYSQL_TYPE_DOUBLE:
4699
4773
  {
4700
4774
    double nr= val_real();
4701
4775
    if (!null_value)
4702
4776
      result= protocol->store(nr, decimals, buffer);
4703
4777
    break;
4704
4778
  }
4705
 
  case DRIZZLE_TYPE_DATETIME:
4706
 
  case DRIZZLE_TYPE_TIMESTAMP:
 
4779
  case MYSQL_TYPE_DATETIME:
 
4780
  case MYSQL_TYPE_DATE:
 
4781
  case MYSQL_TYPE_TIMESTAMP:
4707
4782
  {
4708
 
    DRIZZLE_TIME tm;
 
4783
    MYSQL_TIME tm;
4709
4784
    get_date(&tm, TIME_FUZZY_DATE);
4710
4785
    if (!null_value)
4711
4786
    {
4712
 
      if (f_type == DRIZZLE_TYPE_NEWDATE)
 
4787
      if (f_type == MYSQL_TYPE_DATE)
4713
4788
        return protocol->store_date(&tm);
4714
4789
      else
4715
4790
        result= protocol->store(&tm);
4716
4791
    }
4717
4792
    break;
4718
4793
  }
4719
 
  case DRIZZLE_TYPE_TIME:
 
4794
  case MYSQL_TYPE_TIME:
4720
4795
  {
4721
 
    DRIZZLE_TIME tm;
 
4796
    MYSQL_TIME tm;
4722
4797
    get_time(&tm);
4723
4798
    if (!null_value)
4724
4799
      result= protocol->store_time(&tm);
4731
4806
}
4732
4807
 
4733
4808
 
4734
 
bool Item_field::send(Protocol *protocol,
4735
 
                      String *buffer __attribute__((unused)))
 
4809
bool Item_field::send(Protocol *protocol, String *buffer)
4736
4810
{
4737
4811
  return protocol->store(result_field);
4738
4812
}
4739
4813
 
4740
4814
 
4741
 
void Item_field::update_null_value()
4742
 
{
4743
 
  /*
4744
 
    need to set no_errors to prevent warnings about type conversion
 
4815
void Item_field::update_null_value() 
 
4816
 
4817
  /* 
 
4818
    need to set no_errors to prevent warnings about type conversion 
4745
4819
    popping up.
4746
4820
  */
4747
4821
  THD *thd= field->table->in_use;
4776
4850
    this field    otherwise
4777
4851
*/
4778
4852
 
4779
 
Item *Item_field::update_value_transformer(unsigned char *select_arg)
 
4853
Item *Item_field::update_value_transformer(uchar *select_arg)
4780
4854
{
4781
4855
  SELECT_LEX *select= (SELECT_LEX*)select_arg;
4782
 
  assert(fixed);
 
4856
  DBUG_ASSERT(fixed);
4783
4857
 
4784
 
  if (field->table != select->context.table_list->table)
 
4858
  if (field->table != select->context.table_list->table &&
 
4859
      type() != Item::TRIGGER_FIELD_ITEM)
4785
4860
  {
4786
4861
    List<Item> *all_fields= &select->join->all_fields;
4787
4862
    Item **ref_pointer_array= select->ref_pointer_array;
4818
4893
                   Item **item, const char *table_name_arg,
4819
4894
                   const char *field_name_arg,
4820
4895
                   bool alias_name_used_arg)
4821
 
  :Item_ident(context_arg, NULL, table_name_arg, field_name_arg),
 
4896
  :Item_ident(context_arg, NullS, table_name_arg, field_name_arg),
4822
4897
   result_field(0), ref(item)
4823
4898
{
4824
4899
  alias_name_used= alias_name_used_arg;
4897
4972
bool Item_ref::fix_fields(THD *thd, Item **reference)
4898
4973
{
4899
4974
  enum_parsing_place place= NO_MATTER;
4900
 
  assert(fixed == 0);
 
4975
  DBUG_ASSERT(fixed == 0);
4901
4976
  SELECT_LEX *current_sel= thd->lex->current_select;
4902
4977
 
4903
4978
  if (!ref || ref == not_found_item)
4946
5021
            goto error; /* Some error occurred (e.g. ambiguous names). */
4947
5022
          if (ref != not_found_item)
4948
5023
          {
4949
 
            assert(*ref && (*ref)->fixed);
 
5024
            DBUG_ASSERT(*ref && (*ref)->fixed);
4950
5025
            prev_subselect_item->used_tables_cache|= (*ref)->used_tables();
4951
5026
            prev_subselect_item->const_item_cache&= (*ref)->const_item();
4952
5027
            break;
4996
5071
              (*reference)->used_tables();
4997
5072
            prev_subselect_item->const_item_cache&=
4998
5073
              (*reference)->const_item();
4999
 
            assert((*reference)->type() == REF_ITEM);
 
5074
            DBUG_ASSERT((*reference)->type() == REF_ITEM);
5000
5075
            mark_as_dependent(thd, last_checked_context->select_lex,
5001
5076
                              context->select_lex, this,
5002
5077
                              ((refer_type == REF_ITEM ||
5035
5110
            break;
5036
5111
          }
5037
5112
        }
5038
 
        assert(from_field == not_found_field);
 
5113
        DBUG_ASSERT(from_field == not_found_field);
5039
5114
 
5040
5115
        /* Reference is not found => depend on outer (or just error). */
5041
5116
        prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
5044
5119
        outer_context= outer_context->outer_context;
5045
5120
      } while (outer_context);
5046
5121
 
5047
 
      assert(from_field != 0 && from_field != view_ref_found);
 
5122
      DBUG_ASSERT(from_field != 0 && from_field != view_ref_found);
5048
5123
      if (from_field != not_found_field)
5049
5124
      {
5050
5125
        Item_field* fld;
5073
5148
        goto error;
5074
5149
      }
5075
5150
      /* Should be checked in resolve_ref_in_select_and_group(). */
5076
 
      assert(*ref && (*ref)->fixed);
 
5151
      DBUG_ASSERT(*ref && (*ref)->fixed);
5077
5152
      mark_as_dependent(thd, last_checked_context->select_lex,
5078
5153
                        context->select_lex, this, this);
5079
5154
      /*
5089
5164
    }
5090
5165
  }
5091
5166
 
5092
 
  assert(*ref);
 
5167
  DBUG_ASSERT(*ref);
5093
5168
  /*
5094
5169
    Check if this is an incorrect reference in a group function or forward
5095
5170
    reference. Do not issue an error if this is:
5146
5221
 
5147
5222
void Item_ref::cleanup()
5148
5223
{
 
5224
  DBUG_ENTER("Item_ref::cleanup");
5149
5225
  Item_ident::cleanup();
5150
5226
  result_field= 0;
5151
 
  return;
 
5227
  DBUG_VOID_RETURN;
5152
5228
}
5153
5229
 
5154
5230
 
5190
5266
}
5191
5267
 
5192
5268
 
5193
 
int64_t Item_ref::val_int_result()
 
5269
longlong Item_ref::val_int_result()
5194
5270
{
5195
5271
  if (result_field)
5196
5272
  {
5249
5325
      return result_field->val_real() != 0.0;
5250
5326
    case ROW_RESULT:
5251
5327
    default:
5252
 
      assert(0);
 
5328
      DBUG_ASSERT(0);
5253
5329
    }
5254
5330
  }
5255
5331
  return val_bool();
5258
5334
 
5259
5335
double Item_ref::val_real()
5260
5336
{
5261
 
  assert(fixed);
 
5337
  DBUG_ASSERT(fixed);
5262
5338
  double tmp=(*ref)->val_result();
5263
5339
  null_value=(*ref)->null_value;
5264
5340
  return tmp;
5265
5341
}
5266
5342
 
5267
5343
 
5268
 
int64_t Item_ref::val_int()
 
5344
longlong Item_ref::val_int()
5269
5345
{
5270
 
  assert(fixed);
5271
 
  int64_t tmp=(*ref)->val_int_result();
 
5346
  DBUG_ASSERT(fixed);
 
5347
  longlong tmp=(*ref)->val_int_result();
5272
5348
  null_value=(*ref)->null_value;
5273
5349
  return tmp;
5274
5350
}
5276
5352
 
5277
5353
bool Item_ref::val_bool()
5278
5354
{
5279
 
  assert(fixed);
 
5355
  DBUG_ASSERT(fixed);
5280
5356
  bool tmp= (*ref)->val_bool_result();
5281
5357
  null_value= (*ref)->null_value;
5282
5358
  return tmp;
5285
5361
 
5286
5362
String *Item_ref::val_str(String* tmp)
5287
5363
{
5288
 
  assert(fixed);
 
5364
  DBUG_ASSERT(fixed);
5289
5365
  tmp=(*ref)->str_result(tmp);
5290
5366
  null_value=(*ref)->null_value;
5291
5367
  return tmp;
5294
5370
 
5295
5371
bool Item_ref::is_null()
5296
5372
{
5297
 
  assert(fixed);
 
5373
  DBUG_ASSERT(fixed);
5298
5374
  return (*ref)->is_null();
5299
5375
}
5300
5376
 
5301
5377
 
5302
 
bool Item_ref::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
5378
bool Item_ref::get_date(MYSQL_TIME *ltime,uint fuzzydate)
5303
5379
{
5304
5380
  return (null_value=(*ref)->get_date_result(ltime,fuzzydate));
5305
5381
}
5315
5391
int Item_ref::save_in_field(Field *to, bool no_conversions)
5316
5392
{
5317
5393
  int res;
5318
 
  assert(!result_field);
 
5394
  DBUG_ASSERT(!result_field);
5319
5395
  res= (*ref)->save_in_field(to, no_conversions);
5320
5396
  null_value= (*ref)->null_value;
5321
5397
  return res;
5375
5451
}
5376
5452
 
5377
5453
 
5378
 
int64_t Item_direct_ref::val_int()
 
5454
longlong Item_direct_ref::val_int()
5379
5455
{
5380
 
  int64_t tmp=(*ref)->val_int();
 
5456
  longlong tmp=(*ref)->val_int();
5381
5457
  null_value=(*ref)->null_value;
5382
5458
  return tmp;
5383
5459
}
5413
5489
}
5414
5490
 
5415
5491
 
5416
 
bool Item_direct_ref::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
5492
bool Item_direct_ref::get_date(MYSQL_TIME *ltime,uint fuzzydate)
5417
5493
{
5418
5494
  return (null_value=(*ref)->get_date(ltime,fuzzydate));
5419
5495
}
5434
5510
bool Item_direct_view_ref::fix_fields(THD *thd, Item **reference)
5435
5511
{
5436
5512
  /* view fild reference must be defined */
5437
 
  assert(*ref);
 
5513
  DBUG_ASSERT(*ref);
5438
5514
  /* (*ref)->check_cols() will be made in Item_direct_ref::fix_fields */
5439
5515
  if (!(*ref)->fixed &&
5440
5516
      ((*ref)->fix_fields(thd, ref)))
5478
5554
  }
5479
5555
}
5480
5556
 
5481
 
void Item_ref::fix_after_pullout(st_select_lex *new_parent,
5482
 
                                 Item **refptr __attribute__((unused)))
 
5557
void Item_ref::fix_after_pullout(st_select_lex *new_parent, Item **refptr)
5483
5558
{
5484
5559
  if (depended_from == new_parent)
5485
5560
  {
5505
5580
    false   otherwise
5506
5581
*/
5507
5582
 
5508
 
bool Item_direct_view_ref::eq(const Item *item,
5509
 
                              bool binary_cmp __attribute__((unused))) const
 
5583
bool Item_direct_view_ref::eq(const Item *item, bool binary_cmp) const
5510
5584
{
5511
5585
  if (item->type() == REF_ITEM)
5512
5586
  {
5522
5596
 
5523
5597
bool Item_default_value::eq(const Item *item, bool binary_cmp) const
5524
5598
{
5525
 
  return item->type() == DEFAULT_VALUE_ITEM &&
 
5599
  return item->type() == DEFAULT_VALUE_ITEM && 
5526
5600
    ((Item_default_value *)item)->arg->eq(arg, binary_cmp);
5527
5601
}
5528
5602
 
5529
5603
 
5530
 
bool Item_default_value::fix_fields(THD *thd,
5531
 
                                    Item **items __attribute__((unused)))
 
5604
bool Item_default_value::fix_fields(THD *thd, Item **items)
5532
5605
{
5533
5606
  Item *real_arg;
5534
5607
  Item_field *field_arg;
5535
5608
  Field *def_field;
5536
 
  assert(fixed == 0);
 
5609
  DBUG_ASSERT(fixed == 0);
5537
5610
 
5538
5611
  if (!arg)
5539
5612
  {
5600
5673
 
5601
5674
      {
5602
5675
        push_warning_printf(field_arg->table->in_use,
5603
 
                            DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
5676
                            MYSQL_ERROR::WARN_LEVEL_WARN,
5604
5677
                            ER_NO_DEFAULT_FOR_FIELD,
5605
5678
                            ER(ER_NO_DEFAULT_FOR_FIELD),
5606
5679
                            field_arg->field_name);
5619
5692
  same time it can replace some nodes in the tree.
5620
5693
*/ 
5621
5694
 
5622
 
Item *Item_default_value::transform(Item_transformer transformer, unsigned char *args)
 
5695
Item *Item_default_value::transform(Item_transformer transformer, uchar *args)
5623
5696
{
5624
5697
  Item *new_item= arg->transform(transformer, args);
5625
5698
  if (!new_item)
5644
5717
}
5645
5718
 
5646
5719
 
5647
 
bool Item_insert_value::fix_fields(THD *thd,
5648
 
                                   Item **items __attribute__((unused)))
 
5720
bool Item_insert_value::fix_fields(THD *thd, Item **items)
5649
5721
{
5650
 
  assert(fixed == 0);
 
5722
  DBUG_ASSERT(fixed == 0);
5651
5723
  /* We should only check that arg is in first table */
5652
5724
  if (!arg->fixed)
5653
5725
  {
5654
5726
    bool res;
5655
 
    TableList *orig_next_table= context->last_name_resolution_table;
 
5727
    TABLE_LIST *orig_next_table= context->last_name_resolution_table;
5656
5728
    context->last_name_resolution_table= context->first_name_resolution_table;
5657
5729
    res= arg->fix_fields(thd, &arg);
5658
5730
    context->last_name_resolution_table= orig_next_table;
5674
5746
    According to our SQL grammar, VALUES() function can reference
5675
5747
    only to a column.
5676
5748
  */
5677
 
  assert(arg->type() == FIELD_ITEM);
 
5749
  DBUG_ASSERT(arg->type() == FIELD_ITEM);
5678
5750
 
5679
5751
  Item_field *field_arg= (Item_field *)arg;
5680
5752
 
5747
5819
      new_item= new Item_null(name);
5748
5820
    else
5749
5821
    {
5750
 
      uint32_t length= result->length();
 
5822
      uint length= result->length();
5751
5823
      char *tmp_str= sql_strmake(result->ptr(), length);
5752
5824
      new_item= new Item_string(name, tmp_str, length, result->charset());
5753
5825
    }
5755
5827
  }
5756
5828
  case INT_RESULT:
5757
5829
  {
5758
 
    int64_t result=item->val_int();
5759
 
    uint32_t length=item->max_length;
 
5830
    longlong result=item->val_int();
 
5831
    uint length=item->max_length;
5760
5832
    bool null_value=item->null_value;
5761
5833
    new_item= (null_value ? (Item*) new Item_null(name) :
5762
5834
               (Item*) new Item_int(name, result, length));
5775
5847
    */
5776
5848
    Item_row *item_row= (Item_row*) item;
5777
5849
    Item_row *comp_item_row= (Item_row*) comp_item;
5778
 
    uint32_t col;
 
5850
    uint col;
5779
5851
    new_item= 0;
5780
5852
    /*
5781
5853
      If item and comp_item are both Item_rows and have same number of cols
5783
5855
      We can't ignore NULL values here as this item may be used with <=>, in
5784
5856
      which case NULL's are significant.
5785
5857
    */
5786
 
    assert(item->result_type() == comp_item->result_type());
5787
 
    assert(item_row->cols() == comp_item_row->cols());
 
5858
    DBUG_ASSERT(item->result_type() == comp_item->result_type());
 
5859
    DBUG_ASSERT(item_row->cols() == comp_item_row->cols());
5788
5860
    col= item_row->cols();
5789
5861
    while (col-- > 0)
5790
5862
      resolve_const_item(thd, item_row->addr(col),
5795
5867
  case REAL_RESULT:
5796
5868
  {                                             // It must REAL_RESULT
5797
5869
    double result= item->val_real();
5798
 
    uint32_t length=item->max_length,decimals=item->decimals;
 
5870
    uint length=item->max_length,decimals=item->decimals;
5799
5871
    bool null_value=item->null_value;
5800
5872
    new_item= (null_value ? (Item*) new Item_null(name) : (Item*)
5801
5873
               new Item_float(name, result, decimals, length));
5805
5877
  {
5806
5878
    my_decimal decimal_value;
5807
5879
    my_decimal *result= item->val_decimal(&decimal_value);
5808
 
    uint32_t length= item->max_length, decimals= item->decimals;
 
5880
    uint length= item->max_length, decimals= item->decimals;
5809
5881
    bool null_value= item->null_value;
5810
5882
    new_item= (null_value ?
5811
5883
               (Item*) new Item_null(name) :
5813
5885
    break;
5814
5886
  }
5815
5887
  default:
5816
 
    assert(0);
 
5888
    DBUG_ASSERT(0);
5817
5889
  }
5818
5890
  if (new_item)
5819
5891
    thd->change_item_tree(ref, new_item);
5877
5949
    return new Item_cache_row();
5878
5950
  default:
5879
5951
    // should never be in real life
5880
 
    assert(0);
 
5952
    DBUG_ASSERT(0);
5881
5953
    return 0;
5882
5954
  }
5883
5955
}
5902
5974
}
5903
5975
 
5904
5976
 
5905
 
void Item_cache_int::store(Item *item, int64_t val_arg)
 
5977
void Item_cache_int::store(Item *item, longlong val_arg)
5906
5978
{
5907
5979
  value= val_arg;
5908
5980
  null_value= item->null_value;
5912
5984
 
5913
5985
String *Item_cache_int::val_str(String *str)
5914
5986
{
5915
 
  assert(fixed == 1);
 
5987
  DBUG_ASSERT(fixed == 1);
5916
5988
  str->set(value, default_charset());
5917
5989
  return str;
5918
5990
}
5920
5992
 
5921
5993
my_decimal *Item_cache_int::val_decimal(my_decimal *decimal_val)
5922
5994
{
5923
 
  assert(fixed == 1);
 
5995
  DBUG_ASSERT(fixed == 1);
5924
5996
  int2my_decimal(E_DEC_FATAL_ERROR, value, unsigned_flag, decimal_val);
5925
5997
  return decimal_val;
5926
5998
}
5933
6005
}
5934
6006
 
5935
6007
 
5936
 
int64_t Item_cache_real::val_int()
 
6008
longlong Item_cache_real::val_int()
5937
6009
{
5938
 
  assert(fixed == 1);
5939
 
  return (int64_t) rint(value);
 
6010
  DBUG_ASSERT(fixed == 1);
 
6011
  return (longlong) rint(value);
5940
6012
}
5941
6013
 
5942
6014
 
5943
6015
String* Item_cache_real::val_str(String *str)
5944
6016
{
5945
 
  assert(fixed == 1);
 
6017
  DBUG_ASSERT(fixed == 1);
5946
6018
  str->set_real(value, decimals, default_charset());
5947
6019
  return str;
5948
6020
}
5950
6022
 
5951
6023
my_decimal *Item_cache_real::val_decimal(my_decimal *decimal_val)
5952
6024
{
5953
 
  assert(fixed == 1);
 
6025
  DBUG_ASSERT(fixed == 1);
5954
6026
  double2my_decimal(E_DEC_FATAL_ERROR, value, decimal_val);
5955
6027
  return decimal_val;
5956
6028
}
5965
6037
 
5966
6038
double Item_cache_decimal::val_real()
5967
6039
{
5968
 
  assert(fixed);
 
6040
  DBUG_ASSERT(fixed);
5969
6041
  double res;
5970
6042
  my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &res);
5971
6043
  return res;
5972
6044
}
5973
6045
 
5974
 
int64_t Item_cache_decimal::val_int()
 
6046
longlong Item_cache_decimal::val_int()
5975
6047
{
5976
 
  assert(fixed);
5977
 
  int64_t res;
 
6048
  DBUG_ASSERT(fixed);
 
6049
  longlong res;
5978
6050
  my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &res);
5979
6051
  return res;
5980
6052
}
5981
6053
 
5982
6054
String* Item_cache_decimal::val_str(String *str)
5983
6055
{
5984
 
  assert(fixed);
 
6056
  DBUG_ASSERT(fixed);
5985
6057
  my_decimal_round(E_DEC_FATAL_ERROR, &decimal_value, decimals, false,
5986
6058
                   &decimal_value);
5987
6059
  my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, str);
5988
6060
  return str;
5989
6061
}
5990
6062
 
5991
 
my_decimal *Item_cache_decimal::val_decimal(my_decimal *val __attribute__((unused)))
 
6063
my_decimal *Item_cache_decimal::val_decimal(my_decimal *val)
5992
6064
{
5993
 
  assert(fixed);
 
6065
  DBUG_ASSERT(fixed);
5994
6066
  return &decimal_value;
5995
6067
}
5996
6068
 
6018
6090
 
6019
6091
double Item_cache_str::val_real()
6020
6092
{
6021
 
  assert(fixed == 1);
 
6093
  DBUG_ASSERT(fixed == 1);
6022
6094
  int err_not_used;
6023
6095
  char *end_not_used;
6024
6096
  if (value)
6028
6100
}
6029
6101
 
6030
6102
 
6031
 
int64_t Item_cache_str::val_int()
 
6103
longlong Item_cache_str::val_int()
6032
6104
{
6033
 
  assert(fixed == 1);
 
6105
  DBUG_ASSERT(fixed == 1);
6034
6106
  int err;
6035
6107
  if (value)
6036
6108
    return my_strntoll(value->charset(), value->ptr(),
6037
6109
                       value->length(), 10, (char**) 0, &err);
6038
6110
  else
6039
 
    return (int64_t)0;
 
6111
    return (longlong)0;
6040
6112
}
6041
6113
 
6042
6114
my_decimal *Item_cache_str::val_decimal(my_decimal *decimal_val)
6043
6115
{
6044
 
  assert(fixed == 1);
 
6116
  DBUG_ASSERT(fixed == 1);
6045
6117
  if (value)
6046
6118
    string2my_decimal(E_DEC_FATAL_ERROR, value, decimal_val);
6047
6119
  else
6053
6125
int Item_cache_str::save_in_field(Field *field, bool no_conversions)
6054
6126
{
6055
6127
  int res= Item_cache::save_in_field(field, no_conversions);
6056
 
 
6057
 
  return res;
 
6128
  return (is_varbinary && field->type() == MYSQL_TYPE_STRING &&
 
6129
          value->length() < field->field_length) ? 1 : res;
6058
6130
}
6059
6131
 
6060
6132
 
6061
 
bool Item_cache_row::allocate(uint32_t num)
 
6133
bool Item_cache_row::allocate(uint num)
6062
6134
{
6063
6135
  item_count= num;
6064
6136
  THD *thd= current_thd;
6072
6144
  example= item;
6073
6145
  if (!values && allocate(item->cols()))
6074
6146
    return 1;
6075
 
  for (uint32_t i= 0; i < item_count; i++)
 
6147
  for (uint i= 0; i < item_count; i++)
6076
6148
  {
6077
6149
    Item *el= item->element_index(i);
6078
6150
    Item_cache *tmp;
6088
6160
{
6089
6161
  null_value= 0;
6090
6162
  item->bring_value();
6091
 
  for (uint32_t i= 0; i < item_count; i++)
 
6163
  for (uint i= 0; i < item_count; i++)
6092
6164
  {
6093
6165
    values[i]->store(item->element_index(i));
6094
6166
    null_value|= values[i]->null_value;
6096
6168
}
6097
6169
 
6098
6170
 
6099
 
void Item_cache_row::illegal_method_call(const char *method __attribute__((unused)))
 
6171
void Item_cache_row::illegal_method_call(const char *method)
6100
6172
{
6101
 
  assert(0);
 
6173
  DBUG_ENTER("Item_cache_row::illegal_method_call");
 
6174
  DBUG_PRINT("error", ("!!! %s method was called for row item", method));
 
6175
  DBUG_ASSERT(0);
6102
6176
  my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
6103
 
  return;
 
6177
  DBUG_VOID_RETURN;
6104
6178
}
6105
6179
 
6106
6180
 
6107
 
bool Item_cache_row::check_cols(uint32_t c)
 
6181
bool Item_cache_row::check_cols(uint c)
6108
6182
{
6109
6183
  if (c != item_count)
6110
6184
  {
6117
6191
 
6118
6192
bool Item_cache_row::null_inside()
6119
6193
{
6120
 
  for (uint32_t i= 0; i < item_count; i++)
 
6194
  for (uint i= 0; i < item_count; i++)
6121
6195
  {
6122
6196
    if (values[i]->cols() > 1)
6123
6197
    {
6137
6211
 
6138
6212
void Item_cache_row::bring_value()
6139
6213
{
6140
 
  for (uint32_t i= 0; i < item_count; i++)
 
6214
  for (uint i= 0; i < item_count; i++)
6141
6215
    values[i]->bring_value();
6142
6216
  return;
6143
6217
}
6146
6220
Item_type_holder::Item_type_holder(THD *thd, Item *item)
6147
6221
  :Item(thd, item), enum_set_typelib(0), fld_type(get_real_type(item))
6148
6222
{
6149
 
  assert(item->fixed);
 
6223
  DBUG_ASSERT(item->fixed);
6150
6224
  maybe_null= item->maybe_null;
6151
6225
  collation.set(item->collation);
6152
6226
  get_full_info(item);
6190
6264
    Field *field= ((Item_field *) item)->field;
6191
6265
    enum_field_types type= field->real_type();
6192
6266
    if (field->is_created_from_null_item)
6193
 
      return DRIZZLE_TYPE_NULL;
 
6267
      return MYSQL_TYPE_NULL;
 
6268
    /* work around about varchar type field detection */
 
6269
    if (type == MYSQL_TYPE_STRING && field->type() == MYSQL_TYPE_VAR_STRING)
 
6270
      return MYSQL_TYPE_VAR_STRING;
6194
6271
    return type;
6195
6272
  }
6196
6273
  case SUM_FUNC_ITEM:
6215
6292
      */
6216
6293
      switch (item->result_type()) {
6217
6294
      case STRING_RESULT:
6218
 
        return DRIZZLE_TYPE_VARCHAR;
 
6295
        return MYSQL_TYPE_VAR_STRING;
6219
6296
      case INT_RESULT:
6220
 
        return DRIZZLE_TYPE_LONGLONG;
 
6297
        return MYSQL_TYPE_LONGLONG;
6221
6298
      case REAL_RESULT:
6222
 
        return DRIZZLE_TYPE_DOUBLE;
 
6299
        return MYSQL_TYPE_DOUBLE;
6223
6300
      case DECIMAL_RESULT:
6224
 
        return DRIZZLE_TYPE_NEWDECIMAL;
 
6301
        return MYSQL_TYPE_NEWDECIMAL;
6225
6302
      case ROW_RESULT:
6226
6303
      default:
6227
 
        assert(0);
6228
 
        return DRIZZLE_TYPE_VARCHAR;
 
6304
        DBUG_ASSERT(0);
 
6305
        return MYSQL_TYPE_VAR_STRING;
6229
6306
      }
6230
6307
    }
6231
6308
    break;
6248
6325
    false  OK
6249
6326
*/
6250
6327
 
6251
 
bool Item_type_holder::join_types(THD *thd __attribute__((unused)),
6252
 
                                  Item *item)
 
6328
bool Item_type_holder::join_types(THD *thd, Item *item)
6253
6329
{
6254
 
  uint32_t max_length_orig= max_length;
6255
 
  uint32_t decimals_orig= decimals;
 
6330
  uint max_length_orig= max_length;
 
6331
  uint decimals_orig= decimals;
 
6332
  DBUG_ENTER("Item_type_holder::join_types");
 
6333
  DBUG_PRINT("info:", ("was type %d len %d, dec %d name %s",
 
6334
                       fld_type, max_length, decimals,
 
6335
                       (name ? name : "<NULL>")));
 
6336
  DBUG_PRINT("info:", ("in type %d len %d, dec %d",
 
6337
                       get_real_type(item),
 
6338
                       item->max_length, item->decimals));
6256
6339
  fld_type= Field::field_type_merge(fld_type, get_real_type(item));
6257
6340
  {
6258
6341
    int item_decimals= item->decimals;
6259
6342
    /* fix variable decimals which always is NOT_FIXED_DEC */
6260
6343
    if (Field::result_merge_type(fld_type) == INT_RESULT)
6261
6344
      item_decimals= 0;
6262
 
    decimals= cmax((int)decimals, item_decimals);
 
6345
    decimals= max(decimals, item_decimals);
6263
6346
  }
6264
6347
  if (Field::result_merge_type(fld_type) == DECIMAL_RESULT)
6265
6348
  {
6266
 
    decimals= cmin((int)cmax(decimals, item->decimals), DECIMAL_MAX_SCALE);
6267
 
    int precision= cmin(cmax(prev_decimal_int_part, item->decimal_int_part())
 
6349
    decimals= min(max(decimals, item->decimals), DECIMAL_MAX_SCALE);
 
6350
    int precision= min(max(prev_decimal_int_part, item->decimal_int_part())
6268
6351
                       + decimals, DECIMAL_MAX_PRECISION);
6269
6352
    unsigned_flag&= item->unsigned_flag;
6270
6353
    max_length= my_decimal_precision_to_length(precision, decimals,
6276
6359
  case STRING_RESULT:
6277
6360
  {
6278
6361
    const char *old_cs, *old_derivation;
6279
 
    uint32_t old_max_chars= max_length / collation.collation->mbmaxlen;
 
6362
    uint32 old_max_chars= max_length / collation.collation->mbmaxlen;
6280
6363
    old_cs= collation.collation->name;
6281
6364
    old_derivation= collation.derivation_name();
6282
6365
    if (collation.aggregate(item->collation, MY_COLL_ALLOW_CONV))
6286
6369
               item->collation.collation->name,
6287
6370
               item->collation.derivation_name(),
6288
6371
               "UNION");
6289
 
      return(true);
 
6372
      DBUG_RETURN(true);
6290
6373
    }
6291
6374
    /*
6292
6375
      To figure out max_length, we have to take into account possible
6295
6378
     */
6296
6379
    if (collation.collation != &my_charset_bin)
6297
6380
    {
6298
 
      max_length= cmax(old_max_chars * collation.collation->mbmaxlen,
 
6381
      max_length= max(old_max_chars * collation.collation->mbmaxlen,
6299
6382
                      display_length(item) /
6300
6383
                      item->collation.collation->mbmaxlen *
6301
6384
                      collation.collation->mbmaxlen);
6310
6393
    {
6311
6394
      int delta1= max_length_orig - decimals_orig;
6312
6395
      int delta2= item->max_length - item->decimals;
6313
 
      max_length= cmax(delta1, delta2) + decimals;
6314
 
      if (fld_type == DRIZZLE_TYPE_DOUBLE && max_length > DBL_DIG + 2) 
 
6396
      max_length= max(delta1, delta2) + decimals;
 
6397
      if (fld_type == MYSQL_TYPE_FLOAT && max_length > FLT_DIG + 2) 
 
6398
      {
 
6399
        max_length= FLT_DIG + 6;
 
6400
        decimals= NOT_FIXED_DEC;
 
6401
      } 
 
6402
      if (fld_type == MYSQL_TYPE_DOUBLE && max_length > DBL_DIG + 2) 
6315
6403
      {
6316
6404
        max_length= DBL_DIG + 7;
6317
6405
        decimals= NOT_FIXED_DEC;
6318
6406
      }
6319
6407
    }
6320
6408
    else
6321
 
      max_length= DBL_DIG+7;
 
6409
      max_length= (fld_type == MYSQL_TYPE_FLOAT) ? FLT_DIG+6 : DBL_DIG+7;
6322
6410
    break;
6323
6411
  }
6324
6412
  default:
6325
 
    max_length= cmax(max_length, display_length(item));
 
6413
    max_length= max(max_length, display_length(item));
6326
6414
  };
6327
6415
  maybe_null|= item->maybe_null;
6328
6416
  get_full_info(item);
6329
6417
 
6330
6418
  /* Remember decimal integer part to be used in DECIMAL_RESULT handleng */
6331
6419
  prev_decimal_int_part= decimal_int_part();
6332
 
  return(false);
 
6420
  DBUG_PRINT("info", ("become type: %d  len: %u  dec: %u",
 
6421
                      (int) fld_type, max_length, (uint) decimals));
 
6422
  DBUG_RETURN(false);
6333
6423
}
6334
6424
 
6335
6425
/**
6341
6431
    length
6342
6432
*/
6343
6433
 
6344
 
uint32_t Item_type_holder::display_length(Item *item)
 
6434
uint32 Item_type_holder::display_length(Item *item)
6345
6435
{
6346
6436
  if (item->type() == Item::FIELD_ITEM)
6347
6437
    return ((Item_field *)item)->max_disp_length();
6348
6438
 
6349
6439
  switch (item->field_type())
6350
6440
  {
6351
 
  case DRIZZLE_TYPE_TIMESTAMP:
6352
 
  case DRIZZLE_TYPE_TIME:
6353
 
  case DRIZZLE_TYPE_DATETIME:
6354
 
  case DRIZZLE_TYPE_NEWDATE:
6355
 
  case DRIZZLE_TYPE_VARCHAR:
6356
 
  case DRIZZLE_TYPE_NEWDECIMAL:
6357
 
  case DRIZZLE_TYPE_ENUM:
6358
 
  case DRIZZLE_TYPE_BLOB:
6359
 
  case DRIZZLE_TYPE_TINY:
 
6441
  case MYSQL_TYPE_TIMESTAMP:
 
6442
  case MYSQL_TYPE_DATE:
 
6443
  case MYSQL_TYPE_TIME:
 
6444
  case MYSQL_TYPE_DATETIME:
 
6445
  case MYSQL_TYPE_YEAR:
 
6446
  case MYSQL_TYPE_NEWDATE:
 
6447
  case MYSQL_TYPE_VARCHAR:
 
6448
  case MYSQL_TYPE_NEWDECIMAL:
 
6449
  case MYSQL_TYPE_ENUM:
 
6450
  case MYSQL_TYPE_SET:
 
6451
  case MYSQL_TYPE_TINY_BLOB:
 
6452
  case MYSQL_TYPE_MEDIUM_BLOB:
 
6453
  case MYSQL_TYPE_LONG_BLOB:
 
6454
  case MYSQL_TYPE_BLOB:
 
6455
  case MYSQL_TYPE_VAR_STRING:
 
6456
  case MYSQL_TYPE_STRING:
 
6457
  case MYSQL_TYPE_TINY:
6360
6458
    return 4;
6361
 
  case DRIZZLE_TYPE_LONG:
 
6459
  case MYSQL_TYPE_SHORT:
 
6460
    return 6;
 
6461
  case MYSQL_TYPE_LONG:
6362
6462
    return MY_INT32_NUM_DECIMAL_DIGITS;
6363
 
  case DRIZZLE_TYPE_DOUBLE:
 
6463
  case MYSQL_TYPE_FLOAT:
 
6464
    return 25;
 
6465
  case MYSQL_TYPE_DOUBLE:
6364
6466
    return 53;
6365
 
  case DRIZZLE_TYPE_NULL:
 
6467
  case MYSQL_TYPE_NULL:
6366
6468
    return 0;
6367
 
  case DRIZZLE_TYPE_LONGLONG:
 
6469
  case MYSQL_TYPE_LONGLONG:
6368
6470
    return 20;
6369
6471
  default:
6370
 
    assert(0); // we should never go there
 
6472
    DBUG_ASSERT(0); // we should never go there
6371
6473
    return 0;
6372
6474
  }
6373
6475
}
6383
6485
    created field
6384
6486
*/
6385
6487
 
6386
 
Field *Item_type_holder::make_field_by_type(Table *table)
 
6488
Field *Item_type_holder::make_field_by_type(TABLE *table)
6387
6489
{
6388
6490
  /*
6389
6491
    The field functions defines a field to be not null if null_ptr is not 0
6390
6492
  */
6391
 
  unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
 
6493
  uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
6392
6494
  Field *field;
6393
6495
 
6394
6496
  switch (fld_type) {
6395
 
  case DRIZZLE_TYPE_ENUM:
6396
 
    assert(enum_set_typelib);
6397
 
    field= new Field_enum((unsigned char *) 0, max_length, null_ptr, 0,
 
6497
  case MYSQL_TYPE_ENUM:
 
6498
    DBUG_ASSERT(enum_set_typelib);
 
6499
    field= new Field_enum((uchar *) 0, max_length, null_ptr, 0,
6398
6500
                          Field::NONE, name,
6399
6501
                          get_enum_pack_length(enum_set_typelib->count),
6400
6502
                          enum_set_typelib, collation.collation);
6401
6503
    if (field)
6402
6504
      field->init(table);
6403
6505
    return field;
6404
 
  case DRIZZLE_TYPE_NULL:
 
6506
  case MYSQL_TYPE_SET:
 
6507
    DBUG_ASSERT(enum_set_typelib);
 
6508
    field= new Field_set((uchar *) 0, max_length, null_ptr, 0,
 
6509
                         Field::NONE, name,
 
6510
                         get_set_pack_length(enum_set_typelib->count),
 
6511
                         enum_set_typelib, collation.collation);
 
6512
    if (field)
 
6513
      field->init(table);
 
6514
    return field;
 
6515
  case MYSQL_TYPE_NULL:
6405
6516
    return make_string_field(table);
6406
6517
  default:
6407
6518
    break;
6418
6529
*/
6419
6530
void Item_type_holder::get_full_info(Item *item)
6420
6531
{
6421
 
  if (fld_type == DRIZZLE_TYPE_ENUM)
 
6532
  if (fld_type == MYSQL_TYPE_ENUM ||
 
6533
      fld_type == MYSQL_TYPE_SET)
6422
6534
  {
6423
6535
    if (item->type() == Item::SUM_FUNC_ITEM &&
6424
6536
        (((Item_sum*)item)->sum_func() == Item_sum::MAX_FUNC ||
6428
6540
      We can have enum/set type after merging only if we have one enum|set
6429
6541
      field (or MIN|MAX(enum|set field)) and number of NULL fields
6430
6542
    */
6431
 
    assert((enum_set_typelib &&
6432
 
                 get_real_type(item) == DRIZZLE_TYPE_NULL) ||
 
6543
    DBUG_ASSERT((enum_set_typelib &&
 
6544
                 get_real_type(item) == MYSQL_TYPE_NULL) ||
6433
6545
                (!enum_set_typelib &&
6434
6546
                 item->type() == Item::FIELD_ITEM &&
6435
 
                 (get_real_type(item) == DRIZZLE_TYPE_ENUM) &&
 
6547
                 (get_real_type(item) == MYSQL_TYPE_ENUM ||
 
6548
                  get_real_type(item) == MYSQL_TYPE_SET) &&
6436
6549
                 ((Field_enum*)((Item_field *) item)->field)->typelib));
6437
6550
    if (!enum_set_typelib)
6438
6551
    {
6444
6557
 
6445
6558
double Item_type_holder::val_real()
6446
6559
{
6447
 
  assert(0); // should never be called
 
6560
  DBUG_ASSERT(0); // should never be called
6448
6561
  return 0.0;
6449
6562
}
6450
6563
 
6451
6564
 
6452
 
int64_t Item_type_holder::val_int()
 
6565
longlong Item_type_holder::val_int()
6453
6566
{
6454
 
  assert(0); // should never be called
 
6567
  DBUG_ASSERT(0); // should never be called
6455
6568
  return 0;
6456
6569
}
6457
6570
 
6458
6571
my_decimal *Item_type_holder::val_decimal(my_decimal *)
6459
6572
{
6460
 
  assert(0); // should never be called
 
6573
  DBUG_ASSERT(0); // should never be called
6461
6574
  return 0;
6462
6575
}
6463
6576
 
6464
6577
String *Item_type_holder::val_str(String*)
6465
6578
{
6466
 
  assert(0); // should never be called
 
6579
  DBUG_ASSERT(0); // should never be called
6467
6580
  return 0;
6468
6581
}
6469
6582
 
6470
6583
void Item_result_field::cleanup()
6471
6584
{
 
6585
  DBUG_ENTER("Item_result_field::cleanup()");
6472
6586
  Item::cleanup();
6473
6587
  result_field= 0;
6474
 
  return;
 
6588
  DBUG_VOID_RETURN;
6475
6589
}
6476
6590
 
6477
6591
/**
6481
6595
    do nothing
6482
6596
*/
6483
6597
 
6484
 
void dummy_error_processor(THD *thd __attribute__((unused)),
6485
 
                           void *data __attribute__((unused)))
 
6598
void dummy_error_processor(THD *thd, void *data)
6486
6599
{}
6487
6600
 
6488
6601
/**