~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/item.cc

  • Committer: Monty Taylor
  • Date: 2008-07-13 21:27:17 UTC
  • mto: (77.4.1 glibclient-merge)
  • mto: This revision was merged to the branch mainline in revision 153.
  • Revision ID: monty@inaugust.com-20080713212717-8r4dap6oqxopxrd6
Cleanup to hello_world Makefile.am

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;
205
209
 
206
210
String *Item::val_string_from_int(String *str)
207
211
{
208
 
  int64_t nr= val_int();
 
212
  longlong nr= val_int();
209
213
  if (null_value)
210
214
    return 0;
211
215
  str->set_int(nr, unsigned_flag, &my_charset_bin);
236
240
 
237
241
my_decimal *Item::val_decimal_from_int(my_decimal *decimal_value)
238
242
{
239
 
  int64_t nr= val_int();
 
243
  longlong nr= val_int();
240
244
  if (null_value)
241
245
    return 0;
242
246
  int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
256
260
                     res->ptr(), res->length(), res->charset(),
257
261
                     decimal_value) & E_DEC_BAD_NUM)
258
262
  {
259
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
263
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
260
264
                        ER_TRUNCATED_WRONG_VALUE,
261
265
                        ER(ER_TRUNCATED_WRONG_VALUE), "DECIMAL",
262
266
                        str_value.c_ptr());
268
272
my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value)
269
273
{
270
274
  assert(fixed == 1);
271
 
  DRIZZLE_TIME ltime;
 
275
  MYSQL_TIME ltime;
272
276
  if (get_date(&ltime, TIME_FUZZY_DATE))
273
277
  {
274
278
    my_decimal_set_zero(decimal_value);
282
286
my_decimal *Item::val_decimal_from_time(my_decimal *decimal_value)
283
287
{
284
288
  assert(fixed == 1);
285
 
  DRIZZLE_TIME ltime;
 
289
  MYSQL_TIME ltime;
286
290
  if (get_time(&ltime))
287
291
  {
288
292
    my_decimal_set_zero(decimal_value);
304
308
}
305
309
 
306
310
 
307
 
int64_t Item::val_int_from_decimal()
 
311
longlong Item::val_int_from_decimal()
308
312
{
309
313
  /* Note that fix_fields may not be called for Item_avg_field items */
310
 
  int64_t result;
 
314
  longlong result;
311
315
  my_decimal value, *dec_val= val_decimal(&value);
312
316
  if (null_value)
313
317
    return 0;
317
321
 
318
322
int Item::save_time_in_field(Field *field)
319
323
{
320
 
  DRIZZLE_TIME ltime;
 
324
  MYSQL_TIME ltime;
321
325
  if (get_time(&ltime))
322
326
    return set_field_to_null(field);
323
327
  field->set_notnull();
324
 
  return field->store_time(&ltime, DRIZZLE_TIMESTAMP_TIME);
 
328
  return field->store_time(&ltime, MYSQL_TIMESTAMP_TIME);
325
329
}
326
330
 
327
331
 
328
332
int Item::save_date_in_field(Field *field)
329
333
{
330
 
  DRIZZLE_TIME ltime;
 
334
  MYSQL_TIME ltime;
331
335
  if (get_date(&ltime, TIME_FUZZY_DATE))
332
336
    return set_field_to_null(field);
333
337
  field->set_notnull();
334
 
  return field->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
 
338
  return field->store_time(&ltime, MYSQL_TIMESTAMP_DATETIME);
335
339
}
336
340
 
337
341
 
372
376
  collation(&my_charset_bin, DERIVATION_COERCIBLE)
373
377
{
374
378
  marker= 0;
375
 
  maybe_null= false;
376
 
  null_value= false;
377
 
  with_sum_func= false;
378
 
  unsigned_flag= false;
379
 
  decimals= 0; 
380
 
  max_length= 0;
 
379
  maybe_null=null_value=with_sum_func=unsigned_flag=0;
 
380
  decimals= 0; max_length= 0;
381
381
  with_subselect= 0;
382
382
  cmp_context= (Item_result)-1;
383
383
 
429
429
}
430
430
 
431
431
 
432
 
uint32_t Item::decimal_precision() const
 
432
uint Item::decimal_precision() const
433
433
{
434
434
  Item_result restype= result_type();
435
435
 
436
436
  if ((restype == DECIMAL_RESULT) || (restype == INT_RESULT))
437
 
    return cmin(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
438
 
               (unsigned int)DECIMAL_MAX_PRECISION);
439
 
  return cmin(max_length, (uint32_t)DECIMAL_MAX_PRECISION);
 
437
    return min(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
 
438
               DECIMAL_MAX_PRECISION);
 
439
  return min(max_length, DECIMAL_MAX_PRECISION);
440
440
}
441
441
 
442
442
 
469
469
  @param arg   a dummy parameter, is not used here
470
470
*/
471
471
 
472
 
bool Item::cleanup_processor(unsigned char *arg __attribute__((unused)))
 
472
bool Item::cleanup_processor(uchar *arg __attribute__((__unused__)))
473
473
{
474
474
  if (fixed)
475
475
    cleanup();
524
524
    pointer to newly allocated item is returned.
525
525
*/
526
526
 
527
 
Item* Item::transform(Item_transformer transformer, unsigned char *arg)
 
527
Item* Item::transform(Item_transformer transformer, uchar *arg)
528
528
{
529
529
  return (this->*transformer)(arg);
530
530
}
581
581
  return;
582
582
}
583
583
 
584
 
bool Item_ident::remove_dependence_processor(unsigned char * arg)
 
584
bool Item_ident::remove_dependence_processor(uchar * arg)
585
585
{
586
586
  if (depended_from == (st_select_lex *) arg)
587
587
    depended_from= 0;
607
607
    for the subsequent items.
608
608
*/
609
609
 
610
 
bool Item_field::collect_item_field_processor(unsigned char *arg)
 
610
bool Item_field::collect_item_field_processor(uchar *arg)
611
611
{
612
612
  List<Item_field> *item_list= (List<Item_field>*) arg;
613
613
  List_iterator<Item_field> item_list_it(*item_list);
638
638
    false otherwise
639
639
*/
640
640
 
641
 
bool Item_field::find_item_in_field_list_processor(unsigned char *arg)
 
641
bool Item_field::find_item_in_field_list_processor(uchar *arg)
642
642
{
643
643
  KEY_PART_INFO *first_non_group_part= *((KEY_PART_INFO **) arg);
644
644
  KEY_PART_INFO *last_part= *(((KEY_PART_INFO **) arg) + 1);
661
661
    column read set or to register used fields in a view
662
662
*/
663
663
 
664
 
bool Item_field::register_field_in_read_map(unsigned char *arg)
 
664
bool Item_field::register_field_in_read_map(uchar *arg)
665
665
{
666
 
  Table *table= (Table *) arg;
 
666
  TABLE *table= (TABLE *) arg;
667
667
  if (field->table == table || !table)
668
668
    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
669
  return 0;
673
670
}
674
671
 
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)
 
672
 
 
673
bool Item::check_cols(uint c)
690
674
{
691
675
  if (c != 1)
692
676
  {
697
681
}
698
682
 
699
683
 
700
 
void Item::set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs)
 
684
void Item::set_name(const char *str, uint length, CHARSET_INFO *cs)
701
685
{
702
686
  if (!length)
703
687
  {
708
692
  }
709
693
  if (cs->ctype)
710
694
  {
711
 
    uint32_t orig_len= length;
 
695
    uint orig_len= length;
712
696
    /*
713
697
      This will probably need a better implementation in the future:
714
698
      a function in CHARSET_INFO structure.
721
705
    if (orig_len != length && !is_autogenerated_name)
722
706
    {
723
707
      if (length == 0)
724
 
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
708
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
725
709
                            ER_NAME_BECOMES_EMPTY, ER(ER_NAME_BECOMES_EMPTY),
726
710
                            str + length - orig_len);
727
711
      else
728
 
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
712
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
729
713
                            ER_REMOVED_SPACES, ER(ER_REMOVED_SPACES),
730
714
                            str + length - orig_len);
731
715
    }
738
722
                                   &res_length);
739
723
  }
740
724
  else
741
 
    name= sql_strmake(str, (name_length= cmin(length,(unsigned int)MAX_ALIAS_NAME)));
 
725
    name= sql_strmake(str, (name_length= min(length,MAX_ALIAS_NAME)));
742
726
}
743
727
 
744
728
 
746
730
  @details
747
731
  This function is called when:
748
732
  - 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
 
733
  - When trying to find an ORDER BY/GROUP BY item in the SELECT part
750
734
*/
751
735
 
752
 
bool Item::eq(const Item *item, bool binary_cmp __attribute__((unused))) const
 
736
bool Item::eq(const Item *item, bool binary_cmp __attribute__((__unused__))) const
753
737
{
754
738
  /*
755
739
    Note, that this is never true if item is a Item_param:
761
745
}
762
746
 
763
747
 
764
 
Item *Item::safe_charset_converter(const CHARSET_INFO * const tocs)
 
748
Item *Item::safe_charset_converter(CHARSET_INFO *tocs)
765
749
{
766
750
  Item_func_conv_charset *conv= new Item_func_conv_charset(this, tocs, 1);
767
751
  return conv->safe ? conv : NULL;
779
763
  the latter returns a non-fixed Item, so val_str() crashes afterwards.
780
764
  Override Item_num method, to return a fixed item.
781
765
*/
782
 
Item *Item_num::safe_charset_converter(const CHARSET_INFO * const tocs __attribute__((unused)))
 
766
Item *Item_num::safe_charset_converter(CHARSET_INFO *tocs __attribute__((__unused__)))
783
767
{
784
768
  Item_string *conv;
785
769
  char buf[64];
794
778
}
795
779
 
796
780
 
797
 
Item *Item_static_float_func::safe_charset_converter(const CHARSET_INFO * const tocs __attribute__((unused)))
 
781
Item *Item_static_float_func::safe_charset_converter(CHARSET_INFO *tocs __attribute__((__unused__)))
798
782
{
799
783
  Item_string *conv;
800
784
  char buf[64];
810
794
}
811
795
 
812
796
 
813
 
Item *Item_string::safe_charset_converter(const CHARSET_INFO * const tocs)
 
797
Item *Item_string::safe_charset_converter(CHARSET_INFO *tocs)
814
798
{
815
799
  Item_string *conv;
816
 
  uint32_t conv_errors;
 
800
  uint conv_errors;
817
801
  char *ptr;
818
802
  String tmp, cstr, *ostr= val_str(&tmp);
819
803
  cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
838
822
}
839
823
 
840
824
 
841
 
Item *Item_param::safe_charset_converter(const CHARSET_INFO * const tocs)
 
825
Item *Item_param::safe_charset_converter(CHARSET_INFO *tocs)
842
826
{
843
827
  if (const_item())
844
828
  {
845
 
    uint32_t cnv_errors;
 
829
    uint cnv_errors;
846
830
    String *ostr= val_str(&cnvstr);
847
831
    cnvitem->str_value.copy(ostr->ptr(), ostr->length(),
848
832
                            ostr->charset(), tocs, &cnv_errors);
856
840
}
857
841
 
858
842
 
859
 
Item *Item_static_string_func::safe_charset_converter(const CHARSET_INFO * const tocs)
 
843
Item *Item_static_string_func::safe_charset_converter(CHARSET_INFO *tocs)
860
844
{
861
845
  Item_string *conv;
862
 
  uint32_t conv_errors;
 
846
  uint conv_errors;
863
847
  String tmp, cstr, *ostr= val_str(&tmp);
864
848
  cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
865
849
  if (conv_errors ||
897
881
 
898
882
 
899
883
/**
900
 
  Get the value of the function as a DRIZZLE_TIME structure.
 
884
  Get the value of the function as a MYSQL_TIME structure.
901
885
  As a extra convenience the time structure is reset on error!
902
886
*/
903
887
 
904
 
bool Item::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
888
bool Item::get_date(MYSQL_TIME *ltime,uint fuzzydate)
905
889
{
906
890
  if (result_type() == STRING_RESULT)
907
891
  {
909
893
    String tmp(buff,sizeof(buff), &my_charset_bin),*res;
910
894
    if (!(res=val_str(&tmp)) ||
911
895
        str_to_datetime_with_warn(res->ptr(), res->length(),
912
 
                                  ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
 
896
                                  ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR)
913
897
      goto err;
914
898
  }
915
899
  else
916
900
  {
917
 
    int64_t value= val_int();
 
901
    longlong value= val_int();
918
902
    int was_cut;
919
 
    if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1L)
 
903
    if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1LL)
920
904
    {
921
905
      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);
 
906
      end= longlong10_to_str(value, buff, -10);
 
907
      make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
908
                                   buff, (int) (end-buff), MYSQL_TIMESTAMP_NONE,
 
909
                                   NullS);
926
910
      goto err;
927
911
    }
928
912
  }
929
913
  return 0;
930
914
 
931
915
err:
932
 
  memset(ltime, 0, sizeof(*ltime));
 
916
  bzero((char*) ltime,sizeof(*ltime));
933
917
  return 1;
934
918
}
935
919
 
939
923
  As a extra convenience the time structure is reset on error!
940
924
*/
941
925
 
942
 
bool Item::get_time(DRIZZLE_TIME *ltime)
 
926
bool Item::get_time(MYSQL_TIME *ltime)
943
927
{
944
928
  char buff[40];
945
929
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
946
930
  if (!(res=val_str(&tmp)) ||
947
931
      str_to_time_with_warn(res->ptr(), res->length(), ltime))
948
932
  {
949
 
    memset(ltime, 0, sizeof(*ltime));
 
933
    bzero((char*) ltime,sizeof(*ltime));
950
934
    return 1;
951
935
  }
952
936
  return 0;
953
937
}
954
938
 
955
 
const CHARSET_INFO *Item::default_charset()
 
939
CHARSET_INFO *Item::default_charset()
956
940
{
957
941
  return current_thd->variables.collation_connection;
958
942
}
969
953
int Item::save_in_field_no_warnings(Field *field, bool no_conversions)
970
954
{
971
955
  int res;
972
 
  Table *table= field->table;
 
956
  TABLE *table= field->table;
973
957
  THD *thd= table->in_use;
974
958
  enum_check_fields tmp= thd->count_cuted_fields;
 
959
  my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
975
960
  ulong sql_mode= thd->variables.sql_mode;
976
 
  thd->variables.sql_mode&= ~(MODE_NO_ZERO_DATE);
 
961
  thd->variables.sql_mode&= ~(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE);
977
962
  thd->count_cuted_fields= CHECK_FIELD_IGNORE;
978
963
  res= save_in_field(field, no_conversions);
979
964
  thd->count_cuted_fields= tmp;
 
965
  dbug_tmp_restore_column_map(table->write_set, old_map);
980
966
  thd->variables.sql_mode= sql_mode;
981
967
  return res;
982
968
}
1055
1041
      Item_ref to allow fields from view being stored in tmp table.
1056
1042
    */
1057
1043
    Item_aggregate_ref *item_ref;
1058
 
    uint32_t el= fields.elements;
 
1044
    uint el= fields.elements;
1059
1045
    Item *real_itm= real_item();
1060
1046
 
1061
1047
    ref_pointer_array[el]= real_itm;
1125
1111
  @endcode
1126
1112
*/
1127
1113
 
1128
 
bool DTCollation::aggregate(DTCollation &dt, uint32_t flags)
 
1114
bool DTCollation::aggregate(DTCollation &dt, uint flags)
1129
1115
{
1130
1116
  if (!my_charset_same(collation, dt.collation))
1131
1117
  {
1212
1198
        set(dt);
1213
1199
        return 0;
1214
1200
      }
1215
 
      const CHARSET_INFO * const bin= get_charset_by_csname(collation->csname, 
1216
 
                                                            MY_CS_BINSORT,MYF(0));
 
1201
      CHARSET_INFO *bin= get_charset_by_csname(collation->csname, 
 
1202
                                               MY_CS_BINSORT,MYF(0));
1217
1203
      set(bin, DERIVATION_NONE);
1218
1204
    }
1219
1205
  }
1245
1231
 
1246
1232
 
1247
1233
static
1248
 
void my_coll_agg_error(Item** args, uint32_t count, const char *fname,
 
1234
void my_coll_agg_error(Item** args, uint count, const char *fname,
1249
1235
                       int item_sep)
1250
1236
{
1251
1237
  if (count == 2)
1259
1245
 
1260
1246
 
1261
1247
bool agg_item_collations(DTCollation &c, const char *fname,
1262
 
                         Item **av, uint32_t count, uint32_t flags, int item_sep)
 
1248
                         Item **av, uint count, uint flags, int item_sep)
1263
1249
{
1264
 
  uint32_t i;
 
1250
  uint i;
1265
1251
  Item **arg;
1266
1252
  c.set(av[0]->collation);
1267
1253
  for (i= 1, arg= &av[item_sep]; i < count; i++, arg++)
1283
1269
 
1284
1270
 
1285
1271
bool agg_item_collations_for_comparison(DTCollation &c, const char *fname,
1286
 
                                        Item **av, uint32_t count, uint32_t flags)
 
1272
                                        Item **av, uint count, uint flags)
1287
1273
{
1288
1274
  return (agg_item_collations(c, fname, av, count,
1289
1275
                              flags | MY_COLL_DISALLOW_NONE, 1));
1322
1308
*/
1323
1309
 
1324
1310
bool agg_item_charsets(DTCollation &coll, const char *fname,
1325
 
                       Item **args, uint32_t nargs, uint32_t flags, int item_sep)
 
1311
                       Item **args, uint nargs, uint flags, int item_sep)
1326
1312
{
1327
1313
  Item **arg, *safe_args[2];
1328
1314
 
1345
1331
  }
1346
1332
 
1347
1333
  THD *thd= current_thd;
 
1334
  Query_arena *arena, backup;
1348
1335
  bool res= false;
1349
 
  uint32_t i;
 
1336
  uint i;
 
1337
  /*
 
1338
    In case we're in statement prepare, create conversion item
 
1339
    in its memory: it will be reused on each execute.
 
1340
  */
 
1341
  arena= NULL;
1350
1342
 
1351
1343
  for (i= 0, arg= args; i < nargs; i++, arg+= item_sep)
1352
1344
  {
1353
1345
    Item* conv;
1354
 
    uint32_t dummy_offset;
 
1346
    uint32 dummy_offset;
1355
1347
    if (!String::needs_conversion(0, (*arg)->collation.collation,
1356
1348
                                  coll.collation,
1357
1349
                                  &dummy_offset))
1392
1384
    */
1393
1385
    conv->fix_fields(thd, arg);
1394
1386
  }
1395
 
 
 
1387
  if (arena)
 
1388
    thd->restore_active_arena(arena, &backup);
1396
1389
  return res;
1397
1390
}
1398
1391
 
1413
1406
/**********************************************/
1414
1407
 
1415
1408
Item_field::Item_field(Field *f)
1416
 
  :Item_ident(0, NULL, *f->table_name, f->field_name),
 
1409
  :Item_ident(0, NullS, *f->table_name, f->field_name),
1417
1410
   item_equal(0), no_const_subst(0),
1418
1411
   have_privileges(0), any_privileges(0)
1419
1412
{
1433
1426
  Item_field (this is important in prepared statements).
1434
1427
*/
1435
1428
 
1436
 
Item_field::Item_field(THD *thd __attribute__((unused)),
 
1429
Item_field::Item_field(THD *thd __attribute__((__unused__)),
1437
1430
                       Name_resolution_context *context_arg,
1438
1431
                       Field *f)
1439
1432
  :Item_ident(context_arg, f->table->s->db.str, *f->table_name, f->field_name),
1513
1506
  {
1514
1507
    tmp=(char*) sql_alloc((uint) strlen(db_name)+(uint) strlen(table_name)+
1515
1508
                          (uint) strlen(field_name)+3);
1516
 
    strxmov(tmp,db_name,".",table_name,".",field_name,NULL);
 
1509
    strxmov(tmp,db_name,".",table_name,".",field_name,NullS);
1517
1510
  }
1518
1511
  else
1519
1512
  {
1521
1514
    {
1522
1515
      tmp= (char*) sql_alloc((uint) strlen(table_name) +
1523
1516
                             (uint) strlen(field_name) + 2);
1524
 
      strxmov(tmp, table_name, ".", field_name, NULL);
 
1517
      strxmov(tmp, table_name, ".", field_name, NullS);
1525
1518
    }
1526
1519
    else
1527
1520
      tmp= (char*) field_name;
1530
1523
}
1531
1524
 
1532
1525
void Item_ident::print(String *str,
1533
 
                       enum_query_type query_type __attribute__((unused)))
 
1526
                       enum_query_type query_type __attribute__((__unused__)))
1534
1527
{
1535
1528
  THD *thd= current_thd;
1536
1529
  char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
1540
1533
  {
1541
1534
    if (table_name && table_name[0])
1542
1535
    {
1543
 
      my_stpcpy(t_name_buff, table_name);
 
1536
      strmov(t_name_buff, table_name);
1544
1537
      my_casedn_str(files_charset_info, t_name_buff);
1545
1538
      t_name= t_name_buff;
1546
1539
    }
1547
1540
    if (db_name && db_name[0])
1548
1541
    {
1549
 
      my_stpcpy(d_name_buff, db_name);
 
1542
      strmov(d_name_buff, db_name);
1550
1543
      my_casedn_str(files_charset_info, d_name_buff);
1551
1544
      d_name= d_name_buff;
1552
1545
    }
1602
1595
}
1603
1596
 
1604
1597
 
1605
 
int64_t Item_field::val_int()
 
1598
longlong Item_field::val_int()
1606
1599
{
1607
1600
  assert(fixed == 1);
1608
1601
  if ((null_value=field->is_null()))
1627
1620
  return result_field->val_str(str,&str_value);
1628
1621
}
1629
1622
 
1630
 
bool Item_field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
1623
bool Item_field::get_date(MYSQL_TIME *ltime,uint fuzzydate)
1631
1624
{
1632
1625
  if ((null_value=field->is_null()) || field->get_date(ltime,fuzzydate))
1633
1626
  {
1634
 
    memset(ltime, 0, sizeof(*ltime));
 
1627
    bzero((char*) ltime,sizeof(*ltime));
1635
1628
    return 1;
1636
1629
  }
1637
1630
  return 0;
1638
1631
}
1639
1632
 
1640
 
bool Item_field::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
1633
bool Item_field::get_date_result(MYSQL_TIME *ltime,uint fuzzydate)
1641
1634
{
1642
1635
  if ((null_value=result_field->is_null()) ||
1643
1636
      result_field->get_date(ltime,fuzzydate))
1644
1637
  {
1645
 
    memset(ltime, 0, sizeof(*ltime));
 
1638
    bzero((char*) ltime,sizeof(*ltime));
1646
1639
    return 1;
1647
1640
  }
1648
1641
  return 0;
1649
1642
}
1650
1643
 
1651
 
bool Item_field::get_time(DRIZZLE_TIME *ltime)
 
1644
bool Item_field::get_time(MYSQL_TIME *ltime)
1652
1645
{
1653
1646
  if ((null_value=field->is_null()) || field->get_time(ltime))
1654
1647
  {
1655
 
    memset(ltime, 0, sizeof(*ltime));
 
1648
    bzero((char*) ltime,sizeof(*ltime));
1656
1649
    return 1;
1657
1650
  }
1658
1651
  return 0;
1665
1658
  return result_field->val_real();
1666
1659
}
1667
1660
 
1668
 
int64_t Item_field::val_int_result()
 
1661
longlong Item_field::val_int_result()
1669
1662
{
1670
1663
  if ((null_value=result_field->is_null()))
1671
1664
    return 0;
1708
1701
 
1709
1702
 
1710
1703
bool Item_field::eq(const Item *item,
1711
 
                    bool binary_cmp __attribute__((unused))) const
 
1704
                    bool binary_cmp __attribute__((__unused__))) const
1712
1705
{
1713
1706
  Item *real_item= ((Item *) item)->real_item();
1714
1707
  if (real_item->type() != FIELD_ITEM)
1747
1740
 
1748
1741
 
1749
1742
void Item_field::fix_after_pullout(st_select_lex *new_parent,
1750
 
                                   Item **ref __attribute__((unused)))
 
1743
                                   Item **ref __attribute__((__unused__)))
1751
1744
{
1752
1745
  if (new_parent == depended_from)
1753
1746
    depended_from= NULL;
1768
1761
  return new_item;
1769
1762
}
1770
1763
 
1771
 
int64_t Item_field::val_int_endpoint(bool left_endp __attribute__((unused)),
1772
 
                                      bool *incl_endp __attribute__((unused)))
 
1764
longlong Item_field::val_int_endpoint(bool left_endp __attribute__((__unused__)),
 
1765
                                      bool *incl_endp __attribute__((__unused__)))
1773
1766
{
1774
 
  int64_t res= val_int();
1775
 
  return null_value? INT64_MIN : res;
 
1767
  longlong res= val_int();
 
1768
  return null_value? LONGLONG_MIN : res;
1776
1769
}
1777
1770
 
1778
1771
/**
1779
 
  Create an item from a string we KNOW points to a valid int64_t
 
1772
  Create an item from a string we KNOW points to a valid longlong
1780
1773
  end \\0 terminated number string.
1781
1774
  This is always 'signed'. Unsigned values are created with Item_uint()
1782
1775
*/
1783
1776
 
1784
 
Item_int::Item_int(const char *str_arg, uint32_t length)
 
1777
Item_int::Item_int(const char *str_arg, uint length)
1785
1778
{
1786
1779
  char *end_ptr= (char*) str_arg + length;
1787
1780
  int error;
1807
1800
}
1808
1801
 
1809
1802
void Item_int::print(String *str,
1810
 
                     enum_query_type query_type __attribute__((unused)))
 
1803
                     enum_query_type query_type __attribute__((__unused__)))
1811
1804
{
1812
1805
  // my_charset_bin is good enough for numbers
1813
1806
  str_value.set(value, &my_charset_bin);
1815
1808
}
1816
1809
 
1817
1810
 
1818
 
Item_uint::Item_uint(const char *str_arg, uint32_t length):
 
1811
Item_uint::Item_uint(const char *str_arg, uint length):
1819
1812
  Item_int(str_arg, length)
1820
1813
{
1821
1814
  unsigned_flag= 1;
1822
1815
}
1823
1816
 
1824
1817
 
1825
 
Item_uint::Item_uint(const char *str_arg, int64_t i, uint32_t length):
 
1818
Item_uint::Item_uint(const char *str_arg, longlong i, uint length):
1826
1819
  Item_int(str_arg, i, length)
1827
1820
{
1828
1821
  unsigned_flag= 1;
1833
1826
{
1834
1827
  // following assert is redundant, because fixed=1 assigned in constructor
1835
1828
  assert(fixed == 1);
1836
 
  str->set((uint64_t) value, &my_charset_bin);
 
1829
  str->set((ulonglong) value, &my_charset_bin);
1837
1830
  return str;
1838
1831
}
1839
1832
 
1840
1833
 
1841
1834
void Item_uint::print(String *str,
1842
 
                      enum_query_type query_type __attribute__((unused)))
 
1835
                      enum_query_type query_type __attribute__((__unused__)))
1843
1836
{
1844
1837
  // latin1 is good enough for numbers
1845
 
  str_value.set((uint64_t) value, default_charset());
 
1838
  str_value.set((ulonglong) value, default_charset());
1846
1839
  str->append(str_value);
1847
1840
}
1848
1841
 
1849
1842
 
1850
 
Item_decimal::Item_decimal(const char *str_arg, uint32_t length,
1851
 
                           const CHARSET_INFO * const charset)
 
1843
Item_decimal::Item_decimal(const char *str_arg, uint length,
 
1844
                           CHARSET_INFO *charset)
1852
1845
{
1853
1846
  str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
1854
1847
  name= (char*) str_arg;
1855
 
  decimals= (uint8_t) decimal_value.frac;
 
1848
  decimals= (uint8) decimal_value.frac;
1856
1849
  fixed= 1;
1857
1850
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1858
1851
                                             decimals, unsigned_flag);
1859
1852
}
1860
1853
 
1861
 
Item_decimal::Item_decimal(int64_t val, bool unsig)
 
1854
Item_decimal::Item_decimal(longlong val, bool unsig)
1862
1855
{
1863
1856
  int2my_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
1864
 
  decimals= (uint8_t) decimal_value.frac;
 
1857
  decimals= (uint8) decimal_value.frac;
1865
1858
  fixed= 1;
1866
1859
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1867
1860
                                             decimals, unsigned_flag);
1869
1862
 
1870
1863
 
1871
1864
Item_decimal::Item_decimal(double val,
1872
 
                           int precision __attribute__((unused)),
1873
 
                           int scale __attribute__((unused)))
 
1865
                           int precision __attribute__((__unused__)),
 
1866
                           int scale __attribute__((__unused__)))
1874
1867
{
1875
1868
  double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
1876
 
  decimals= (uint8_t) decimal_value.frac;
 
1869
  decimals= (uint8) decimal_value.frac;
1877
1870
  fixed= 1;
1878
1871
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1879
1872
                                             decimals, unsigned_flag);
1881
1874
 
1882
1875
 
1883
1876
Item_decimal::Item_decimal(const char *str, const my_decimal *val_arg,
1884
 
                           uint32_t decimal_par, uint32_t length)
 
1877
                           uint decimal_par, uint length)
1885
1878
{
1886
1879
  my_decimal2decimal(val_arg, &decimal_value);
1887
1880
  name= (char*) str;
1888
 
  decimals= (uint8_t) decimal_par;
 
1881
  decimals= (uint8) decimal_par;
1889
1882
  max_length= length;
1890
1883
  fixed= 1;
1891
1884
}
1894
1887
Item_decimal::Item_decimal(my_decimal *value_par)
1895
1888
{
1896
1889
  my_decimal2decimal(value_par, &decimal_value);
1897
 
  decimals= (uint8_t) decimal_value.frac;
 
1890
  decimals= (uint8) decimal_value.frac;
1898
1891
  fixed= 1;
1899
1892
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1900
1893
                                             decimals, unsigned_flag);
1901
1894
}
1902
1895
 
1903
1896
 
1904
 
Item_decimal::Item_decimal(const unsigned char *bin, int precision, int scale)
 
1897
Item_decimal::Item_decimal(const uchar *bin, int precision, int scale)
1905
1898
{
1906
1899
  binary2my_decimal(E_DEC_FATAL_ERROR, bin,
1907
1900
                    &decimal_value, precision, scale);
1908
 
  decimals= (uint8_t) decimal_value.frac;
 
1901
  decimals= (uint8) decimal_value.frac;
1909
1902
  fixed= 1;
1910
1903
  max_length= my_decimal_precision_to_length(precision, decimals,
1911
1904
                                             unsigned_flag);
1912
1905
}
1913
1906
 
1914
1907
 
1915
 
int64_t Item_decimal::val_int()
 
1908
longlong Item_decimal::val_int()
1916
1909
{
1917
 
  int64_t result;
 
1910
  longlong result;
1918
1911
  my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &result);
1919
1912
  return result;
1920
1913
}
1934
1927
}
1935
1928
 
1936
1929
void Item_decimal::print(String *str,
1937
 
                         enum_query_type query_type __attribute__((unused)))
 
1930
                         enum_query_type query_type __attribute__((__unused__)))
1938
1931
{
1939
1932
  my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, &str_value);
1940
1933
  str->append(str_value);
1942
1935
 
1943
1936
 
1944
1937
bool Item_decimal::eq(const Item *item,
1945
 
                      bool binary_cmp __attribute__((unused))) const
 
1938
                      bool binary_cmp __attribute__((__unused__))) const
1946
1939
{
1947
1940
  if (type() == item->type() && item->basic_const_item())
1948
1941
  {
1963
1956
void Item_decimal::set_decimal_value(my_decimal *value_par)
1964
1957
{
1965
1958
  my_decimal2decimal(value_par, &decimal_value);
1966
 
  decimals= (uint8_t) decimal_value.frac;
 
1959
  decimals= (uint8) decimal_value.frac;
1967
1960
  unsigned_flag= !decimal_value.sign();
1968
1961
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1969
1962
                                             decimals, unsigned_flag);
2031
2024
  int error;
2032
2025
  char *end, *org_end;
2033
2026
  double tmp;
2034
 
  const CHARSET_INFO * const cs= str_value.charset();
 
2027
  CHARSET_INFO *cs= str_value.charset();
2035
2028
 
2036
2029
  org_end= (char*) str_value.ptr() + str_value.length();
2037
2030
  tmp= my_strntod(cs, (char*) str_value.ptr(), str_value.length(), &end,
2042
2035
      We can use str_value.ptr() here as Item_string is gurantee to put an
2043
2036
      end \0 here.
2044
2037
    */
2045
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2038
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2046
2039
                        ER_TRUNCATED_WRONG_VALUE,
2047
2040
                        ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE",
2048
2041
                        str_value.ptr());
2055
2048
  @todo
2056
2049
  Give error if we wanted a signed integer and we got an unsigned one
2057
2050
*/
2058
 
int64_t Item_string::val_int()
 
2051
longlong Item_string::val_int()
2059
2052
{
2060
2053
  assert(fixed == 1);
2061
2054
  int err;
2062
 
  int64_t tmp;
 
2055
  longlong tmp;
2063
2056
  char *end= (char*) str_value.ptr()+ str_value.length();
2064
2057
  char *org_end= end;
2065
 
  const CHARSET_INFO * const cs= str_value.charset();
 
2058
  CHARSET_INFO *cs= str_value.charset();
2066
2059
 
2067
2060
  tmp= (*(cs->cset->strtoll10))(cs, str_value.ptr(), &end, &err);
2068
2061
  /*
2072
2065
  if (err > 0 ||
2073
2066
      (end != org_end && !check_if_only_end_space(cs, end, org_end)))
2074
2067
  {
2075
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2068
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2076
2069
                        ER_TRUNCATED_WRONG_VALUE,
2077
2070
                        ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
2078
2071
                        str_value.ptr());
2088
2081
 
2089
2082
 
2090
2083
bool Item_null::eq(const Item *item,
2091
 
                   bool binary_cmp __attribute__((unused))) const
 
2084
                   bool binary_cmp __attribute__((__unused__))) const
2092
2085
{ return item->type() == type(); }
2093
2086
 
2094
2087
 
2099
2092
  null_value=1;
2100
2093
  return 0.0;
2101
2094
}
2102
 
int64_t Item_null::val_int()
 
2095
longlong Item_null::val_int()
2103
2096
{
2104
2097
  // following assert is redundant, because fixed=1 assigned in constructor
2105
2098
  assert(fixed == 1);
2107
2100
  return 0;
2108
2101
}
2109
2102
/* ARGSUSED */
2110
 
String *Item_null::val_str(String *str __attribute__((unused)))
 
2103
String *Item_null::val_str(String *str __attribute__((__unused__)))
2111
2104
{
2112
2105
  // following assert is redundant, because fixed=1 assigned in constructor
2113
2106
  assert(fixed == 1);
2115
2108
  return 0;
2116
2109
}
2117
2110
 
2118
 
my_decimal *Item_null::val_decimal(my_decimal *decimal_value __attribute__((unused)))
 
2111
my_decimal *Item_null::val_decimal(my_decimal *decimal_value __attribute__((__unused__)))
2119
2112
{
2120
2113
  return 0;
2121
2114
}
2122
2115
 
2123
2116
 
2124
 
Item *Item_null::safe_charset_converter(const CHARSET_INFO * const tocs)
 
2117
Item *Item_null::safe_charset_converter(CHARSET_INFO *tocs)
2125
2118
{
2126
2119
  collation.set(tocs);
2127
2120
  return this;
2136
2129
 
2137
2130
static void
2138
2131
default_set_param_func(Item_param *param,
2139
 
                       unsigned char **pos __attribute__((unused)),
 
2132
                       uchar **pos __attribute__((unused)),
2140
2133
                       ulong len __attribute__((unused)))
2141
2134
{
2142
2135
  param->set_null();
2143
2136
}
2144
2137
 
2145
2138
 
2146
 
Item_param::Item_param(uint32_t pos_in_query_arg) :
 
2139
Item_param::Item_param(uint pos_in_query_arg) :
2147
2140
  state(NO_VALUE),
2148
2141
  item_result_type(STRING_RESULT),
2149
2142
  /* Don't pretend to be a literal unless value for this item is set. */
2150
2143
  item_type(PARAM_ITEM),
2151
 
  param_type(DRIZZLE_TYPE_VARCHAR),
 
2144
  param_type(MYSQL_TYPE_VARCHAR),
2152
2145
  pos_in_query(pos_in_query_arg),
2153
2146
  set_param_func(default_set_param_func),
2154
2147
  limit_clause_param(false)
2181
2174
  return;
2182
2175
}
2183
2176
 
2184
 
void Item_param::set_int(int64_t i, uint32_t max_length_arg)
 
2177
void Item_param::set_int(longlong i, uint32 max_length_arg)
2185
2178
{
2186
 
  value.integer= (int64_t) i;
 
2179
  value.integer= (longlong) i;
2187
2180
  state= INT_VALUE;
2188
2181
  max_length= max_length_arg;
2189
2182
  decimals= 0;
2214
2207
    internal decimal value.
2215
2208
*/
2216
2209
 
2217
 
void Item_param::set_decimal(char *str, ulong length)
 
2210
void Item_param::set_decimal(const char *str, ulong length)
2218
2211
{
2219
2212
  char *end;
2220
2213
 
2221
 
  end= str+length;
2222
 
  str2my_decimal((uint)E_DEC_FATAL_ERROR, str, &decimal_value, &end);
 
2214
  end= (char*) str+length;
 
2215
  str2my_decimal(E_DEC_FATAL_ERROR, str, &decimal_value, &end);
2223
2216
  state= DECIMAL_VALUE;
2224
2217
  decimals= decimal_value.frac;
2225
2218
  max_length= my_decimal_precision_to_length(decimal_value.precision(),
2230
2223
 
2231
2224
 
2232
2225
/**
2233
 
  Set parameter value from DRIZZLE_TIME value.
 
2226
  Set parameter value from MYSQL_TIME value.
2234
2227
 
2235
2228
  @param tm              datetime value to set (time_type is ignored)
2236
2229
  @param type            type of datetime value
2242
2235
    the fact that even wrong value sent over binary protocol fits into
2243
2236
    MAX_DATE_STRING_REP_LENGTH buffer.
2244
2237
*/
2245
 
void Item_param::set_time(DRIZZLE_TIME *tm,
2246
 
                          enum enum_drizzle_timestamp_type time_type,
2247
 
                          uint32_t max_length_arg)
 
2238
void Item_param::set_time(MYSQL_TIME *tm, timestamp_type time_type,
 
2239
                          uint32 max_length_arg)
2248
2240
2249
2241
  value.time= *tm;
2250
2242
  value.time.time_type= time_type;
2251
2243
 
2252
2244
  if (value.time.year > 9999 || value.time.month > 12 ||
2253
2245
      value.time.day > 31 ||
2254
 
      ((time_type != DRIZZLE_TIMESTAMP_TIME) && value.time.hour > 23) ||
 
2246
      ((time_type != MYSQL_TIMESTAMP_TIME) && value.time.hour > 23) ||
2255
2247
      value.time.minute > 59 || value.time.second > 59)
2256
2248
  {
2257
2249
    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,
 
2250
    uint length= my_TIME_to_str(&value.time, buff);
 
2251
    make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2260
2252
                                 buff, length, time_type, 0);
2261
 
    set_zero_time(&value.time, DRIZZLE_TIMESTAMP_ERROR);
 
2253
    set_zero_time(&value.time, MYSQL_TIMESTAMP_ERROR);
2262
2254
  }
2263
2255
 
2264
2256
  state= TIME_VALUE;
2275
2267
    Assign string with no conversion: data is converted only after it's
2276
2268
    been written to the binary log.
2277
2269
  */
2278
 
  uint32_t dummy_errors;
 
2270
  uint dummy_errors;
2279
2271
  if (str_value.copy(str, length, &my_charset_bin, &my_charset_bin,
2280
2272
                     &dummy_errors))
2281
2273
    return(true);
2328
2320
    unsigned_flag= entry->unsigned_flag;
2329
2321
    if (limit_clause_param)
2330
2322
    {
2331
 
      bool unused;
 
2323
      my_bool unused;
2332
2324
      set_int(entry->val_int(&unused), MY_INT64_NUM_DECIMAL_DIGITS);
2333
2325
      item_type= Item::INT_ITEM;
2334
2326
      return(!unsigned_flag && value.integer < 0 ? 1 : 0);
2339
2331
      item_type= Item::REAL_ITEM;
2340
2332
      break;
2341
2333
    case INT_RESULT:
2342
 
      set_int(*(int64_t*)entry->value, MY_INT64_NUM_DECIMAL_DIGITS);
 
2334
      set_int(*(longlong*)entry->value, MY_INT64_NUM_DECIMAL_DIGITS);
2343
2335
      item_type= Item::INT_ITEM;
2344
2336
      break;
2345
2337
    case STRING_RESULT:
2346
2338
    {
2347
 
      const CHARSET_INFO * const fromcs= entry->collation.collation;
2348
 
      const CHARSET_INFO * const tocs= thd->variables.collation_connection;
2349
 
      uint32_t dummy_offset;
 
2339
      CHARSET_INFO *fromcs= entry->collation.collation;
 
2340
      CHARSET_INFO *tocs= thd->variables.collation_connection;
 
2341
      uint32 dummy_offset;
2350
2342
 
2351
2343
      value.cs_info.character_set_of_placeholder= 
2352
2344
        value.cs_info.character_set_client= fromcs;
2456
2448
}
2457
2449
 
2458
2450
 
2459
 
bool Item_param::get_time(DRIZZLE_TIME *res)
 
2451
bool Item_param::get_time(MYSQL_TIME *res)
2460
2452
{
2461
2453
  if (state == TIME_VALUE)
2462
2454
  {
2471
2463
}
2472
2464
 
2473
2465
 
2474
 
bool Item_param::get_date(DRIZZLE_TIME *res, uint32_t fuzzydate)
 
2466
bool Item_param::get_date(MYSQL_TIME *res, uint fuzzydate)
2475
2467
{
2476
2468
  if (state == TIME_VALUE)
2477
2469
  {
2508
2500
      This works for example when user says SELECT ?+0.0 and supplies
2509
2501
      time value for the placeholder.
2510
2502
    */
2511
 
    return uint64_t2double(TIME_to_uint64_t(&value.time));
 
2503
    return ulonglong2double(TIME_to_ulonglong(&value.time));
2512
2504
  case NULL_VALUE:
2513
2505
    return 0.0;
2514
2506
  default:
2518
2510
2519
2511
 
2520
2512
 
2521
 
int64_t Item_param::val_int() 
 
2513
longlong Item_param::val_int() 
2522
2514
2523
2515
  switch (state) {
2524
2516
  case REAL_VALUE:
2525
 
    return (int64_t) rint(value.real);
 
2517
    return (longlong) rint(value.real);
2526
2518
  case INT_VALUE:
2527
2519
    return value.integer;
2528
2520
  case DECIMAL_VALUE:
2529
2521
  {
2530
 
    int64_t i;
 
2522
    longlong i;
2531
2523
    my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &i);
2532
2524
    return i;
2533
2525
  }
2539
2531
                         str_value.length(), 10, (char**) 0, &dummy_err);
2540
2532
    }
2541
2533
  case TIME_VALUE:
2542
 
    return (int64_t) TIME_to_uint64_t(&value.time);
 
2534
    return (longlong) TIME_to_ulonglong(&value.time);
2543
2535
  case NULL_VALUE:
2544
2536
    return 0; 
2545
2537
  default:
2566
2558
    return dec;
2567
2559
  case TIME_VALUE:
2568
2560
  {
2569
 
    int64_t i= (int64_t) TIME_to_uint64_t(&value.time);
 
2561
    longlong i= (longlong) TIME_to_ulonglong(&value.time);
2570
2562
    int2my_decimal(E_DEC_FATAL_ERROR, i, 0, dec);
2571
2563
    return dec;
2572
2564
  }
2654
2646
      *ptr++= '\'';
2655
2647
      ptr+= (uint) my_TIME_to_str(&value.time, ptr);
2656
2648
      *ptr++= '\'';
2657
 
      str->length((uint32_t) (ptr - buf));
 
2649
      str->length((uint32) (ptr - buf));
2658
2650
      break;
2659
2651
    }
2660
2652
  case STRING_VALUE:
2784
2776
/* End of Item_param related */
2785
2777
 
2786
2778
void Item_param::print(String *str,
2787
 
                       enum_query_type query_type __attribute__((unused)))
 
2779
                       enum_query_type query_type __attribute__((__unused__)))
2788
2780
{
2789
2781
  if (state == NO_VALUE)
2790
2782
  {
2814
2806
}
2815
2807
 
2816
2808
/* ARGSUSED */
2817
 
String *Item_copy_string::val_str(String *str __attribute__((unused)))
 
2809
String *Item_copy_string::val_str(String *str __attribute__((__unused__)))
2818
2810
{
2819
2811
  // Item_copy_string is used without fix_fields call
2820
2812
  if (null_value)
2838
2830
*/
2839
2831
 
2840
2832
/* ARGSUSED */
2841
 
bool Item::fix_fields(THD *thd __attribute__((unused)),
2842
 
                      Item **ref __attribute__((unused)))
 
2833
bool Item::fix_fields(THD *thd __attribute__((__unused__)),
 
2834
                      Item **ref __attribute__((__unused__)))
2843
2835
{
2844
2836
 
2845
2837
  // We do not check fields which are fixed during construction
2857
2849
}
2858
2850
 
2859
2851
 
2860
 
int64_t Item_ref_null_helper::val_int()
 
2852
longlong Item_ref_null_helper::val_int()
2861
2853
{
2862
2854
  assert(fixed == 1);
2863
 
  int64_t tmp= (*ref)->val_int_result();
 
2855
  longlong tmp= (*ref)->val_int_result();
2864
2856
  owner->was_null|= null_value= (*ref)->null_value;
2865
2857
  return tmp;
2866
2858
}
2893
2885
}
2894
2886
 
2895
2887
 
2896
 
bool Item_ref_null_helper::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate)
 
2888
bool Item_ref_null_helper::get_date(MYSQL_TIME *ltime, uint fuzzydate)
2897
2889
{  
2898
2890
  return (owner->was_null|= null_value= (*ref)->get_date(ltime, fuzzydate));
2899
2891
}
2925
2917
  current->mark_as_dependent(last);
2926
2918
  if (thd->lex->describe & DESCRIBE_EXTENDED)
2927
2919
  {
2928
 
    char warn_buff[DRIZZLE_ERRMSG_SIZE];
 
2920
    char warn_buff[MYSQL_ERRMSG_SIZE];
2929
2921
    sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED),
2930
2922
            db_name, (db_name[0] ? "." : ""),
2931
2923
            table_name, (table_name [0] ? "." : ""),
2932
2924
            resolved_item->field_name,
2933
2925
            current->select_number, last->select_number);
2934
 
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
 
2926
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
2935
2927
                 ER_WARN_FIELD_RESOLVED, warn_buff);
2936
2928
  }
2937
2929
}
3016
3008
    - NULL if find_item is not in group_list
3017
3009
*/
3018
3010
 
3019
 
static Item** find_field_in_group_list(Item *find_item, order_st *group_list)
 
3011
static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
3020
3012
{
3021
3013
  const char *db_name;
3022
3014
  const char *table_name;
3023
3015
  const char *field_name;
3024
 
  order_st      *found_group= NULL;
 
3016
  ORDER      *found_group= NULL;
3025
3017
  int         found_match_degree= 0;
3026
3018
  Item_ident *cur_field;
3027
3019
  int         cur_match_degree= 0;
3047
3039
 
3048
3040
  assert(field_name != 0);
3049
3041
 
3050
 
  for (order_st *cur_group= group_list ; cur_group ; cur_group= cur_group->next)
 
3042
  for (ORDER *cur_group= group_list ; cur_group ; cur_group= cur_group->next)
3051
3043
  {
3052
3044
    if ((*(cur_group->item))->real_item()->type() == Item::FIELD_ITEM)
3053
3045
    {
3148
3140
{
3149
3141
  Item **group_by_ref= NULL;
3150
3142
  Item **select_ref= NULL;
3151
 
  order_st *group_list= (order_st*) select->group_list.first;
 
3143
  ORDER *group_list= (ORDER*) select->group_list.first;
3152
3144
  bool ambiguous_fields= false;
3153
 
  uint32_t counter;
 
3145
  uint counter;
3154
3146
  enum_resolution_type resolution;
3155
3147
 
3156
3148
  /*
3174
3166
        !((*group_by_ref)->eq(*select_ref, 0)))
3175
3167
    {
3176
3168
      ambiguous_fields= true;
3177
 
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
 
3169
      push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
3178
3170
                          ER(ER_NON_UNIQ_ERROR), ref->full_name(),
3179
3171
                          current_thd->where);
3180
3172
 
3567
3559
      /* Look up in current select's item_list to find aliased fields */
3568
3560
      if (thd->lex->current_select->is_item_list_lookup)
3569
3561
      {
3570
 
        uint32_t counter;
 
3562
        uint counter;
3571
3563
        enum_resolution_type resolution;
3572
3564
        Item** res= find_item_in_list(this, thd->lex->current_select->item_list,
3573
3565
                                      &counter, REPORT_EXCEPT_NOT_FOUND,
3665
3657
  }
3666
3658
  else if (thd->mark_used_columns != MARK_COLUMNS_NONE)
3667
3659
  {
3668
 
    Table *table= field->table;
 
3660
    TABLE *table= field->table;
3669
3661
    MY_BITMAP *current_bitmap, *other_bitmap;
3670
3662
    if (thd->mark_used_columns == MARK_COLUMNS_READ)
3671
3663
    {
3698
3690
  return true;
3699
3691
}
3700
3692
 
3701
 
Item *Item_field::safe_charset_converter(const CHARSET_INFO * const tocs)
 
3693
Item *Item_field::safe_charset_converter(CHARSET_INFO *tocs)
3702
3694
{
3703
3695
  no_const_subst= 1;
3704
3696
  return Item::safe_charset_converter(tocs);
3787
3779
    false  otherwise
3788
3780
*/
3789
3781
 
3790
 
bool Item_field::subst_argument_checker(unsigned char **arg)
 
3782
bool Item_field::subst_argument_checker(uchar **arg)
3791
3783
{
3792
3784
  return (result_type() != STRING_RESULT) || (*arg);
3793
3785
}
3794
3786
 
3795
3787
 
3796
3788
/**
 
3789
  Convert a numeric value to a zero-filled string
 
3790
 
 
3791
  @param[in,out]  item   the item to operate on
 
3792
  @param          field  The field that this value is equated to
 
3793
 
 
3794
  This function converts a numeric value to a string. In this conversion
 
3795
  the zero-fill flag of the field is taken into account.
 
3796
  This is required so the resulting string value can be used instead of
 
3797
  the field reference when propagating equalities.
 
3798
*/
 
3799
 
 
3800
static void convert_zerofill_number_to_string(Item **item, Field_num *field)
 
3801
{
 
3802
  char buff[MAX_FIELD_WIDTH],*pos;
 
3803
  String tmp(buff,sizeof(buff), field->charset()), *res;
 
3804
 
 
3805
  res= (*item)->val_str(&tmp);
 
3806
  field->prepend_zeros(res);
 
3807
  pos= (char *) sql_strmake (res->ptr(), res->length());
 
3808
  *item= new Item_string(pos, res->length(), field->charset());
 
3809
}
 
3810
 
 
3811
 
 
3812
/**
3797
3813
  Set a pointer to the multiple equality the field reference belongs to
3798
3814
  (if any).
3799
3815
 
3817
3833
    - pointer to the field item, otherwise.
3818
3834
*/
3819
3835
 
3820
 
Item *Item_field::equal_fields_propagator(unsigned char *arg)
 
3836
Item *Item_field::equal_fields_propagator(uchar *arg)
3821
3837
{
3822
3838
  if (no_const_subst)
3823
3839
    return this;
3839
3855
  if (!item ||
3840
3856
      (cmp_context != (Item_result)-1 && item->cmp_context != cmp_context))
3841
3857
    item= this;
3842
 
 
 
3858
  else if (field && (field->flags & ZEROFILL_FLAG) && IS_NUM(field->type()))
 
3859
  {
 
3860
    if (item && cmp_context != INT_RESULT)
 
3861
      convert_zerofill_number_to_string(&item, (Field_num *)field);
 
3862
    else
 
3863
      item= this;
 
3864
  }
3843
3865
  return item;
3844
3866
}
3845
3867
 
3850
3872
  See comments in Arg_comparator::set_compare_func() for details.
3851
3873
*/
3852
3874
 
3853
 
bool Item_field::set_no_const_sub(unsigned char *arg __attribute__((unused)))
 
3875
bool Item_field::set_no_const_sub(uchar *arg __attribute__((__unused__)))
3854
3876
{
3855
3877
  if (field->charset() != &my_charset_bin)
3856
3878
    no_const_subst=1;
3883
3905
    - this - otherwise.
3884
3906
*/
3885
3907
 
3886
 
Item *Item_field::replace_equal_field(unsigned char *arg __attribute__((unused)))
 
3908
Item *Item_field::replace_equal_field(uchar *arg __attribute__((__unused__)))
3887
3909
{
3888
3910
  if (item_equal)
3889
3911
  {
3919
3941
  tmp_field->type=              field_type_arg;
3920
3942
  tmp_field->length=max_length;
3921
3943
  tmp_field->decimals=decimals;
 
3944
  if (unsigned_flag)
 
3945
    tmp_field->flags |= UNSIGNED_FLAG;
3922
3946
}
3923
3947
 
3924
3948
void Item::make_field(Send_field *tmp_field)
3929
3953
 
3930
3954
enum_field_types Item::string_field_type() const
3931
3955
{
3932
 
  enum_field_types f_type= DRIZZLE_TYPE_VARCHAR;
 
3956
  enum_field_types f_type= MYSQL_TYPE_VAR_STRING;
3933
3957
  if (max_length >= 65536)
3934
 
    f_type= DRIZZLE_TYPE_BLOB;
 
3958
    f_type= MYSQL_TYPE_BLOB;
3935
3959
  return f_type;
3936
3960
}
3937
3961
 
3946
3970
{
3947
3971
  switch (result_type()) {
3948
3972
  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;
 
3973
  case INT_RESULT:     return MYSQL_TYPE_LONGLONG;
 
3974
  case DECIMAL_RESULT: return MYSQL_TYPE_NEWDECIMAL;
 
3975
  case REAL_RESULT:    return MYSQL_TYPE_DOUBLE;
3952
3976
  case ROW_RESULT:
3953
3977
  default:
3954
3978
    assert(0);
3955
 
    return DRIZZLE_TYPE_VARCHAR;
 
3979
    return MYSQL_TYPE_VARCHAR;
3956
3980
  }
3957
3981
}
3958
3982
 
3961
3985
{
3962
3986
  switch (field_type())
3963
3987
  {
3964
 
    case DRIZZLE_TYPE_NEWDATE:
3965
 
    case DRIZZLE_TYPE_DATETIME:
3966
 
    case DRIZZLE_TYPE_TIMESTAMP:
 
3988
    case MYSQL_TYPE_NEWDATE:
 
3989
    case MYSQL_TYPE_DATETIME:
 
3990
    case MYSQL_TYPE_TIMESTAMP:
3967
3991
      return true;
3968
3992
    default:
3969
3993
      break;
3975
3999
String *Item::check_well_formed_result(String *str, bool send_error)
3976
4000
{
3977
4001
  /* Check whether we got a well-formed string */
3978
 
  const CHARSET_INFO * const cs= str->charset();
 
4002
  CHARSET_INFO *cs= str->charset();
3979
4003
  int well_formed_error;
3980
 
  uint32_t wlen= cs->cset->well_formed_len(cs,
 
4004
  uint wlen= cs->cset->well_formed_len(cs,
3981
4005
                                       str->ptr(), str->ptr() + str->length(),
3982
4006
                                       str->length(), &well_formed_error);
3983
4007
  if (wlen < str->length())
3984
4008
  {
3985
4009
    THD *thd= current_thd;
3986
4010
    char hexbuf[7];
3987
 
    enum DRIZZLE_ERROR::enum_warning_level level;
3988
 
    uint32_t diff= str->length() - wlen;
 
4011
    enum MYSQL_ERROR::enum_warning_level level;
 
4012
    uint diff= str->length() - wlen;
3989
4013
    set_if_smaller(diff, 3);
3990
4014
    octet2hex(hexbuf, str->ptr() + wlen, diff);
3991
4015
    if (send_error)
3995
4019
      return 0;
3996
4020
    }
3997
4021
    {
3998
 
      level= DRIZZLE_ERROR::WARN_LEVEL_ERROR;
 
4022
      level= MYSQL_ERROR::WARN_LEVEL_ERROR;
3999
4023
      null_value= 1;
4000
4024
      str= 0;
4001
4025
    }
4026
4050
    0    otherwise
4027
4051
*/
4028
4052
 
4029
 
bool Item::eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO * const cs)
 
4053
bool Item::eq_by_collation(Item *item, bool binary_cmp, CHARSET_INFO *cs)
4030
4054
{
4031
 
  const CHARSET_INFO *save_cs= 0;
4032
 
  const CHARSET_INFO *save_item_cs= 0;
 
4055
  CHARSET_INFO *save_cs= 0;
 
4056
  CHARSET_INFO *save_item_cs= 0;
4033
4057
  if (collation.collation != cs)
4034
4058
  {
4035
4059
    save_cs= collation.collation;
4059
4083
  @param table          Table for which the field is created
4060
4084
*/
4061
4085
 
4062
 
Field *Item::make_string_field(Table *table)
 
4086
Field *Item::make_string_field(TABLE *table)
4063
4087
{
4064
4088
  Field *field;
4065
4089
  assert(collation.collation);
4066
4090
  if (max_length/collation.collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB)
4067
4091
    field= new Field_blob(max_length, maybe_null, name,
4068
4092
                          collation.collation);
4069
 
  else
 
4093
  /* Item_type_holder holds the exact type, do not change it */
 
4094
  else if (max_length > 0 &&
 
4095
      (type() != Item::TYPE_HOLDER || field_type() != MYSQL_TYPE_STRING))
4070
4096
    field= new Field_varstring(max_length, maybe_null, name, table->s,
4071
4097
                               collation.collation);
4072
 
 
 
4098
  else
 
4099
    field= new Field_string(max_length, maybe_null, name,
 
4100
                            collation.collation);
4073
4101
  if (field)
4074
4102
    field->init(table);
4075
4103
  return field;
4088
4116
    \#    Created field
4089
4117
*/
4090
4118
 
4091
 
Field *Item::tmp_table_field_from_field_type(Table *table, bool fixed_length __attribute__((unused)))
 
4119
Field *Item::tmp_table_field_from_field_type(TABLE *table, bool fixed_length)
4092
4120
{
4093
4121
  /*
4094
4122
    The field functions defines a field to be not null if null_ptr is not 0
4095
4123
  */
4096
 
  unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
 
4124
  uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
4097
4125
  Field *field;
4098
4126
 
4099
4127
  switch (field_type()) {
4100
 
  case DRIZZLE_TYPE_NEWDECIMAL:
4101
 
    field= new Field_new_decimal((unsigned char*) 0, max_length, null_ptr, 0,
 
4128
  case MYSQL_TYPE_NEWDECIMAL:
 
4129
    field= new Field_new_decimal((uchar*) 0, max_length, null_ptr, 0,
4102
4130
                                 Field::NONE, name, decimals, 0,
4103
4131
                                 unsigned_flag);
4104
4132
    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,
 
4133
  case MYSQL_TYPE_TINY:
 
4134
    field= new Field_tiny((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4135
                          name, 0, unsigned_flag);
 
4136
    break;
 
4137
  case MYSQL_TYPE_SHORT:
 
4138
    field= new Field_short((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4139
                           name, 0, unsigned_flag);
 
4140
    break;
 
4141
  case MYSQL_TYPE_LONG:
 
4142
    field= new Field_long((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4143
                          name, 0, unsigned_flag);
 
4144
    break;
 
4145
  case MYSQL_TYPE_LONGLONG:
 
4146
    field= new Field_longlong((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4115
4147
                              name, 0, unsigned_flag);
4116
4148
    break;
4117
 
  case DRIZZLE_TYPE_DOUBLE:
4118
 
    field= new Field_double((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
 
4149
  case MYSQL_TYPE_FLOAT:
 
4150
    field= new Field_float((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4151
                           name, decimals, 0, unsigned_flag);
 
4152
    break;
 
4153
  case MYSQL_TYPE_DOUBLE:
 
4154
    field= new Field_double((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4119
4155
                            name, decimals, 0, unsigned_flag);
4120
4156
    break;
4121
 
  case DRIZZLE_TYPE_NULL:
4122
 
    field= new Field_null((unsigned char*) 0, max_length, Field::NONE,
 
4157
  case MYSQL_TYPE_NULL:
 
4158
    field= new Field_null((uchar*) 0, max_length, Field::NONE,
4123
4159
                          name, &my_charset_bin);
4124
4160
    break;
4125
 
  case DRIZZLE_TYPE_NEWDATE:
 
4161
  case MYSQL_TYPE_NEWDATE:
4126
4162
    field= new Field_newdate(maybe_null, name, &my_charset_bin);
4127
4163
    break;
4128
 
  case DRIZZLE_TYPE_TIME:
 
4164
  case MYSQL_TYPE_TIME:
4129
4165
    field= new Field_time(maybe_null, name, &my_charset_bin);
4130
4166
    break;
4131
 
  case DRIZZLE_TYPE_TIMESTAMP:
 
4167
  case MYSQL_TYPE_TIMESTAMP:
4132
4168
    field= new Field_timestamp(maybe_null, name, &my_charset_bin);
4133
4169
    break;
4134
 
  case DRIZZLE_TYPE_DATETIME:
 
4170
  case MYSQL_TYPE_DATETIME:
4135
4171
    field= new Field_datetime(maybe_null, name, &my_charset_bin);
4136
4172
    break;
 
4173
  case MYSQL_TYPE_YEAR:
 
4174
    field= new Field_year((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4175
                          name);
 
4176
    break;
4137
4177
  default:
4138
4178
    /* This case should never be chosen */
4139
4179
    assert(0);
 
4180
    /* If something goes awfully wrong, it's better to get a string than die */
 
4181
  case MYSQL_TYPE_STRING:
 
4182
    if (fixed_length && max_length < CONVERT_IF_BIGGER_TO_BLOB)
 
4183
    {
 
4184
      field= new Field_string(max_length, maybe_null, name,
 
4185
                              collation.collation);
 
4186
      break;
 
4187
    }
4140
4188
    /* Fall through to make_string_field() */
4141
 
  case DRIZZLE_TYPE_ENUM:
4142
 
  case DRIZZLE_TYPE_VARCHAR:
 
4189
  case MYSQL_TYPE_ENUM:
 
4190
  case MYSQL_TYPE_SET:
 
4191
  case MYSQL_TYPE_VAR_STRING:
 
4192
  case MYSQL_TYPE_VARCHAR:
4143
4193
    return make_string_field(table);
4144
 
  case DRIZZLE_TYPE_BLOB:
 
4194
  case MYSQL_TYPE_BLOB:
4145
4195
    if (this->type() == Item::TYPE_HOLDER)
4146
4196
      field= new Field_blob(max_length, maybe_null, name, collation.collation,
4147
4197
                            1);
4255
4305
  if (result_type() == STRING_RESULT)
4256
4306
  {
4257
4307
    String *result;
4258
 
    const CHARSET_INFO * const cs= collation.collation;
 
4308
    CHARSET_INFO *cs= collation.collation;
4259
4309
    char buff[MAX_FIELD_WIDTH];         // Alloc buffer for small columns
4260
4310
    str_value.set_quick(buff, sizeof(buff), cs);
4261
4311
    result=val_str(&str_value);
4299
4349
  }
4300
4350
  else
4301
4351
  {
4302
 
    int64_t nr=val_int();
 
4352
    longlong nr=val_int();
4303
4353
    if (null_value)
4304
4354
      return set_field_to_null_with_conversions(field, no_conversions);
4305
4355
    field->set_notnull();
4310
4360
 
4311
4361
 
4312
4362
int Item_string::save_in_field(Field *field,
4313
 
                               bool no_conversions __attribute__((unused)))
 
4363
                               bool no_conversions __attribute__((__unused__)))
4314
4364
{
4315
4365
  String *result;
4316
4366
  result=val_str(&str_value);
4326
4376
 
4327
4377
 
4328
4378
int Item_int::save_in_field(Field *field,
4329
 
                            bool no_conversions __attribute__((unused)))
 
4379
                            bool no_conversions __attribute__((__unused__)))
4330
4380
{
4331
 
  int64_t nr=val_int();
 
4381
  longlong nr=val_int();
4332
4382
  if (null_value)
4333
4383
    return set_field_to_null(field);
4334
4384
  field->set_notnull();
4337
4387
 
4338
4388
 
4339
4389
int Item_decimal::save_in_field(Field *field,
4340
 
                                bool no_conversions __attribute__((unused)))
 
4390
                                bool no_conversions __attribute__((__unused__)))
4341
4391
{
4342
4392
  field->set_notnull();
4343
4393
  return field->store_decimal(&decimal_value);
4345
4395
 
4346
4396
 
4347
4397
bool Item_int::eq(const Item *arg,
4348
 
                  bool binary_cmp __attribute__((unused))) const
 
4398
                  bool binary_cmp __attribute__((__unused__))) const
4349
4399
{
4350
4400
  /* No need to check for null value as basic constant can't be NULL */
4351
4401
  if (arg->basic_const_item() && arg->type() == type())
4381
4431
}
4382
4432
 
4383
4433
 
4384
 
static uint32_t nr_of_decimals(const char *str, const char *end)
 
4434
static uint nr_of_decimals(const char *str, const char *end)
4385
4435
{
4386
4436
  const char *decimal_point;
4387
4437
 
4409
4459
  value is not a true double value (overflow)
4410
4460
*/
4411
4461
 
4412
 
Item_float::Item_float(const char *str_arg, uint32_t length)
 
4462
Item_float::Item_float(const char *str_arg, uint length)
4413
4463
{
4414
4464
  int error;
4415
4465
  char *end_not_used;
4425
4475
    my_error(ER_ILLEGAL_VALUE_FOR_TYPE, MYF(0), "double", (char*) str_arg);
4426
4476
  }
4427
4477
  presentation= name=(char*) str_arg;
4428
 
  decimals=(uint8_t) nr_of_decimals(str_arg, str_arg+length);
 
4478
  decimals=(uint8) nr_of_decimals(str_arg, str_arg+length);
4429
4479
  max_length=length;
4430
4480
  fixed= 1;
4431
4481
}
4432
4482
 
4433
4483
 
4434
4484
int Item_float::save_in_field(Field *field,
4435
 
                              bool no_conversions __attribute__((unused)))
 
4485
                              bool no_conversions __attribute__((__unused__)))
4436
4486
{
4437
4487
  double nr= val_real();
4438
4488
  if (null_value)
4443
4493
 
4444
4494
 
4445
4495
void Item_float::print(String *str,
4446
 
                       enum_query_type query_type __attribute__((unused)))
 
4496
                       enum_query_type query_type __attribute__((__unused__)))
4447
4497
{
4448
4498
  if (presentation)
4449
4499
  {
4460
4510
/*
4461
4511
  hex item
4462
4512
  In string context this is a binary string.
4463
 
  In number context this is a int64_t value.
 
4513
  In number context this is a longlong value.
4464
4514
*/
4465
4515
 
4466
4516
bool Item_float::eq(const Item *arg,
4467
 
                    bool binary_cmp __attribute__((unused))) const
 
4517
                    bool binary_cmp __attribute__((__unused__))) const
4468
4518
{
4469
4519
  if (arg->basic_const_item() && arg->type() == type())
4470
4520
  {
4479
4529
}
4480
4530
 
4481
4531
 
4482
 
inline uint32_t char_val(char X)
 
4532
inline uint char_val(char X)
4483
4533
{
4484
4534
  return (uint) (X >= '0' && X <= '9' ? X-'0' :
4485
4535
                 X >= 'A' && X <= 'Z' ? X-'A'+10 :
4487
4537
}
4488
4538
 
4489
4539
 
4490
 
Item_hex_string::Item_hex_string(const char *str, uint32_t str_length)
 
4540
Item_hex_string::Item_hex_string(const char *str, uint str_length)
4491
4541
{
4492
4542
  max_length=(str_length+1)/2;
4493
4543
  char *ptr=(char*) sql_alloc(max_length+1);
4508
4558
  unsigned_flag= 1;
4509
4559
}
4510
4560
 
4511
 
int64_t Item_hex_string::val_int()
 
4561
longlong Item_hex_string::val_int()
4512
4562
{
4513
4563
  // following assert is redundant, because fixed=1 assigned in constructor
4514
4564
  assert(fixed == 1);
4515
4565
  char *end=(char*) str_value.ptr()+str_value.length(),
4516
 
       *ptr=end-cmin(str_value.length(),(uint32_t)sizeof(int64_t));
 
4566
       *ptr=end-min(str_value.length(),sizeof(longlong));
4517
4567
 
4518
 
  uint64_t value=0;
 
4568
  ulonglong value=0;
4519
4569
  for (; ptr != end ; ptr++)
4520
 
    value=(value << 8)+ (uint64_t) (unsigned char) *ptr;
4521
 
  return (int64_t) value;
 
4570
    value=(value << 8)+ (ulonglong) (uchar) *ptr;
 
4571
  return (longlong) value;
4522
4572
}
4523
4573
 
4524
4574
 
4526
4576
{
4527
4577
  // following assert is redundant, because fixed=1 assigned in constructor
4528
4578
  assert(fixed == 1);
4529
 
  uint64_t value= (uint64_t)val_int();
 
4579
  ulonglong value= (ulonglong)val_int();
4530
4580
  int2my_decimal(E_DEC_FATAL_ERROR, value, true, decimal_value);
4531
4581
  return (decimal_value);
4532
4582
}
4533
4583
 
4534
4584
 
4535
4585
int Item_hex_string::save_in_field(Field *field,
4536
 
                                   bool no_conversions __attribute__((unused)))
 
4586
                                   bool no_conversions __attribute__((__unused__)))
4537
4587
{
4538
4588
  field->set_notnull();
4539
4589
  if (field->result_type() == STRING_RESULT)
4540
4590
    return field->store(str_value.ptr(), str_value.length(), 
4541
4591
                        collation.collation);
4542
4592
 
4543
 
  uint64_t nr;
4544
 
  uint32_t length= str_value.length();
 
4593
  ulonglong nr;
 
4594
  uint32 length= str_value.length();
4545
4595
  if (length > 8)
4546
4596
  {
4547
 
    nr= field->flags & UNSIGNED_FLAG ? UINT64_MAX : INT64_MAX;
 
4597
    nr= field->flags & UNSIGNED_FLAG ? ULONGLONG_MAX : LONGLONG_MAX;
4548
4598
    goto warn;
4549
4599
  }
4550
 
  nr= (uint64_t) val_int();
4551
 
  if ((length == 8) && !(field->flags & UNSIGNED_FLAG) && (nr > INT64_MAX))
 
4600
  nr= (ulonglong) val_int();
 
4601
  if ((length == 8) && !(field->flags & UNSIGNED_FLAG) && (nr > LONGLONG_MAX))
4552
4602
  {
4553
 
    nr= INT64_MAX;
 
4603
    nr= LONGLONG_MAX;
4554
4604
    goto warn;
4555
4605
  }
4556
 
  return field->store((int64_t) nr, true);  // Assume hex numbers are unsigned
 
4606
  return field->store((longlong) nr, true);  // Assume hex numbers are unsigned
4557
4607
 
4558
4608
warn:
4559
 
  if (!field->store((int64_t) nr, true))
4560
 
    field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE,
 
4609
  if (!field->store((longlong) nr, true))
 
4610
    field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE,
4561
4611
                       1);
4562
4612
  return 1;
4563
4613
}
4564
4614
 
4565
4615
 
4566
4616
void Item_hex_string::print(String *str,
4567
 
                            enum_query_type query_type __attribute__((unused)))
 
4617
                            enum_query_type query_type __attribute__((__unused__)))
4568
4618
{
4569
4619
  char *end= (char*) str_value.ptr() + str_value.length(),
4570
 
       *ptr= end - cmin(str_value.length(), (uint32_t)sizeof(int64_t));
 
4620
       *ptr= end - min(str_value.length(), sizeof(longlong));
4571
4621
  str->append("0x");
4572
4622
  for (; ptr != end ; ptr++)
4573
4623
  {
4574
 
    str->append(_dig_vec_lower[((unsigned char) *ptr) >> 4]);
4575
 
    str->append(_dig_vec_lower[((unsigned char) *ptr) & 0x0F]);
 
4624
    str->append(_dig_vec_lower[((uchar) *ptr) >> 4]);
 
4625
    str->append(_dig_vec_lower[((uchar) *ptr) & 0x0F]);
4576
4626
  }
4577
4627
}
4578
4628
 
4589
4639
}
4590
4640
 
4591
4641
 
4592
 
Item *Item_hex_string::safe_charset_converter(const CHARSET_INFO * const tocs)
 
4642
Item *Item_hex_string::safe_charset_converter(CHARSET_INFO *tocs)
4593
4643
{
4594
4644
  Item_string *conv;
4595
4645
  String tmp, *str= val_str(&tmp);
4605
4655
/*
4606
4656
  bin item.
4607
4657
  In string context this is a binary string.
4608
 
  In number context this is a int64_t value.
 
4658
  In number context this is a longlong value.
4609
4659
*/
4610
4660
  
4611
 
Item_bin_string::Item_bin_string(const char *str, uint32_t str_length)
 
4661
Item_bin_string::Item_bin_string(const char *str, uint str_length)
4612
4662
{
4613
4663
  const char *end= str + str_length - 1;
4614
 
  unsigned char bits= 0;
4615
 
  uint32_t power= 1;
 
4664
  uchar bits= 0;
 
4665
  uint power= 1;
4616
4666
 
4617
4667
  max_length= (str_length + 7) >> 3;
4618
4668
  char *ptr= (char*) sql_alloc(max_length + 1);
4644
4694
*/
4645
4695
 
4646
4696
bool Item_null::send(Protocol *protocol,
4647
 
                     String *packet __attribute__((unused)))
 
4697
                     String *packet __attribute__((__unused__)))
4648
4698
{
4649
4699
  return protocol->store_null();
4650
4700
}
4660
4710
 
4661
4711
  switch ((f_type=field_type())) {
4662
4712
  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:
 
4713
  case MYSQL_TYPE_NULL:
 
4714
  case MYSQL_TYPE_ENUM:
 
4715
  case MYSQL_TYPE_SET:
 
4716
  case MYSQL_TYPE_BLOB:
 
4717
  case MYSQL_TYPE_STRING:
 
4718
  case MYSQL_TYPE_VAR_STRING:
 
4719
  case MYSQL_TYPE_VARCHAR:
 
4720
  case MYSQL_TYPE_NEWDECIMAL:
4668
4721
  {
4669
4722
    String *res;
4670
4723
    if ((res=val_str(buffer)))
4671
4724
      result= protocol->store(res->ptr(),res->length(),res->charset());
4672
4725
    break;
4673
4726
  }
4674
 
  case DRIZZLE_TYPE_TINY:
 
4727
  case MYSQL_TYPE_TINY:
4675
4728
  {
4676
 
    int64_t nr;
 
4729
    longlong nr;
4677
4730
    nr= val_int();
4678
4731
    if (!null_value)
4679
4732
      result= protocol->store_tiny(nr);
4680
4733
    break;
4681
4734
  }
4682
 
  case DRIZZLE_TYPE_LONG:
4683
 
  {
4684
 
    int64_t nr;
 
4735
  case MYSQL_TYPE_SHORT:
 
4736
  case MYSQL_TYPE_YEAR:
 
4737
  {
 
4738
    longlong nr;
 
4739
    nr= val_int();
 
4740
    if (!null_value)
 
4741
      result= protocol->store_short(nr);
 
4742
    break;
 
4743
  }
 
4744
  case MYSQL_TYPE_LONG:
 
4745
  {
 
4746
    longlong nr;
4685
4747
    nr= val_int();
4686
4748
    if (!null_value)
4687
4749
      result= protocol->store_long(nr);
4688
4750
    break;
4689
4751
  }
4690
 
  case DRIZZLE_TYPE_LONGLONG:
 
4752
  case MYSQL_TYPE_LONGLONG:
4691
4753
  {
4692
 
    int64_t nr;
 
4754
    longlong nr;
4693
4755
    nr= val_int();
4694
4756
    if (!null_value)
4695
 
      result= protocol->store_int64_t(nr, unsigned_flag);
4696
 
    break;
4697
 
  }
4698
 
  case DRIZZLE_TYPE_DOUBLE:
 
4757
      result= protocol->store_longlong(nr, unsigned_flag);
 
4758
    break;
 
4759
  }
 
4760
  case MYSQL_TYPE_FLOAT:
 
4761
  {
 
4762
    float nr;
 
4763
    nr= (float) val_real();
 
4764
    if (!null_value)
 
4765
      result= protocol->store(nr, decimals, buffer);
 
4766
    break;
 
4767
  }
 
4768
  case MYSQL_TYPE_DOUBLE:
4699
4769
  {
4700
4770
    double nr= val_real();
4701
4771
    if (!null_value)
4702
4772
      result= protocol->store(nr, decimals, buffer);
4703
4773
    break;
4704
4774
  }
4705
 
  case DRIZZLE_TYPE_DATETIME:
4706
 
  case DRIZZLE_TYPE_TIMESTAMP:
 
4775
  case MYSQL_TYPE_DATETIME:
 
4776
  case MYSQL_TYPE_TIMESTAMP:
4707
4777
  {
4708
 
    DRIZZLE_TIME tm;
 
4778
    MYSQL_TIME tm;
4709
4779
    get_date(&tm, TIME_FUZZY_DATE);
4710
4780
    if (!null_value)
4711
4781
    {
4712
 
      if (f_type == DRIZZLE_TYPE_NEWDATE)
 
4782
      if (f_type == MYSQL_TYPE_NEWDATE)
4713
4783
        return protocol->store_date(&tm);
4714
4784
      else
4715
4785
        result= protocol->store(&tm);
4716
4786
    }
4717
4787
    break;
4718
4788
  }
4719
 
  case DRIZZLE_TYPE_TIME:
 
4789
  case MYSQL_TYPE_TIME:
4720
4790
  {
4721
 
    DRIZZLE_TIME tm;
 
4791
    MYSQL_TIME tm;
4722
4792
    get_time(&tm);
4723
4793
    if (!null_value)
4724
4794
      result= protocol->store_time(&tm);
4732
4802
 
4733
4803
 
4734
4804
bool Item_field::send(Protocol *protocol,
4735
 
                      String *buffer __attribute__((unused)))
 
4805
                      String *buffer __attribute__((__unused__)))
4736
4806
{
4737
4807
  return protocol->store(result_field);
4738
4808
}
4776
4846
    this field    otherwise
4777
4847
*/
4778
4848
 
4779
 
Item *Item_field::update_value_transformer(unsigned char *select_arg)
 
4849
Item *Item_field::update_value_transformer(uchar *select_arg)
4780
4850
{
4781
4851
  SELECT_LEX *select= (SELECT_LEX*)select_arg;
4782
4852
  assert(fixed);
4783
4853
 
4784
 
  if (field->table != select->context.table_list->table)
 
4854
  if (field->table != select->context.table_list->table &&
 
4855
      type() != Item::TRIGGER_FIELD_ITEM)
4785
4856
  {
4786
4857
    List<Item> *all_fields= &select->join->all_fields;
4787
4858
    Item **ref_pointer_array= select->ref_pointer_array;
4818
4889
                   Item **item, const char *table_name_arg,
4819
4890
                   const char *field_name_arg,
4820
4891
                   bool alias_name_used_arg)
4821
 
  :Item_ident(context_arg, NULL, table_name_arg, field_name_arg),
 
4892
  :Item_ident(context_arg, NullS, table_name_arg, field_name_arg),
4822
4893
   result_field(0), ref(item)
4823
4894
{
4824
4895
  alias_name_used= alias_name_used_arg;
5190
5261
}
5191
5262
 
5192
5263
 
5193
 
int64_t Item_ref::val_int_result()
 
5264
longlong Item_ref::val_int_result()
5194
5265
{
5195
5266
  if (result_field)
5196
5267
  {
5265
5336
}
5266
5337
 
5267
5338
 
5268
 
int64_t Item_ref::val_int()
 
5339
longlong Item_ref::val_int()
5269
5340
{
5270
5341
  assert(fixed);
5271
 
  int64_t tmp=(*ref)->val_int_result();
 
5342
  longlong tmp=(*ref)->val_int_result();
5272
5343
  null_value=(*ref)->null_value;
5273
5344
  return tmp;
5274
5345
}
5299
5370
}
5300
5371
 
5301
5372
 
5302
 
bool Item_ref::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
5373
bool Item_ref::get_date(MYSQL_TIME *ltime,uint fuzzydate)
5303
5374
{
5304
5375
  return (null_value=(*ref)->get_date_result(ltime,fuzzydate));
5305
5376
}
5375
5446
}
5376
5447
 
5377
5448
 
5378
 
int64_t Item_direct_ref::val_int()
 
5449
longlong Item_direct_ref::val_int()
5379
5450
{
5380
 
  int64_t tmp=(*ref)->val_int();
 
5451
  longlong tmp=(*ref)->val_int();
5381
5452
  null_value=(*ref)->null_value;
5382
5453
  return tmp;
5383
5454
}
5413
5484
}
5414
5485
 
5415
5486
 
5416
 
bool Item_direct_ref::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
5487
bool Item_direct_ref::get_date(MYSQL_TIME *ltime,uint fuzzydate)
5417
5488
{
5418
5489
  return (null_value=(*ref)->get_date(ltime,fuzzydate));
5419
5490
}
5479
5550
}
5480
5551
 
5481
5552
void Item_ref::fix_after_pullout(st_select_lex *new_parent,
5482
 
                                 Item **refptr __attribute__((unused)))
 
5553
                                 Item **refptr __attribute__((__unused__)))
5483
5554
{
5484
5555
  if (depended_from == new_parent)
5485
5556
  {
5506
5577
*/
5507
5578
 
5508
5579
bool Item_direct_view_ref::eq(const Item *item,
5509
 
                              bool binary_cmp __attribute__((unused))) const
 
5580
                              bool binary_cmp __attribute__((__unused__))) const
5510
5581
{
5511
5582
  if (item->type() == REF_ITEM)
5512
5583
  {
5528
5599
 
5529
5600
 
5530
5601
bool Item_default_value::fix_fields(THD *thd,
5531
 
                                    Item **items __attribute__((unused)))
 
5602
                                    Item **items __attribute__((__unused__)))
5532
5603
{
5533
5604
  Item *real_arg;
5534
5605
  Item_field *field_arg;
5600
5671
 
5601
5672
      {
5602
5673
        push_warning_printf(field_arg->table->in_use,
5603
 
                            DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
5674
                            MYSQL_ERROR::WARN_LEVEL_WARN,
5604
5675
                            ER_NO_DEFAULT_FOR_FIELD,
5605
5676
                            ER(ER_NO_DEFAULT_FOR_FIELD),
5606
5677
                            field_arg->field_name);
5619
5690
  same time it can replace some nodes in the tree.
5620
5691
*/ 
5621
5692
 
5622
 
Item *Item_default_value::transform(Item_transformer transformer, unsigned char *args)
 
5693
Item *Item_default_value::transform(Item_transformer transformer, uchar *args)
5623
5694
{
5624
5695
  Item *new_item= arg->transform(transformer, args);
5625
5696
  if (!new_item)
5645
5716
 
5646
5717
 
5647
5718
bool Item_insert_value::fix_fields(THD *thd,
5648
 
                                   Item **items __attribute__((unused)))
 
5719
                                   Item **items __attribute__((__unused__)))
5649
5720
{
5650
5721
  assert(fixed == 0);
5651
5722
  /* We should only check that arg is in first table */
5652
5723
  if (!arg->fixed)
5653
5724
  {
5654
5725
    bool res;
5655
 
    TableList *orig_next_table= context->last_name_resolution_table;
 
5726
    TABLE_LIST *orig_next_table= context->last_name_resolution_table;
5656
5727
    context->last_name_resolution_table= context->first_name_resolution_table;
5657
5728
    res= arg->fix_fields(thd, &arg);
5658
5729
    context->last_name_resolution_table= orig_next_table;
5747
5818
      new_item= new Item_null(name);
5748
5819
    else
5749
5820
    {
5750
 
      uint32_t length= result->length();
 
5821
      uint length= result->length();
5751
5822
      char *tmp_str= sql_strmake(result->ptr(), length);
5752
5823
      new_item= new Item_string(name, tmp_str, length, result->charset());
5753
5824
    }
5755
5826
  }
5756
5827
  case INT_RESULT:
5757
5828
  {
5758
 
    int64_t result=item->val_int();
5759
 
    uint32_t length=item->max_length;
 
5829
    longlong result=item->val_int();
 
5830
    uint length=item->max_length;
5760
5831
    bool null_value=item->null_value;
5761
5832
    new_item= (null_value ? (Item*) new Item_null(name) :
5762
5833
               (Item*) new Item_int(name, result, length));
5775
5846
    */
5776
5847
    Item_row *item_row= (Item_row*) item;
5777
5848
    Item_row *comp_item_row= (Item_row*) comp_item;
5778
 
    uint32_t col;
 
5849
    uint col;
5779
5850
    new_item= 0;
5780
5851
    /*
5781
5852
      If item and comp_item are both Item_rows and have same number of cols
5795
5866
  case REAL_RESULT:
5796
5867
  {                                             // It must REAL_RESULT
5797
5868
    double result= item->val_real();
5798
 
    uint32_t length=item->max_length,decimals=item->decimals;
 
5869
    uint length=item->max_length,decimals=item->decimals;
5799
5870
    bool null_value=item->null_value;
5800
5871
    new_item= (null_value ? (Item*) new Item_null(name) : (Item*)
5801
5872
               new Item_float(name, result, decimals, length));
5805
5876
  {
5806
5877
    my_decimal decimal_value;
5807
5878
    my_decimal *result= item->val_decimal(&decimal_value);
5808
 
    uint32_t length= item->max_length, decimals= item->decimals;
 
5879
    uint length= item->max_length, decimals= item->decimals;
5809
5880
    bool null_value= item->null_value;
5810
5881
    new_item= (null_value ?
5811
5882
               (Item*) new Item_null(name) :
5902
5973
}
5903
5974
 
5904
5975
 
5905
 
void Item_cache_int::store(Item *item, int64_t val_arg)
 
5976
void Item_cache_int::store(Item *item, longlong val_arg)
5906
5977
{
5907
5978
  value= val_arg;
5908
5979
  null_value= item->null_value;
5933
6004
}
5934
6005
 
5935
6006
 
5936
 
int64_t Item_cache_real::val_int()
 
6007
longlong Item_cache_real::val_int()
5937
6008
{
5938
6009
  assert(fixed == 1);
5939
 
  return (int64_t) rint(value);
 
6010
  return (longlong) rint(value);
5940
6011
}
5941
6012
 
5942
6013
 
5971
6042
  return res;
5972
6043
}
5973
6044
 
5974
 
int64_t Item_cache_decimal::val_int()
 
6045
longlong Item_cache_decimal::val_int()
5975
6046
{
5976
6047
  assert(fixed);
5977
 
  int64_t res;
 
6048
  longlong res;
5978
6049
  my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &res);
5979
6050
  return res;
5980
6051
}
5988
6059
  return str;
5989
6060
}
5990
6061
 
5991
 
my_decimal *Item_cache_decimal::val_decimal(my_decimal *val __attribute__((unused)))
 
6062
my_decimal *Item_cache_decimal::val_decimal(my_decimal *val __attribute__((__unused__)))
5992
6063
{
5993
6064
  assert(fixed);
5994
6065
  return &decimal_value;
6028
6099
}
6029
6100
 
6030
6101
 
6031
 
int64_t Item_cache_str::val_int()
 
6102
longlong Item_cache_str::val_int()
6032
6103
{
6033
6104
  assert(fixed == 1);
6034
6105
  int err;
6036
6107
    return my_strntoll(value->charset(), value->ptr(),
6037
6108
                       value->length(), 10, (char**) 0, &err);
6038
6109
  else
6039
 
    return (int64_t)0;
 
6110
    return (longlong)0;
6040
6111
}
6041
6112
 
6042
6113
my_decimal *Item_cache_str::val_decimal(my_decimal *decimal_val)
6053
6124
int Item_cache_str::save_in_field(Field *field, bool no_conversions)
6054
6125
{
6055
6126
  int res= Item_cache::save_in_field(field, no_conversions);
6056
 
 
6057
 
  return res;
 
6127
  return (is_varbinary && field->type() == MYSQL_TYPE_STRING &&
 
6128
          value->length() < field->field_length) ? 1 : res;
6058
6129
}
6059
6130
 
6060
6131
 
6061
 
bool Item_cache_row::allocate(uint32_t num)
 
6132
bool Item_cache_row::allocate(uint num)
6062
6133
{
6063
6134
  item_count= num;
6064
6135
  THD *thd= current_thd;
6072
6143
  example= item;
6073
6144
  if (!values && allocate(item->cols()))
6074
6145
    return 1;
6075
 
  for (uint32_t i= 0; i < item_count; i++)
 
6146
  for (uint i= 0; i < item_count; i++)
6076
6147
  {
6077
6148
    Item *el= item->element_index(i);
6078
6149
    Item_cache *tmp;
6088
6159
{
6089
6160
  null_value= 0;
6090
6161
  item->bring_value();
6091
 
  for (uint32_t i= 0; i < item_count; i++)
 
6162
  for (uint i= 0; i < item_count; i++)
6092
6163
  {
6093
6164
    values[i]->store(item->element_index(i));
6094
6165
    null_value|= values[i]->null_value;
6096
6167
}
6097
6168
 
6098
6169
 
6099
 
void Item_cache_row::illegal_method_call(const char *method __attribute__((unused)))
 
6170
void Item_cache_row::illegal_method_call(const char *method __attribute__((__unused__)))
6100
6171
{
6101
6172
  assert(0);
6102
6173
  my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
6104
6175
}
6105
6176
 
6106
6177
 
6107
 
bool Item_cache_row::check_cols(uint32_t c)
 
6178
bool Item_cache_row::check_cols(uint c)
6108
6179
{
6109
6180
  if (c != item_count)
6110
6181
  {
6117
6188
 
6118
6189
bool Item_cache_row::null_inside()
6119
6190
{
6120
 
  for (uint32_t i= 0; i < item_count; i++)
 
6191
  for (uint i= 0; i < item_count; i++)
6121
6192
  {
6122
6193
    if (values[i]->cols() > 1)
6123
6194
    {
6137
6208
 
6138
6209
void Item_cache_row::bring_value()
6139
6210
{
6140
 
  for (uint32_t i= 0; i < item_count; i++)
 
6211
  for (uint i= 0; i < item_count; i++)
6141
6212
    values[i]->bring_value();
6142
6213
  return;
6143
6214
}
6190
6261
    Field *field= ((Item_field *) item)->field;
6191
6262
    enum_field_types type= field->real_type();
6192
6263
    if (field->is_created_from_null_item)
6193
 
      return DRIZZLE_TYPE_NULL;
 
6264
      return MYSQL_TYPE_NULL;
 
6265
    /* work around about varchar type field detection */
 
6266
    if (type == MYSQL_TYPE_STRING && field->type() == MYSQL_TYPE_VAR_STRING)
 
6267
      return MYSQL_TYPE_VAR_STRING;
6194
6268
    return type;
6195
6269
  }
6196
6270
  case SUM_FUNC_ITEM:
6215
6289
      */
6216
6290
      switch (item->result_type()) {
6217
6291
      case STRING_RESULT:
6218
 
        return DRIZZLE_TYPE_VARCHAR;
 
6292
        return MYSQL_TYPE_VAR_STRING;
6219
6293
      case INT_RESULT:
6220
 
        return DRIZZLE_TYPE_LONGLONG;
 
6294
        return MYSQL_TYPE_LONGLONG;
6221
6295
      case REAL_RESULT:
6222
 
        return DRIZZLE_TYPE_DOUBLE;
 
6296
        return MYSQL_TYPE_DOUBLE;
6223
6297
      case DECIMAL_RESULT:
6224
 
        return DRIZZLE_TYPE_NEWDECIMAL;
 
6298
        return MYSQL_TYPE_NEWDECIMAL;
6225
6299
      case ROW_RESULT:
6226
6300
      default:
6227
6301
        assert(0);
6228
 
        return DRIZZLE_TYPE_VARCHAR;
 
6302
        return MYSQL_TYPE_VAR_STRING;
6229
6303
      }
6230
6304
    }
6231
6305
    break;
6248
6322
    false  OK
6249
6323
*/
6250
6324
 
6251
 
bool Item_type_holder::join_types(THD *thd __attribute__((unused)),
 
6325
bool Item_type_holder::join_types(THD *thd __attribute__((__unused__)),
6252
6326
                                  Item *item)
6253
6327
{
6254
 
  uint32_t max_length_orig= max_length;
6255
 
  uint32_t decimals_orig= decimals;
 
6328
  uint max_length_orig= max_length;
 
6329
  uint decimals_orig= decimals;
6256
6330
  fld_type= Field::field_type_merge(fld_type, get_real_type(item));
6257
6331
  {
6258
6332
    int item_decimals= item->decimals;
6259
6333
    /* fix variable decimals which always is NOT_FIXED_DEC */
6260
6334
    if (Field::result_merge_type(fld_type) == INT_RESULT)
6261
6335
      item_decimals= 0;
6262
 
    decimals= cmax((int)decimals, item_decimals);
 
6336
    decimals= max(decimals, item_decimals);
6263
6337
  }
6264
6338
  if (Field::result_merge_type(fld_type) == DECIMAL_RESULT)
6265
6339
  {
6266
 
    decimals= cmin((int)cmax(decimals, item->decimals), DECIMAL_MAX_SCALE);
6267
 
    int precision= cmin(cmax(prev_decimal_int_part, item->decimal_int_part())
 
6340
    decimals= min(max(decimals, item->decimals), DECIMAL_MAX_SCALE);
 
6341
    int precision= min(max(prev_decimal_int_part, item->decimal_int_part())
6268
6342
                       + decimals, DECIMAL_MAX_PRECISION);
6269
6343
    unsigned_flag&= item->unsigned_flag;
6270
6344
    max_length= my_decimal_precision_to_length(precision, decimals,
6276
6350
  case STRING_RESULT:
6277
6351
  {
6278
6352
    const char *old_cs, *old_derivation;
6279
 
    uint32_t old_max_chars= max_length / collation.collation->mbmaxlen;
 
6353
    uint32 old_max_chars= max_length / collation.collation->mbmaxlen;
6280
6354
    old_cs= collation.collation->name;
6281
6355
    old_derivation= collation.derivation_name();
6282
6356
    if (collation.aggregate(item->collation, MY_COLL_ALLOW_CONV))
6295
6369
     */
6296
6370
    if (collation.collation != &my_charset_bin)
6297
6371
    {
6298
 
      max_length= cmax(old_max_chars * collation.collation->mbmaxlen,
 
6372
      max_length= max(old_max_chars * collation.collation->mbmaxlen,
6299
6373
                      display_length(item) /
6300
6374
                      item->collation.collation->mbmaxlen *
6301
6375
                      collation.collation->mbmaxlen);
6310
6384
    {
6311
6385
      int delta1= max_length_orig - decimals_orig;
6312
6386
      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) 
 
6387
      max_length= max(delta1, delta2) + decimals;
 
6388
      if (fld_type == MYSQL_TYPE_FLOAT && max_length > FLT_DIG + 2) 
 
6389
      {
 
6390
        max_length= FLT_DIG + 6;
 
6391
        decimals= NOT_FIXED_DEC;
 
6392
      } 
 
6393
      if (fld_type == MYSQL_TYPE_DOUBLE && max_length > DBL_DIG + 2) 
6315
6394
      {
6316
6395
        max_length= DBL_DIG + 7;
6317
6396
        decimals= NOT_FIXED_DEC;
6318
6397
      }
6319
6398
    }
6320
6399
    else
6321
 
      max_length= DBL_DIG+7;
 
6400
      max_length= (fld_type == MYSQL_TYPE_FLOAT) ? FLT_DIG+6 : DBL_DIG+7;
6322
6401
    break;
6323
6402
  }
6324
6403
  default:
6325
 
    max_length= cmax(max_length, display_length(item));
 
6404
    max_length= max(max_length, display_length(item));
6326
6405
  };
6327
6406
  maybe_null|= item->maybe_null;
6328
6407
  get_full_info(item);
6341
6420
    length
6342
6421
*/
6343
6422
 
6344
 
uint32_t Item_type_holder::display_length(Item *item)
 
6423
uint32 Item_type_holder::display_length(Item *item)
6345
6424
{
6346
6425
  if (item->type() == Item::FIELD_ITEM)
6347
6426
    return ((Item_field *)item)->max_disp_length();
6348
6427
 
6349
6428
  switch (item->field_type())
6350
6429
  {
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:
 
6430
  case MYSQL_TYPE_TIMESTAMP:
 
6431
  case MYSQL_TYPE_TIME:
 
6432
  case MYSQL_TYPE_DATETIME:
 
6433
  case MYSQL_TYPE_YEAR:
 
6434
  case MYSQL_TYPE_NEWDATE:
 
6435
  case MYSQL_TYPE_VARCHAR:
 
6436
  case MYSQL_TYPE_NEWDECIMAL:
 
6437
  case MYSQL_TYPE_ENUM:
 
6438
  case MYSQL_TYPE_SET:
 
6439
  case MYSQL_TYPE_BLOB:
 
6440
  case MYSQL_TYPE_VAR_STRING:
 
6441
  case MYSQL_TYPE_STRING:
 
6442
  case MYSQL_TYPE_TINY:
6360
6443
    return 4;
6361
 
  case DRIZZLE_TYPE_LONG:
 
6444
  case MYSQL_TYPE_SHORT:
 
6445
    return 6;
 
6446
  case MYSQL_TYPE_LONG:
6362
6447
    return MY_INT32_NUM_DECIMAL_DIGITS;
6363
 
  case DRIZZLE_TYPE_DOUBLE:
 
6448
  case MYSQL_TYPE_FLOAT:
 
6449
    return 25;
 
6450
  case MYSQL_TYPE_DOUBLE:
6364
6451
    return 53;
6365
 
  case DRIZZLE_TYPE_NULL:
 
6452
  case MYSQL_TYPE_NULL:
6366
6453
    return 0;
6367
 
  case DRIZZLE_TYPE_LONGLONG:
 
6454
  case MYSQL_TYPE_LONGLONG:
6368
6455
    return 20;
6369
6456
  default:
6370
6457
    assert(0); // we should never go there
6383
6470
    created field
6384
6471
*/
6385
6472
 
6386
 
Field *Item_type_holder::make_field_by_type(Table *table)
 
6473
Field *Item_type_holder::make_field_by_type(TABLE *table)
6387
6474
{
6388
6475
  /*
6389
6476
    The field functions defines a field to be not null if null_ptr is not 0
6390
6477
  */
6391
 
  unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
 
6478
  uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
6392
6479
  Field *field;
6393
6480
 
6394
6481
  switch (fld_type) {
6395
 
  case DRIZZLE_TYPE_ENUM:
 
6482
  case MYSQL_TYPE_ENUM:
6396
6483
    assert(enum_set_typelib);
6397
 
    field= new Field_enum((unsigned char *) 0, max_length, null_ptr, 0,
 
6484
    field= new Field_enum((uchar *) 0, max_length, null_ptr, 0,
6398
6485
                          Field::NONE, name,
6399
6486
                          get_enum_pack_length(enum_set_typelib->count),
6400
6487
                          enum_set_typelib, collation.collation);
6401
6488
    if (field)
6402
6489
      field->init(table);
6403
6490
    return field;
6404
 
  case DRIZZLE_TYPE_NULL:
 
6491
  case MYSQL_TYPE_SET:
 
6492
    assert(enum_set_typelib);
 
6493
    field= new Field_set((uchar *) 0, max_length, null_ptr, 0,
 
6494
                         Field::NONE, name,
 
6495
                         get_set_pack_length(enum_set_typelib->count),
 
6496
                         enum_set_typelib, collation.collation);
 
6497
    if (field)
 
6498
      field->init(table);
 
6499
    return field;
 
6500
  case MYSQL_TYPE_NULL:
6405
6501
    return make_string_field(table);
6406
6502
  default:
6407
6503
    break;
6418
6514
*/
6419
6515
void Item_type_holder::get_full_info(Item *item)
6420
6516
{
6421
 
  if (fld_type == DRIZZLE_TYPE_ENUM)
 
6517
  if (fld_type == MYSQL_TYPE_ENUM ||
 
6518
      fld_type == MYSQL_TYPE_SET)
6422
6519
  {
6423
6520
    if (item->type() == Item::SUM_FUNC_ITEM &&
6424
6521
        (((Item_sum*)item)->sum_func() == Item_sum::MAX_FUNC ||
6429
6526
      field (or MIN|MAX(enum|set field)) and number of NULL fields
6430
6527
    */
6431
6528
    assert((enum_set_typelib &&
6432
 
                 get_real_type(item) == DRIZZLE_TYPE_NULL) ||
 
6529
                 get_real_type(item) == MYSQL_TYPE_NULL) ||
6433
6530
                (!enum_set_typelib &&
6434
6531
                 item->type() == Item::FIELD_ITEM &&
6435
 
                 (get_real_type(item) == DRIZZLE_TYPE_ENUM) &&
 
6532
                 (get_real_type(item) == MYSQL_TYPE_ENUM ||
 
6533
                  get_real_type(item) == MYSQL_TYPE_SET) &&
6436
6534
                 ((Field_enum*)((Item_field *) item)->field)->typelib));
6437
6535
    if (!enum_set_typelib)
6438
6536
    {
6449
6547
}
6450
6548
 
6451
6549
 
6452
 
int64_t Item_type_holder::val_int()
 
6550
longlong Item_type_holder::val_int()
6453
6551
{
6454
6552
  assert(0); // should never be called
6455
6553
  return 0;
6481
6579
    do nothing
6482
6580
*/
6483
6581
 
6484
 
void dummy_error_processor(THD *thd __attribute__((unused)),
6485
 
                           void *data __attribute__((unused)))
 
6582
void dummy_error_processor(THD *thd __attribute__((__unused__)),
 
6583
                           void *data __attribute__((__unused__)))
6486
6584
{}
6487
6585
 
6488
6586
/**