~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/item.cc

  • Committer: Brian Aker
  • Date: 2008-07-14 22:40:46 UTC
  • Revision ID: brian@tangent.org-20080714224046-x183907w9wp1txwv
Removed sql_manager. Ever heard of just setting up the OS to sync when you
want it to?

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
 
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;
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);
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
669
  return 0;
670
670
}
671
671
 
672
672
 
673
 
bool Item::check_cols(uint32_t c)
 
673
bool Item::check_cols(uint c)
674
674
{
675
675
  if (c != 1)
676
676
  {
681
681
}
682
682
 
683
683
 
684
 
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)
685
685
{
686
686
  if (!length)
687
687
  {
692
692
  }
693
693
  if (cs->ctype)
694
694
  {
695
 
    uint32_t orig_len= length;
 
695
    uint orig_len= length;
696
696
    /*
697
697
      This will probably need a better implementation in the future:
698
698
      a function in CHARSET_INFO structure.
705
705
    if (orig_len != length && !is_autogenerated_name)
706
706
    {
707
707
      if (length == 0)
708
 
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
708
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
709
709
                            ER_NAME_BECOMES_EMPTY, ER(ER_NAME_BECOMES_EMPTY),
710
710
                            str + length - orig_len);
711
711
      else
712
 
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
712
        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
713
713
                            ER_REMOVED_SPACES, ER(ER_REMOVED_SPACES),
714
714
                            str + length - orig_len);
715
715
    }
722
722
                                   &res_length);
723
723
  }
724
724
  else
725
 
    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)));
726
726
}
727
727
 
728
728
 
730
730
  @details
731
731
  This function is called when:
732
732
  - Comparing items in the WHERE clause (when doing where optimization)
733
 
  - 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
734
734
*/
735
735
 
736
 
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
737
737
{
738
738
  /*
739
739
    Note, that this is never true if item is a Item_param:
745
745
}
746
746
 
747
747
 
748
 
Item *Item::safe_charset_converter(const CHARSET_INFO * const tocs)
 
748
Item *Item::safe_charset_converter(CHARSET_INFO *tocs)
749
749
{
750
750
  Item_func_conv_charset *conv= new Item_func_conv_charset(this, tocs, 1);
751
751
  return conv->safe ? conv : NULL;
763
763
  the latter returns a non-fixed Item, so val_str() crashes afterwards.
764
764
  Override Item_num method, to return a fixed item.
765
765
*/
766
 
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__)))
767
767
{
768
768
  Item_string *conv;
769
769
  char buf[64];
778
778
}
779
779
 
780
780
 
781
 
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__)))
782
782
{
783
783
  Item_string *conv;
784
784
  char buf[64];
794
794
}
795
795
 
796
796
 
797
 
Item *Item_string::safe_charset_converter(const CHARSET_INFO * const tocs)
 
797
Item *Item_string::safe_charset_converter(CHARSET_INFO *tocs)
798
798
{
799
799
  Item_string *conv;
800
 
  uint32_t conv_errors;
 
800
  uint conv_errors;
801
801
  char *ptr;
802
802
  String tmp, cstr, *ostr= val_str(&tmp);
803
803
  cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
822
822
}
823
823
 
824
824
 
825
 
Item *Item_param::safe_charset_converter(const CHARSET_INFO * const tocs)
 
825
Item *Item_param::safe_charset_converter(CHARSET_INFO *tocs)
826
826
{
827
827
  if (const_item())
828
828
  {
829
 
    uint32_t cnv_errors;
 
829
    uint cnv_errors;
830
830
    String *ostr= val_str(&cnvstr);
831
831
    cnvitem->str_value.copy(ostr->ptr(), ostr->length(),
832
832
                            ostr->charset(), tocs, &cnv_errors);
840
840
}
841
841
 
842
842
 
843
 
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)
844
844
{
845
845
  Item_string *conv;
846
 
  uint32_t conv_errors;
 
846
  uint conv_errors;
847
847
  String tmp, cstr, *ostr= val_str(&tmp);
848
848
  cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
849
849
  if (conv_errors ||
881
881
 
882
882
 
883
883
/**
884
 
  Get the value of the function as a DRIZZLE_TIME structure.
 
884
  Get the value of the function as a MYSQL_TIME structure.
885
885
  As a extra convenience the time structure is reset on error!
886
886
*/
887
887
 
888
 
bool Item::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
888
bool Item::get_date(MYSQL_TIME *ltime,uint fuzzydate)
889
889
{
890
890
  if (result_type() == STRING_RESULT)
891
891
  {
893
893
    String tmp(buff,sizeof(buff), &my_charset_bin),*res;
894
894
    if (!(res=val_str(&tmp)) ||
895
895
        str_to_datetime_with_warn(res->ptr(), res->length(),
896
 
                                  ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
 
896
                                  ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR)
897
897
      goto err;
898
898
  }
899
899
  else
900
900
  {
901
901
    int64_t value= val_int();
902
902
    int was_cut;
903
 
    if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1L)
 
903
    if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1LL)
904
904
    {
905
905
      char buff[22], *end;
906
906
      end= int64_t10_to_str(value, buff, -10);
907
 
      make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
908
 
                                   buff, (int) (end-buff), DRIZZLE_TIMESTAMP_NONE,
909
 
                                   NULL);
 
907
      make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
908
                                   buff, (int) (end-buff), MYSQL_TIMESTAMP_NONE,
 
909
                                   NullS);
910
910
      goto err;
911
911
    }
912
912
  }
913
913
  return 0;
914
914
 
915
915
err:
916
 
  memset(ltime, 0, sizeof(*ltime));
 
916
  bzero((char*) ltime,sizeof(*ltime));
917
917
  return 1;
918
918
}
919
919
 
923
923
  As a extra convenience the time structure is reset on error!
924
924
*/
925
925
 
926
 
bool Item::get_time(DRIZZLE_TIME *ltime)
 
926
bool Item::get_time(MYSQL_TIME *ltime)
927
927
{
928
928
  char buff[40];
929
929
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
930
930
  if (!(res=val_str(&tmp)) ||
931
931
      str_to_time_with_warn(res->ptr(), res->length(), ltime))
932
932
  {
933
 
    memset(ltime, 0, sizeof(*ltime));
 
933
    bzero((char*) ltime,sizeof(*ltime));
934
934
    return 1;
935
935
  }
936
936
  return 0;
937
937
}
938
938
 
939
 
const CHARSET_INFO *Item::default_charset()
 
939
CHARSET_INFO *Item::default_charset()
940
940
{
941
941
  return current_thd->variables.collation_connection;
942
942
}
953
953
int Item::save_in_field_no_warnings(Field *field, bool no_conversions)
954
954
{
955
955
  int res;
956
 
  Table *table= field->table;
 
956
  TABLE *table= field->table;
957
957
  THD *thd= table->in_use;
958
958
  enum_check_fields tmp= thd->count_cuted_fields;
 
959
  my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
959
960
  ulong sql_mode= thd->variables.sql_mode;
960
 
  thd->variables.sql_mode&= ~(MODE_NO_ZERO_DATE);
 
961
  thd->variables.sql_mode&= ~(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE);
961
962
  thd->count_cuted_fields= CHECK_FIELD_IGNORE;
962
963
  res= save_in_field(field, no_conversions);
963
964
  thd->count_cuted_fields= tmp;
 
965
  dbug_tmp_restore_column_map(table->write_set, old_map);
964
966
  thd->variables.sql_mode= sql_mode;
965
967
  return res;
966
968
}
1039
1041
      Item_ref to allow fields from view being stored in tmp table.
1040
1042
    */
1041
1043
    Item_aggregate_ref *item_ref;
1042
 
    uint32_t el= fields.elements;
 
1044
    uint el= fields.elements;
1043
1045
    Item *real_itm= real_item();
1044
1046
 
1045
1047
    ref_pointer_array[el]= real_itm;
1109
1111
  @endcode
1110
1112
*/
1111
1113
 
1112
 
bool DTCollation::aggregate(DTCollation &dt, uint32_t flags)
 
1114
bool DTCollation::aggregate(DTCollation &dt, uint flags)
1113
1115
{
1114
1116
  if (!my_charset_same(collation, dt.collation))
1115
1117
  {
1196
1198
        set(dt);
1197
1199
        return 0;
1198
1200
      }
1199
 
      const CHARSET_INFO * const bin= get_charset_by_csname(collation->csname, 
1200
 
                                                            MY_CS_BINSORT,MYF(0));
 
1201
      CHARSET_INFO *bin= get_charset_by_csname(collation->csname, 
 
1202
                                               MY_CS_BINSORT,MYF(0));
1201
1203
      set(bin, DERIVATION_NONE);
1202
1204
    }
1203
1205
  }
1229
1231
 
1230
1232
 
1231
1233
static
1232
 
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,
1233
1235
                       int item_sep)
1234
1236
{
1235
1237
  if (count == 2)
1243
1245
 
1244
1246
 
1245
1247
bool agg_item_collations(DTCollation &c, const char *fname,
1246
 
                         Item **av, uint32_t count, uint32_t flags, int item_sep)
 
1248
                         Item **av, uint count, uint flags, int item_sep)
1247
1249
{
1248
 
  uint32_t i;
 
1250
  uint i;
1249
1251
  Item **arg;
1250
1252
  c.set(av[0]->collation);
1251
1253
  for (i= 1, arg= &av[item_sep]; i < count; i++, arg++)
1267
1269
 
1268
1270
 
1269
1271
bool agg_item_collations_for_comparison(DTCollation &c, const char *fname,
1270
 
                                        Item **av, uint32_t count, uint32_t flags)
 
1272
                                        Item **av, uint count, uint flags)
1271
1273
{
1272
1274
  return (agg_item_collations(c, fname, av, count,
1273
1275
                              flags | MY_COLL_DISALLOW_NONE, 1));
1306
1308
*/
1307
1309
 
1308
1310
bool agg_item_charsets(DTCollation &coll, const char *fname,
1309
 
                       Item **args, uint32_t nargs, uint32_t flags, int item_sep)
 
1311
                       Item **args, uint nargs, uint flags, int item_sep)
1310
1312
{
1311
1313
  Item **arg, *safe_args[2];
1312
1314
 
1329
1331
  }
1330
1332
 
1331
1333
  THD *thd= current_thd;
 
1334
  Query_arena *arena, backup;
1332
1335
  bool res= false;
1333
 
  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;
1334
1342
 
1335
1343
  for (i= 0, arg= args; i < nargs; i++, arg+= item_sep)
1336
1344
  {
1337
1345
    Item* conv;
1338
 
    uint32_t dummy_offset;
 
1346
    uint32 dummy_offset;
1339
1347
    if (!String::needs_conversion(0, (*arg)->collation.collation,
1340
1348
                                  coll.collation,
1341
1349
                                  &dummy_offset))
1376
1384
    */
1377
1385
    conv->fix_fields(thd, arg);
1378
1386
  }
1379
 
 
 
1387
  if (arena)
 
1388
    thd->restore_active_arena(arena, &backup);
1380
1389
  return res;
1381
1390
}
1382
1391
 
1397
1406
/**********************************************/
1398
1407
 
1399
1408
Item_field::Item_field(Field *f)
1400
 
  :Item_ident(0, NULL, *f->table_name, f->field_name),
 
1409
  :Item_ident(0, NullS, *f->table_name, f->field_name),
1401
1410
   item_equal(0), no_const_subst(0),
1402
1411
   have_privileges(0), any_privileges(0)
1403
1412
{
1417
1426
  Item_field (this is important in prepared statements).
1418
1427
*/
1419
1428
 
1420
 
Item_field::Item_field(THD *thd __attribute__((unused)),
 
1429
Item_field::Item_field(THD *thd __attribute__((__unused__)),
1421
1430
                       Name_resolution_context *context_arg,
1422
1431
                       Field *f)
1423
1432
  :Item_ident(context_arg, f->table->s->db.str, *f->table_name, f->field_name),
1497
1506
  {
1498
1507
    tmp=(char*) sql_alloc((uint) strlen(db_name)+(uint) strlen(table_name)+
1499
1508
                          (uint) strlen(field_name)+3);
1500
 
    strxmov(tmp,db_name,".",table_name,".",field_name,NULL);
 
1509
    strxmov(tmp,db_name,".",table_name,".",field_name,NullS);
1501
1510
  }
1502
1511
  else
1503
1512
  {
1505
1514
    {
1506
1515
      tmp= (char*) sql_alloc((uint) strlen(table_name) +
1507
1516
                             (uint) strlen(field_name) + 2);
1508
 
      strxmov(tmp, table_name, ".", field_name, NULL);
 
1517
      strxmov(tmp, table_name, ".", field_name, NullS);
1509
1518
    }
1510
1519
    else
1511
1520
      tmp= (char*) field_name;
1514
1523
}
1515
1524
 
1516
1525
void Item_ident::print(String *str,
1517
 
                       enum_query_type query_type __attribute__((unused)))
 
1526
                       enum_query_type query_type __attribute__((__unused__)))
1518
1527
{
1519
1528
  THD *thd= current_thd;
1520
1529
  char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
1524
1533
  {
1525
1534
    if (table_name && table_name[0])
1526
1535
    {
1527
 
      my_stpcpy(t_name_buff, table_name);
 
1536
      strmov(t_name_buff, table_name);
1528
1537
      my_casedn_str(files_charset_info, t_name_buff);
1529
1538
      t_name= t_name_buff;
1530
1539
    }
1531
1540
    if (db_name && db_name[0])
1532
1541
    {
1533
 
      my_stpcpy(d_name_buff, db_name);
 
1542
      strmov(d_name_buff, db_name);
1534
1543
      my_casedn_str(files_charset_info, d_name_buff);
1535
1544
      d_name= d_name_buff;
1536
1545
    }
1611
1620
  return result_field->val_str(str,&str_value);
1612
1621
}
1613
1622
 
1614
 
bool Item_field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
1623
bool Item_field::get_date(MYSQL_TIME *ltime,uint fuzzydate)
1615
1624
{
1616
1625
  if ((null_value=field->is_null()) || field->get_date(ltime,fuzzydate))
1617
1626
  {
1618
 
    memset(ltime, 0, sizeof(*ltime));
 
1627
    bzero((char*) ltime,sizeof(*ltime));
1619
1628
    return 1;
1620
1629
  }
1621
1630
  return 0;
1622
1631
}
1623
1632
 
1624
 
bool Item_field::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
1633
bool Item_field::get_date_result(MYSQL_TIME *ltime,uint fuzzydate)
1625
1634
{
1626
1635
  if ((null_value=result_field->is_null()) ||
1627
1636
      result_field->get_date(ltime,fuzzydate))
1628
1637
  {
1629
 
    memset(ltime, 0, sizeof(*ltime));
 
1638
    bzero((char*) ltime,sizeof(*ltime));
1630
1639
    return 1;
1631
1640
  }
1632
1641
  return 0;
1633
1642
}
1634
1643
 
1635
 
bool Item_field::get_time(DRIZZLE_TIME *ltime)
 
1644
bool Item_field::get_time(MYSQL_TIME *ltime)
1636
1645
{
1637
1646
  if ((null_value=field->is_null()) || field->get_time(ltime))
1638
1647
  {
1639
 
    memset(ltime, 0, sizeof(*ltime));
 
1648
    bzero((char*) ltime,sizeof(*ltime));
1640
1649
    return 1;
1641
1650
  }
1642
1651
  return 0;
1692
1701
 
1693
1702
 
1694
1703
bool Item_field::eq(const Item *item,
1695
 
                    bool binary_cmp __attribute__((unused))) const
 
1704
                    bool binary_cmp __attribute__((__unused__))) const
1696
1705
{
1697
1706
  Item *real_item= ((Item *) item)->real_item();
1698
1707
  if (real_item->type() != FIELD_ITEM)
1731
1740
 
1732
1741
 
1733
1742
void Item_field::fix_after_pullout(st_select_lex *new_parent,
1734
 
                                   Item **ref __attribute__((unused)))
 
1743
                                   Item **ref __attribute__((__unused__)))
1735
1744
{
1736
1745
  if (new_parent == depended_from)
1737
1746
    depended_from= NULL;
1752
1761
  return new_item;
1753
1762
}
1754
1763
 
1755
 
int64_t Item_field::val_int_endpoint(bool left_endp __attribute__((unused)),
1756
 
                                      bool *incl_endp __attribute__((unused)))
 
1764
int64_t Item_field::val_int_endpoint(bool left_endp __attribute__((__unused__)),
 
1765
                                      bool *incl_endp __attribute__((__unused__)))
1757
1766
{
1758
1767
  int64_t res= val_int();
1759
 
  return null_value? INT64_MIN : res;
 
1768
  return null_value? LONGLONG_MIN : res;
1760
1769
}
1761
1770
 
1762
1771
/**
1765
1774
  This is always 'signed'. Unsigned values are created with Item_uint()
1766
1775
*/
1767
1776
 
1768
 
Item_int::Item_int(const char *str_arg, uint32_t length)
 
1777
Item_int::Item_int(const char *str_arg, uint length)
1769
1778
{
1770
1779
  char *end_ptr= (char*) str_arg + length;
1771
1780
  int error;
1791
1800
}
1792
1801
 
1793
1802
void Item_int::print(String *str,
1794
 
                     enum_query_type query_type __attribute__((unused)))
 
1803
                     enum_query_type query_type __attribute__((__unused__)))
1795
1804
{
1796
1805
  // my_charset_bin is good enough for numbers
1797
1806
  str_value.set(value, &my_charset_bin);
1799
1808
}
1800
1809
 
1801
1810
 
1802
 
Item_uint::Item_uint(const char *str_arg, uint32_t length):
 
1811
Item_uint::Item_uint(const char *str_arg, uint length):
1803
1812
  Item_int(str_arg, length)
1804
1813
{
1805
1814
  unsigned_flag= 1;
1806
1815
}
1807
1816
 
1808
1817
 
1809
 
Item_uint::Item_uint(const char *str_arg, int64_t i, uint32_t length):
 
1818
Item_uint::Item_uint(const char *str_arg, int64_t i, uint length):
1810
1819
  Item_int(str_arg, i, length)
1811
1820
{
1812
1821
  unsigned_flag= 1;
1823
1832
 
1824
1833
 
1825
1834
void Item_uint::print(String *str,
1826
 
                      enum_query_type query_type __attribute__((unused)))
 
1835
                      enum_query_type query_type __attribute__((__unused__)))
1827
1836
{
1828
1837
  // latin1 is good enough for numbers
1829
1838
  str_value.set((uint64_t) value, default_charset());
1831
1840
}
1832
1841
 
1833
1842
 
1834
 
Item_decimal::Item_decimal(const char *str_arg, uint32_t length,
1835
 
                           const CHARSET_INFO * const charset)
 
1843
Item_decimal::Item_decimal(const char *str_arg, uint length,
 
1844
                           CHARSET_INFO *charset)
1836
1845
{
1837
1846
  str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
1838
1847
  name= (char*) str_arg;
1839
 
  decimals= (uint8_t) decimal_value.frac;
 
1848
  decimals= (uint8) decimal_value.frac;
1840
1849
  fixed= 1;
1841
1850
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1842
1851
                                             decimals, unsigned_flag);
1845
1854
Item_decimal::Item_decimal(int64_t val, bool unsig)
1846
1855
{
1847
1856
  int2my_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
1848
 
  decimals= (uint8_t) decimal_value.frac;
 
1857
  decimals= (uint8) decimal_value.frac;
1849
1858
  fixed= 1;
1850
1859
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1851
1860
                                             decimals, unsigned_flag);
1853
1862
 
1854
1863
 
1855
1864
Item_decimal::Item_decimal(double val,
1856
 
                           int precision __attribute__((unused)),
1857
 
                           int scale __attribute__((unused)))
 
1865
                           int precision __attribute__((__unused__)),
 
1866
                           int scale __attribute__((__unused__)))
1858
1867
{
1859
1868
  double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
1860
 
  decimals= (uint8_t) decimal_value.frac;
 
1869
  decimals= (uint8) decimal_value.frac;
1861
1870
  fixed= 1;
1862
1871
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1863
1872
                                             decimals, unsigned_flag);
1865
1874
 
1866
1875
 
1867
1876
Item_decimal::Item_decimal(const char *str, const my_decimal *val_arg,
1868
 
                           uint32_t decimal_par, uint32_t length)
 
1877
                           uint decimal_par, uint length)
1869
1878
{
1870
1879
  my_decimal2decimal(val_arg, &decimal_value);
1871
1880
  name= (char*) str;
1872
 
  decimals= (uint8_t) decimal_par;
 
1881
  decimals= (uint8) decimal_par;
1873
1882
  max_length= length;
1874
1883
  fixed= 1;
1875
1884
}
1878
1887
Item_decimal::Item_decimal(my_decimal *value_par)
1879
1888
{
1880
1889
  my_decimal2decimal(value_par, &decimal_value);
1881
 
  decimals= (uint8_t) decimal_value.frac;
 
1890
  decimals= (uint8) decimal_value.frac;
1882
1891
  fixed= 1;
1883
1892
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1884
1893
                                             decimals, unsigned_flag);
1885
1894
}
1886
1895
 
1887
1896
 
1888
 
Item_decimal::Item_decimal(const unsigned char *bin, int precision, int scale)
 
1897
Item_decimal::Item_decimal(const uchar *bin, int precision, int scale)
1889
1898
{
1890
1899
  binary2my_decimal(E_DEC_FATAL_ERROR, bin,
1891
1900
                    &decimal_value, precision, scale);
1892
 
  decimals= (uint8_t) decimal_value.frac;
 
1901
  decimals= (uint8) decimal_value.frac;
1893
1902
  fixed= 1;
1894
1903
  max_length= my_decimal_precision_to_length(precision, decimals,
1895
1904
                                             unsigned_flag);
1918
1927
}
1919
1928
 
1920
1929
void Item_decimal::print(String *str,
1921
 
                         enum_query_type query_type __attribute__((unused)))
 
1930
                         enum_query_type query_type __attribute__((__unused__)))
1922
1931
{
1923
1932
  my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, &str_value);
1924
1933
  str->append(str_value);
1926
1935
 
1927
1936
 
1928
1937
bool Item_decimal::eq(const Item *item,
1929
 
                      bool binary_cmp __attribute__((unused))) const
 
1938
                      bool binary_cmp __attribute__((__unused__))) const
1930
1939
{
1931
1940
  if (type() == item->type() && item->basic_const_item())
1932
1941
  {
1947
1956
void Item_decimal::set_decimal_value(my_decimal *value_par)
1948
1957
{
1949
1958
  my_decimal2decimal(value_par, &decimal_value);
1950
 
  decimals= (uint8_t) decimal_value.frac;
 
1959
  decimals= (uint8) decimal_value.frac;
1951
1960
  unsigned_flag= !decimal_value.sign();
1952
1961
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
1953
1962
                                             decimals, unsigned_flag);
2015
2024
  int error;
2016
2025
  char *end, *org_end;
2017
2026
  double tmp;
2018
 
  const CHARSET_INFO * const cs= str_value.charset();
 
2027
  CHARSET_INFO *cs= str_value.charset();
2019
2028
 
2020
2029
  org_end= (char*) str_value.ptr() + str_value.length();
2021
2030
  tmp= my_strntod(cs, (char*) str_value.ptr(), str_value.length(), &end,
2026
2035
      We can use str_value.ptr() here as Item_string is gurantee to put an
2027
2036
      end \0 here.
2028
2037
    */
2029
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2038
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2030
2039
                        ER_TRUNCATED_WRONG_VALUE,
2031
2040
                        ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE",
2032
2041
                        str_value.ptr());
2046
2055
  int64_t tmp;
2047
2056
  char *end= (char*) str_value.ptr()+ str_value.length();
2048
2057
  char *org_end= end;
2049
 
  const CHARSET_INFO * const cs= str_value.charset();
 
2058
  CHARSET_INFO *cs= str_value.charset();
2050
2059
 
2051
2060
  tmp= (*(cs->cset->strtoll10))(cs, str_value.ptr(), &end, &err);
2052
2061
  /*
2056
2065
  if (err > 0 ||
2057
2066
      (end != org_end && !check_if_only_end_space(cs, end, org_end)))
2058
2067
  {
2059
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2068
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2060
2069
                        ER_TRUNCATED_WRONG_VALUE,
2061
2070
                        ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
2062
2071
                        str_value.ptr());
2072
2081
 
2073
2082
 
2074
2083
bool Item_null::eq(const Item *item,
2075
 
                   bool binary_cmp __attribute__((unused))) const
 
2084
                   bool binary_cmp __attribute__((__unused__))) const
2076
2085
{ return item->type() == type(); }
2077
2086
 
2078
2087
 
2091
2100
  return 0;
2092
2101
}
2093
2102
/* ARGSUSED */
2094
 
String *Item_null::val_str(String *str __attribute__((unused)))
 
2103
String *Item_null::val_str(String *str __attribute__((__unused__)))
2095
2104
{
2096
2105
  // following assert is redundant, because fixed=1 assigned in constructor
2097
2106
  assert(fixed == 1);
2099
2108
  return 0;
2100
2109
}
2101
2110
 
2102
 
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__)))
2103
2112
{
2104
2113
  return 0;
2105
2114
}
2106
2115
 
2107
2116
 
2108
 
Item *Item_null::safe_charset_converter(const CHARSET_INFO * const tocs)
 
2117
Item *Item_null::safe_charset_converter(CHARSET_INFO *tocs)
2109
2118
{
2110
2119
  collation.set(tocs);
2111
2120
  return this;
2120
2129
 
2121
2130
static void
2122
2131
default_set_param_func(Item_param *param,
2123
 
                       unsigned char **pos __attribute__((unused)),
 
2132
                       uchar **pos __attribute__((unused)),
2124
2133
                       ulong len __attribute__((unused)))
2125
2134
{
2126
2135
  param->set_null();
2127
2136
}
2128
2137
 
2129
2138
 
2130
 
Item_param::Item_param(uint32_t pos_in_query_arg) :
 
2139
Item_param::Item_param(uint pos_in_query_arg) :
2131
2140
  state(NO_VALUE),
2132
2141
  item_result_type(STRING_RESULT),
2133
2142
  /* Don't pretend to be a literal unless value for this item is set. */
2134
2143
  item_type(PARAM_ITEM),
2135
 
  param_type(DRIZZLE_TYPE_VARCHAR),
 
2144
  param_type(MYSQL_TYPE_VARCHAR),
2136
2145
  pos_in_query(pos_in_query_arg),
2137
2146
  set_param_func(default_set_param_func),
2138
2147
  limit_clause_param(false)
2165
2174
  return;
2166
2175
}
2167
2176
 
2168
 
void Item_param::set_int(int64_t i, uint32_t max_length_arg)
 
2177
void Item_param::set_int(int64_t i, uint32 max_length_arg)
2169
2178
{
2170
2179
  value.integer= (int64_t) i;
2171
2180
  state= INT_VALUE;
2198
2207
    internal decimal value.
2199
2208
*/
2200
2209
 
2201
 
void Item_param::set_decimal(char *str, ulong length)
 
2210
void Item_param::set_decimal(const char *str, ulong length)
2202
2211
{
2203
2212
  char *end;
2204
2213
 
2205
 
  end= str+length;
2206
 
  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);
2207
2216
  state= DECIMAL_VALUE;
2208
2217
  decimals= decimal_value.frac;
2209
2218
  max_length= my_decimal_precision_to_length(decimal_value.precision(),
2214
2223
 
2215
2224
 
2216
2225
/**
2217
 
  Set parameter value from DRIZZLE_TIME value.
 
2226
  Set parameter value from MYSQL_TIME value.
2218
2227
 
2219
2228
  @param tm              datetime value to set (time_type is ignored)
2220
2229
  @param type            type of datetime value
2226
2235
    the fact that even wrong value sent over binary protocol fits into
2227
2236
    MAX_DATE_STRING_REP_LENGTH buffer.
2228
2237
*/
2229
 
void Item_param::set_time(DRIZZLE_TIME *tm,
2230
 
                          enum enum_drizzle_timestamp_type time_type,
2231
 
                          uint32_t max_length_arg)
 
2238
void Item_param::set_time(MYSQL_TIME *tm, timestamp_type time_type,
 
2239
                          uint32 max_length_arg)
2232
2240
2233
2241
  value.time= *tm;
2234
2242
  value.time.time_type= time_type;
2235
2243
 
2236
2244
  if (value.time.year > 9999 || value.time.month > 12 ||
2237
2245
      value.time.day > 31 ||
2238
 
      ((time_type != DRIZZLE_TIMESTAMP_TIME) && value.time.hour > 23) ||
 
2246
      ((time_type != MYSQL_TIMESTAMP_TIME) && value.time.hour > 23) ||
2239
2247
      value.time.minute > 59 || value.time.second > 59)
2240
2248
  {
2241
2249
    char buff[MAX_DATE_STRING_REP_LENGTH];
2242
 
    uint32_t length= my_TIME_to_str(&value.time, buff);
2243
 
    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,
2244
2252
                                 buff, length, time_type, 0);
2245
 
    set_zero_time(&value.time, DRIZZLE_TIMESTAMP_ERROR);
 
2253
    set_zero_time(&value.time, MYSQL_TIMESTAMP_ERROR);
2246
2254
  }
2247
2255
 
2248
2256
  state= TIME_VALUE;
2259
2267
    Assign string with no conversion: data is converted only after it's
2260
2268
    been written to the binary log.
2261
2269
  */
2262
 
  uint32_t dummy_errors;
 
2270
  uint dummy_errors;
2263
2271
  if (str_value.copy(str, length, &my_charset_bin, &my_charset_bin,
2264
2272
                     &dummy_errors))
2265
2273
    return(true);
2312
2320
    unsigned_flag= entry->unsigned_flag;
2313
2321
    if (limit_clause_param)
2314
2322
    {
2315
 
      bool unused;
 
2323
      my_bool unused;
2316
2324
      set_int(entry->val_int(&unused), MY_INT64_NUM_DECIMAL_DIGITS);
2317
2325
      item_type= Item::INT_ITEM;
2318
2326
      return(!unsigned_flag && value.integer < 0 ? 1 : 0);
2328
2336
      break;
2329
2337
    case STRING_RESULT:
2330
2338
    {
2331
 
      const CHARSET_INFO * const fromcs= entry->collation.collation;
2332
 
      const CHARSET_INFO * const tocs= thd->variables.collation_connection;
2333
 
      uint32_t dummy_offset;
 
2339
      CHARSET_INFO *fromcs= entry->collation.collation;
 
2340
      CHARSET_INFO *tocs= thd->variables.collation_connection;
 
2341
      uint32 dummy_offset;
2334
2342
 
2335
2343
      value.cs_info.character_set_of_placeholder= 
2336
2344
        value.cs_info.character_set_client= fromcs;
2440
2448
}
2441
2449
 
2442
2450
 
2443
 
bool Item_param::get_time(DRIZZLE_TIME *res)
 
2451
bool Item_param::get_time(MYSQL_TIME *res)
2444
2452
{
2445
2453
  if (state == TIME_VALUE)
2446
2454
  {
2455
2463
}
2456
2464
 
2457
2465
 
2458
 
bool Item_param::get_date(DRIZZLE_TIME *res, uint32_t fuzzydate)
 
2466
bool Item_param::get_date(MYSQL_TIME *res, uint fuzzydate)
2459
2467
{
2460
2468
  if (state == TIME_VALUE)
2461
2469
  {
2638
2646
      *ptr++= '\'';
2639
2647
      ptr+= (uint) my_TIME_to_str(&value.time, ptr);
2640
2648
      *ptr++= '\'';
2641
 
      str->length((uint32_t) (ptr - buf));
 
2649
      str->length((uint32) (ptr - buf));
2642
2650
      break;
2643
2651
    }
2644
2652
  case STRING_VALUE:
2768
2776
/* End of Item_param related */
2769
2777
 
2770
2778
void Item_param::print(String *str,
2771
 
                       enum_query_type query_type __attribute__((unused)))
 
2779
                       enum_query_type query_type __attribute__((__unused__)))
2772
2780
{
2773
2781
  if (state == NO_VALUE)
2774
2782
  {
2798
2806
}
2799
2807
 
2800
2808
/* ARGSUSED */
2801
 
String *Item_copy_string::val_str(String *str __attribute__((unused)))
 
2809
String *Item_copy_string::val_str(String *str __attribute__((__unused__)))
2802
2810
{
2803
2811
  // Item_copy_string is used without fix_fields call
2804
2812
  if (null_value)
2822
2830
*/
2823
2831
 
2824
2832
/* ARGSUSED */
2825
 
bool Item::fix_fields(THD *thd __attribute__((unused)),
2826
 
                      Item **ref __attribute__((unused)))
 
2833
bool Item::fix_fields(THD *thd __attribute__((__unused__)),
 
2834
                      Item **ref __attribute__((__unused__)))
2827
2835
{
2828
2836
 
2829
2837
  // We do not check fields which are fixed during construction
2877
2885
}
2878
2886
 
2879
2887
 
2880
 
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)
2881
2889
{  
2882
2890
  return (owner->was_null|= null_value= (*ref)->get_date(ltime, fuzzydate));
2883
2891
}
2909
2917
  current->mark_as_dependent(last);
2910
2918
  if (thd->lex->describe & DESCRIBE_EXTENDED)
2911
2919
  {
2912
 
    char warn_buff[DRIZZLE_ERRMSG_SIZE];
 
2920
    char warn_buff[MYSQL_ERRMSG_SIZE];
2913
2921
    sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED),
2914
2922
            db_name, (db_name[0] ? "." : ""),
2915
2923
            table_name, (table_name [0] ? "." : ""),
2916
2924
            resolved_item->field_name,
2917
2925
            current->select_number, last->select_number);
2918
 
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
 
2926
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
2919
2927
                 ER_WARN_FIELD_RESOLVED, warn_buff);
2920
2928
  }
2921
2929
}
3000
3008
    - NULL if find_item is not in group_list
3001
3009
*/
3002
3010
 
3003
 
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)
3004
3012
{
3005
3013
  const char *db_name;
3006
3014
  const char *table_name;
3007
3015
  const char *field_name;
3008
 
  order_st      *found_group= NULL;
 
3016
  ORDER      *found_group= NULL;
3009
3017
  int         found_match_degree= 0;
3010
3018
  Item_ident *cur_field;
3011
3019
  int         cur_match_degree= 0;
3031
3039
 
3032
3040
  assert(field_name != 0);
3033
3041
 
3034
 
  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)
3035
3043
  {
3036
3044
    if ((*(cur_group->item))->real_item()->type() == Item::FIELD_ITEM)
3037
3045
    {
3132
3140
{
3133
3141
  Item **group_by_ref= NULL;
3134
3142
  Item **select_ref= NULL;
3135
 
  order_st *group_list= (order_st*) select->group_list.first;
 
3143
  ORDER *group_list= (ORDER*) select->group_list.first;
3136
3144
  bool ambiguous_fields= false;
3137
 
  uint32_t counter;
 
3145
  uint counter;
3138
3146
  enum_resolution_type resolution;
3139
3147
 
3140
3148
  /*
3158
3166
        !((*group_by_ref)->eq(*select_ref, 0)))
3159
3167
    {
3160
3168
      ambiguous_fields= true;
3161
 
      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,
3162
3170
                          ER(ER_NON_UNIQ_ERROR), ref->full_name(),
3163
3171
                          current_thd->where);
3164
3172
 
3551
3559
      /* Look up in current select's item_list to find aliased fields */
3552
3560
      if (thd->lex->current_select->is_item_list_lookup)
3553
3561
      {
3554
 
        uint32_t counter;
 
3562
        uint counter;
3555
3563
        enum_resolution_type resolution;
3556
3564
        Item** res= find_item_in_list(this, thd->lex->current_select->item_list,
3557
3565
                                      &counter, REPORT_EXCEPT_NOT_FOUND,
3649
3657
  }
3650
3658
  else if (thd->mark_used_columns != MARK_COLUMNS_NONE)
3651
3659
  {
3652
 
    Table *table= field->table;
 
3660
    TABLE *table= field->table;
3653
3661
    MY_BITMAP *current_bitmap, *other_bitmap;
3654
3662
    if (thd->mark_used_columns == MARK_COLUMNS_READ)
3655
3663
    {
3682
3690
  return true;
3683
3691
}
3684
3692
 
3685
 
Item *Item_field::safe_charset_converter(const CHARSET_INFO * const tocs)
 
3693
Item *Item_field::safe_charset_converter(CHARSET_INFO *tocs)
3686
3694
{
3687
3695
  no_const_subst= 1;
3688
3696
  return Item::safe_charset_converter(tocs);
3771
3779
    false  otherwise
3772
3780
*/
3773
3781
 
3774
 
bool Item_field::subst_argument_checker(unsigned char **arg)
 
3782
bool Item_field::subst_argument_checker(uchar **arg)
3775
3783
{
3776
3784
  return (result_type() != STRING_RESULT) || (*arg);
3777
3785
}
3778
3786
 
3779
3787
 
3780
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
/**
3781
3813
  Set a pointer to the multiple equality the field reference belongs to
3782
3814
  (if any).
3783
3815
 
3801
3833
    - pointer to the field item, otherwise.
3802
3834
*/
3803
3835
 
3804
 
Item *Item_field::equal_fields_propagator(unsigned char *arg)
 
3836
Item *Item_field::equal_fields_propagator(uchar *arg)
3805
3837
{
3806
3838
  if (no_const_subst)
3807
3839
    return this;
3823
3855
  if (!item ||
3824
3856
      (cmp_context != (Item_result)-1 && item->cmp_context != cmp_context))
3825
3857
    item= this;
3826
 
 
 
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
  }
3827
3865
  return item;
3828
3866
}
3829
3867
 
3834
3872
  See comments in Arg_comparator::set_compare_func() for details.
3835
3873
*/
3836
3874
 
3837
 
bool Item_field::set_no_const_sub(unsigned char *arg __attribute__((unused)))
 
3875
bool Item_field::set_no_const_sub(uchar *arg __attribute__((__unused__)))
3838
3876
{
3839
3877
  if (field->charset() != &my_charset_bin)
3840
3878
    no_const_subst=1;
3867
3905
    - this - otherwise.
3868
3906
*/
3869
3907
 
3870
 
Item *Item_field::replace_equal_field(unsigned char *arg __attribute__((unused)))
 
3908
Item *Item_field::replace_equal_field(uchar *arg __attribute__((__unused__)))
3871
3909
{
3872
3910
  if (item_equal)
3873
3911
  {
3915
3953
 
3916
3954
enum_field_types Item::string_field_type() const
3917
3955
{
3918
 
  enum_field_types f_type= DRIZZLE_TYPE_VARCHAR;
 
3956
  enum_field_types f_type= MYSQL_TYPE_VAR_STRING;
3919
3957
  if (max_length >= 65536)
3920
 
    f_type= DRIZZLE_TYPE_BLOB;
 
3958
    f_type= MYSQL_TYPE_BLOB;
3921
3959
  return f_type;
3922
3960
}
3923
3961
 
3932
3970
{
3933
3971
  switch (result_type()) {
3934
3972
  case STRING_RESULT:  return string_field_type();
3935
 
  case INT_RESULT:     return DRIZZLE_TYPE_LONGLONG;
3936
 
  case DECIMAL_RESULT: return DRIZZLE_TYPE_NEWDECIMAL;
3937
 
  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;
3938
3976
  case ROW_RESULT:
3939
3977
  default:
3940
3978
    assert(0);
3941
 
    return DRIZZLE_TYPE_VARCHAR;
 
3979
    return MYSQL_TYPE_VARCHAR;
3942
3980
  }
3943
3981
}
3944
3982
 
3947
3985
{
3948
3986
  switch (field_type())
3949
3987
  {
3950
 
    case DRIZZLE_TYPE_NEWDATE:
3951
 
    case DRIZZLE_TYPE_DATETIME:
3952
 
    case DRIZZLE_TYPE_TIMESTAMP:
 
3988
    case MYSQL_TYPE_NEWDATE:
 
3989
    case MYSQL_TYPE_DATETIME:
 
3990
    case MYSQL_TYPE_TIMESTAMP:
3953
3991
      return true;
3954
3992
    default:
3955
3993
      break;
3961
3999
String *Item::check_well_formed_result(String *str, bool send_error)
3962
4000
{
3963
4001
  /* Check whether we got a well-formed string */
3964
 
  const CHARSET_INFO * const cs= str->charset();
 
4002
  CHARSET_INFO *cs= str->charset();
3965
4003
  int well_formed_error;
3966
 
  uint32_t wlen= cs->cset->well_formed_len(cs,
 
4004
  uint wlen= cs->cset->well_formed_len(cs,
3967
4005
                                       str->ptr(), str->ptr() + str->length(),
3968
4006
                                       str->length(), &well_formed_error);
3969
4007
  if (wlen < str->length())
3970
4008
  {
3971
4009
    THD *thd= current_thd;
3972
4010
    char hexbuf[7];
3973
 
    enum DRIZZLE_ERROR::enum_warning_level level;
3974
 
    uint32_t diff= str->length() - wlen;
 
4011
    enum MYSQL_ERROR::enum_warning_level level;
 
4012
    uint diff= str->length() - wlen;
3975
4013
    set_if_smaller(diff, 3);
3976
4014
    octet2hex(hexbuf, str->ptr() + wlen, diff);
3977
4015
    if (send_error)
3981
4019
      return 0;
3982
4020
    }
3983
4021
    {
3984
 
      level= DRIZZLE_ERROR::WARN_LEVEL_ERROR;
 
4022
      level= MYSQL_ERROR::WARN_LEVEL_ERROR;
3985
4023
      null_value= 1;
3986
4024
      str= 0;
3987
4025
    }
4012
4050
    0    otherwise
4013
4051
*/
4014
4052
 
4015
 
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)
4016
4054
{
4017
 
  const CHARSET_INFO *save_cs= 0;
4018
 
  const CHARSET_INFO *save_item_cs= 0;
 
4055
  CHARSET_INFO *save_cs= 0;
 
4056
  CHARSET_INFO *save_item_cs= 0;
4019
4057
  if (collation.collation != cs)
4020
4058
  {
4021
4059
    save_cs= collation.collation;
4045
4083
  @param table          Table for which the field is created
4046
4084
*/
4047
4085
 
4048
 
Field *Item::make_string_field(Table *table)
 
4086
Field *Item::make_string_field(TABLE *table)
4049
4087
{
4050
4088
  Field *field;
4051
4089
  assert(collation.collation);
4052
4090
  if (max_length/collation.collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB)
4053
4091
    field= new Field_blob(max_length, maybe_null, name,
4054
4092
                          collation.collation);
4055
 
  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))
4056
4096
    field= new Field_varstring(max_length, maybe_null, name, table->s,
4057
4097
                               collation.collation);
4058
 
 
 
4098
  else
 
4099
    field= new Field_string(max_length, maybe_null, name,
 
4100
                            collation.collation);
4059
4101
  if (field)
4060
4102
    field->init(table);
4061
4103
  return field;
4074
4116
    \#    Created field
4075
4117
*/
4076
4118
 
4077
 
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)
4078
4120
{
4079
4121
  /*
4080
4122
    The field functions defines a field to be not null if null_ptr is not 0
4081
4123
  */
4082
 
  unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
 
4124
  uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
4083
4125
  Field *field;
4084
4126
 
4085
4127
  switch (field_type()) {
4086
 
  case DRIZZLE_TYPE_NEWDECIMAL:
4087
 
    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,
4088
4130
                                 Field::NONE, name, decimals, 0,
4089
4131
                                 unsigned_flag);
4090
4132
    break;
4091
 
  case DRIZZLE_TYPE_TINY:
4092
 
    field= new Field_tiny((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4093
 
                          name, 0, unsigned_flag);
4094
 
    break;
4095
 
  case DRIZZLE_TYPE_LONG:
4096
 
    field= new Field_long((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4097
 
                          name, 0, unsigned_flag);
4098
 
    break;
4099
 
  case DRIZZLE_TYPE_LONGLONG:
4100
 
    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_int64_t((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4101
4147
                              name, 0, unsigned_flag);
4102
4148
    break;
4103
 
  case DRIZZLE_TYPE_DOUBLE:
4104
 
    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,
4105
4155
                            name, decimals, 0, unsigned_flag);
4106
4156
    break;
4107
 
  case DRIZZLE_TYPE_NULL:
4108
 
    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,
4109
4159
                          name, &my_charset_bin);
4110
4160
    break;
4111
 
  case DRIZZLE_TYPE_NEWDATE:
 
4161
  case MYSQL_TYPE_NEWDATE:
4112
4162
    field= new Field_newdate(maybe_null, name, &my_charset_bin);
4113
4163
    break;
4114
 
  case DRIZZLE_TYPE_TIME:
 
4164
  case MYSQL_TYPE_TIME:
4115
4165
    field= new Field_time(maybe_null, name, &my_charset_bin);
4116
4166
    break;
4117
 
  case DRIZZLE_TYPE_TIMESTAMP:
 
4167
  case MYSQL_TYPE_TIMESTAMP:
4118
4168
    field= new Field_timestamp(maybe_null, name, &my_charset_bin);
4119
4169
    break;
4120
 
  case DRIZZLE_TYPE_DATETIME:
 
4170
  case MYSQL_TYPE_DATETIME:
4121
4171
    field= new Field_datetime(maybe_null, name, &my_charset_bin);
4122
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;
4123
4177
  default:
4124
4178
    /* This case should never be chosen */
4125
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
    }
4126
4188
    /* Fall through to make_string_field() */
4127
 
  case DRIZZLE_TYPE_ENUM:
4128
 
  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:
4129
4193
    return make_string_field(table);
4130
 
  case DRIZZLE_TYPE_BLOB:
 
4194
  case MYSQL_TYPE_BLOB:
4131
4195
    if (this->type() == Item::TYPE_HOLDER)
4132
4196
      field= new Field_blob(max_length, maybe_null, name, collation.collation,
4133
4197
                            1);
4241
4305
  if (result_type() == STRING_RESULT)
4242
4306
  {
4243
4307
    String *result;
4244
 
    const CHARSET_INFO * const cs= collation.collation;
 
4308
    CHARSET_INFO *cs= collation.collation;
4245
4309
    char buff[MAX_FIELD_WIDTH];         // Alloc buffer for small columns
4246
4310
    str_value.set_quick(buff, sizeof(buff), cs);
4247
4311
    result=val_str(&str_value);
4296
4360
 
4297
4361
 
4298
4362
int Item_string::save_in_field(Field *field,
4299
 
                               bool no_conversions __attribute__((unused)))
 
4363
                               bool no_conversions __attribute__((__unused__)))
4300
4364
{
4301
4365
  String *result;
4302
4366
  result=val_str(&str_value);
4312
4376
 
4313
4377
 
4314
4378
int Item_int::save_in_field(Field *field,
4315
 
                            bool no_conversions __attribute__((unused)))
 
4379
                            bool no_conversions __attribute__((__unused__)))
4316
4380
{
4317
4381
  int64_t nr=val_int();
4318
4382
  if (null_value)
4323
4387
 
4324
4388
 
4325
4389
int Item_decimal::save_in_field(Field *field,
4326
 
                                bool no_conversions __attribute__((unused)))
 
4390
                                bool no_conversions __attribute__((__unused__)))
4327
4391
{
4328
4392
  field->set_notnull();
4329
4393
  return field->store_decimal(&decimal_value);
4331
4395
 
4332
4396
 
4333
4397
bool Item_int::eq(const Item *arg,
4334
 
                  bool binary_cmp __attribute__((unused))) const
 
4398
                  bool binary_cmp __attribute__((__unused__))) const
4335
4399
{
4336
4400
  /* No need to check for null value as basic constant can't be NULL */
4337
4401
  if (arg->basic_const_item() && arg->type() == type())
4367
4431
}
4368
4432
 
4369
4433
 
4370
 
static uint32_t nr_of_decimals(const char *str, const char *end)
 
4434
static uint nr_of_decimals(const char *str, const char *end)
4371
4435
{
4372
4436
  const char *decimal_point;
4373
4437
 
4395
4459
  value is not a true double value (overflow)
4396
4460
*/
4397
4461
 
4398
 
Item_float::Item_float(const char *str_arg, uint32_t length)
 
4462
Item_float::Item_float(const char *str_arg, uint length)
4399
4463
{
4400
4464
  int error;
4401
4465
  char *end_not_used;
4411
4475
    my_error(ER_ILLEGAL_VALUE_FOR_TYPE, MYF(0), "double", (char*) str_arg);
4412
4476
  }
4413
4477
  presentation= name=(char*) str_arg;
4414
 
  decimals=(uint8_t) nr_of_decimals(str_arg, str_arg+length);
 
4478
  decimals=(uint8) nr_of_decimals(str_arg, str_arg+length);
4415
4479
  max_length=length;
4416
4480
  fixed= 1;
4417
4481
}
4418
4482
 
4419
4483
 
4420
4484
int Item_float::save_in_field(Field *field,
4421
 
                              bool no_conversions __attribute__((unused)))
 
4485
                              bool no_conversions __attribute__((__unused__)))
4422
4486
{
4423
4487
  double nr= val_real();
4424
4488
  if (null_value)
4429
4493
 
4430
4494
 
4431
4495
void Item_float::print(String *str,
4432
 
                       enum_query_type query_type __attribute__((unused)))
 
4496
                       enum_query_type query_type __attribute__((__unused__)))
4433
4497
{
4434
4498
  if (presentation)
4435
4499
  {
4450
4514
*/
4451
4515
 
4452
4516
bool Item_float::eq(const Item *arg,
4453
 
                    bool binary_cmp __attribute__((unused))) const
 
4517
                    bool binary_cmp __attribute__((__unused__))) const
4454
4518
{
4455
4519
  if (arg->basic_const_item() && arg->type() == type())
4456
4520
  {
4465
4529
}
4466
4530
 
4467
4531
 
4468
 
inline uint32_t char_val(char X)
 
4532
inline uint char_val(char X)
4469
4533
{
4470
4534
  return (uint) (X >= '0' && X <= '9' ? X-'0' :
4471
4535
                 X >= 'A' && X <= 'Z' ? X-'A'+10 :
4473
4537
}
4474
4538
 
4475
4539
 
4476
 
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)
4477
4541
{
4478
4542
  max_length=(str_length+1)/2;
4479
4543
  char *ptr=(char*) sql_alloc(max_length+1);
4499
4563
  // following assert is redundant, because fixed=1 assigned in constructor
4500
4564
  assert(fixed == 1);
4501
4565
  char *end=(char*) str_value.ptr()+str_value.length(),
4502
 
       *ptr=end-cmin(str_value.length(),(uint32_t)sizeof(int64_t));
 
4566
       *ptr=end-min(str_value.length(),sizeof(int64_t));
4503
4567
 
4504
4568
  uint64_t value=0;
4505
4569
  for (; ptr != end ; ptr++)
4506
 
    value=(value << 8)+ (uint64_t) (unsigned char) *ptr;
 
4570
    value=(value << 8)+ (uint64_t) (uchar) *ptr;
4507
4571
  return (int64_t) value;
4508
4572
}
4509
4573
 
4519
4583
 
4520
4584
 
4521
4585
int Item_hex_string::save_in_field(Field *field,
4522
 
                                   bool no_conversions __attribute__((unused)))
 
4586
                                   bool no_conversions __attribute__((__unused__)))
4523
4587
{
4524
4588
  field->set_notnull();
4525
4589
  if (field->result_type() == STRING_RESULT)
4527
4591
                        collation.collation);
4528
4592
 
4529
4593
  uint64_t nr;
4530
 
  uint32_t length= str_value.length();
 
4594
  uint32 length= str_value.length();
4531
4595
  if (length > 8)
4532
4596
  {
4533
 
    nr= field->flags & UNSIGNED_FLAG ? UINT64_MAX : INT64_MAX;
 
4597
    nr= field->flags & UNSIGNED_FLAG ? ULONGLONG_MAX : LONGLONG_MAX;
4534
4598
    goto warn;
4535
4599
  }
4536
4600
  nr= (uint64_t) val_int();
4537
 
  if ((length == 8) && !(field->flags & UNSIGNED_FLAG) && (nr > INT64_MAX))
 
4601
  if ((length == 8) && !(field->flags & UNSIGNED_FLAG) && (nr > LONGLONG_MAX))
4538
4602
  {
4539
 
    nr= INT64_MAX;
 
4603
    nr= LONGLONG_MAX;
4540
4604
    goto warn;
4541
4605
  }
4542
4606
  return field->store((int64_t) nr, true);  // Assume hex numbers are unsigned
4543
4607
 
4544
4608
warn:
4545
4609
  if (!field->store((int64_t) nr, true))
4546
 
    field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE,
 
4610
    field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE,
4547
4611
                       1);
4548
4612
  return 1;
4549
4613
}
4550
4614
 
4551
4615
 
4552
4616
void Item_hex_string::print(String *str,
4553
 
                            enum_query_type query_type __attribute__((unused)))
 
4617
                            enum_query_type query_type __attribute__((__unused__)))
4554
4618
{
4555
4619
  char *end= (char*) str_value.ptr() + str_value.length(),
4556
 
       *ptr= end - cmin(str_value.length(), (uint32_t)sizeof(int64_t));
 
4620
       *ptr= end - min(str_value.length(), sizeof(int64_t));
4557
4621
  str->append("0x");
4558
4622
  for (; ptr != end ; ptr++)
4559
4623
  {
4560
 
    str->append(_dig_vec_lower[((unsigned char) *ptr) >> 4]);
4561
 
    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]);
4562
4626
  }
4563
4627
}
4564
4628
 
4575
4639
}
4576
4640
 
4577
4641
 
4578
 
Item *Item_hex_string::safe_charset_converter(const CHARSET_INFO * const tocs)
 
4642
Item *Item_hex_string::safe_charset_converter(CHARSET_INFO *tocs)
4579
4643
{
4580
4644
  Item_string *conv;
4581
4645
  String tmp, *str= val_str(&tmp);
4594
4658
  In number context this is a int64_t value.
4595
4659
*/
4596
4660
  
4597
 
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)
4598
4662
{
4599
4663
  const char *end= str + str_length - 1;
4600
 
  unsigned char bits= 0;
4601
 
  uint32_t power= 1;
 
4664
  uchar bits= 0;
 
4665
  uint power= 1;
4602
4666
 
4603
4667
  max_length= (str_length + 7) >> 3;
4604
4668
  char *ptr= (char*) sql_alloc(max_length + 1);
4630
4694
*/
4631
4695
 
4632
4696
bool Item_null::send(Protocol *protocol,
4633
 
                     String *packet __attribute__((unused)))
 
4697
                     String *packet __attribute__((__unused__)))
4634
4698
{
4635
4699
  return protocol->store_null();
4636
4700
}
4646
4710
 
4647
4711
  switch ((f_type=field_type())) {
4648
4712
  default:
4649
 
  case DRIZZLE_TYPE_NULL:
4650
 
  case DRIZZLE_TYPE_ENUM:
4651
 
  case DRIZZLE_TYPE_BLOB:
4652
 
  case DRIZZLE_TYPE_VARCHAR:
4653
 
  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:
4654
4721
  {
4655
4722
    String *res;
4656
4723
    if ((res=val_str(buffer)))
4657
4724
      result= protocol->store(res->ptr(),res->length(),res->charset());
4658
4725
    break;
4659
4726
  }
4660
 
  case DRIZZLE_TYPE_TINY:
 
4727
  case MYSQL_TYPE_TINY:
4661
4728
  {
4662
4729
    int64_t nr;
4663
4730
    nr= val_int();
4665
4732
      result= protocol->store_tiny(nr);
4666
4733
    break;
4667
4734
  }
4668
 
  case DRIZZLE_TYPE_LONG:
 
4735
  case MYSQL_TYPE_SHORT:
 
4736
  case MYSQL_TYPE_YEAR:
 
4737
  {
 
4738
    int64_t nr;
 
4739
    nr= val_int();
 
4740
    if (!null_value)
 
4741
      result= protocol->store_short(nr);
 
4742
    break;
 
4743
  }
 
4744
  case MYSQL_TYPE_LONG:
4669
4745
  {
4670
4746
    int64_t nr;
4671
4747
    nr= val_int();
4673
4749
      result= protocol->store_long(nr);
4674
4750
    break;
4675
4751
  }
4676
 
  case DRIZZLE_TYPE_LONGLONG:
 
4752
  case MYSQL_TYPE_LONGLONG:
4677
4753
  {
4678
4754
    int64_t nr;
4679
4755
    nr= val_int();
4681
4757
      result= protocol->store_int64_t(nr, unsigned_flag);
4682
4758
    break;
4683
4759
  }
4684
 
  case DRIZZLE_TYPE_DOUBLE:
 
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:
4685
4769
  {
4686
4770
    double nr= val_real();
4687
4771
    if (!null_value)
4688
4772
      result= protocol->store(nr, decimals, buffer);
4689
4773
    break;
4690
4774
  }
4691
 
  case DRIZZLE_TYPE_DATETIME:
4692
 
  case DRIZZLE_TYPE_TIMESTAMP:
 
4775
  case MYSQL_TYPE_DATETIME:
 
4776
  case MYSQL_TYPE_TIMESTAMP:
4693
4777
  {
4694
 
    DRIZZLE_TIME tm;
 
4778
    MYSQL_TIME tm;
4695
4779
    get_date(&tm, TIME_FUZZY_DATE);
4696
4780
    if (!null_value)
4697
4781
    {
4698
 
      if (f_type == DRIZZLE_TYPE_NEWDATE)
 
4782
      if (f_type == MYSQL_TYPE_NEWDATE)
4699
4783
        return protocol->store_date(&tm);
4700
4784
      else
4701
4785
        result= protocol->store(&tm);
4702
4786
    }
4703
4787
    break;
4704
4788
  }
4705
 
  case DRIZZLE_TYPE_TIME:
 
4789
  case MYSQL_TYPE_TIME:
4706
4790
  {
4707
 
    DRIZZLE_TIME tm;
 
4791
    MYSQL_TIME tm;
4708
4792
    get_time(&tm);
4709
4793
    if (!null_value)
4710
4794
      result= protocol->store_time(&tm);
4718
4802
 
4719
4803
 
4720
4804
bool Item_field::send(Protocol *protocol,
4721
 
                      String *buffer __attribute__((unused)))
 
4805
                      String *buffer __attribute__((__unused__)))
4722
4806
{
4723
4807
  return protocol->store(result_field);
4724
4808
}
4762
4846
    this field    otherwise
4763
4847
*/
4764
4848
 
4765
 
Item *Item_field::update_value_transformer(unsigned char *select_arg)
 
4849
Item *Item_field::update_value_transformer(uchar *select_arg)
4766
4850
{
4767
4851
  SELECT_LEX *select= (SELECT_LEX*)select_arg;
4768
4852
  assert(fixed);
4769
4853
 
4770
 
  if (field->table != select->context.table_list->table)
 
4854
  if (field->table != select->context.table_list->table &&
 
4855
      type() != Item::TRIGGER_FIELD_ITEM)
4771
4856
  {
4772
4857
    List<Item> *all_fields= &select->join->all_fields;
4773
4858
    Item **ref_pointer_array= select->ref_pointer_array;
4804
4889
                   Item **item, const char *table_name_arg,
4805
4890
                   const char *field_name_arg,
4806
4891
                   bool alias_name_used_arg)
4807
 
  :Item_ident(context_arg, NULL, table_name_arg, field_name_arg),
 
4892
  :Item_ident(context_arg, NullS, table_name_arg, field_name_arg),
4808
4893
   result_field(0), ref(item)
4809
4894
{
4810
4895
  alias_name_used= alias_name_used_arg;
5285
5370
}
5286
5371
 
5287
5372
 
5288
 
bool Item_ref::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
5373
bool Item_ref::get_date(MYSQL_TIME *ltime,uint fuzzydate)
5289
5374
{
5290
5375
  return (null_value=(*ref)->get_date_result(ltime,fuzzydate));
5291
5376
}
5399
5484
}
5400
5485
 
5401
5486
 
5402
 
bool Item_direct_ref::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
5487
bool Item_direct_ref::get_date(MYSQL_TIME *ltime,uint fuzzydate)
5403
5488
{
5404
5489
  return (null_value=(*ref)->get_date(ltime,fuzzydate));
5405
5490
}
5465
5550
}
5466
5551
 
5467
5552
void Item_ref::fix_after_pullout(st_select_lex *new_parent,
5468
 
                                 Item **refptr __attribute__((unused)))
 
5553
                                 Item **refptr __attribute__((__unused__)))
5469
5554
{
5470
5555
  if (depended_from == new_parent)
5471
5556
  {
5492
5577
*/
5493
5578
 
5494
5579
bool Item_direct_view_ref::eq(const Item *item,
5495
 
                              bool binary_cmp __attribute__((unused))) const
 
5580
                              bool binary_cmp __attribute__((__unused__))) const
5496
5581
{
5497
5582
  if (item->type() == REF_ITEM)
5498
5583
  {
5514
5599
 
5515
5600
 
5516
5601
bool Item_default_value::fix_fields(THD *thd,
5517
 
                                    Item **items __attribute__((unused)))
 
5602
                                    Item **items __attribute__((__unused__)))
5518
5603
{
5519
5604
  Item *real_arg;
5520
5605
  Item_field *field_arg;
5586
5671
 
5587
5672
      {
5588
5673
        push_warning_printf(field_arg->table->in_use,
5589
 
                            DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
5674
                            MYSQL_ERROR::WARN_LEVEL_WARN,
5590
5675
                            ER_NO_DEFAULT_FOR_FIELD,
5591
5676
                            ER(ER_NO_DEFAULT_FOR_FIELD),
5592
5677
                            field_arg->field_name);
5605
5690
  same time it can replace some nodes in the tree.
5606
5691
*/ 
5607
5692
 
5608
 
Item *Item_default_value::transform(Item_transformer transformer, unsigned char *args)
 
5693
Item *Item_default_value::transform(Item_transformer transformer, uchar *args)
5609
5694
{
5610
5695
  Item *new_item= arg->transform(transformer, args);
5611
5696
  if (!new_item)
5631
5716
 
5632
5717
 
5633
5718
bool Item_insert_value::fix_fields(THD *thd,
5634
 
                                   Item **items __attribute__((unused)))
 
5719
                                   Item **items __attribute__((__unused__)))
5635
5720
{
5636
5721
  assert(fixed == 0);
5637
5722
  /* We should only check that arg is in first table */
5638
5723
  if (!arg->fixed)
5639
5724
  {
5640
5725
    bool res;
5641
 
    TableList *orig_next_table= context->last_name_resolution_table;
 
5726
    TABLE_LIST *orig_next_table= context->last_name_resolution_table;
5642
5727
    context->last_name_resolution_table= context->first_name_resolution_table;
5643
5728
    res= arg->fix_fields(thd, &arg);
5644
5729
    context->last_name_resolution_table= orig_next_table;
5733
5818
      new_item= new Item_null(name);
5734
5819
    else
5735
5820
    {
5736
 
      uint32_t length= result->length();
 
5821
      uint length= result->length();
5737
5822
      char *tmp_str= sql_strmake(result->ptr(), length);
5738
5823
      new_item= new Item_string(name, tmp_str, length, result->charset());
5739
5824
    }
5742
5827
  case INT_RESULT:
5743
5828
  {
5744
5829
    int64_t result=item->val_int();
5745
 
    uint32_t length=item->max_length;
 
5830
    uint length=item->max_length;
5746
5831
    bool null_value=item->null_value;
5747
5832
    new_item= (null_value ? (Item*) new Item_null(name) :
5748
5833
               (Item*) new Item_int(name, result, length));
5761
5846
    */
5762
5847
    Item_row *item_row= (Item_row*) item;
5763
5848
    Item_row *comp_item_row= (Item_row*) comp_item;
5764
 
    uint32_t col;
 
5849
    uint col;
5765
5850
    new_item= 0;
5766
5851
    /*
5767
5852
      If item and comp_item are both Item_rows and have same number of cols
5781
5866
  case REAL_RESULT:
5782
5867
  {                                             // It must REAL_RESULT
5783
5868
    double result= item->val_real();
5784
 
    uint32_t length=item->max_length,decimals=item->decimals;
 
5869
    uint length=item->max_length,decimals=item->decimals;
5785
5870
    bool null_value=item->null_value;
5786
5871
    new_item= (null_value ? (Item*) new Item_null(name) : (Item*)
5787
5872
               new Item_float(name, result, decimals, length));
5791
5876
  {
5792
5877
    my_decimal decimal_value;
5793
5878
    my_decimal *result= item->val_decimal(&decimal_value);
5794
 
    uint32_t length= item->max_length, decimals= item->decimals;
 
5879
    uint length= item->max_length, decimals= item->decimals;
5795
5880
    bool null_value= item->null_value;
5796
5881
    new_item= (null_value ?
5797
5882
               (Item*) new Item_null(name) :
5974
6059
  return str;
5975
6060
}
5976
6061
 
5977
 
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__)))
5978
6063
{
5979
6064
  assert(fixed);
5980
6065
  return &decimal_value;
6039
6124
int Item_cache_str::save_in_field(Field *field, bool no_conversions)
6040
6125
{
6041
6126
  int res= Item_cache::save_in_field(field, no_conversions);
6042
 
 
6043
 
  return res;
 
6127
  return (is_varbinary && field->type() == MYSQL_TYPE_STRING &&
 
6128
          value->length() < field->field_length) ? 1 : res;
6044
6129
}
6045
6130
 
6046
6131
 
6047
 
bool Item_cache_row::allocate(uint32_t num)
 
6132
bool Item_cache_row::allocate(uint num)
6048
6133
{
6049
6134
  item_count= num;
6050
6135
  THD *thd= current_thd;
6058
6143
  example= item;
6059
6144
  if (!values && allocate(item->cols()))
6060
6145
    return 1;
6061
 
  for (uint32_t i= 0; i < item_count; i++)
 
6146
  for (uint i= 0; i < item_count; i++)
6062
6147
  {
6063
6148
    Item *el= item->element_index(i);
6064
6149
    Item_cache *tmp;
6074
6159
{
6075
6160
  null_value= 0;
6076
6161
  item->bring_value();
6077
 
  for (uint32_t i= 0; i < item_count; i++)
 
6162
  for (uint i= 0; i < item_count; i++)
6078
6163
  {
6079
6164
    values[i]->store(item->element_index(i));
6080
6165
    null_value|= values[i]->null_value;
6082
6167
}
6083
6168
 
6084
6169
 
6085
 
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__)))
6086
6171
{
6087
6172
  assert(0);
6088
6173
  my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
6090
6175
}
6091
6176
 
6092
6177
 
6093
 
bool Item_cache_row::check_cols(uint32_t c)
 
6178
bool Item_cache_row::check_cols(uint c)
6094
6179
{
6095
6180
  if (c != item_count)
6096
6181
  {
6103
6188
 
6104
6189
bool Item_cache_row::null_inside()
6105
6190
{
6106
 
  for (uint32_t i= 0; i < item_count; i++)
 
6191
  for (uint i= 0; i < item_count; i++)
6107
6192
  {
6108
6193
    if (values[i]->cols() > 1)
6109
6194
    {
6123
6208
 
6124
6209
void Item_cache_row::bring_value()
6125
6210
{
6126
 
  for (uint32_t i= 0; i < item_count; i++)
 
6211
  for (uint i= 0; i < item_count; i++)
6127
6212
    values[i]->bring_value();
6128
6213
  return;
6129
6214
}
6176
6261
    Field *field= ((Item_field *) item)->field;
6177
6262
    enum_field_types type= field->real_type();
6178
6263
    if (field->is_created_from_null_item)
6179
 
      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;
6180
6268
    return type;
6181
6269
  }
6182
6270
  case SUM_FUNC_ITEM:
6201
6289
      */
6202
6290
      switch (item->result_type()) {
6203
6291
      case STRING_RESULT:
6204
 
        return DRIZZLE_TYPE_VARCHAR;
 
6292
        return MYSQL_TYPE_VAR_STRING;
6205
6293
      case INT_RESULT:
6206
 
        return DRIZZLE_TYPE_LONGLONG;
 
6294
        return MYSQL_TYPE_LONGLONG;
6207
6295
      case REAL_RESULT:
6208
 
        return DRIZZLE_TYPE_DOUBLE;
 
6296
        return MYSQL_TYPE_DOUBLE;
6209
6297
      case DECIMAL_RESULT:
6210
 
        return DRIZZLE_TYPE_NEWDECIMAL;
 
6298
        return MYSQL_TYPE_NEWDECIMAL;
6211
6299
      case ROW_RESULT:
6212
6300
      default:
6213
6301
        assert(0);
6214
 
        return DRIZZLE_TYPE_VARCHAR;
 
6302
        return MYSQL_TYPE_VAR_STRING;
6215
6303
      }
6216
6304
    }
6217
6305
    break;
6234
6322
    false  OK
6235
6323
*/
6236
6324
 
6237
 
bool Item_type_holder::join_types(THD *thd __attribute__((unused)),
 
6325
bool Item_type_holder::join_types(THD *thd __attribute__((__unused__)),
6238
6326
                                  Item *item)
6239
6327
{
6240
 
  uint32_t max_length_orig= max_length;
6241
 
  uint32_t decimals_orig= decimals;
 
6328
  uint max_length_orig= max_length;
 
6329
  uint decimals_orig= decimals;
6242
6330
  fld_type= Field::field_type_merge(fld_type, get_real_type(item));
6243
6331
  {
6244
6332
    int item_decimals= item->decimals;
6245
6333
    /* fix variable decimals which always is NOT_FIXED_DEC */
6246
6334
    if (Field::result_merge_type(fld_type) == INT_RESULT)
6247
6335
      item_decimals= 0;
6248
 
    decimals= cmax((int)decimals, item_decimals);
 
6336
    decimals= max(decimals, item_decimals);
6249
6337
  }
6250
6338
  if (Field::result_merge_type(fld_type) == DECIMAL_RESULT)
6251
6339
  {
6252
 
    decimals= cmin((int)cmax(decimals, item->decimals), DECIMAL_MAX_SCALE);
6253
 
    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())
6254
6342
                       + decimals, DECIMAL_MAX_PRECISION);
6255
6343
    unsigned_flag&= item->unsigned_flag;
6256
6344
    max_length= my_decimal_precision_to_length(precision, decimals,
6262
6350
  case STRING_RESULT:
6263
6351
  {
6264
6352
    const char *old_cs, *old_derivation;
6265
 
    uint32_t old_max_chars= max_length / collation.collation->mbmaxlen;
 
6353
    uint32 old_max_chars= max_length / collation.collation->mbmaxlen;
6266
6354
    old_cs= collation.collation->name;
6267
6355
    old_derivation= collation.derivation_name();
6268
6356
    if (collation.aggregate(item->collation, MY_COLL_ALLOW_CONV))
6281
6369
     */
6282
6370
    if (collation.collation != &my_charset_bin)
6283
6371
    {
6284
 
      max_length= cmax(old_max_chars * collation.collation->mbmaxlen,
 
6372
      max_length= max(old_max_chars * collation.collation->mbmaxlen,
6285
6373
                      display_length(item) /
6286
6374
                      item->collation.collation->mbmaxlen *
6287
6375
                      collation.collation->mbmaxlen);
6296
6384
    {
6297
6385
      int delta1= max_length_orig - decimals_orig;
6298
6386
      int delta2= item->max_length - item->decimals;
6299
 
      max_length= cmax(delta1, delta2) + decimals;
6300
 
      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) 
6301
6394
      {
6302
6395
        max_length= DBL_DIG + 7;
6303
6396
        decimals= NOT_FIXED_DEC;
6304
6397
      }
6305
6398
    }
6306
6399
    else
6307
 
      max_length= DBL_DIG+7;
 
6400
      max_length= (fld_type == MYSQL_TYPE_FLOAT) ? FLT_DIG+6 : DBL_DIG+7;
6308
6401
    break;
6309
6402
  }
6310
6403
  default:
6311
 
    max_length= cmax(max_length, display_length(item));
 
6404
    max_length= max(max_length, display_length(item));
6312
6405
  };
6313
6406
  maybe_null|= item->maybe_null;
6314
6407
  get_full_info(item);
6327
6420
    length
6328
6421
*/
6329
6422
 
6330
 
uint32_t Item_type_holder::display_length(Item *item)
 
6423
uint32 Item_type_holder::display_length(Item *item)
6331
6424
{
6332
6425
  if (item->type() == Item::FIELD_ITEM)
6333
6426
    return ((Item_field *)item)->max_disp_length();
6334
6427
 
6335
6428
  switch (item->field_type())
6336
6429
  {
6337
 
  case DRIZZLE_TYPE_TIMESTAMP:
6338
 
  case DRIZZLE_TYPE_TIME:
6339
 
  case DRIZZLE_TYPE_DATETIME:
6340
 
  case DRIZZLE_TYPE_NEWDATE:
6341
 
  case DRIZZLE_TYPE_VARCHAR:
6342
 
  case DRIZZLE_TYPE_NEWDECIMAL:
6343
 
  case DRIZZLE_TYPE_ENUM:
6344
 
  case DRIZZLE_TYPE_BLOB:
6345
 
  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:
6346
6443
    return 4;
6347
 
  case DRIZZLE_TYPE_LONG:
 
6444
  case MYSQL_TYPE_SHORT:
 
6445
    return 6;
 
6446
  case MYSQL_TYPE_LONG:
6348
6447
    return MY_INT32_NUM_DECIMAL_DIGITS;
6349
 
  case DRIZZLE_TYPE_DOUBLE:
 
6448
  case MYSQL_TYPE_FLOAT:
 
6449
    return 25;
 
6450
  case MYSQL_TYPE_DOUBLE:
6350
6451
    return 53;
6351
 
  case DRIZZLE_TYPE_NULL:
 
6452
  case MYSQL_TYPE_NULL:
6352
6453
    return 0;
6353
 
  case DRIZZLE_TYPE_LONGLONG:
 
6454
  case MYSQL_TYPE_LONGLONG:
6354
6455
    return 20;
6355
6456
  default:
6356
6457
    assert(0); // we should never go there
6369
6470
    created field
6370
6471
*/
6371
6472
 
6372
 
Field *Item_type_holder::make_field_by_type(Table *table)
 
6473
Field *Item_type_holder::make_field_by_type(TABLE *table)
6373
6474
{
6374
6475
  /*
6375
6476
    The field functions defines a field to be not null if null_ptr is not 0
6376
6477
  */
6377
 
  unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
 
6478
  uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
6378
6479
  Field *field;
6379
6480
 
6380
6481
  switch (fld_type) {
6381
 
  case DRIZZLE_TYPE_ENUM:
 
6482
  case MYSQL_TYPE_ENUM:
6382
6483
    assert(enum_set_typelib);
6383
 
    field= new Field_enum((unsigned char *) 0, max_length, null_ptr, 0,
 
6484
    field= new Field_enum((uchar *) 0, max_length, null_ptr, 0,
6384
6485
                          Field::NONE, name,
6385
6486
                          get_enum_pack_length(enum_set_typelib->count),
6386
6487
                          enum_set_typelib, collation.collation);
6387
6488
    if (field)
6388
6489
      field->init(table);
6389
6490
    return field;
6390
 
  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:
6391
6501
    return make_string_field(table);
6392
6502
  default:
6393
6503
    break;
6404
6514
*/
6405
6515
void Item_type_holder::get_full_info(Item *item)
6406
6516
{
6407
 
  if (fld_type == DRIZZLE_TYPE_ENUM)
 
6517
  if (fld_type == MYSQL_TYPE_ENUM ||
 
6518
      fld_type == MYSQL_TYPE_SET)
6408
6519
  {
6409
6520
    if (item->type() == Item::SUM_FUNC_ITEM &&
6410
6521
        (((Item_sum*)item)->sum_func() == Item_sum::MAX_FUNC ||
6415
6526
      field (or MIN|MAX(enum|set field)) and number of NULL fields
6416
6527
    */
6417
6528
    assert((enum_set_typelib &&
6418
 
                 get_real_type(item) == DRIZZLE_TYPE_NULL) ||
 
6529
                 get_real_type(item) == MYSQL_TYPE_NULL) ||
6419
6530
                (!enum_set_typelib &&
6420
6531
                 item->type() == Item::FIELD_ITEM &&
6421
 
                 (get_real_type(item) == DRIZZLE_TYPE_ENUM) &&
 
6532
                 (get_real_type(item) == MYSQL_TYPE_ENUM ||
 
6533
                  get_real_type(item) == MYSQL_TYPE_SET) &&
6422
6534
                 ((Field_enum*)((Item_field *) item)->field)->typelib));
6423
6535
    if (!enum_set_typelib)
6424
6536
    {
6467
6579
    do nothing
6468
6580
*/
6469
6581
 
6470
 
void dummy_error_processor(THD *thd __attribute__((unused)),
6471
 
                           void *data __attribute__((unused)))
 
6582
void dummy_error_processor(THD *thd __attribute__((__unused__)),
 
6583
                           void *data __attribute__((__unused__)))
6472
6584
{}
6473
6585
 
6474
6586
/**