~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/item.cc

Removed/replaced DBUG symbols and standardized TRUE/FALSE

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 <m_ctype.h>
 
22
#include "my_dir.h"
 
23
#include "sql_select.h"
20
24
 
21
25
const String my_null_string("NULL", 4, default_charset_info);
22
26
 
40
44
 
41
45
my_decimal *
42
46
Hybrid_type_traits::val_decimal(Hybrid_type *val,
43
 
                                my_decimal *to __attribute__((unused))) const
 
47
                                my_decimal *to __attribute__((__unused__))) 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]);
144
148
 
145
149
void
146
150
Hybrid_type_traits_integer::fix_length_and_dec(Item *item,
147
 
                                               Item *arg __attribute__((unused))) const
 
151
                                               Item *arg __attribute__((__unused__))) const
148
152
{
149
153
  item->decimals= 0;
150
154
  item->max_length= MY_INT64_NUM_DECIMAL_DIGITS;
161
165
 
162
166
void item_init(void)
163
167
{
 
168
  uuid_short_init();
164
169
}
165
170
 
166
171
 
187
192
    return val_real() != 0.0;
188
193
  case ROW_RESULT:
189
194
  default:
190
 
    assert(0);
 
195
    DBUG_ASSERT(0);
191
196
    return 0;                                   // Wrong (but safe)
192
197
  }
193
198
}
205
210
 
206
211
String *Item::val_string_from_int(String *str)
207
212
{
208
 
  int64_t nr= val_int();
 
213
  longlong nr= val_int();
209
214
  if (null_value)
210
215
    return 0;
211
216
  str->set_int(nr, unsigned_flag, &my_charset_bin);
236
241
 
237
242
my_decimal *Item::val_decimal_from_int(my_decimal *decimal_value)
238
243
{
239
 
  int64_t nr= val_int();
 
244
  longlong nr= val_int();
240
245
  if (null_value)
241
246
    return 0;
242
247
  int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
256
261
                     res->ptr(), res->length(), res->charset(),
257
262
                     decimal_value) & E_DEC_BAD_NUM)
258
263
  {
259
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
264
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
260
265
                        ER_TRUNCATED_WRONG_VALUE,
261
266
                        ER(ER_TRUNCATED_WRONG_VALUE), "DECIMAL",
262
267
                        str_value.c_ptr());
267
272
 
268
273
my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value)
269
274
{
270
 
  assert(fixed == 1);
271
 
  DRIZZLE_TIME ltime;
 
275
  DBUG_ASSERT(fixed == 1);
 
276
  MYSQL_TIME ltime;
272
277
  if (get_date(&ltime, TIME_FUZZY_DATE))
273
278
  {
274
279
    my_decimal_set_zero(decimal_value);
281
286
 
282
287
my_decimal *Item::val_decimal_from_time(my_decimal *decimal_value)
283
288
{
284
 
  assert(fixed == 1);
285
 
  DRIZZLE_TIME ltime;
 
289
  DBUG_ASSERT(fixed == 1);
 
290
  MYSQL_TIME ltime;
286
291
  if (get_time(&ltime))
287
292
  {
288
293
    my_decimal_set_zero(decimal_value);
304
309
}
305
310
 
306
311
 
307
 
int64_t Item::val_int_from_decimal()
 
312
longlong Item::val_int_from_decimal()
308
313
{
309
314
  /* Note that fix_fields may not be called for Item_avg_field items */
310
 
  int64_t result;
 
315
  longlong result;
311
316
  my_decimal value, *dec_val= val_decimal(&value);
312
317
  if (null_value)
313
318
    return 0;
317
322
 
318
323
int Item::save_time_in_field(Field *field)
319
324
{
320
 
  DRIZZLE_TIME ltime;
 
325
  MYSQL_TIME ltime;
321
326
  if (get_time(&ltime))
322
327
    return set_field_to_null(field);
323
328
  field->set_notnull();
324
 
  return field->store_time(&ltime, DRIZZLE_TIMESTAMP_TIME);
 
329
  return field->store_time(&ltime, MYSQL_TIMESTAMP_TIME);
325
330
}
326
331
 
327
332
 
328
333
int Item::save_date_in_field(Field *field)
329
334
{
330
 
  DRIZZLE_TIME ltime;
 
335
  MYSQL_TIME ltime;
331
336
  if (get_date(&ltime, TIME_FUZZY_DATE))
332
337
    return set_field_to_null(field);
333
338
  field->set_notnull();
334
 
  return field->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
 
339
  return field->store_time(&ltime, MYSQL_TIMESTAMP_DATETIME);
335
340
}
336
341
 
337
342
 
372
377
  collation(&my_charset_bin, DERIVATION_COERCIBLE)
373
378
{
374
379
  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;
 
380
  maybe_null=null_value=with_sum_func=unsigned_flag=0;
 
381
  decimals= 0; max_length= 0;
381
382
  with_subselect= 0;
382
383
  cmp_context= (Item_result)-1;
383
384
 
429
430
}
430
431
 
431
432
 
432
 
uint32_t Item::decimal_precision() const
 
433
uint Item::decimal_precision() const
433
434
{
434
435
  Item_result restype= result_type();
435
436
 
436
437
  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);
 
438
    return min(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
 
439
               DECIMAL_MAX_PRECISION);
 
440
  return min(max_length, DECIMAL_MAX_PRECISION);
440
441
}
441
442
 
442
443
 
455
456
 
456
457
void Item::cleanup()
457
458
{
 
459
  DBUG_ENTER("Item::cleanup");
458
460
  fixed=0;
459
461
  marker= 0;
460
462
  if (orig_name)
461
463
    name= orig_name;
462
 
  return;
 
464
  DBUG_VOID_RETURN;
463
465
}
464
466
 
465
467
 
469
471
  @param arg   a dummy parameter, is not used here
470
472
*/
471
473
 
472
 
bool Item::cleanup_processor(unsigned char *arg __attribute__((unused)))
 
474
bool Item::cleanup_processor(uchar *arg __attribute__((__unused__)))
473
475
{
474
476
  if (fixed)
475
477
    cleanup();
524
526
    pointer to newly allocated item is returned.
525
527
*/
526
528
 
527
 
Item* Item::transform(Item_transformer transformer, unsigned char *arg)
 
529
Item* Item::transform(Item_transformer transformer, uchar *arg)
528
530
{
529
531
  return (this->*transformer)(arg);
530
532
}
565
567
 
566
568
void Item_ident::cleanup()
567
569
{
 
570
  DBUG_ENTER("Item_ident::cleanup");
568
571
#ifdef CANT_BE_USED_AS_MEMORY_IS_FREED
569
572
                       db_name ? db_name : "(null)",
570
573
                       orig_db_name ? orig_db_name : "(null)",
578
581
  table_name= orig_table_name;
579
582
  field_name= orig_field_name;
580
583
  depended_from= 0;
581
 
  return;
 
584
  DBUG_VOID_RETURN;
582
585
}
583
586
 
584
 
bool Item_ident::remove_dependence_processor(unsigned char * arg)
 
587
bool Item_ident::remove_dependence_processor(uchar * arg)
585
588
{
 
589
  DBUG_ENTER("Item_ident::remove_dependence_processor");
586
590
  if (depended_from == (st_select_lex *) arg)
587
591
    depended_from= 0;
588
 
  return(0);
 
592
  DBUG_RETURN(0);
589
593
}
590
594
 
591
595
 
607
611
    for the subsequent items.
608
612
*/
609
613
 
610
 
bool Item_field::collect_item_field_processor(unsigned char *arg)
 
614
bool Item_field::collect_item_field_processor(uchar *arg)
611
615
{
 
616
  DBUG_ENTER("Item_field::collect_item_field_processor");
 
617
  DBUG_PRINT("info", ("%s", field->field_name ? field->field_name : "noname"));
612
618
  List<Item_field> *item_list= (List<Item_field>*) arg;
613
619
  List_iterator<Item_field> item_list_it(*item_list);
614
620
  Item_field *curr_item;
615
621
  while ((curr_item= item_list_it++))
616
622
  {
617
623
    if (curr_item->eq(this, 1))
618
 
      return(false); /* Already in the set. */
 
624
      DBUG_RETURN(false); /* Already in the set. */
619
625
  }
620
626
  item_list->push_back(this);
621
 
  return(false);
 
627
  DBUG_RETURN(false);
622
628
}
623
629
 
624
630
 
638
644
    false otherwise
639
645
*/
640
646
 
641
 
bool Item_field::find_item_in_field_list_processor(unsigned char *arg)
 
647
bool Item_field::find_item_in_field_list_processor(uchar *arg)
642
648
{
643
649
  KEY_PART_INFO *first_non_group_part= *((KEY_PART_INFO **) arg);
644
650
  KEY_PART_INFO *last_part= *(((KEY_PART_INFO **) arg) + 1);
661
667
    column read set or to register used fields in a view
662
668
*/
663
669
 
664
 
bool Item_field::register_field_in_read_map(unsigned char *arg)
 
670
bool Item_field::register_field_in_read_map(uchar *arg)
665
671
{
666
 
  Table *table= (Table *) arg;
 
672
  TABLE *table= (TABLE *) arg;
667
673
  if (field->table == table || !table)
668
674
    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
675
  return 0;
673
676
}
674
677
 
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)
 
678
 
 
679
bool Item::check_cols(uint c)
690
680
{
691
681
  if (c != 1)
692
682
  {
697
687
}
698
688
 
699
689
 
700
 
void Item::set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs)
 
690
void Item::set_name(const char *str, uint length, CHARSET_INFO *cs)
701
691
{
702
692
  if (!length)
703
693
  {
708
698
  }
709
699
  if (cs->ctype)
710
700
  {
711
 
    uint32_t orig_len= length;
 
701
    uint orig_len= length;
712
702
    /*
713
703
      This will probably need a better implementation in the future:
714
704
      a function in CHARSET_INFO structure.
721
711
    if (orig_len != length && !is_autogenerated_name)
722
712
    {
723
713
      if (length == 0)
724
 
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
714
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
725
715
                            ER_NAME_BECOMES_EMPTY, ER(ER_NAME_BECOMES_EMPTY),
726
716
                            str + length - orig_len);
727
717
      else
728
 
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
718
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
729
719
                            ER_REMOVED_SPACES, ER(ER_REMOVED_SPACES),
730
720
                            str + length - orig_len);
731
721
    }
738
728
                                   &res_length);
739
729
  }
740
730
  else
741
 
    name= sql_strmake(str, (name_length= cmin(length,(unsigned int)MAX_ALIAS_NAME)));
 
731
    name= sql_strmake(str, (name_length= min(length,MAX_ALIAS_NAME)));
742
732
}
743
733
 
744
734
 
746
736
  @details
747
737
  This function is called when:
748
738
  - 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
 
739
  - When trying to find an ORDER BY/GROUP BY item in the SELECT part
750
740
*/
751
741
 
752
 
bool Item::eq(const Item *item, bool binary_cmp __attribute__((unused))) const
 
742
bool Item::eq(const Item *item, bool binary_cmp __attribute__((__unused__))) const
753
743
{
754
744
  /*
755
745
    Note, that this is never true if item is a Item_param:
761
751
}
762
752
 
763
753
 
764
 
Item *Item::safe_charset_converter(const CHARSET_INFO * const tocs)
 
754
Item *Item::safe_charset_converter(CHARSET_INFO *tocs)
765
755
{
766
756
  Item_func_conv_charset *conv= new Item_func_conv_charset(this, tocs, 1);
767
757
  return conv->safe ? conv : NULL;
779
769
  the latter returns a non-fixed Item, so val_str() crashes afterwards.
780
770
  Override Item_num method, to return a fixed item.
781
771
*/
782
 
Item *Item_num::safe_charset_converter(const CHARSET_INFO * const tocs __attribute__((unused)))
 
772
Item *Item_num::safe_charset_converter(CHARSET_INFO *tocs __attribute__((__unused__)))
783
773
{
784
774
  Item_string *conv;
785
775
  char buf[64];
794
784
}
795
785
 
796
786
 
797
 
Item *Item_static_float_func::safe_charset_converter(const CHARSET_INFO * const tocs __attribute__((unused)))
 
787
Item *Item_static_float_func::safe_charset_converter(CHARSET_INFO *tocs __attribute__((__unused__)))
798
788
{
799
789
  Item_string *conv;
800
790
  char buf[64];
810
800
}
811
801
 
812
802
 
813
 
Item *Item_string::safe_charset_converter(const CHARSET_INFO * const tocs)
 
803
Item *Item_string::safe_charset_converter(CHARSET_INFO *tocs)
814
804
{
815
805
  Item_string *conv;
816
 
  uint32_t conv_errors;
 
806
  uint conv_errors;
817
807
  char *ptr;
818
808
  String tmp, cstr, *ostr= val_str(&tmp);
819
809
  cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
838
828
}
839
829
 
840
830
 
841
 
Item *Item_param::safe_charset_converter(const CHARSET_INFO * const tocs)
 
831
Item *Item_param::safe_charset_converter(CHARSET_INFO *tocs)
842
832
{
843
833
  if (const_item())
844
834
  {
845
 
    uint32_t cnv_errors;
 
835
    uint cnv_errors;
846
836
    String *ostr= val_str(&cnvstr);
847
837
    cnvitem->str_value.copy(ostr->ptr(), ostr->length(),
848
838
                            ostr->charset(), tocs, &cnv_errors);
856
846
}
857
847
 
858
848
 
859
 
Item *Item_static_string_func::safe_charset_converter(const CHARSET_INFO * const tocs)
 
849
Item *Item_static_string_func::safe_charset_converter(CHARSET_INFO *tocs)
860
850
{
861
851
  Item_string *conv;
862
 
  uint32_t conv_errors;
 
852
  uint conv_errors;
863
853
  String tmp, cstr, *ostr= val_str(&tmp);
864
854
  cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
865
855
  if (conv_errors ||
897
887
 
898
888
 
899
889
/**
900
 
  Get the value of the function as a DRIZZLE_TIME structure.
 
890
  Get the value of the function as a MYSQL_TIME structure.
901
891
  As a extra convenience the time structure is reset on error!
902
892
*/
903
893
 
904
 
bool Item::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
894
bool Item::get_date(MYSQL_TIME *ltime,uint fuzzydate)
905
895
{
906
896
  if (result_type() == STRING_RESULT)
907
897
  {
909
899
    String tmp(buff,sizeof(buff), &my_charset_bin),*res;
910
900
    if (!(res=val_str(&tmp)) ||
911
901
        str_to_datetime_with_warn(res->ptr(), res->length(),
912
 
                                  ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
 
902
                                  ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR)
913
903
      goto err;
914
904
  }
915
905
  else
916
906
  {
917
 
    int64_t value= val_int();
 
907
    longlong value= val_int();
918
908
    int was_cut;
919
 
    if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1L)
 
909
    if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1LL)
920
910
    {
921
911
      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);
 
912
      end= longlong10_to_str(value, buff, -10);
 
913
      make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
914
                                   buff, (int) (end-buff), MYSQL_TIMESTAMP_NONE,
 
915
                                   NullS);
926
916
      goto err;
927
917
    }
928
918
  }
929
919
  return 0;
930
920
 
931
921
err:
932
 
  memset(ltime, 0, sizeof(*ltime));
 
922
  bzero((char*) ltime,sizeof(*ltime));
933
923
  return 1;
934
924
}
935
925
 
939
929
  As a extra convenience the time structure is reset on error!
940
930
*/
941
931
 
942
 
bool Item::get_time(DRIZZLE_TIME *ltime)
 
932
bool Item::get_time(MYSQL_TIME *ltime)
943
933
{
944
934
  char buff[40];
945
935
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
946
936
  if (!(res=val_str(&tmp)) ||
947
937
      str_to_time_with_warn(res->ptr(), res->length(), ltime))
948
938
  {
949
 
    memset(ltime, 0, sizeof(*ltime));
 
939
    bzero((char*) ltime,sizeof(*ltime));
950
940
    return 1;
951
941
  }
952
942
  return 0;
953
943
}
954
944
 
955
 
const CHARSET_INFO *Item::default_charset()
 
945
CHARSET_INFO *Item::default_charset()
956
946
{
957
947
  return current_thd->variables.collation_connection;
958
948
}
969
959
int Item::save_in_field_no_warnings(Field *field, bool no_conversions)
970
960
{
971
961
  int res;
972
 
  Table *table= field->table;
 
962
  TABLE *table= field->table;
973
963
  THD *thd= table->in_use;
974
964
  enum_check_fields tmp= thd->count_cuted_fields;
 
965
  my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
975
966
  ulong sql_mode= thd->variables.sql_mode;
976
 
  thd->variables.sql_mode&= ~(MODE_NO_ZERO_DATE);
 
967
  thd->variables.sql_mode&= ~(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE);
977
968
  thd->count_cuted_fields= CHECK_FIELD_IGNORE;
978
969
  res= save_in_field(field, no_conversions);
979
970
  thd->count_cuted_fields= tmp;
 
971
  dbug_tmp_restore_column_map(table->write_set, old_map);
980
972
  thd->variables.sql_mode= sql_mode;
981
973
  return res;
982
974
}
1055
1047
      Item_ref to allow fields from view being stored in tmp table.
1056
1048
    */
1057
1049
    Item_aggregate_ref *item_ref;
1058
 
    uint32_t el= fields.elements;
 
1050
    uint el= fields.elements;
1059
1051
    Item *real_itm= real_item();
1060
1052
 
1061
1053
    ref_pointer_array[el]= real_itm;
1125
1117
  @endcode
1126
1118
*/
1127
1119
 
1128
 
bool DTCollation::aggregate(DTCollation &dt, uint32_t flags)
 
1120
bool DTCollation::aggregate(DTCollation &dt, uint flags)
1129
1121
{
1130
1122
  if (!my_charset_same(collation, dt.collation))
1131
1123
  {
1212
1204
        set(dt);
1213
1205
        return 0;
1214
1206
      }
1215
 
      const CHARSET_INFO * const bin= get_charset_by_csname(collation->csname, 
1216
 
                                                            MY_CS_BINSORT,MYF(0));
 
1207
      CHARSET_INFO *bin= get_charset_by_csname(collation->csname, 
 
1208
                                               MY_CS_BINSORT,MYF(0));
1217
1209
      set(bin, DERIVATION_NONE);
1218
1210
    }
1219
1211
  }
1245
1237
 
1246
1238
 
1247
1239
static
1248
 
void my_coll_agg_error(Item** args, uint32_t count, const char *fname,
 
1240
void my_coll_agg_error(Item** args, uint count, const char *fname,
1249
1241
                       int item_sep)
1250
1242
{
1251
1243
  if (count == 2)
1259
1251
 
1260
1252
 
1261
1253
bool agg_item_collations(DTCollation &c, const char *fname,
1262
 
                         Item **av, uint32_t count, uint32_t flags, int item_sep)
 
1254
                         Item **av, uint count, uint flags, int item_sep)
1263
1255
{
1264
 
  uint32_t i;
 
1256
  uint i;
1265
1257
  Item **arg;
1266
1258
  c.set(av[0]->collation);
1267
1259
  for (i= 1, arg= &av[item_sep]; i < count; i++, arg++)
1283
1275
 
1284
1276
 
1285
1277
bool agg_item_collations_for_comparison(DTCollation &c, const char *fname,
1286
 
                                        Item **av, uint32_t count, uint32_t flags)
 
1278
                                        Item **av, uint count, uint flags)
1287
1279
{
1288
1280
  return (agg_item_collations(c, fname, av, count,
1289
1281
                              flags | MY_COLL_DISALLOW_NONE, 1));
1322
1314
*/
1323
1315
 
1324
1316
bool agg_item_charsets(DTCollation &coll, const char *fname,
1325
 
                       Item **args, uint32_t nargs, uint32_t flags, int item_sep)
 
1317
                       Item **args, uint nargs, uint flags, int item_sep)
1326
1318
{
1327
1319
  Item **arg, *safe_args[2];
1328
1320
 
1345
1337
  }
1346
1338
 
1347
1339
  THD *thd= current_thd;
 
1340
  Query_arena *arena, backup;
1348
1341
  bool res= false;
1349
 
  uint32_t i;
 
1342
  uint i;
 
1343
  /*
 
1344
    In case we're in statement prepare, create conversion item
 
1345
    in its memory: it will be reused on each execute.
 
1346
  */
 
1347
  arena= NULL;
1350
1348
 
1351
1349
  for (i= 0, arg= args; i < nargs; i++, arg+= item_sep)
1352
1350
  {
1353
1351
    Item* conv;
1354
 
    uint32_t dummy_offset;
 
1352
    uint32 dummy_offset;
1355
1353
    if (!String::needs_conversion(0, (*arg)->collation.collation,
1356
1354
                                  coll.collation,
1357
1355
                                  &dummy_offset))
1392
1390
    */
1393
1391
    conv->fix_fields(thd, arg);
1394
1392
  }
1395
 
 
 
1393
  if (arena)
 
1394
    thd->restore_active_arena(arena, &backup);
1396
1395
  return res;
1397
1396
}
1398
1397
 
1413
1412
/**********************************************/
1414
1413
 
1415
1414
Item_field::Item_field(Field *f)
1416
 
  :Item_ident(0, NULL, *f->table_name, f->field_name),
 
1415
  :Item_ident(0, NullS, *f->table_name, f->field_name),
1417
1416
   item_equal(0), no_const_subst(0),
1418
1417
   have_privileges(0), any_privileges(0)
1419
1418
{
1433
1432
  Item_field (this is important in prepared statements).
1434
1433
*/
1435
1434
 
1436
 
Item_field::Item_field(THD *thd __attribute__((unused)),
 
1435
Item_field::Item_field(THD *thd __attribute__((__unused__)),
1437
1436
                       Name_resolution_context *context_arg,
1438
1437
                       Field *f)
1439
1438
  :Item_ident(context_arg, f->table->s->db.str, *f->table_name, f->field_name),
1513
1512
  {
1514
1513
    tmp=(char*) sql_alloc((uint) strlen(db_name)+(uint) strlen(table_name)+
1515
1514
                          (uint) strlen(field_name)+3);
1516
 
    strxmov(tmp,db_name,".",table_name,".",field_name,NULL);
 
1515
    strxmov(tmp,db_name,".",table_name,".",field_name,NullS);
1517
1516
  }
1518
1517
  else
1519
1518
  {
1521
1520
    {
1522
1521
      tmp= (char*) sql_alloc((uint) strlen(table_name) +
1523
1522
                             (uint) strlen(field_name) + 2);
1524
 
      strxmov(tmp, table_name, ".", field_name, NULL);
 
1523
      strxmov(tmp, table_name, ".", field_name, NullS);
1525
1524
    }
1526
1525
    else
1527
1526
      tmp= (char*) field_name;
1530
1529
}
1531
1530
 
1532
1531
void Item_ident::print(String *str,
1533
 
                       enum_query_type query_type __attribute__((unused)))
 
1532
                       enum_query_type query_type __attribute__((__unused__)))
1534
1533
{
1535
1534
  THD *thd= current_thd;
1536
1535
  char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
1540
1539
  {
1541
1540
    if (table_name && table_name[0])
1542
1541
    {
1543
 
      my_stpcpy(t_name_buff, table_name);
 
1542
      strmov(t_name_buff, table_name);
1544
1543
      my_casedn_str(files_charset_info, t_name_buff);
1545
1544
      t_name= t_name_buff;
1546
1545
    }
1547
1546
    if (db_name && db_name[0])
1548
1547
    {
1549
 
      my_stpcpy(d_name_buff, db_name);
 
1548
      strmov(d_name_buff, db_name);
1550
1549
      my_casedn_str(files_charset_info, d_name_buff);
1551
1550
      d_name= d_name_buff;
1552
1551
    }
1585
1584
/* ARGSUSED */
1586
1585
String *Item_field::val_str(String *str)
1587
1586
{
1588
 
  assert(fixed == 1);
 
1587
  DBUG_ASSERT(fixed == 1);
1589
1588
  if ((null_value=field->is_null()))
1590
1589
    return 0;
1591
1590
  str->set_charset(str_value.charset());
1595
1594
 
1596
1595
double Item_field::val_real()
1597
1596
{
1598
 
  assert(fixed == 1);
 
1597
  DBUG_ASSERT(fixed == 1);
1599
1598
  if ((null_value=field->is_null()))
1600
1599
    return 0.0;
1601
1600
  return field->val_real();
1602
1601
}
1603
1602
 
1604
1603
 
1605
 
int64_t Item_field::val_int()
 
1604
longlong Item_field::val_int()
1606
1605
{
1607
 
  assert(fixed == 1);
 
1606
  DBUG_ASSERT(fixed == 1);
1608
1607
  if ((null_value=field->is_null()))
1609
1608
    return 0;
1610
1609
  return field->val_int();
1627
1626
  return result_field->val_str(str,&str_value);
1628
1627
}
1629
1628
 
1630
 
bool Item_field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
1629
bool Item_field::get_date(MYSQL_TIME *ltime,uint fuzzydate)
1631
1630
{
1632
1631
  if ((null_value=field->is_null()) || field->get_date(ltime,fuzzydate))
1633
1632
  {
1634
 
    memset(ltime, 0, sizeof(*ltime));
 
1633
    bzero((char*) ltime,sizeof(*ltime));
1635
1634
    return 1;
1636
1635
  }
1637
1636
  return 0;
1638
1637
}
1639
1638
 
1640
 
bool Item_field::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
1639
bool Item_field::get_date_result(MYSQL_TIME *ltime,uint fuzzydate)
1641
1640
{
1642
1641
  if ((null_value=result_field->is_null()) ||
1643
1642
      result_field->get_date(ltime,fuzzydate))
1644
1643
  {
1645
 
    memset(ltime, 0, sizeof(*ltime));
 
1644
    bzero((char*) ltime,sizeof(*ltime));
1646
1645
    return 1;
1647
1646
  }
1648
1647
  return 0;
1649
1648
}
1650
1649
 
1651
 
bool Item_field::get_time(DRIZZLE_TIME *ltime)
 
1650
bool Item_field::get_time(MYSQL_TIME *ltime)
1652
1651
{
1653
1652
  if ((null_value=field->is_null()) || field->get_time(ltime))
1654
1653
  {
1655
 
    memset(ltime, 0, sizeof(*ltime));
 
1654
    bzero((char*) ltime,sizeof(*ltime));
1656
1655
    return 1;
1657
1656
  }
1658
1657
  return 0;
1665
1664
  return result_field->val_real();
1666
1665
}
1667
1666
 
1668
 
int64_t Item_field::val_int_result()
 
1667
longlong Item_field::val_int_result()
1669
1668
{
1670
1669
  if ((null_value=result_field->is_null()))
1671
1670
    return 0;
1701
1700
    return result_field->val_real() != 0.0;
1702
1701
  case ROW_RESULT:
1703
1702
  default:
1704
 
    assert(0);
 
1703
    DBUG_ASSERT(0);
1705
1704
    return 0;                                   // Shut up compiler
1706
1705
  }
1707
1706
}
1708
1707
 
1709
1708
 
1710
1709
bool Item_field::eq(const Item *item,
1711
 
                    bool binary_cmp __attribute__((unused))) const
 
1710
                    bool binary_cmp __attribute__((__unused__))) const
1712
1711
{
1713
1712
  Item *real_item= ((Item *) item)->real_item();
1714
1713
  if (real_item->type() != FIELD_ITEM)
1747
1746
 
1748
1747
 
1749
1748
void Item_field::fix_after_pullout(st_select_lex *new_parent,
1750
 
                                   Item **ref __attribute__((unused)))
 
1749
                                   Item **ref __attribute__((__unused__)))
1751
1750
{
1752
1751
  if (new_parent == depended_from)
1753
1752
    depended_from= NULL;
1768
1767
  return new_item;
1769
1768
}
1770
1769
 
1771
 
int64_t Item_field::val_int_endpoint(bool left_endp __attribute__((unused)),
1772
 
                                      bool *incl_endp __attribute__((unused)))
 
1770
longlong Item_field::val_int_endpoint(bool left_endp __attribute__((__unused__)),
 
1771
                                      bool *incl_endp __attribute__((__unused__)))
1773
1772
{
1774
 
  int64_t res= val_int();
1775
 
  return null_value? INT64_MIN : res;
 
1773
  longlong res= val_int();
 
1774
  return null_value? LONGLONG_MIN : res;
1776
1775
}
1777
1776
 
1778
1777
/**
1779
 
  Create an item from a string we KNOW points to a valid int64_t
 
1778
  Create an item from a string we KNOW points to a valid longlong
1780
1779
  end \\0 terminated number string.
1781
1780
  This is always 'signed'. Unsigned values are created with Item_uint()
1782
1781
*/
1783
1782
 
1784
 
Item_int::Item_int(const char *str_arg, uint32_t length)
 
1783
Item_int::Item_int(const char *str_arg, uint length)
1785
1784
{
1786
1785
  char *end_ptr= (char*) str_arg + length;
1787
1786
  int error;
1801
1800
String *Item_int::val_str(String *str)
1802
1801
{
1803
1802
  // following assert is redundant, because fixed=1 assigned in constructor
1804
 
  assert(fixed == 1);
 
1803
  DBUG_ASSERT(fixed == 1);
1805
1804
  str->set(value, &my_charset_bin);
1806
1805
  return str;
1807
1806
}
1808
1807
 
1809
1808
void Item_int::print(String *str,
1810
 
                     enum_query_type query_type __attribute__((unused)))
 
1809
                     enum_query_type query_type __attribute__((__unused__)))
1811
1810
{
1812
1811
  // my_charset_bin is good enough for numbers
1813
1812
  str_value.set(value, &my_charset_bin);
1815
1814
}
1816
1815
 
1817
1816
 
1818
 
Item_uint::Item_uint(const char *str_arg, uint32_t length):
 
1817
Item_uint::Item_uint(const char *str_arg, uint length):
1819
1818
  Item_int(str_arg, length)
1820
1819
{
1821
1820
  unsigned_flag= 1;
1822
1821
}
1823
1822
 
1824
1823
 
1825
 
Item_uint::Item_uint(const char *str_arg, int64_t i, uint32_t length):
 
1824
Item_uint::Item_uint(const char *str_arg, longlong i, uint length):
1826
1825
  Item_int(str_arg, i, length)
1827
1826
{
1828
1827
  unsigned_flag= 1;
1832
1831
String *Item_uint::val_str(String *str)
1833
1832
{
1834
1833
  // following assert is redundant, because fixed=1 assigned in constructor
1835
 
  assert(fixed == 1);
1836
 
  str->set((uint64_t) value, &my_charset_bin);
 
1834
  DBUG_ASSERT(fixed == 1);
 
1835
  str->set((ulonglong) value, &my_charset_bin);
1837
1836
  return str;
1838
1837
}
1839
1838
 
1840
1839
 
1841
1840
void Item_uint::print(String *str,
1842
 
                      enum_query_type query_type __attribute__((unused)))
 
1841
                      enum_query_type query_type __attribute__((__unused__)))
1843
1842
{
1844
1843
  // latin1 is good enough for numbers
1845
 
  str_value.set((uint64_t) value, default_charset());
 
1844
  str_value.set((ulonglong) value, default_charset());
1846
1845
  str->append(str_value);
1847
1846
}
1848
1847
 
1849
1848
 
1850
 
Item_decimal::Item_decimal(const char *str_arg, uint32_t length,
1851
 
                           const CHARSET_INFO * const charset)
 
1849
Item_decimal::Item_decimal(const char *str_arg, uint length,
 
1850
                           CHARSET_INFO *charset)
1852
1851
{
1853
1852
  str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
1854
1853
  name= (char*) str_arg;
1855
 
  decimals= (uint8_t) decimal_value.frac;
 
1854
  decimals= (uint8) decimal_value.frac;
1856
1855
  fixed= 1;
1857
1856
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1858
1857
                                             decimals, unsigned_flag);
1859
1858
}
1860
1859
 
1861
 
Item_decimal::Item_decimal(int64_t val, bool unsig)
 
1860
Item_decimal::Item_decimal(longlong val, bool unsig)
1862
1861
{
1863
1862
  int2my_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
1864
 
  decimals= (uint8_t) decimal_value.frac;
 
1863
  decimals= (uint8) decimal_value.frac;
1865
1864
  fixed= 1;
1866
1865
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1867
1866
                                             decimals, unsigned_flag);
1869
1868
 
1870
1869
 
1871
1870
Item_decimal::Item_decimal(double val,
1872
 
                           int precision __attribute__((unused)),
1873
 
                           int scale __attribute__((unused)))
 
1871
                           int precision __attribute__((__unused__)),
 
1872
                           int scale __attribute__((__unused__)))
1874
1873
{
1875
1874
  double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
1876
 
  decimals= (uint8_t) decimal_value.frac;
 
1875
  decimals= (uint8) decimal_value.frac;
1877
1876
  fixed= 1;
1878
1877
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1879
1878
                                             decimals, unsigned_flag);
1881
1880
 
1882
1881
 
1883
1882
Item_decimal::Item_decimal(const char *str, const my_decimal *val_arg,
1884
 
                           uint32_t decimal_par, uint32_t length)
 
1883
                           uint decimal_par, uint length)
1885
1884
{
1886
1885
  my_decimal2decimal(val_arg, &decimal_value);
1887
1886
  name= (char*) str;
1888
 
  decimals= (uint8_t) decimal_par;
 
1887
  decimals= (uint8) decimal_par;
1889
1888
  max_length= length;
1890
1889
  fixed= 1;
1891
1890
}
1894
1893
Item_decimal::Item_decimal(my_decimal *value_par)
1895
1894
{
1896
1895
  my_decimal2decimal(value_par, &decimal_value);
1897
 
  decimals= (uint8_t) decimal_value.frac;
 
1896
  decimals= (uint8) decimal_value.frac;
1898
1897
  fixed= 1;
1899
1898
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1900
1899
                                             decimals, unsigned_flag);
1901
1900
}
1902
1901
 
1903
1902
 
1904
 
Item_decimal::Item_decimal(const unsigned char *bin, int precision, int scale)
 
1903
Item_decimal::Item_decimal(const uchar *bin, int precision, int scale)
1905
1904
{
1906
1905
  binary2my_decimal(E_DEC_FATAL_ERROR, bin,
1907
1906
                    &decimal_value, precision, scale);
1908
 
  decimals= (uint8_t) decimal_value.frac;
 
1907
  decimals= (uint8) decimal_value.frac;
1909
1908
  fixed= 1;
1910
1909
  max_length= my_decimal_precision_to_length(precision, decimals,
1911
1910
                                             unsigned_flag);
1912
1911
}
1913
1912
 
1914
1913
 
1915
 
int64_t Item_decimal::val_int()
 
1914
longlong Item_decimal::val_int()
1916
1915
{
1917
 
  int64_t result;
 
1916
  longlong result;
1918
1917
  my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &result);
1919
1918
  return result;
1920
1919
}
1934
1933
}
1935
1934
 
1936
1935
void Item_decimal::print(String *str,
1937
 
                         enum_query_type query_type __attribute__((unused)))
 
1936
                         enum_query_type query_type __attribute__((__unused__)))
1938
1937
{
1939
1938
  my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, &str_value);
1940
1939
  str->append(str_value);
1942
1941
 
1943
1942
 
1944
1943
bool Item_decimal::eq(const Item *item,
1945
 
                      bool binary_cmp __attribute__((unused))) const
 
1944
                      bool binary_cmp __attribute__((__unused__))) const
1946
1945
{
1947
1946
  if (type() == item->type() && item->basic_const_item())
1948
1947
  {
1963
1962
void Item_decimal::set_decimal_value(my_decimal *value_par)
1964
1963
{
1965
1964
  my_decimal2decimal(value_par, &decimal_value);
1966
 
  decimals= (uint8_t) decimal_value.frac;
 
1965
  decimals= (uint8) decimal_value.frac;
1967
1966
  unsigned_flag= !decimal_value.sign();
1968
1967
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1969
1968
                                             decimals, unsigned_flag);
1973
1972
String *Item_float::val_str(String *str)
1974
1973
{
1975
1974
  // following assert is redundant, because fixed=1 assigned in constructor
1976
 
  assert(fixed == 1);
 
1975
  DBUG_ASSERT(fixed == 1);
1977
1976
  str->set_real(value,decimals,&my_charset_bin);
1978
1977
  return str;
1979
1978
}
1982
1981
my_decimal *Item_float::val_decimal(my_decimal *decimal_value)
1983
1982
{
1984
1983
  // following assert is redundant, because fixed=1 assigned in constructor
1985
 
  assert(fixed == 1);
 
1984
  DBUG_ASSERT(fixed == 1);
1986
1985
  double2my_decimal(E_DEC_FATAL_ERROR, value, decimal_value);
1987
1986
  return (decimal_value);
1988
1987
}
2027
2026
 
2028
2027
double Item_string::val_real()
2029
2028
{
2030
 
  assert(fixed == 1);
 
2029
  DBUG_ASSERT(fixed == 1);
2031
2030
  int error;
2032
2031
  char *end, *org_end;
2033
2032
  double tmp;
2034
 
  const CHARSET_INFO * const cs= str_value.charset();
 
2033
  CHARSET_INFO *cs= str_value.charset();
2035
2034
 
2036
2035
  org_end= (char*) str_value.ptr() + str_value.length();
2037
2036
  tmp= my_strntod(cs, (char*) str_value.ptr(), str_value.length(), &end,
2042
2041
      We can use str_value.ptr() here as Item_string is gurantee to put an
2043
2042
      end \0 here.
2044
2043
    */
2045
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2044
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2046
2045
                        ER_TRUNCATED_WRONG_VALUE,
2047
2046
                        ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE",
2048
2047
                        str_value.ptr());
2055
2054
  @todo
2056
2055
  Give error if we wanted a signed integer and we got an unsigned one
2057
2056
*/
2058
 
int64_t Item_string::val_int()
 
2057
longlong Item_string::val_int()
2059
2058
{
2060
 
  assert(fixed == 1);
 
2059
  DBUG_ASSERT(fixed == 1);
2061
2060
  int err;
2062
 
  int64_t tmp;
 
2061
  longlong tmp;
2063
2062
  char *end= (char*) str_value.ptr()+ str_value.length();
2064
2063
  char *org_end= end;
2065
 
  const CHARSET_INFO * const cs= str_value.charset();
 
2064
  CHARSET_INFO *cs= str_value.charset();
2066
2065
 
2067
2066
  tmp= (*(cs->cset->strtoll10))(cs, str_value.ptr(), &end, &err);
2068
2067
  /*
2072
2071
  if (err > 0 ||
2073
2072
      (end != org_end && !check_if_only_end_space(cs, end, org_end)))
2074
2073
  {
2075
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2074
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2076
2075
                        ER_TRUNCATED_WRONG_VALUE,
2077
2076
                        ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
2078
2077
                        str_value.ptr());
2088
2087
 
2089
2088
 
2090
2089
bool Item_null::eq(const Item *item,
2091
 
                   bool binary_cmp __attribute__((unused))) const
 
2090
                   bool binary_cmp __attribute__((__unused__))) const
2092
2091
{ return item->type() == type(); }
2093
2092
 
2094
2093
 
2095
2094
double Item_null::val_real()
2096
2095
{
2097
2096
  // following assert is redundant, because fixed=1 assigned in constructor
2098
 
  assert(fixed == 1);
 
2097
  DBUG_ASSERT(fixed == 1);
2099
2098
  null_value=1;
2100
2099
  return 0.0;
2101
2100
}
2102
 
int64_t Item_null::val_int()
 
2101
longlong Item_null::val_int()
2103
2102
{
2104
2103
  // following assert is redundant, because fixed=1 assigned in constructor
2105
 
  assert(fixed == 1);
 
2104
  DBUG_ASSERT(fixed == 1);
2106
2105
  null_value=1;
2107
2106
  return 0;
2108
2107
}
2109
2108
/* ARGSUSED */
2110
 
String *Item_null::val_str(String *str __attribute__((unused)))
 
2109
String *Item_null::val_str(String *str __attribute__((__unused__)))
2111
2110
{
2112
2111
  // following assert is redundant, because fixed=1 assigned in constructor
2113
 
  assert(fixed == 1);
 
2112
  DBUG_ASSERT(fixed == 1);
2114
2113
  null_value=1;
2115
2114
  return 0;
2116
2115
}
2117
2116
 
2118
 
my_decimal *Item_null::val_decimal(my_decimal *decimal_value __attribute__((unused)))
 
2117
my_decimal *Item_null::val_decimal(my_decimal *decimal_value __attribute__((__unused__)))
2119
2118
{
2120
2119
  return 0;
2121
2120
}
2122
2121
 
2123
2122
 
2124
 
Item *Item_null::safe_charset_converter(const CHARSET_INFO * const tocs)
 
2123
Item *Item_null::safe_charset_converter(CHARSET_INFO *tocs)
2125
2124
{
2126
2125
  collation.set(tocs);
2127
2126
  return this;
2136
2135
 
2137
2136
static void
2138
2137
default_set_param_func(Item_param *param,
2139
 
                       unsigned char **pos __attribute__((unused)),
 
2138
                       uchar **pos __attribute__((unused)),
2140
2139
                       ulong len __attribute__((unused)))
2141
2140
{
2142
2141
  param->set_null();
2143
2142
}
2144
2143
 
2145
2144
 
2146
 
Item_param::Item_param(uint32_t pos_in_query_arg) :
 
2145
Item_param::Item_param(uint pos_in_query_arg) :
2147
2146
  state(NO_VALUE),
2148
2147
  item_result_type(STRING_RESULT),
2149
2148
  /* Don't pretend to be a literal unless value for this item is set. */
2150
2149
  item_type(PARAM_ITEM),
2151
 
  param_type(DRIZZLE_TYPE_VARCHAR),
 
2150
  param_type(MYSQL_TYPE_VARCHAR),
2152
2151
  pos_in_query(pos_in_query_arg),
2153
2152
  set_param_func(default_set_param_func),
2154
2153
  limit_clause_param(false)
2167
2166
 
2168
2167
void Item_param::set_null()
2169
2168
{
 
2169
  DBUG_ENTER("Item_param::set_null");
2170
2170
  /* These are cleared after each execution by reset() method */
2171
2171
  null_value= 1;
2172
2172
  /* 
2178
2178
  decimals= 0;
2179
2179
  state= NULL_VALUE;
2180
2180
  item_type= Item::NULL_ITEM;
2181
 
  return;
 
2181
  DBUG_VOID_RETURN;
2182
2182
}
2183
2183
 
2184
 
void Item_param::set_int(int64_t i, uint32_t max_length_arg)
 
2184
void Item_param::set_int(longlong i, uint32 max_length_arg)
2185
2185
{
2186
 
  value.integer= (int64_t) i;
 
2186
  DBUG_ENTER("Item_param::set_int");
 
2187
  value.integer= (longlong) i;
2187
2188
  state= INT_VALUE;
2188
2189
  max_length= max_length_arg;
2189
2190
  decimals= 0;
2190
2191
  maybe_null= 0;
2191
 
  return;
 
2192
  DBUG_VOID_RETURN;
2192
2193
}
2193
2194
 
2194
2195
void Item_param::set_double(double d)
2195
2196
{
 
2197
  DBUG_ENTER("Item_param::set_double");
2196
2198
  value.real= d;
2197
2199
  state= REAL_VALUE;
2198
2200
  max_length= DBL_DIG + 8;
2199
2201
  decimals= NOT_FIXED_DEC;
2200
2202
  maybe_null= 0;
2201
 
  return;
 
2203
  DBUG_VOID_RETURN;
2202
2204
}
2203
2205
 
2204
2206
 
2214
2216
    internal decimal value.
2215
2217
*/
2216
2218
 
2217
 
void Item_param::set_decimal(char *str, ulong length)
 
2219
void Item_param::set_decimal(const char *str, ulong length)
2218
2220
{
2219
2221
  char *end;
 
2222
  DBUG_ENTER("Item_param::set_decimal");
2220
2223
 
2221
 
  end= str+length;
2222
 
  str2my_decimal((uint)E_DEC_FATAL_ERROR, str, &decimal_value, &end);
 
2224
  end= (char*) str+length;
 
2225
  str2my_decimal(E_DEC_FATAL_ERROR, str, &decimal_value, &end);
2223
2226
  state= DECIMAL_VALUE;
2224
2227
  decimals= decimal_value.frac;
2225
2228
  max_length= my_decimal_precision_to_length(decimal_value.precision(),
2226
2229
                                             decimals, unsigned_flag);
2227
2230
  maybe_null= 0;
2228
 
  return;
 
2231
  DBUG_VOID_RETURN;
2229
2232
}
2230
2233
 
2231
2234
 
2232
2235
/**
2233
 
  Set parameter value from DRIZZLE_TIME value.
 
2236
  Set parameter value from MYSQL_TIME value.
2234
2237
 
2235
2238
  @param tm              datetime value to set (time_type is ignored)
2236
2239
  @param type            type of datetime value
2242
2245
    the fact that even wrong value sent over binary protocol fits into
2243
2246
    MAX_DATE_STRING_REP_LENGTH buffer.
2244
2247
*/
2245
 
void Item_param::set_time(DRIZZLE_TIME *tm,
2246
 
                          enum enum_drizzle_timestamp_type time_type,
2247
 
                          uint32_t max_length_arg)
 
2248
void Item_param::set_time(MYSQL_TIME *tm, timestamp_type time_type,
 
2249
                          uint32 max_length_arg)
2248
2250
 
2251
  DBUG_ENTER("Item_param::set_time");
 
2252
 
2249
2253
  value.time= *tm;
2250
2254
  value.time.time_type= time_type;
2251
2255
 
2252
2256
  if (value.time.year > 9999 || value.time.month > 12 ||
2253
2257
      value.time.day > 31 ||
2254
 
      ((time_type != DRIZZLE_TIMESTAMP_TIME) && value.time.hour > 23) ||
 
2258
      ((time_type != MYSQL_TIMESTAMP_TIME) && value.time.hour > 23) ||
2255
2259
      value.time.minute > 59 || value.time.second > 59)
2256
2260
  {
2257
2261
    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,
 
2262
    uint length= my_TIME_to_str(&value.time, buff);
 
2263
    make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2260
2264
                                 buff, length, time_type, 0);
2261
 
    set_zero_time(&value.time, DRIZZLE_TIMESTAMP_ERROR);
 
2265
    set_zero_time(&value.time, MYSQL_TIMESTAMP_ERROR);
2262
2266
  }
2263
2267
 
2264
2268
  state= TIME_VALUE;
2265
2269
  maybe_null= 0;
2266
2270
  max_length= max_length_arg;
2267
2271
  decimals= 0;
2268
 
  return;
 
2272
  DBUG_VOID_RETURN;
2269
2273
}
2270
2274
 
2271
2275
 
2272
2276
bool Item_param::set_str(const char *str, ulong length)
2273
2277
{
 
2278
  DBUG_ENTER("Item_param::set_str");
2274
2279
  /*
2275
2280
    Assign string with no conversion: data is converted only after it's
2276
2281
    been written to the binary log.
2277
2282
  */
2278
 
  uint32_t dummy_errors;
 
2283
  uint dummy_errors;
2279
2284
  if (str_value.copy(str, length, &my_charset_bin, &my_charset_bin,
2280
2285
                     &dummy_errors))
2281
 
    return(true);
 
2286
    DBUG_RETURN(true);
2282
2287
  state= STRING_VALUE;
2283
2288
  max_length= length;
2284
2289
  maybe_null= 0;
2285
2290
  /* max_length and decimals are set after charset conversion */
2286
 
  /* sic: str may be not null-terminated */
2287
 
  return(false);
 
2291
  /* sic: str may be not null-terminated, don't add DBUG_PRINT here */
 
2292
  DBUG_RETURN(false);
2288
2293
}
2289
2294
 
2290
2295
 
2291
2296
bool Item_param::set_longdata(const char *str, ulong length)
2292
2297
{
 
2298
  DBUG_ENTER("Item_param::set_longdata");
 
2299
 
2293
2300
  /*
2294
2301
    If client character set is multibyte, end of long data packet
2295
2302
    may hit at the middle of a multibyte character.  Additionally,
2300
2307
    write query to the binary log and only then perform conversion.
2301
2308
  */
2302
2309
  if (str_value.append(str, length, &my_charset_bin))
2303
 
    return(true);
 
2310
    DBUG_RETURN(true);
2304
2311
  state= LONG_DATA_VALUE;
2305
2312
  maybe_null= 0;
2306
2313
 
2307
 
  return(false);
 
2314
  DBUG_RETURN(false);
2308
2315
}
2309
2316
 
2310
2317
 
2322
2329
 
2323
2330
bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry)
2324
2331
{
 
2332
  DBUG_ENTER("Item_param::set_from_user_var");
2325
2333
  if (entry && entry->value)
2326
2334
  {
2327
2335
    item_result_type= entry->type;
2328
2336
    unsigned_flag= entry->unsigned_flag;
2329
2337
    if (limit_clause_param)
2330
2338
    {
2331
 
      bool unused;
 
2339
      my_bool unused;
2332
2340
      set_int(entry->val_int(&unused), MY_INT64_NUM_DECIMAL_DIGITS);
2333
2341
      item_type= Item::INT_ITEM;
2334
 
      return(!unsigned_flag && value.integer < 0 ? 1 : 0);
 
2342
      DBUG_RETURN(!unsigned_flag && value.integer < 0 ? 1 : 0);
2335
2343
    }
2336
2344
    switch (item_result_type) {
2337
2345
    case REAL_RESULT:
2339
2347
      item_type= Item::REAL_ITEM;
2340
2348
      break;
2341
2349
    case INT_RESULT:
2342
 
      set_int(*(int64_t*)entry->value, MY_INT64_NUM_DECIMAL_DIGITS);
 
2350
      set_int(*(longlong*)entry->value, MY_INT64_NUM_DECIMAL_DIGITS);
2343
2351
      item_type= Item::INT_ITEM;
2344
2352
      break;
2345
2353
    case STRING_RESULT:
2346
2354
    {
2347
 
      const CHARSET_INFO * const fromcs= entry->collation.collation;
2348
 
      const CHARSET_INFO * const tocs= thd->variables.collation_connection;
2349
 
      uint32_t dummy_offset;
 
2355
      CHARSET_INFO *fromcs= entry->collation.collation;
 
2356
      CHARSET_INFO *tocs= thd->variables.collation_connection;
 
2357
      uint32 dummy_offset;
2350
2358
 
2351
2359
      value.cs_info.character_set_of_placeholder= 
2352
2360
        value.cs_info.character_set_client= fromcs;
2365
2373
      item_type= Item::STRING_ITEM;
2366
2374
 
2367
2375
      if (set_str((const char *)entry->value, entry->length))
2368
 
        return(1);
 
2376
        DBUG_RETURN(1);
2369
2377
      break;
2370
2378
    }
2371
2379
    case DECIMAL_RESULT:
2380
2388
      break;
2381
2389
    }
2382
2390
    default:
2383
 
      assert(0);
 
2391
      DBUG_ASSERT(0);
2384
2392
      set_null();
2385
2393
    }
2386
2394
  }
2387
2395
  else
2388
2396
    set_null();
2389
2397
 
2390
 
  return(0);
 
2398
  DBUG_RETURN(0);
2391
2399
}
2392
2400
 
2393
2401
/**
2400
2408
 
2401
2409
void Item_param::reset()
2402
2410
{
 
2411
  DBUG_ENTER("Item_param::reset");
2403
2412
  /* Shrink string buffer if it's bigger than max possible CHAR column */
2404
2413
  if (str_value.alloced_length() > MAX_CHAR_WIDTH)
2405
2414
    str_value.free();
2421
2430
    contain a literal of some kind.
2422
2431
    In all other cases when this object is accessed its value is
2423
2432
    set (this assumption is guarded by 'state' and
2424
 
    assertS(state != NO_VALUE) in all Item_param::get_*
 
2433
    DBUG_ASSERTS(state != NO_VALUE) in all Item_param::get_*
2425
2434
    methods).
2426
2435
  */
2427
 
  return;
 
2436
  DBUG_VOID_RETURN;
2428
2437
}
2429
2438
 
2430
2439
 
2450
2459
    return set_field_to_null_with_conversions(field, no_conversions);
2451
2460
  case NO_VALUE:
2452
2461
  default:
2453
 
    assert(0);
 
2462
    DBUG_ASSERT(0);
2454
2463
  }
2455
2464
  return 1;
2456
2465
}
2457
2466
 
2458
2467
 
2459
 
bool Item_param::get_time(DRIZZLE_TIME *res)
 
2468
bool Item_param::get_time(MYSQL_TIME *res)
2460
2469
{
2461
2470
  if (state == TIME_VALUE)
2462
2471
  {
2471
2480
}
2472
2481
 
2473
2482
 
2474
 
bool Item_param::get_date(DRIZZLE_TIME *res, uint32_t fuzzydate)
 
2483
bool Item_param::get_date(MYSQL_TIME *res, uint fuzzydate)
2475
2484
{
2476
2485
  if (state == TIME_VALUE)
2477
2486
  {
2508
2517
      This works for example when user says SELECT ?+0.0 and supplies
2509
2518
      time value for the placeholder.
2510
2519
    */
2511
 
    return uint64_t2double(TIME_to_uint64_t(&value.time));
 
2520
    return ulonglong2double(TIME_to_ulonglong(&value.time));
2512
2521
  case NULL_VALUE:
2513
2522
    return 0.0;
2514
2523
  default:
2515
 
    assert(0);
 
2524
    DBUG_ASSERT(0);
2516
2525
  }
2517
2526
  return 0.0;
2518
2527
2519
2528
 
2520
2529
 
2521
 
int64_t Item_param::val_int() 
 
2530
longlong Item_param::val_int() 
2522
2531
2523
2532
  switch (state) {
2524
2533
  case REAL_VALUE:
2525
 
    return (int64_t) rint(value.real);
 
2534
    return (longlong) rint(value.real);
2526
2535
  case INT_VALUE:
2527
2536
    return value.integer;
2528
2537
  case DECIMAL_VALUE:
2529
2538
  {
2530
 
    int64_t i;
 
2539
    longlong i;
2531
2540
    my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &i);
2532
2541
    return i;
2533
2542
  }
2539
2548
                         str_value.length(), 10, (char**) 0, &dummy_err);
2540
2549
    }
2541
2550
  case TIME_VALUE:
2542
 
    return (int64_t) TIME_to_uint64_t(&value.time);
 
2551
    return (longlong) TIME_to_ulonglong(&value.time);
2543
2552
  case NULL_VALUE:
2544
2553
    return 0; 
2545
2554
  default:
2546
 
    assert(0);
 
2555
    DBUG_ASSERT(0);
2547
2556
  }
2548
2557
  return 0;
2549
2558
}
2566
2575
    return dec;
2567
2576
  case TIME_VALUE:
2568
2577
  {
2569
 
    int64_t i= (int64_t) TIME_to_uint64_t(&value.time);
 
2578
    longlong i= (longlong) TIME_to_ulonglong(&value.time);
2570
2579
    int2my_decimal(E_DEC_FATAL_ERROR, i, 0, dec);
2571
2580
    return dec;
2572
2581
  }
2573
2582
  case NULL_VALUE:
2574
2583
    return 0; 
2575
2584
  default:
2576
 
    assert(0);
 
2585
    DBUG_ASSERT(0);
2577
2586
  }
2578
2587
  return 0;
2579
2588
}
2607
2616
  case NULL_VALUE:
2608
2617
    return NULL; 
2609
2618
  default:
2610
 
    assert(0);
 
2619
    DBUG_ASSERT(0);
2611
2620
  }
2612
2621
  return str;
2613
2622
}
2654
2663
      *ptr++= '\'';
2655
2664
      ptr+= (uint) my_TIME_to_str(&value.time, ptr);
2656
2665
      *ptr++= '\'';
2657
 
      str->length((uint32_t) (ptr - buf));
 
2666
      str->length((uint32) (ptr - buf));
2658
2667
      break;
2659
2668
    }
2660
2669
  case STRING_VALUE:
2667
2676
  case NULL_VALUE:
2668
2677
    return &my_null_string;
2669
2678
  default:
2670
 
    assert(0);
 
2679
    DBUG_ASSERT(0);
2671
2680
  }
2672
2681
  return str;
2673
2682
}
2744
2753
    break;
2745
2754
  case NO_VALUE:
2746
2755
  default:
2747
 
    assert(0);
 
2756
    DBUG_ASSERT(0);
2748
2757
  };
2749
2758
  return 0;
2750
2759
}
2784
2793
/* End of Item_param related */
2785
2794
 
2786
2795
void Item_param::print(String *str,
2787
 
                       enum_query_type query_type __attribute__((unused)))
 
2796
                       enum_query_type query_type __attribute__((__unused__)))
2788
2797
{
2789
2798
  if (state == NO_VALUE)
2790
2799
  {
2814
2823
}
2815
2824
 
2816
2825
/* ARGSUSED */
2817
 
String *Item_copy_string::val_str(String *str __attribute__((unused)))
 
2826
String *Item_copy_string::val_str(String *str __attribute__((__unused__)))
2818
2827
{
2819
2828
  // Item_copy_string is used without fix_fields call
2820
2829
  if (null_value)
2838
2847
*/
2839
2848
 
2840
2849
/* ARGSUSED */
2841
 
bool Item::fix_fields(THD *thd __attribute__((unused)),
2842
 
                      Item **ref __attribute__((unused)))
 
2850
bool Item::fix_fields(THD *thd __attribute__((__unused__)),
 
2851
                      Item **ref __attribute__((__unused__)))
2843
2852
{
2844
2853
 
2845
2854
  // We do not check fields which are fixed during construction
2846
 
  assert(fixed == 0 || basic_const_item());
 
2855
  DBUG_ASSERT(fixed == 0 || basic_const_item());
2847
2856
  fixed= 1;
2848
2857
  return false;
2849
2858
}
2850
2859
 
2851
2860
double Item_ref_null_helper::val_real()
2852
2861
{
2853
 
  assert(fixed == 1);
 
2862
  DBUG_ASSERT(fixed == 1);
2854
2863
  double tmp= (*ref)->val_result();
2855
2864
  owner->was_null|= null_value= (*ref)->null_value;
2856
2865
  return tmp;
2857
2866
}
2858
2867
 
2859
2868
 
2860
 
int64_t Item_ref_null_helper::val_int()
 
2869
longlong Item_ref_null_helper::val_int()
2861
2870
{
2862
 
  assert(fixed == 1);
2863
 
  int64_t tmp= (*ref)->val_int_result();
 
2871
  DBUG_ASSERT(fixed == 1);
 
2872
  longlong tmp= (*ref)->val_int_result();
2864
2873
  owner->was_null|= null_value= (*ref)->null_value;
2865
2874
  return tmp;
2866
2875
}
2868
2877
 
2869
2878
my_decimal *Item_ref_null_helper::val_decimal(my_decimal *decimal_value)
2870
2879
{
2871
 
  assert(fixed == 1);
 
2880
  DBUG_ASSERT(fixed == 1);
2872
2881
  my_decimal *val= (*ref)->val_decimal_result(decimal_value);
2873
2882
  owner->was_null|= null_value= (*ref)->null_value;
2874
2883
  return val;
2877
2886
 
2878
2887
bool Item_ref_null_helper::val_bool()
2879
2888
{
2880
 
  assert(fixed == 1);
 
2889
  DBUG_ASSERT(fixed == 1);
2881
2890
  bool val= (*ref)->val_bool_result();
2882
2891
  owner->was_null|= null_value= (*ref)->null_value;
2883
2892
  return val;
2886
2895
 
2887
2896
String* Item_ref_null_helper::val_str(String* s)
2888
2897
{
2889
 
  assert(fixed == 1);
 
2898
  DBUG_ASSERT(fixed == 1);
2890
2899
  String* tmp= (*ref)->str_result(s);
2891
2900
  owner->was_null|= null_value= (*ref)->null_value;
2892
2901
  return tmp;
2893
2902
}
2894
2903
 
2895
2904
 
2896
 
bool Item_ref_null_helper::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate)
 
2905
bool Item_ref_null_helper::get_date(MYSQL_TIME *ltime, uint fuzzydate)
2897
2906
{  
2898
2907
  return (owner->was_null|= null_value= (*ref)->get_date(ltime, fuzzydate));
2899
2908
}
2925
2934
  current->mark_as_dependent(last);
2926
2935
  if (thd->lex->describe & DESCRIBE_EXTENDED)
2927
2936
  {
2928
 
    char warn_buff[DRIZZLE_ERRMSG_SIZE];
 
2937
    char warn_buff[MYSQL_ERRMSG_SIZE];
2929
2938
    sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED),
2930
2939
            db_name, (db_name[0] ? "." : ""),
2931
2940
            table_name, (table_name [0] ? "." : ""),
2932
2941
            resolved_item->field_name,
2933
2942
            current->select_number, last->select_number);
2934
 
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
 
2943
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
2935
2944
                 ER_WARN_FIELD_RESOLVED, warn_buff);
2936
2945
  }
2937
2946
}
3016
3025
    - NULL if find_item is not in group_list
3017
3026
*/
3018
3027
 
3019
 
static Item** find_field_in_group_list(Item *find_item, order_st *group_list)
 
3028
static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
3020
3029
{
3021
3030
  const char *db_name;
3022
3031
  const char *table_name;
3023
3032
  const char *field_name;
3024
 
  order_st      *found_group= NULL;
 
3033
  ORDER      *found_group= NULL;
3025
3034
  int         found_match_degree= 0;
3026
3035
  Item_ident *cur_field;
3027
3036
  int         cur_match_degree= 0;
3045
3054
    db_name= name_buff;
3046
3055
  }
3047
3056
 
3048
 
  assert(field_name != 0);
 
3057
  DBUG_ASSERT(field_name != 0);
3049
3058
 
3050
 
  for (order_st *cur_group= group_list ; cur_group ; cur_group= cur_group->next)
 
3059
  for (ORDER *cur_group= group_list ; cur_group ; cur_group= cur_group->next)
3051
3060
  {
3052
3061
    if ((*(cur_group->item))->real_item()->type() == Item::FIELD_ITEM)
3053
3062
    {
3054
3063
      cur_field= (Item_ident*) *cur_group->item;
3055
3064
      cur_match_degree= 0;
3056
3065
      
3057
 
      assert(cur_field->field_name != 0);
 
3066
      DBUG_ASSERT(cur_field->field_name != 0);
3058
3067
 
3059
3068
      if (!my_strcasecmp(system_charset_info,
3060
3069
                         cur_field->field_name, field_name))
3148
3157
{
3149
3158
  Item **group_by_ref= NULL;
3150
3159
  Item **select_ref= NULL;
3151
 
  order_st *group_list= (order_st*) select->group_list.first;
 
3160
  ORDER *group_list= (ORDER*) select->group_list.first;
3152
3161
  bool ambiguous_fields= false;
3153
 
  uint32_t counter;
 
3162
  uint counter;
3154
3163
  enum_resolution_type resolution;
3155
3164
 
3156
3165
  /*
3174
3183
        !((*group_by_ref)->eq(*select_ref, 0)))
3175
3184
    {
3176
3185
      ambiguous_fields= true;
3177
 
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
 
3186
      push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
3178
3187
                          ER(ER_NON_UNIQ_ERROR), ref->full_name(),
3179
3188
                          current_thd->where);
3180
3189
 
3185
3194
  {
3186
3195
    if (select_ref != not_found_item && !ambiguous_fields)
3187
3196
    {
3188
 
      assert(*select_ref != 0);
 
3197
      DBUG_ASSERT(*select_ref != 0);
3189
3198
      if (!select->ref_pointer_array[counter])
3190
3199
      {
3191
3200
        my_error(ER_ILLEGAL_REFERENCE, MYF(0),
3192
3201
                 ref->name, "forward reference in item list");
3193
3202
        return NULL;
3194
3203
      }
3195
 
      assert((*select_ref)->fixed);
 
3204
      DBUG_ASSERT((*select_ref)->fixed);
3196
3205
      return (select->ref_pointer_array + counter);
3197
3206
    }
3198
3207
    if (group_by_ref)
3199
3208
      return group_by_ref;
3200
 
    assert(false);
 
3209
    DBUG_ASSERT(false);
3201
3210
    return NULL; /* So there is no compiler warning. */
3202
3211
  }
3203
3212
 
3382
3391
        return -1; /* Some error occurred (e.g. ambiguous names). */
3383
3392
      if (ref != not_found_item)
3384
3393
      {
3385
 
        assert(*ref && (*ref)->fixed);
 
3394
        DBUG_ASSERT(*ref && (*ref)->fixed);
3386
3395
        prev_subselect_item->used_tables_cache|= (*ref)->used_tables();
3387
3396
        prev_subselect_item->const_item_cache&= (*ref)->const_item();
3388
3397
        break;
3398
3407
    prev_subselect_item->const_item_cache= 0;
3399
3408
  }
3400
3409
 
3401
 
  assert(ref != 0);
 
3410
  DBUG_ASSERT(ref != 0);
3402
3411
  if (!*from_field)
3403
3412
    return -1;
3404
3413
  if (ref == not_found_item && *from_field == not_found_field)
3426
3435
    Item_ref *rf;
3427
3436
 
3428
3437
    /* Should have been checked in resolve_ref_in_select_and_group(). */
3429
 
    assert(*ref && (*ref)->fixed);
 
3438
    DBUG_ASSERT(*ref && (*ref)->fixed);
3430
3439
    /*
3431
3440
      Here, a subset of actions performed by Item_ref::set_properties
3432
3441
      is not enough. So we pass ptr to NULL into Item_[direct]_ref
3457
3466
      rf is Item_ref => never substitute other items (in this case)
3458
3467
      during fix_fields() => we can use rf after fix_fields()
3459
3468
    */
3460
 
    assert(!rf->fixed);                // Assured by Item_ref()
 
3469
    DBUG_ASSERT(!rf->fixed);                // Assured by Item_ref()
3461
3470
    if (rf->fix_fields(thd, reference) || rf->check_cols(1))
3462
3471
      return -1;
3463
3472
 
3484
3493
        rf is Item_ref => never substitute other items (in this case)
3485
3494
        during fix_fields() => we can use rf after fix_fields()
3486
3495
      */
3487
 
      assert(!rf->fixed);                // Assured by Item_ref()
 
3496
      DBUG_ASSERT(!rf->fixed);                // Assured by Item_ref()
3488
3497
      if (rf->fix_fields(thd, reference) || rf->check_cols(1))
3489
3498
        return -1;
3490
3499
      return 0;
3541
3550
 
3542
3551
bool Item_field::fix_fields(THD *thd, Item **reference)
3543
3552
{
3544
 
  assert(fixed == 0);
 
3553
  DBUG_ASSERT(fixed == 0);
3545
3554
  Field *from_field= (Field *)not_found_field;
3546
3555
  bool outer_fixed= false;
3547
3556
 
3567
3576
      /* Look up in current select's item_list to find aliased fields */
3568
3577
      if (thd->lex->current_select->is_item_list_lookup)
3569
3578
      {
3570
 
        uint32_t counter;
 
3579
        uint counter;
3571
3580
        enum_resolution_type resolution;
3572
3581
        Item** res= find_item_in_list(this, thd->lex->current_select->item_list,
3573
3582
                                      &counter, REPORT_EXCEPT_NOT_FOUND,
3665
3674
  }
3666
3675
  else if (thd->mark_used_columns != MARK_COLUMNS_NONE)
3667
3676
  {
3668
 
    Table *table= field->table;
 
3677
    TABLE *table= field->table;
3669
3678
    MY_BITMAP *current_bitmap, *other_bitmap;
3670
3679
    if (thd->mark_used_columns == MARK_COLUMNS_READ)
3671
3680
    {
3698
3707
  return true;
3699
3708
}
3700
3709
 
3701
 
Item *Item_field::safe_charset_converter(const CHARSET_INFO * const tocs)
 
3710
Item *Item_field::safe_charset_converter(CHARSET_INFO *tocs)
3702
3711
{
3703
3712
  no_const_subst= 1;
3704
3713
  return Item::safe_charset_converter(tocs);
3707
3716
 
3708
3717
void Item_field::cleanup()
3709
3718
{
 
3719
  DBUG_ENTER("Item_field::cleanup");
3710
3720
  Item_ident::cleanup();
3711
3721
  /*
3712
3722
    Even if this object was created by direct link to field in setup_wild()
3715
3725
   */
3716
3726
  field= result_field= 0;
3717
3727
  null_value= false;
3718
 
  return;
 
3728
  DBUG_VOID_RETURN;
3719
3729
}
3720
3730
 
3721
3731
/**
3787
3797
    false  otherwise
3788
3798
*/
3789
3799
 
3790
 
bool Item_field::subst_argument_checker(unsigned char **arg)
 
3800
bool Item_field::subst_argument_checker(uchar **arg)
3791
3801
{
3792
3802
  return (result_type() != STRING_RESULT) || (*arg);
3793
3803
}
3794
3804
 
3795
3805
 
3796
3806
/**
 
3807
  Convert a numeric value to a zero-filled string
 
3808
 
 
3809
  @param[in,out]  item   the item to operate on
 
3810
  @param          field  The field that this value is equated to
 
3811
 
 
3812
  This function converts a numeric value to a string. In this conversion
 
3813
  the zero-fill flag of the field is taken into account.
 
3814
  This is required so the resulting string value can be used instead of
 
3815
  the field reference when propagating equalities.
 
3816
*/
 
3817
 
 
3818
static void convert_zerofill_number_to_string(Item **item, Field_num *field)
 
3819
{
 
3820
  char buff[MAX_FIELD_WIDTH],*pos;
 
3821
  String tmp(buff,sizeof(buff), field->charset()), *res;
 
3822
 
 
3823
  res= (*item)->val_str(&tmp);
 
3824
  field->prepend_zeros(res);
 
3825
  pos= (char *) sql_strmake (res->ptr(), res->length());
 
3826
  *item= new Item_string(pos, res->length(), field->charset());
 
3827
}
 
3828
 
 
3829
 
 
3830
/**
3797
3831
  Set a pointer to the multiple equality the field reference belongs to
3798
3832
  (if any).
3799
3833
 
3817
3851
    - pointer to the field item, otherwise.
3818
3852
*/
3819
3853
 
3820
 
Item *Item_field::equal_fields_propagator(unsigned char *arg)
 
3854
Item *Item_field::equal_fields_propagator(uchar *arg)
3821
3855
{
3822
3856
  if (no_const_subst)
3823
3857
    return this;
3839
3873
  if (!item ||
3840
3874
      (cmp_context != (Item_result)-1 && item->cmp_context != cmp_context))
3841
3875
    item= this;
3842
 
 
 
3876
  else if (field && (field->flags & ZEROFILL_FLAG) && IS_NUM(field->type()))
 
3877
  {
 
3878
    if (item && cmp_context != INT_RESULT)
 
3879
      convert_zerofill_number_to_string(&item, (Field_num *)field);
 
3880
    else
 
3881
      item= this;
 
3882
  }
3843
3883
  return item;
3844
3884
}
3845
3885
 
3850
3890
  See comments in Arg_comparator::set_compare_func() for details.
3851
3891
*/
3852
3892
 
3853
 
bool Item_field::set_no_const_sub(unsigned char *arg __attribute__((unused)))
 
3893
bool Item_field::set_no_const_sub(uchar *arg __attribute__((__unused__)))
3854
3894
{
3855
3895
  if (field->charset() != &my_charset_bin)
3856
3896
    no_const_subst=1;
3883
3923
    - this - otherwise.
3884
3924
*/
3885
3925
 
3886
 
Item *Item_field::replace_equal_field(unsigned char *arg __attribute__((unused)))
 
3926
Item *Item_field::replace_equal_field(uchar *arg __attribute__((__unused__)))
3887
3927
{
3888
3928
  if (item_equal)
3889
3929
  {
3919
3959
  tmp_field->type=              field_type_arg;
3920
3960
  tmp_field->length=max_length;
3921
3961
  tmp_field->decimals=decimals;
 
3962
  if (unsigned_flag)
 
3963
    tmp_field->flags |= UNSIGNED_FLAG;
3922
3964
}
3923
3965
 
3924
3966
void Item::make_field(Send_field *tmp_field)
3929
3971
 
3930
3972
enum_field_types Item::string_field_type() const
3931
3973
{
3932
 
  enum_field_types f_type= DRIZZLE_TYPE_VARCHAR;
 
3974
  enum_field_types f_type= MYSQL_TYPE_VAR_STRING;
3933
3975
  if (max_length >= 65536)
3934
 
    f_type= DRIZZLE_TYPE_BLOB;
 
3976
    f_type= MYSQL_TYPE_BLOB;
3935
3977
  return f_type;
3936
3978
}
3937
3979
 
3946
3988
{
3947
3989
  switch (result_type()) {
3948
3990
  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;
 
3991
  case INT_RESULT:     return MYSQL_TYPE_LONGLONG;
 
3992
  case DECIMAL_RESULT: return MYSQL_TYPE_NEWDECIMAL;
 
3993
  case REAL_RESULT:    return MYSQL_TYPE_DOUBLE;
3952
3994
  case ROW_RESULT:
3953
3995
  default:
3954
 
    assert(0);
3955
 
    return DRIZZLE_TYPE_VARCHAR;
 
3996
    DBUG_ASSERT(0);
 
3997
    return MYSQL_TYPE_VARCHAR;
3956
3998
  }
3957
3999
}
3958
4000
 
3961
4003
{
3962
4004
  switch (field_type())
3963
4005
  {
3964
 
    case DRIZZLE_TYPE_NEWDATE:
3965
 
    case DRIZZLE_TYPE_DATETIME:
3966
 
    case DRIZZLE_TYPE_TIMESTAMP:
 
4006
    case MYSQL_TYPE_NEWDATE:
 
4007
    case MYSQL_TYPE_DATETIME:
 
4008
    case MYSQL_TYPE_TIMESTAMP:
3967
4009
      return true;
3968
4010
    default:
3969
4011
      break;
3975
4017
String *Item::check_well_formed_result(String *str, bool send_error)
3976
4018
{
3977
4019
  /* Check whether we got a well-formed string */
3978
 
  const CHARSET_INFO * const cs= str->charset();
 
4020
  CHARSET_INFO *cs= str->charset();
3979
4021
  int well_formed_error;
3980
 
  uint32_t wlen= cs->cset->well_formed_len(cs,
 
4022
  uint wlen= cs->cset->well_formed_len(cs,
3981
4023
                                       str->ptr(), str->ptr() + str->length(),
3982
4024
                                       str->length(), &well_formed_error);
3983
4025
  if (wlen < str->length())
3984
4026
  {
3985
4027
    THD *thd= current_thd;
3986
4028
    char hexbuf[7];
3987
 
    enum DRIZZLE_ERROR::enum_warning_level level;
3988
 
    uint32_t diff= str->length() - wlen;
 
4029
    enum MYSQL_ERROR::enum_warning_level level;
 
4030
    uint diff= str->length() - wlen;
3989
4031
    set_if_smaller(diff, 3);
3990
4032
    octet2hex(hexbuf, str->ptr() + wlen, diff);
3991
4033
    if (send_error)
3995
4037
      return 0;
3996
4038
    }
3997
4039
    {
3998
 
      level= DRIZZLE_ERROR::WARN_LEVEL_ERROR;
 
4040
      level= MYSQL_ERROR::WARN_LEVEL_ERROR;
3999
4041
      null_value= 1;
4000
4042
      str= 0;
4001
4043
    }
4026
4068
    0    otherwise
4027
4069
*/
4028
4070
 
4029
 
bool Item::eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO * const cs)
 
4071
bool Item::eq_by_collation(Item *item, bool binary_cmp, CHARSET_INFO *cs)
4030
4072
{
4031
 
  const CHARSET_INFO *save_cs= 0;
4032
 
  const CHARSET_INFO *save_item_cs= 0;
 
4073
  CHARSET_INFO *save_cs= 0;
 
4074
  CHARSET_INFO *save_item_cs= 0;
4033
4075
  if (collation.collation != cs)
4034
4076
  {
4035
4077
    save_cs= collation.collation;
4059
4101
  @param table          Table for which the field is created
4060
4102
*/
4061
4103
 
4062
 
Field *Item::make_string_field(Table *table)
 
4104
Field *Item::make_string_field(TABLE *table)
4063
4105
{
4064
4106
  Field *field;
4065
 
  assert(collation.collation);
 
4107
  DBUG_ASSERT(collation.collation);
4066
4108
  if (max_length/collation.collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB)
4067
4109
    field= new Field_blob(max_length, maybe_null, name,
4068
4110
                          collation.collation);
4069
 
  else
 
4111
  /* Item_type_holder holds the exact type, do not change it */
 
4112
  else if (max_length > 0 &&
 
4113
      (type() != Item::TYPE_HOLDER || field_type() != MYSQL_TYPE_STRING))
4070
4114
    field= new Field_varstring(max_length, maybe_null, name, table->s,
4071
4115
                               collation.collation);
4072
 
 
 
4116
  else
 
4117
    field= new Field_string(max_length, maybe_null, name,
 
4118
                            collation.collation);
4073
4119
  if (field)
4074
4120
    field->init(table);
4075
4121
  return field;
4088
4134
    \#    Created field
4089
4135
*/
4090
4136
 
4091
 
Field *Item::tmp_table_field_from_field_type(Table *table, bool fixed_length __attribute__((unused)))
 
4137
Field *Item::tmp_table_field_from_field_type(TABLE *table, bool fixed_length)
4092
4138
{
4093
4139
  /*
4094
4140
    The field functions defines a field to be not null if null_ptr is not 0
4095
4141
  */
4096
 
  unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
 
4142
  uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
4097
4143
  Field *field;
4098
4144
 
4099
4145
  switch (field_type()) {
4100
 
  case DRIZZLE_TYPE_NEWDECIMAL:
4101
 
    field= new Field_new_decimal((unsigned char*) 0, max_length, null_ptr, 0,
 
4146
  case MYSQL_TYPE_NEWDECIMAL:
 
4147
    field= new Field_new_decimal((uchar*) 0, max_length, null_ptr, 0,
4102
4148
                                 Field::NONE, name, decimals, 0,
4103
4149
                                 unsigned_flag);
4104
4150
    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,
 
4151
  case MYSQL_TYPE_TINY:
 
4152
    field= new Field_tiny((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4153
                          name, 0, unsigned_flag);
 
4154
    break;
 
4155
  case MYSQL_TYPE_SHORT:
 
4156
    field= new Field_short((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4157
                           name, 0, unsigned_flag);
 
4158
    break;
 
4159
  case MYSQL_TYPE_LONG:
 
4160
    field= new Field_long((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4161
                          name, 0, unsigned_flag);
 
4162
    break;
 
4163
  case MYSQL_TYPE_LONGLONG:
 
4164
    field= new Field_longlong((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4115
4165
                              name, 0, unsigned_flag);
4116
4166
    break;
4117
 
  case DRIZZLE_TYPE_DOUBLE:
4118
 
    field= new Field_double((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
 
4167
  case MYSQL_TYPE_FLOAT:
 
4168
    field= new Field_float((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4169
                           name, decimals, 0, unsigned_flag);
 
4170
    break;
 
4171
  case MYSQL_TYPE_DOUBLE:
 
4172
    field= new Field_double((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4119
4173
                            name, decimals, 0, unsigned_flag);
4120
4174
    break;
4121
 
  case DRIZZLE_TYPE_NULL:
4122
 
    field= new Field_null((unsigned char*) 0, max_length, Field::NONE,
 
4175
  case MYSQL_TYPE_NULL:
 
4176
    field= new Field_null((uchar*) 0, max_length, Field::NONE,
4123
4177
                          name, &my_charset_bin);
4124
4178
    break;
4125
 
  case DRIZZLE_TYPE_NEWDATE:
 
4179
  case MYSQL_TYPE_NEWDATE:
4126
4180
    field= new Field_newdate(maybe_null, name, &my_charset_bin);
4127
4181
    break;
4128
 
  case DRIZZLE_TYPE_TIME:
 
4182
  case MYSQL_TYPE_TIME:
4129
4183
    field= new Field_time(maybe_null, name, &my_charset_bin);
4130
4184
    break;
4131
 
  case DRIZZLE_TYPE_TIMESTAMP:
 
4185
  case MYSQL_TYPE_TIMESTAMP:
4132
4186
    field= new Field_timestamp(maybe_null, name, &my_charset_bin);
4133
4187
    break;
4134
 
  case DRIZZLE_TYPE_DATETIME:
 
4188
  case MYSQL_TYPE_DATETIME:
4135
4189
    field= new Field_datetime(maybe_null, name, &my_charset_bin);
4136
4190
    break;
 
4191
  case MYSQL_TYPE_YEAR:
 
4192
    field= new Field_year((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4193
                          name);
 
4194
    break;
4137
4195
  default:
4138
4196
    /* This case should never be chosen */
4139
 
    assert(0);
 
4197
    DBUG_ASSERT(0);
 
4198
    /* If something goes awfully wrong, it's better to get a string than die */
 
4199
  case MYSQL_TYPE_STRING:
 
4200
    if (fixed_length && max_length < CONVERT_IF_BIGGER_TO_BLOB)
 
4201
    {
 
4202
      field= new Field_string(max_length, maybe_null, name,
 
4203
                              collation.collation);
 
4204
      break;
 
4205
    }
4140
4206
    /* Fall through to make_string_field() */
4141
 
  case DRIZZLE_TYPE_ENUM:
4142
 
  case DRIZZLE_TYPE_VARCHAR:
 
4207
  case MYSQL_TYPE_ENUM:
 
4208
  case MYSQL_TYPE_SET:
 
4209
  case MYSQL_TYPE_VAR_STRING:
 
4210
  case MYSQL_TYPE_VARCHAR:
4143
4211
    return make_string_field(table);
4144
 
  case DRIZZLE_TYPE_BLOB:
 
4212
  case MYSQL_TYPE_BLOB:
4145
4213
    if (this->type() == Item::TYPE_HOLDER)
4146
4214
      field= new Field_blob(max_length, maybe_null, name, collation.collation,
4147
4215
                            1);
4159
4227
void Item_field::make_field(Send_field *tmp_field)
4160
4228
{
4161
4229
  field->make_field(tmp_field);
4162
 
  assert(tmp_field->table_name != 0);
 
4230
  DBUG_ASSERT(tmp_field->table_name != 0);
4163
4231
  if (name)
4164
4232
    tmp_field->col_name=name;                   // Use user supplied name
4165
4233
  if (table_name)
4191
4259
int Item_field::save_in_field(Field *to, bool no_conversions)
4192
4260
{
4193
4261
  int res;
 
4262
  DBUG_ENTER("Item_field::save_in_field");
4194
4263
  if (result_field->is_null())
4195
4264
  {
4196
4265
    null_value=1;
4199
4268
  else
4200
4269
  {
4201
4270
    to->set_notnull();
 
4271
    DBUG_EXECUTE("info", dbug_print(););
4202
4272
    res= field_conv(to,result_field);
4203
4273
    null_value=0;
4204
4274
  }
4205
 
  return(res);
 
4275
  DBUG_RETURN(res);
4206
4276
}
4207
4277
 
4208
4278
 
4255
4325
  if (result_type() == STRING_RESULT)
4256
4326
  {
4257
4327
    String *result;
4258
 
    const CHARSET_INFO * const cs= collation.collation;
 
4328
    CHARSET_INFO *cs= collation.collation;
4259
4329
    char buff[MAX_FIELD_WIDTH];         // Alloc buffer for small columns
4260
4330
    str_value.set_quick(buff, sizeof(buff), cs);
4261
4331
    result=val_str(&str_value);
4299
4369
  }
4300
4370
  else
4301
4371
  {
4302
 
    int64_t nr=val_int();
 
4372
    longlong nr=val_int();
4303
4373
    if (null_value)
4304
4374
      return set_field_to_null_with_conversions(field, no_conversions);
4305
4375
    field->set_notnull();
4310
4380
 
4311
4381
 
4312
4382
int Item_string::save_in_field(Field *field,
4313
 
                               bool no_conversions __attribute__((unused)))
 
4383
                               bool no_conversions __attribute__((__unused__)))
4314
4384
{
4315
4385
  String *result;
4316
4386
  result=val_str(&str_value);
4326
4396
 
4327
4397
 
4328
4398
int Item_int::save_in_field(Field *field,
4329
 
                            bool no_conversions __attribute__((unused)))
 
4399
                            bool no_conversions __attribute__((__unused__)))
4330
4400
{
4331
 
  int64_t nr=val_int();
 
4401
  longlong nr=val_int();
4332
4402
  if (null_value)
4333
4403
    return set_field_to_null(field);
4334
4404
  field->set_notnull();
4337
4407
 
4338
4408
 
4339
4409
int Item_decimal::save_in_field(Field *field,
4340
 
                                bool no_conversions __attribute__((unused)))
 
4410
                                bool no_conversions __attribute__((__unused__)))
4341
4411
{
4342
4412
  field->set_notnull();
4343
4413
  return field->store_decimal(&decimal_value);
4345
4415
 
4346
4416
 
4347
4417
bool Item_int::eq(const Item *arg,
4348
 
                  bool binary_cmp __attribute__((unused))) const
 
4418
                  bool binary_cmp __attribute__((__unused__))) const
4349
4419
{
4350
4420
  /* No need to check for null value as basic constant can't be NULL */
4351
4421
  if (arg->basic_const_item() && arg->type() == type())
4363
4433
 
4364
4434
Item *Item_int_with_ref::clone_item()
4365
4435
{
4366
 
  assert(ref->const_item());
 
4436
  DBUG_ASSERT(ref->const_item());
4367
4437
  /*
4368
4438
    We need to evaluate the constant to make sure it works with
4369
4439
    parameter markers.
4381
4451
}
4382
4452
 
4383
4453
 
4384
 
static uint32_t nr_of_decimals(const char *str, const char *end)
 
4454
static uint nr_of_decimals(const char *str, const char *end)
4385
4455
{
4386
4456
  const char *decimal_point;
4387
4457
 
4409
4479
  value is not a true double value (overflow)
4410
4480
*/
4411
4481
 
4412
 
Item_float::Item_float(const char *str_arg, uint32_t length)
 
4482
Item_float::Item_float(const char *str_arg, uint length)
4413
4483
{
4414
4484
  int error;
4415
4485
  char *end_not_used;
4421
4491
      Note that we depend on that str_arg is null terminated, which is true
4422
4492
      when we are in the parser
4423
4493
    */
4424
 
    assert(str_arg[length] == 0);
 
4494
    DBUG_ASSERT(str_arg[length] == 0);
4425
4495
    my_error(ER_ILLEGAL_VALUE_FOR_TYPE, MYF(0), "double", (char*) str_arg);
4426
4496
  }
4427
4497
  presentation= name=(char*) str_arg;
4428
 
  decimals=(uint8_t) nr_of_decimals(str_arg, str_arg+length);
 
4498
  decimals=(uint8) nr_of_decimals(str_arg, str_arg+length);
4429
4499
  max_length=length;
4430
4500
  fixed= 1;
4431
4501
}
4432
4502
 
4433
4503
 
4434
4504
int Item_float::save_in_field(Field *field,
4435
 
                              bool no_conversions __attribute__((unused)))
 
4505
                              bool no_conversions __attribute__((__unused__)))
4436
4506
{
4437
4507
  double nr= val_real();
4438
4508
  if (null_value)
4443
4513
 
4444
4514
 
4445
4515
void Item_float::print(String *str,
4446
 
                       enum_query_type query_type __attribute__((unused)))
 
4516
                       enum_query_type query_type __attribute__((__unused__)))
4447
4517
{
4448
4518
  if (presentation)
4449
4519
  {
4460
4530
/*
4461
4531
  hex item
4462
4532
  In string context this is a binary string.
4463
 
  In number context this is a int64_t value.
 
4533
  In number context this is a longlong value.
4464
4534
*/
4465
4535
 
4466
4536
bool Item_float::eq(const Item *arg,
4467
 
                    bool binary_cmp __attribute__((unused))) const
 
4537
                    bool binary_cmp __attribute__((__unused__))) const
4468
4538
{
4469
4539
  if (arg->basic_const_item() && arg->type() == type())
4470
4540
  {
4479
4549
}
4480
4550
 
4481
4551
 
4482
 
inline uint32_t char_val(char X)
 
4552
inline uint char_val(char X)
4483
4553
{
4484
4554
  return (uint) (X >= '0' && X <= '9' ? X-'0' :
4485
4555
                 X >= 'A' && X <= 'Z' ? X-'A'+10 :
4487
4557
}
4488
4558
 
4489
4559
 
4490
 
Item_hex_string::Item_hex_string(const char *str, uint32_t str_length)
 
4560
Item_hex_string::Item_hex_string(const char *str, uint str_length)
4491
4561
{
4492
4562
  max_length=(str_length+1)/2;
4493
4563
  char *ptr=(char*) sql_alloc(max_length+1);
4508
4578
  unsigned_flag= 1;
4509
4579
}
4510
4580
 
4511
 
int64_t Item_hex_string::val_int()
 
4581
longlong Item_hex_string::val_int()
4512
4582
{
4513
4583
  // following assert is redundant, because fixed=1 assigned in constructor
4514
 
  assert(fixed == 1);
 
4584
  DBUG_ASSERT(fixed == 1);
4515
4585
  char *end=(char*) str_value.ptr()+str_value.length(),
4516
 
       *ptr=end-cmin(str_value.length(),(uint32_t)sizeof(int64_t));
 
4586
       *ptr=end-min(str_value.length(),sizeof(longlong));
4517
4587
 
4518
 
  uint64_t value=0;
 
4588
  ulonglong value=0;
4519
4589
  for (; ptr != end ; ptr++)
4520
 
    value=(value << 8)+ (uint64_t) (unsigned char) *ptr;
4521
 
  return (int64_t) value;
 
4590
    value=(value << 8)+ (ulonglong) (uchar) *ptr;
 
4591
  return (longlong) value;
4522
4592
}
4523
4593
 
4524
4594
 
4525
4595
my_decimal *Item_hex_string::val_decimal(my_decimal *decimal_value)
4526
4596
{
4527
4597
  // following assert is redundant, because fixed=1 assigned in constructor
4528
 
  assert(fixed == 1);
4529
 
  uint64_t value= (uint64_t)val_int();
 
4598
  DBUG_ASSERT(fixed == 1);
 
4599
  ulonglong value= (ulonglong)val_int();
4530
4600
  int2my_decimal(E_DEC_FATAL_ERROR, value, true, decimal_value);
4531
4601
  return (decimal_value);
4532
4602
}
4533
4603
 
4534
4604
 
4535
4605
int Item_hex_string::save_in_field(Field *field,
4536
 
                                   bool no_conversions __attribute__((unused)))
 
4606
                                   bool no_conversions __attribute__((__unused__)))
4537
4607
{
4538
4608
  field->set_notnull();
4539
4609
  if (field->result_type() == STRING_RESULT)
4540
4610
    return field->store(str_value.ptr(), str_value.length(), 
4541
4611
                        collation.collation);
4542
4612
 
4543
 
  uint64_t nr;
4544
 
  uint32_t length= str_value.length();
 
4613
  ulonglong nr;
 
4614
  uint32 length= str_value.length();
4545
4615
  if (length > 8)
4546
4616
  {
4547
 
    nr= field->flags & UNSIGNED_FLAG ? UINT64_MAX : INT64_MAX;
 
4617
    nr= field->flags & UNSIGNED_FLAG ? ULONGLONG_MAX : LONGLONG_MAX;
4548
4618
    goto warn;
4549
4619
  }
4550
 
  nr= (uint64_t) val_int();
4551
 
  if ((length == 8) && !(field->flags & UNSIGNED_FLAG) && (nr > INT64_MAX))
 
4620
  nr= (ulonglong) val_int();
 
4621
  if ((length == 8) && !(field->flags & UNSIGNED_FLAG) && (nr > LONGLONG_MAX))
4552
4622
  {
4553
 
    nr= INT64_MAX;
 
4623
    nr= LONGLONG_MAX;
4554
4624
    goto warn;
4555
4625
  }
4556
 
  return field->store((int64_t) nr, true);  // Assume hex numbers are unsigned
 
4626
  return field->store((longlong) nr, true);  // Assume hex numbers are unsigned
4557
4627
 
4558
4628
warn:
4559
 
  if (!field->store((int64_t) nr, true))
4560
 
    field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE,
 
4629
  if (!field->store((longlong) nr, true))
 
4630
    field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE,
4561
4631
                       1);
4562
4632
  return 1;
4563
4633
}
4564
4634
 
4565
4635
 
4566
4636
void Item_hex_string::print(String *str,
4567
 
                            enum_query_type query_type __attribute__((unused)))
 
4637
                            enum_query_type query_type __attribute__((__unused__)))
4568
4638
{
4569
4639
  char *end= (char*) str_value.ptr() + str_value.length(),
4570
 
       *ptr= end - cmin(str_value.length(), (uint32_t)sizeof(int64_t));
 
4640
       *ptr= end - min(str_value.length(), sizeof(longlong));
4571
4641
  str->append("0x");
4572
4642
  for (; ptr != end ; ptr++)
4573
4643
  {
4574
 
    str->append(_dig_vec_lower[((unsigned char) *ptr) >> 4]);
4575
 
    str->append(_dig_vec_lower[((unsigned char) *ptr) & 0x0F]);
 
4644
    str->append(_dig_vec_lower[((uchar) *ptr) >> 4]);
 
4645
    str->append(_dig_vec_lower[((uchar) *ptr) & 0x0F]);
4576
4646
  }
4577
4647
}
4578
4648
 
4589
4659
}
4590
4660
 
4591
4661
 
4592
 
Item *Item_hex_string::safe_charset_converter(const CHARSET_INFO * const tocs)
 
4662
Item *Item_hex_string::safe_charset_converter(CHARSET_INFO *tocs)
4593
4663
{
4594
4664
  Item_string *conv;
4595
4665
  String tmp, *str= val_str(&tmp);
4605
4675
/*
4606
4676
  bin item.
4607
4677
  In string context this is a binary string.
4608
 
  In number context this is a int64_t value.
 
4678
  In number context this is a longlong value.
4609
4679
*/
4610
4680
  
4611
 
Item_bin_string::Item_bin_string(const char *str, uint32_t str_length)
 
4681
Item_bin_string::Item_bin_string(const char *str, uint str_length)
4612
4682
{
4613
4683
  const char *end= str + str_length - 1;
4614
 
  unsigned char bits= 0;
4615
 
  uint32_t power= 1;
 
4684
  uchar bits= 0;
 
4685
  uint power= 1;
4616
4686
 
4617
4687
  max_length= (str_length + 7) >> 3;
4618
4688
  char *ptr= (char*) sql_alloc(max_length + 1);
4644
4714
*/
4645
4715
 
4646
4716
bool Item_null::send(Protocol *protocol,
4647
 
                     String *packet __attribute__((unused)))
 
4717
                     String *packet __attribute__((__unused__)))
4648
4718
{
4649
4719
  return protocol->store_null();
4650
4720
}
4660
4730
 
4661
4731
  switch ((f_type=field_type())) {
4662
4732
  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:
 
4733
  case MYSQL_TYPE_NULL:
 
4734
  case MYSQL_TYPE_ENUM:
 
4735
  case MYSQL_TYPE_SET:
 
4736
  case MYSQL_TYPE_BLOB:
 
4737
  case MYSQL_TYPE_STRING:
 
4738
  case MYSQL_TYPE_VAR_STRING:
 
4739
  case MYSQL_TYPE_VARCHAR:
 
4740
  case MYSQL_TYPE_NEWDECIMAL:
4668
4741
  {
4669
4742
    String *res;
4670
4743
    if ((res=val_str(buffer)))
4671
4744
      result= protocol->store(res->ptr(),res->length(),res->charset());
4672
4745
    break;
4673
4746
  }
4674
 
  case DRIZZLE_TYPE_TINY:
 
4747
  case MYSQL_TYPE_TINY:
4675
4748
  {
4676
 
    int64_t nr;
 
4749
    longlong nr;
4677
4750
    nr= val_int();
4678
4751
    if (!null_value)
4679
4752
      result= protocol->store_tiny(nr);
4680
4753
    break;
4681
4754
  }
4682
 
  case DRIZZLE_TYPE_LONG:
4683
 
  {
4684
 
    int64_t nr;
 
4755
  case MYSQL_TYPE_SHORT:
 
4756
  case MYSQL_TYPE_YEAR:
 
4757
  {
 
4758
    longlong nr;
 
4759
    nr= val_int();
 
4760
    if (!null_value)
 
4761
      result= protocol->store_short(nr);
 
4762
    break;
 
4763
  }
 
4764
  case MYSQL_TYPE_LONG:
 
4765
  {
 
4766
    longlong nr;
4685
4767
    nr= val_int();
4686
4768
    if (!null_value)
4687
4769
      result= protocol->store_long(nr);
4688
4770
    break;
4689
4771
  }
4690
 
  case DRIZZLE_TYPE_LONGLONG:
 
4772
  case MYSQL_TYPE_LONGLONG:
4691
4773
  {
4692
 
    int64_t nr;
 
4774
    longlong nr;
4693
4775
    nr= val_int();
4694
4776
    if (!null_value)
4695
 
      result= protocol->store_int64_t(nr, unsigned_flag);
4696
 
    break;
4697
 
  }
4698
 
  case DRIZZLE_TYPE_DOUBLE:
 
4777
      result= protocol->store_longlong(nr, unsigned_flag);
 
4778
    break;
 
4779
  }
 
4780
  case MYSQL_TYPE_FLOAT:
 
4781
  {
 
4782
    float nr;
 
4783
    nr= (float) val_real();
 
4784
    if (!null_value)
 
4785
      result= protocol->store(nr, decimals, buffer);
 
4786
    break;
 
4787
  }
 
4788
  case MYSQL_TYPE_DOUBLE:
4699
4789
  {
4700
4790
    double nr= val_real();
4701
4791
    if (!null_value)
4702
4792
      result= protocol->store(nr, decimals, buffer);
4703
4793
    break;
4704
4794
  }
4705
 
  case DRIZZLE_TYPE_DATETIME:
4706
 
  case DRIZZLE_TYPE_TIMESTAMP:
 
4795
  case MYSQL_TYPE_DATETIME:
 
4796
  case MYSQL_TYPE_TIMESTAMP:
4707
4797
  {
4708
 
    DRIZZLE_TIME tm;
 
4798
    MYSQL_TIME tm;
4709
4799
    get_date(&tm, TIME_FUZZY_DATE);
4710
4800
    if (!null_value)
4711
4801
    {
4712
 
      if (f_type == DRIZZLE_TYPE_NEWDATE)
 
4802
      if (f_type == MYSQL_TYPE_NEWDATE)
4713
4803
        return protocol->store_date(&tm);
4714
4804
      else
4715
4805
        result= protocol->store(&tm);
4716
4806
    }
4717
4807
    break;
4718
4808
  }
4719
 
  case DRIZZLE_TYPE_TIME:
 
4809
  case MYSQL_TYPE_TIME:
4720
4810
  {
4721
 
    DRIZZLE_TIME tm;
 
4811
    MYSQL_TIME tm;
4722
4812
    get_time(&tm);
4723
4813
    if (!null_value)
4724
4814
      result= protocol->store_time(&tm);
4732
4822
 
4733
4823
 
4734
4824
bool Item_field::send(Protocol *protocol,
4735
 
                      String *buffer __attribute__((unused)))
 
4825
                      String *buffer __attribute__((__unused__)))
4736
4826
{
4737
4827
  return protocol->store(result_field);
4738
4828
}
4776
4866
    this field    otherwise
4777
4867
*/
4778
4868
 
4779
 
Item *Item_field::update_value_transformer(unsigned char *select_arg)
 
4869
Item *Item_field::update_value_transformer(uchar *select_arg)
4780
4870
{
4781
4871
  SELECT_LEX *select= (SELECT_LEX*)select_arg;
4782
 
  assert(fixed);
 
4872
  DBUG_ASSERT(fixed);
4783
4873
 
4784
 
  if (field->table != select->context.table_list->table)
 
4874
  if (field->table != select->context.table_list->table &&
 
4875
      type() != Item::TRIGGER_FIELD_ITEM)
4785
4876
  {
4786
4877
    List<Item> *all_fields= &select->join->all_fields;
4787
4878
    Item **ref_pointer_array= select->ref_pointer_array;
4818
4909
                   Item **item, const char *table_name_arg,
4819
4910
                   const char *field_name_arg,
4820
4911
                   bool alias_name_used_arg)
4821
 
  :Item_ident(context_arg, NULL, table_name_arg, field_name_arg),
 
4912
  :Item_ident(context_arg, NullS, table_name_arg, field_name_arg),
4822
4913
   result_field(0), ref(item)
4823
4914
{
4824
4915
  alias_name_used= alias_name_used_arg;
4897
4988
bool Item_ref::fix_fields(THD *thd, Item **reference)
4898
4989
{
4899
4990
  enum_parsing_place place= NO_MATTER;
4900
 
  assert(fixed == 0);
 
4991
  DBUG_ASSERT(fixed == 0);
4901
4992
  SELECT_LEX *current_sel= thd->lex->current_select;
4902
4993
 
4903
4994
  if (!ref || ref == not_found_item)
4946
5037
            goto error; /* Some error occurred (e.g. ambiguous names). */
4947
5038
          if (ref != not_found_item)
4948
5039
          {
4949
 
            assert(*ref && (*ref)->fixed);
 
5040
            DBUG_ASSERT(*ref && (*ref)->fixed);
4950
5041
            prev_subselect_item->used_tables_cache|= (*ref)->used_tables();
4951
5042
            prev_subselect_item->const_item_cache&= (*ref)->const_item();
4952
5043
            break;
4996
5087
              (*reference)->used_tables();
4997
5088
            prev_subselect_item->const_item_cache&=
4998
5089
              (*reference)->const_item();
4999
 
            assert((*reference)->type() == REF_ITEM);
 
5090
            DBUG_ASSERT((*reference)->type() == REF_ITEM);
5000
5091
            mark_as_dependent(thd, last_checked_context->select_lex,
5001
5092
                              context->select_lex, this,
5002
5093
                              ((refer_type == REF_ITEM ||
5035
5126
            break;
5036
5127
          }
5037
5128
        }
5038
 
        assert(from_field == not_found_field);
 
5129
        DBUG_ASSERT(from_field == not_found_field);
5039
5130
 
5040
5131
        /* Reference is not found => depend on outer (or just error). */
5041
5132
        prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
5044
5135
        outer_context= outer_context->outer_context;
5045
5136
      } while (outer_context);
5046
5137
 
5047
 
      assert(from_field != 0 && from_field != view_ref_found);
 
5138
      DBUG_ASSERT(from_field != 0 && from_field != view_ref_found);
5048
5139
      if (from_field != not_found_field)
5049
5140
      {
5050
5141
        Item_field* fld;
5073
5164
        goto error;
5074
5165
      }
5075
5166
      /* Should be checked in resolve_ref_in_select_and_group(). */
5076
 
      assert(*ref && (*ref)->fixed);
 
5167
      DBUG_ASSERT(*ref && (*ref)->fixed);
5077
5168
      mark_as_dependent(thd, last_checked_context->select_lex,
5078
5169
                        context->select_lex, this, this);
5079
5170
      /*
5089
5180
    }
5090
5181
  }
5091
5182
 
5092
 
  assert(*ref);
 
5183
  DBUG_ASSERT(*ref);
5093
5184
  /*
5094
5185
    Check if this is an incorrect reference in a group function or forward
5095
5186
    reference. Do not issue an error if this is:
5146
5237
 
5147
5238
void Item_ref::cleanup()
5148
5239
{
 
5240
  DBUG_ENTER("Item_ref::cleanup");
5149
5241
  Item_ident::cleanup();
5150
5242
  result_field= 0;
5151
 
  return;
 
5243
  DBUG_VOID_RETURN;
5152
5244
}
5153
5245
 
5154
5246
 
5190
5282
}
5191
5283
 
5192
5284
 
5193
 
int64_t Item_ref::val_int_result()
 
5285
longlong Item_ref::val_int_result()
5194
5286
{
5195
5287
  if (result_field)
5196
5288
  {
5249
5341
      return result_field->val_real() != 0.0;
5250
5342
    case ROW_RESULT:
5251
5343
    default:
5252
 
      assert(0);
 
5344
      DBUG_ASSERT(0);
5253
5345
    }
5254
5346
  }
5255
5347
  return val_bool();
5258
5350
 
5259
5351
double Item_ref::val_real()
5260
5352
{
5261
 
  assert(fixed);
 
5353
  DBUG_ASSERT(fixed);
5262
5354
  double tmp=(*ref)->val_result();
5263
5355
  null_value=(*ref)->null_value;
5264
5356
  return tmp;
5265
5357
}
5266
5358
 
5267
5359
 
5268
 
int64_t Item_ref::val_int()
 
5360
longlong Item_ref::val_int()
5269
5361
{
5270
 
  assert(fixed);
5271
 
  int64_t tmp=(*ref)->val_int_result();
 
5362
  DBUG_ASSERT(fixed);
 
5363
  longlong tmp=(*ref)->val_int_result();
5272
5364
  null_value=(*ref)->null_value;
5273
5365
  return tmp;
5274
5366
}
5276
5368
 
5277
5369
bool Item_ref::val_bool()
5278
5370
{
5279
 
  assert(fixed);
 
5371
  DBUG_ASSERT(fixed);
5280
5372
  bool tmp= (*ref)->val_bool_result();
5281
5373
  null_value= (*ref)->null_value;
5282
5374
  return tmp;
5285
5377
 
5286
5378
String *Item_ref::val_str(String* tmp)
5287
5379
{
5288
 
  assert(fixed);
 
5380
  DBUG_ASSERT(fixed);
5289
5381
  tmp=(*ref)->str_result(tmp);
5290
5382
  null_value=(*ref)->null_value;
5291
5383
  return tmp;
5294
5386
 
5295
5387
bool Item_ref::is_null()
5296
5388
{
5297
 
  assert(fixed);
 
5389
  DBUG_ASSERT(fixed);
5298
5390
  return (*ref)->is_null();
5299
5391
}
5300
5392
 
5301
5393
 
5302
 
bool Item_ref::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
5394
bool Item_ref::get_date(MYSQL_TIME *ltime,uint fuzzydate)
5303
5395
{
5304
5396
  return (null_value=(*ref)->get_date_result(ltime,fuzzydate));
5305
5397
}
5315
5407
int Item_ref::save_in_field(Field *to, bool no_conversions)
5316
5408
{
5317
5409
  int res;
5318
 
  assert(!result_field);
 
5410
  DBUG_ASSERT(!result_field);
5319
5411
  res= (*ref)->save_in_field(to, no_conversions);
5320
5412
  null_value= (*ref)->null_value;
5321
5413
  return res;
5375
5467
}
5376
5468
 
5377
5469
 
5378
 
int64_t Item_direct_ref::val_int()
 
5470
longlong Item_direct_ref::val_int()
5379
5471
{
5380
 
  int64_t tmp=(*ref)->val_int();
 
5472
  longlong tmp=(*ref)->val_int();
5381
5473
  null_value=(*ref)->null_value;
5382
5474
  return tmp;
5383
5475
}
5413
5505
}
5414
5506
 
5415
5507
 
5416
 
bool Item_direct_ref::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
5508
bool Item_direct_ref::get_date(MYSQL_TIME *ltime,uint fuzzydate)
5417
5509
{
5418
5510
  return (null_value=(*ref)->get_date(ltime,fuzzydate));
5419
5511
}
5434
5526
bool Item_direct_view_ref::fix_fields(THD *thd, Item **reference)
5435
5527
{
5436
5528
  /* view fild reference must be defined */
5437
 
  assert(*ref);
 
5529
  DBUG_ASSERT(*ref);
5438
5530
  /* (*ref)->check_cols() will be made in Item_direct_ref::fix_fields */
5439
5531
  if (!(*ref)->fixed &&
5440
5532
      ((*ref)->fix_fields(thd, ref)))
5479
5571
}
5480
5572
 
5481
5573
void Item_ref::fix_after_pullout(st_select_lex *new_parent,
5482
 
                                 Item **refptr __attribute__((unused)))
 
5574
                                 Item **refptr __attribute__((__unused__)))
5483
5575
{
5484
5576
  if (depended_from == new_parent)
5485
5577
  {
5506
5598
*/
5507
5599
 
5508
5600
bool Item_direct_view_ref::eq(const Item *item,
5509
 
                              bool binary_cmp __attribute__((unused))) const
 
5601
                              bool binary_cmp __attribute__((__unused__))) const
5510
5602
{
5511
5603
  if (item->type() == REF_ITEM)
5512
5604
  {
5528
5620
 
5529
5621
 
5530
5622
bool Item_default_value::fix_fields(THD *thd,
5531
 
                                    Item **items __attribute__((unused)))
 
5623
                                    Item **items __attribute__((__unused__)))
5532
5624
{
5533
5625
  Item *real_arg;
5534
5626
  Item_field *field_arg;
5535
5627
  Field *def_field;
5536
 
  assert(fixed == 0);
 
5628
  DBUG_ASSERT(fixed == 0);
5537
5629
 
5538
5630
  if (!arg)
5539
5631
  {
5600
5692
 
5601
5693
      {
5602
5694
        push_warning_printf(field_arg->table->in_use,
5603
 
                            DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
5695
                            MYSQL_ERROR::WARN_LEVEL_WARN,
5604
5696
                            ER_NO_DEFAULT_FOR_FIELD,
5605
5697
                            ER(ER_NO_DEFAULT_FOR_FIELD),
5606
5698
                            field_arg->field_name);
5619
5711
  same time it can replace some nodes in the tree.
5620
5712
*/ 
5621
5713
 
5622
 
Item *Item_default_value::transform(Item_transformer transformer, unsigned char *args)
 
5714
Item *Item_default_value::transform(Item_transformer transformer, uchar *args)
5623
5715
{
5624
5716
  Item *new_item= arg->transform(transformer, args);
5625
5717
  if (!new_item)
5645
5737
 
5646
5738
 
5647
5739
bool Item_insert_value::fix_fields(THD *thd,
5648
 
                                   Item **items __attribute__((unused)))
 
5740
                                   Item **items __attribute__((__unused__)))
5649
5741
{
5650
 
  assert(fixed == 0);
 
5742
  DBUG_ASSERT(fixed == 0);
5651
5743
  /* We should only check that arg is in first table */
5652
5744
  if (!arg->fixed)
5653
5745
  {
5654
5746
    bool res;
5655
 
    TableList *orig_next_table= context->last_name_resolution_table;
 
5747
    TABLE_LIST *orig_next_table= context->last_name_resolution_table;
5656
5748
    context->last_name_resolution_table= context->first_name_resolution_table;
5657
5749
    res= arg->fix_fields(thd, &arg);
5658
5750
    context->last_name_resolution_table= orig_next_table;
5674
5766
    According to our SQL grammar, VALUES() function can reference
5675
5767
    only to a column.
5676
5768
  */
5677
 
  assert(arg->type() == FIELD_ITEM);
 
5769
  DBUG_ASSERT(arg->type() == FIELD_ITEM);
5678
5770
 
5679
5771
  Item_field *field_arg= (Item_field *)arg;
5680
5772
 
5747
5839
      new_item= new Item_null(name);
5748
5840
    else
5749
5841
    {
5750
 
      uint32_t length= result->length();
 
5842
      uint length= result->length();
5751
5843
      char *tmp_str= sql_strmake(result->ptr(), length);
5752
5844
      new_item= new Item_string(name, tmp_str, length, result->charset());
5753
5845
    }
5755
5847
  }
5756
5848
  case INT_RESULT:
5757
5849
  {
5758
 
    int64_t result=item->val_int();
5759
 
    uint32_t length=item->max_length;
 
5850
    longlong result=item->val_int();
 
5851
    uint length=item->max_length;
5760
5852
    bool null_value=item->null_value;
5761
5853
    new_item= (null_value ? (Item*) new Item_null(name) :
5762
5854
               (Item*) new Item_int(name, result, length));
5775
5867
    */
5776
5868
    Item_row *item_row= (Item_row*) item;
5777
5869
    Item_row *comp_item_row= (Item_row*) comp_item;
5778
 
    uint32_t col;
 
5870
    uint col;
5779
5871
    new_item= 0;
5780
5872
    /*
5781
5873
      If item and comp_item are both Item_rows and have same number of cols
5783
5875
      We can't ignore NULL values here as this item may be used with <=>, in
5784
5876
      which case NULL's are significant.
5785
5877
    */
5786
 
    assert(item->result_type() == comp_item->result_type());
5787
 
    assert(item_row->cols() == comp_item_row->cols());
 
5878
    DBUG_ASSERT(item->result_type() == comp_item->result_type());
 
5879
    DBUG_ASSERT(item_row->cols() == comp_item_row->cols());
5788
5880
    col= item_row->cols();
5789
5881
    while (col-- > 0)
5790
5882
      resolve_const_item(thd, item_row->addr(col),
5795
5887
  case REAL_RESULT:
5796
5888
  {                                             // It must REAL_RESULT
5797
5889
    double result= item->val_real();
5798
 
    uint32_t length=item->max_length,decimals=item->decimals;
 
5890
    uint length=item->max_length,decimals=item->decimals;
5799
5891
    bool null_value=item->null_value;
5800
5892
    new_item= (null_value ? (Item*) new Item_null(name) : (Item*)
5801
5893
               new Item_float(name, result, decimals, length));
5805
5897
  {
5806
5898
    my_decimal decimal_value;
5807
5899
    my_decimal *result= item->val_decimal(&decimal_value);
5808
 
    uint32_t length= item->max_length, decimals= item->decimals;
 
5900
    uint length= item->max_length, decimals= item->decimals;
5809
5901
    bool null_value= item->null_value;
5810
5902
    new_item= (null_value ?
5811
5903
               (Item*) new Item_null(name) :
5813
5905
    break;
5814
5906
  }
5815
5907
  default:
5816
 
    assert(0);
 
5908
    DBUG_ASSERT(0);
5817
5909
  }
5818
5910
  if (new_item)
5819
5911
    thd->change_item_tree(ref, new_item);
5877
5969
    return new Item_cache_row();
5878
5970
  default:
5879
5971
    // should never be in real life
5880
 
    assert(0);
 
5972
    DBUG_ASSERT(0);
5881
5973
    return 0;
5882
5974
  }
5883
5975
}
5902
5994
}
5903
5995
 
5904
5996
 
5905
 
void Item_cache_int::store(Item *item, int64_t val_arg)
 
5997
void Item_cache_int::store(Item *item, longlong val_arg)
5906
5998
{
5907
5999
  value= val_arg;
5908
6000
  null_value= item->null_value;
5912
6004
 
5913
6005
String *Item_cache_int::val_str(String *str)
5914
6006
{
5915
 
  assert(fixed == 1);
 
6007
  DBUG_ASSERT(fixed == 1);
5916
6008
  str->set(value, default_charset());
5917
6009
  return str;
5918
6010
}
5920
6012
 
5921
6013
my_decimal *Item_cache_int::val_decimal(my_decimal *decimal_val)
5922
6014
{
5923
 
  assert(fixed == 1);
 
6015
  DBUG_ASSERT(fixed == 1);
5924
6016
  int2my_decimal(E_DEC_FATAL_ERROR, value, unsigned_flag, decimal_val);
5925
6017
  return decimal_val;
5926
6018
}
5933
6025
}
5934
6026
 
5935
6027
 
5936
 
int64_t Item_cache_real::val_int()
 
6028
longlong Item_cache_real::val_int()
5937
6029
{
5938
 
  assert(fixed == 1);
5939
 
  return (int64_t) rint(value);
 
6030
  DBUG_ASSERT(fixed == 1);
 
6031
  return (longlong) rint(value);
5940
6032
}
5941
6033
 
5942
6034
 
5943
6035
String* Item_cache_real::val_str(String *str)
5944
6036
{
5945
 
  assert(fixed == 1);
 
6037
  DBUG_ASSERT(fixed == 1);
5946
6038
  str->set_real(value, decimals, default_charset());
5947
6039
  return str;
5948
6040
}
5950
6042
 
5951
6043
my_decimal *Item_cache_real::val_decimal(my_decimal *decimal_val)
5952
6044
{
5953
 
  assert(fixed == 1);
 
6045
  DBUG_ASSERT(fixed == 1);
5954
6046
  double2my_decimal(E_DEC_FATAL_ERROR, value, decimal_val);
5955
6047
  return decimal_val;
5956
6048
}
5965
6057
 
5966
6058
double Item_cache_decimal::val_real()
5967
6059
{
5968
 
  assert(fixed);
 
6060
  DBUG_ASSERT(fixed);
5969
6061
  double res;
5970
6062
  my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &res);
5971
6063
  return res;
5972
6064
}
5973
6065
 
5974
 
int64_t Item_cache_decimal::val_int()
 
6066
longlong Item_cache_decimal::val_int()
5975
6067
{
5976
 
  assert(fixed);
5977
 
  int64_t res;
 
6068
  DBUG_ASSERT(fixed);
 
6069
  longlong res;
5978
6070
  my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &res);
5979
6071
  return res;
5980
6072
}
5981
6073
 
5982
6074
String* Item_cache_decimal::val_str(String *str)
5983
6075
{
5984
 
  assert(fixed);
 
6076
  DBUG_ASSERT(fixed);
5985
6077
  my_decimal_round(E_DEC_FATAL_ERROR, &decimal_value, decimals, false,
5986
6078
                   &decimal_value);
5987
6079
  my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, str);
5988
6080
  return str;
5989
6081
}
5990
6082
 
5991
 
my_decimal *Item_cache_decimal::val_decimal(my_decimal *val __attribute__((unused)))
 
6083
my_decimal *Item_cache_decimal::val_decimal(my_decimal *val __attribute__((__unused__)))
5992
6084
{
5993
 
  assert(fixed);
 
6085
  DBUG_ASSERT(fixed);
5994
6086
  return &decimal_value;
5995
6087
}
5996
6088
 
6018
6110
 
6019
6111
double Item_cache_str::val_real()
6020
6112
{
6021
 
  assert(fixed == 1);
 
6113
  DBUG_ASSERT(fixed == 1);
6022
6114
  int err_not_used;
6023
6115
  char *end_not_used;
6024
6116
  if (value)
6028
6120
}
6029
6121
 
6030
6122
 
6031
 
int64_t Item_cache_str::val_int()
 
6123
longlong Item_cache_str::val_int()
6032
6124
{
6033
 
  assert(fixed == 1);
 
6125
  DBUG_ASSERT(fixed == 1);
6034
6126
  int err;
6035
6127
  if (value)
6036
6128
    return my_strntoll(value->charset(), value->ptr(),
6037
6129
                       value->length(), 10, (char**) 0, &err);
6038
6130
  else
6039
 
    return (int64_t)0;
 
6131
    return (longlong)0;
6040
6132
}
6041
6133
 
6042
6134
my_decimal *Item_cache_str::val_decimal(my_decimal *decimal_val)
6043
6135
{
6044
 
  assert(fixed == 1);
 
6136
  DBUG_ASSERT(fixed == 1);
6045
6137
  if (value)
6046
6138
    string2my_decimal(E_DEC_FATAL_ERROR, value, decimal_val);
6047
6139
  else
6053
6145
int Item_cache_str::save_in_field(Field *field, bool no_conversions)
6054
6146
{
6055
6147
  int res= Item_cache::save_in_field(field, no_conversions);
6056
 
 
6057
 
  return res;
 
6148
  return (is_varbinary && field->type() == MYSQL_TYPE_STRING &&
 
6149
          value->length() < field->field_length) ? 1 : res;
6058
6150
}
6059
6151
 
6060
6152
 
6061
 
bool Item_cache_row::allocate(uint32_t num)
 
6153
bool Item_cache_row::allocate(uint num)
6062
6154
{
6063
6155
  item_count= num;
6064
6156
  THD *thd= current_thd;
6072
6164
  example= item;
6073
6165
  if (!values && allocate(item->cols()))
6074
6166
    return 1;
6075
 
  for (uint32_t i= 0; i < item_count; i++)
 
6167
  for (uint i= 0; i < item_count; i++)
6076
6168
  {
6077
6169
    Item *el= item->element_index(i);
6078
6170
    Item_cache *tmp;
6088
6180
{
6089
6181
  null_value= 0;
6090
6182
  item->bring_value();
6091
 
  for (uint32_t i= 0; i < item_count; i++)
 
6183
  for (uint i= 0; i < item_count; i++)
6092
6184
  {
6093
6185
    values[i]->store(item->element_index(i));
6094
6186
    null_value|= values[i]->null_value;
6096
6188
}
6097
6189
 
6098
6190
 
6099
 
void Item_cache_row::illegal_method_call(const char *method __attribute__((unused)))
 
6191
void Item_cache_row::illegal_method_call(const char *method __attribute__((__unused__)))
6100
6192
{
6101
 
  assert(0);
 
6193
  DBUG_ENTER("Item_cache_row::illegal_method_call");
 
6194
  DBUG_PRINT("error", ("!!! %s method was called for row item", method));
 
6195
  DBUG_ASSERT(0);
6102
6196
  my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
6103
 
  return;
 
6197
  DBUG_VOID_RETURN;
6104
6198
}
6105
6199
 
6106
6200
 
6107
 
bool Item_cache_row::check_cols(uint32_t c)
 
6201
bool Item_cache_row::check_cols(uint c)
6108
6202
{
6109
6203
  if (c != item_count)
6110
6204
  {
6117
6211
 
6118
6212
bool Item_cache_row::null_inside()
6119
6213
{
6120
 
  for (uint32_t i= 0; i < item_count; i++)
 
6214
  for (uint i= 0; i < item_count; i++)
6121
6215
  {
6122
6216
    if (values[i]->cols() > 1)
6123
6217
    {
6137
6231
 
6138
6232
void Item_cache_row::bring_value()
6139
6233
{
6140
 
  for (uint32_t i= 0; i < item_count; i++)
 
6234
  for (uint i= 0; i < item_count; i++)
6141
6235
    values[i]->bring_value();
6142
6236
  return;
6143
6237
}
6146
6240
Item_type_holder::Item_type_holder(THD *thd, Item *item)
6147
6241
  :Item(thd, item), enum_set_typelib(0), fld_type(get_real_type(item))
6148
6242
{
6149
 
  assert(item->fixed);
 
6243
  DBUG_ASSERT(item->fixed);
6150
6244
  maybe_null= item->maybe_null;
6151
6245
  collation.set(item->collation);
6152
6246
  get_full_info(item);
6190
6284
    Field *field= ((Item_field *) item)->field;
6191
6285
    enum_field_types type= field->real_type();
6192
6286
    if (field->is_created_from_null_item)
6193
 
      return DRIZZLE_TYPE_NULL;
 
6287
      return MYSQL_TYPE_NULL;
 
6288
    /* work around about varchar type field detection */
 
6289
    if (type == MYSQL_TYPE_STRING && field->type() == MYSQL_TYPE_VAR_STRING)
 
6290
      return MYSQL_TYPE_VAR_STRING;
6194
6291
    return type;
6195
6292
  }
6196
6293
  case SUM_FUNC_ITEM:
6215
6312
      */
6216
6313
      switch (item->result_type()) {
6217
6314
      case STRING_RESULT:
6218
 
        return DRIZZLE_TYPE_VARCHAR;
 
6315
        return MYSQL_TYPE_VAR_STRING;
6219
6316
      case INT_RESULT:
6220
 
        return DRIZZLE_TYPE_LONGLONG;
 
6317
        return MYSQL_TYPE_LONGLONG;
6221
6318
      case REAL_RESULT:
6222
 
        return DRIZZLE_TYPE_DOUBLE;
 
6319
        return MYSQL_TYPE_DOUBLE;
6223
6320
      case DECIMAL_RESULT:
6224
 
        return DRIZZLE_TYPE_NEWDECIMAL;
 
6321
        return MYSQL_TYPE_NEWDECIMAL;
6225
6322
      case ROW_RESULT:
6226
6323
      default:
6227
 
        assert(0);
6228
 
        return DRIZZLE_TYPE_VARCHAR;
 
6324
        DBUG_ASSERT(0);
 
6325
        return MYSQL_TYPE_VAR_STRING;
6229
6326
      }
6230
6327
    }
6231
6328
    break;
6248
6345
    false  OK
6249
6346
*/
6250
6347
 
6251
 
bool Item_type_holder::join_types(THD *thd __attribute__((unused)),
 
6348
bool Item_type_holder::join_types(THD *thd __attribute__((__unused__)),
6252
6349
                                  Item *item)
6253
6350
{
6254
 
  uint32_t max_length_orig= max_length;
6255
 
  uint32_t decimals_orig= decimals;
 
6351
  uint max_length_orig= max_length;
 
6352
  uint decimals_orig= decimals;
 
6353
  DBUG_ENTER("Item_type_holder::join_types");
 
6354
  DBUG_PRINT("info:", ("was type %d len %d, dec %d name %s",
 
6355
                       fld_type, max_length, decimals,
 
6356
                       (name ? name : "<NULL>")));
 
6357
  DBUG_PRINT("info:", ("in type %d len %d, dec %d",
 
6358
                       get_real_type(item),
 
6359
                       item->max_length, item->decimals));
6256
6360
  fld_type= Field::field_type_merge(fld_type, get_real_type(item));
6257
6361
  {
6258
6362
    int item_decimals= item->decimals;
6259
6363
    /* fix variable decimals which always is NOT_FIXED_DEC */
6260
6364
    if (Field::result_merge_type(fld_type) == INT_RESULT)
6261
6365
      item_decimals= 0;
6262
 
    decimals= cmax((int)decimals, item_decimals);
 
6366
    decimals= max(decimals, item_decimals);
6263
6367
  }
6264
6368
  if (Field::result_merge_type(fld_type) == DECIMAL_RESULT)
6265
6369
  {
6266
 
    decimals= cmin((int)cmax(decimals, item->decimals), DECIMAL_MAX_SCALE);
6267
 
    int precision= cmin(cmax(prev_decimal_int_part, item->decimal_int_part())
 
6370
    decimals= min(max(decimals, item->decimals), DECIMAL_MAX_SCALE);
 
6371
    int precision= min(max(prev_decimal_int_part, item->decimal_int_part())
6268
6372
                       + decimals, DECIMAL_MAX_PRECISION);
6269
6373
    unsigned_flag&= item->unsigned_flag;
6270
6374
    max_length= my_decimal_precision_to_length(precision, decimals,
6276
6380
  case STRING_RESULT:
6277
6381
  {
6278
6382
    const char *old_cs, *old_derivation;
6279
 
    uint32_t old_max_chars= max_length / collation.collation->mbmaxlen;
 
6383
    uint32 old_max_chars= max_length / collation.collation->mbmaxlen;
6280
6384
    old_cs= collation.collation->name;
6281
6385
    old_derivation= collation.derivation_name();
6282
6386
    if (collation.aggregate(item->collation, MY_COLL_ALLOW_CONV))
6286
6390
               item->collation.collation->name,
6287
6391
               item->collation.derivation_name(),
6288
6392
               "UNION");
6289
 
      return(true);
 
6393
      DBUG_RETURN(true);
6290
6394
    }
6291
6395
    /*
6292
6396
      To figure out max_length, we have to take into account possible
6295
6399
     */
6296
6400
    if (collation.collation != &my_charset_bin)
6297
6401
    {
6298
 
      max_length= cmax(old_max_chars * collation.collation->mbmaxlen,
 
6402
      max_length= max(old_max_chars * collation.collation->mbmaxlen,
6299
6403
                      display_length(item) /
6300
6404
                      item->collation.collation->mbmaxlen *
6301
6405
                      collation.collation->mbmaxlen);
6310
6414
    {
6311
6415
      int delta1= max_length_orig - decimals_orig;
6312
6416
      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) 
 
6417
      max_length= max(delta1, delta2) + decimals;
 
6418
      if (fld_type == MYSQL_TYPE_FLOAT && max_length > FLT_DIG + 2) 
 
6419
      {
 
6420
        max_length= FLT_DIG + 6;
 
6421
        decimals= NOT_FIXED_DEC;
 
6422
      } 
 
6423
      if (fld_type == MYSQL_TYPE_DOUBLE && max_length > DBL_DIG + 2) 
6315
6424
      {
6316
6425
        max_length= DBL_DIG + 7;
6317
6426
        decimals= NOT_FIXED_DEC;
6318
6427
      }
6319
6428
    }
6320
6429
    else
6321
 
      max_length= DBL_DIG+7;
 
6430
      max_length= (fld_type == MYSQL_TYPE_FLOAT) ? FLT_DIG+6 : DBL_DIG+7;
6322
6431
    break;
6323
6432
  }
6324
6433
  default:
6325
 
    max_length= cmax(max_length, display_length(item));
 
6434
    max_length= max(max_length, display_length(item));
6326
6435
  };
6327
6436
  maybe_null|= item->maybe_null;
6328
6437
  get_full_info(item);
6329
6438
 
6330
6439
  /* Remember decimal integer part to be used in DECIMAL_RESULT handleng */
6331
6440
  prev_decimal_int_part= decimal_int_part();
6332
 
  return(false);
 
6441
  DBUG_PRINT("info", ("become type: %d  len: %u  dec: %u",
 
6442
                      (int) fld_type, max_length, (uint) decimals));
 
6443
  DBUG_RETURN(false);
6333
6444
}
6334
6445
 
6335
6446
/**
6341
6452
    length
6342
6453
*/
6343
6454
 
6344
 
uint32_t Item_type_holder::display_length(Item *item)
 
6455
uint32 Item_type_holder::display_length(Item *item)
6345
6456
{
6346
6457
  if (item->type() == Item::FIELD_ITEM)
6347
6458
    return ((Item_field *)item)->max_disp_length();
6348
6459
 
6349
6460
  switch (item->field_type())
6350
6461
  {
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:
 
6462
  case MYSQL_TYPE_TIMESTAMP:
 
6463
  case MYSQL_TYPE_TIME:
 
6464
  case MYSQL_TYPE_DATETIME:
 
6465
  case MYSQL_TYPE_YEAR:
 
6466
  case MYSQL_TYPE_NEWDATE:
 
6467
  case MYSQL_TYPE_VARCHAR:
 
6468
  case MYSQL_TYPE_NEWDECIMAL:
 
6469
  case MYSQL_TYPE_ENUM:
 
6470
  case MYSQL_TYPE_SET:
 
6471
  case MYSQL_TYPE_BLOB:
 
6472
  case MYSQL_TYPE_VAR_STRING:
 
6473
  case MYSQL_TYPE_STRING:
 
6474
  case MYSQL_TYPE_TINY:
6360
6475
    return 4;
6361
 
  case DRIZZLE_TYPE_LONG:
 
6476
  case MYSQL_TYPE_SHORT:
 
6477
    return 6;
 
6478
  case MYSQL_TYPE_LONG:
6362
6479
    return MY_INT32_NUM_DECIMAL_DIGITS;
6363
 
  case DRIZZLE_TYPE_DOUBLE:
 
6480
  case MYSQL_TYPE_FLOAT:
 
6481
    return 25;
 
6482
  case MYSQL_TYPE_DOUBLE:
6364
6483
    return 53;
6365
 
  case DRIZZLE_TYPE_NULL:
 
6484
  case MYSQL_TYPE_NULL:
6366
6485
    return 0;
6367
 
  case DRIZZLE_TYPE_LONGLONG:
 
6486
  case MYSQL_TYPE_LONGLONG:
6368
6487
    return 20;
6369
6488
  default:
6370
 
    assert(0); // we should never go there
 
6489
    DBUG_ASSERT(0); // we should never go there
6371
6490
    return 0;
6372
6491
  }
6373
6492
}
6383
6502
    created field
6384
6503
*/
6385
6504
 
6386
 
Field *Item_type_holder::make_field_by_type(Table *table)
 
6505
Field *Item_type_holder::make_field_by_type(TABLE *table)
6387
6506
{
6388
6507
  /*
6389
6508
    The field functions defines a field to be not null if null_ptr is not 0
6390
6509
  */
6391
 
  unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
 
6510
  uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
6392
6511
  Field *field;
6393
6512
 
6394
6513
  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,
 
6514
  case MYSQL_TYPE_ENUM:
 
6515
    DBUG_ASSERT(enum_set_typelib);
 
6516
    field= new Field_enum((uchar *) 0, max_length, null_ptr, 0,
6398
6517
                          Field::NONE, name,
6399
6518
                          get_enum_pack_length(enum_set_typelib->count),
6400
6519
                          enum_set_typelib, collation.collation);
6401
6520
    if (field)
6402
6521
      field->init(table);
6403
6522
    return field;
6404
 
  case DRIZZLE_TYPE_NULL:
 
6523
  case MYSQL_TYPE_SET:
 
6524
    DBUG_ASSERT(enum_set_typelib);
 
6525
    field= new Field_set((uchar *) 0, max_length, null_ptr, 0,
 
6526
                         Field::NONE, name,
 
6527
                         get_set_pack_length(enum_set_typelib->count),
 
6528
                         enum_set_typelib, collation.collation);
 
6529
    if (field)
 
6530
      field->init(table);
 
6531
    return field;
 
6532
  case MYSQL_TYPE_NULL:
6405
6533
    return make_string_field(table);
6406
6534
  default:
6407
6535
    break;
6418
6546
*/
6419
6547
void Item_type_holder::get_full_info(Item *item)
6420
6548
{
6421
 
  if (fld_type == DRIZZLE_TYPE_ENUM)
 
6549
  if (fld_type == MYSQL_TYPE_ENUM ||
 
6550
      fld_type == MYSQL_TYPE_SET)
6422
6551
  {
6423
6552
    if (item->type() == Item::SUM_FUNC_ITEM &&
6424
6553
        (((Item_sum*)item)->sum_func() == Item_sum::MAX_FUNC ||
6428
6557
      We can have enum/set type after merging only if we have one enum|set
6429
6558
      field (or MIN|MAX(enum|set field)) and number of NULL fields
6430
6559
    */
6431
 
    assert((enum_set_typelib &&
6432
 
                 get_real_type(item) == DRIZZLE_TYPE_NULL) ||
 
6560
    DBUG_ASSERT((enum_set_typelib &&
 
6561
                 get_real_type(item) == MYSQL_TYPE_NULL) ||
6433
6562
                (!enum_set_typelib &&
6434
6563
                 item->type() == Item::FIELD_ITEM &&
6435
 
                 (get_real_type(item) == DRIZZLE_TYPE_ENUM) &&
 
6564
                 (get_real_type(item) == MYSQL_TYPE_ENUM ||
 
6565
                  get_real_type(item) == MYSQL_TYPE_SET) &&
6436
6566
                 ((Field_enum*)((Item_field *) item)->field)->typelib));
6437
6567
    if (!enum_set_typelib)
6438
6568
    {
6444
6574
 
6445
6575
double Item_type_holder::val_real()
6446
6576
{
6447
 
  assert(0); // should never be called
 
6577
  DBUG_ASSERT(0); // should never be called
6448
6578
  return 0.0;
6449
6579
}
6450
6580
 
6451
6581
 
6452
 
int64_t Item_type_holder::val_int()
 
6582
longlong Item_type_holder::val_int()
6453
6583
{
6454
 
  assert(0); // should never be called
 
6584
  DBUG_ASSERT(0); // should never be called
6455
6585
  return 0;
6456
6586
}
6457
6587
 
6458
6588
my_decimal *Item_type_holder::val_decimal(my_decimal *)
6459
6589
{
6460
 
  assert(0); // should never be called
 
6590
  DBUG_ASSERT(0); // should never be called
6461
6591
  return 0;
6462
6592
}
6463
6593
 
6464
6594
String *Item_type_holder::val_str(String*)
6465
6595
{
6466
 
  assert(0); // should never be called
 
6596
  DBUG_ASSERT(0); // should never be called
6467
6597
  return 0;
6468
6598
}
6469
6599
 
6470
6600
void Item_result_field::cleanup()
6471
6601
{
 
6602
  DBUG_ENTER("Item_result_field::cleanup()");
6472
6603
  Item::cleanup();
6473
6604
  result_field= 0;
6474
 
  return;
 
6605
  DBUG_VOID_RETURN;
6475
6606
}
6476
6607
 
6477
6608
/**
6481
6612
    do nothing
6482
6613
*/
6483
6614
 
6484
 
void dummy_error_processor(THD *thd __attribute__((unused)),
6485
 
                           void *data __attribute__((unused)))
 
6615
void dummy_error_processor(THD *thd __attribute__((__unused__)),
 
6616
                           void *data __attribute__((__unused__)))
6486
6617
{}
6487
6618
 
6488
6619
/**