~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.cc

  • Committer: Brian Aker
  • Date: 2008-11-04 15:39:09 UTC
  • mfrom: (575.1.2 devel)
  • Revision ID: brian@tangent.org-20081104153909-c72hn65udxs1ccal
Merge of Monty's work

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
#include <drizzled/server_includes.h>
18
18
#include <drizzled/sql_select.h>
19
 
#include <drizzled/drizzled_error_messages.h>
 
19
#include <drizzled/error.h>
 
20
#include CMATH_H
 
21
 
 
22
#if defined(CMATH_NAMESPACE)
 
23
using namespace CMATH_NAMESPACE;
 
24
#endif
20
25
 
21
26
const String my_null_string("NULL", 4, default_charset_info);
22
27
 
37
42
  return &real_traits_instance;
38
43
}
39
44
 
 
45
int64_t Hybrid_type_traits::val_int(Hybrid_type *val,
 
46
                                    bool) const
 
47
{
 
48
  return (int64_t) rint(val->real);
 
49
}
40
50
 
41
51
my_decimal *
42
 
Hybrid_type_traits::val_decimal(Hybrid_type *val,
43
 
                                my_decimal *to __attribute__((unused))) const
 
52
Hybrid_type_traits::val_decimal(Hybrid_type *val, my_decimal *) const
44
53
{
45
54
  double2my_decimal(E_DEC_FATAL_ERROR, val->real, val->dec_buf);
46
55
  return val->dec_buf;
67
76
Hybrid_type_traits_decimal::fix_length_and_dec(Item *item, Item *arg) const
68
77
{
69
78
  item->decimals= arg->decimals;
70
 
  item->max_length= min(arg->max_length + DECIMAL_LONGLONG_DIGITS,
 
79
  item->max_length= cmin(arg->max_length + DECIMAL_LONGLONG_DIGITS,
71
80
                        (unsigned int)DECIMAL_MAX_STR_LENGTH);
72
81
}
73
82
 
143
152
}
144
153
 
145
154
void
146
 
Hybrid_type_traits_integer::fix_length_and_dec(Item *item,
147
 
                                               Item *arg __attribute__((unused))) const
 
155
Hybrid_type_traits_integer::fix_length_and_dec(Item *item, Item *) const
148
156
{
149
157
  item->decimals= 0;
150
158
  item->max_length= MY_INT64_NUM_DECIMAL_DIGITS;
256
264
                     res->ptr(), res->length(), res->charset(),
257
265
                     decimal_value) & E_DEC_BAD_NUM)
258
266
  {
259
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
267
    push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
260
268
                        ER_TRUNCATED_WRONG_VALUE,
261
269
                        ER(ER_TRUNCATED_WRONG_VALUE), "DECIMAL",
262
270
                        str_value.c_ptr());
382
390
  cmp_context= (Item_result)-1;
383
391
 
384
392
  /* Put item in free list so that we can free all items at end */
385
 
  THD *thd= current_thd;
386
 
  next= thd->free_list;
387
 
  thd->free_list= this;
 
393
  Session *session= current_session;
 
394
  next= session->free_list;
 
395
  session->free_list= this;
388
396
  /*
389
397
    Item constructor can be called during execution other then SQL_COM
390
 
    command => we should check thd->lex->current_select on zero (thd->lex
 
398
    command => we should check session->lex->current_select on zero (session->lex
391
399
    can be uninitialised)
392
400
  */
393
 
  if (thd->lex->current_select)
 
401
  if (session->lex->current_select)
394
402
  {
395
403
    enum_parsing_place place= 
396
 
      thd->lex->current_select->parsing_place;
 
404
      session->lex->current_select->parsing_place;
397
405
    if (place == SELECT_LIST ||
398
406
        place == IN_HAVING)
399
 
      thd->lex->current_select->select_n_having_items++;
 
407
      session->lex->current_select->select_n_having_items++;
400
408
  }
401
409
}
402
410
 
407
415
  Used for duplicating lists in processing queries with temporary
408
416
  tables.
409
417
*/
410
 
Item::Item(THD *thd, Item *item):
 
418
Item::Item(Session *session, Item *item):
411
419
  is_expensive_cache(-1),
412
420
  rsize(0),
413
421
  str_value(item->str_value),
424
432
  collation(item->collation),
425
433
  cmp_context(item->cmp_context)
426
434
{
427
 
  next= thd->free_list;                         // Put in free list
428
 
  thd->free_list= this;
 
435
  next= session->free_list;                             // Put in free list
 
436
  session->free_list= this;
429
437
}
430
438
 
431
439
 
432
 
uint Item::decimal_precision() const
 
440
uint32_t Item::decimal_precision() const
433
441
{
434
442
  Item_result restype= result_type();
435
443
 
436
444
  if ((restype == DECIMAL_RESULT) || (restype == INT_RESULT))
437
 
    return min(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
 
445
    return cmin(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
438
446
               (unsigned int)DECIMAL_MAX_PRECISION);
439
 
  return min(max_length, (uint32_t)DECIMAL_MAX_PRECISION);
 
447
  return cmin(max_length, (uint32_t)DECIMAL_MAX_PRECISION);
440
448
}
441
449
 
442
450
 
446
454
 
447
455
  if (name)
448
456
  {
449
 
    THD *thd= current_thd;
 
457
    Session *session= current_session;
450
458
    str->append(STRING_WITH_LEN(" AS "));
451
 
    append_identifier(thd, str, name, (uint) strlen(name));
 
459
    append_identifier(session, str, name, (uint) strlen(name));
452
460
  }
453
461
}
454
462
 
469
477
  @param arg   a dummy parameter, is not used here
470
478
*/
471
479
 
472
 
bool Item::cleanup_processor(uchar *arg __attribute__((unused)))
 
480
bool Item::cleanup_processor(unsigned char *)
473
481
{
474
482
  if (fixed)
475
483
    cleanup();
500
508
 
501
509
  This function is designed to ease transformation of Item trees.
502
510
  Re-execution note: every such transformation is registered for
503
 
  rollback by THD::change_item_tree() and is rolled back at the end
504
 
  of execution by THD::rollback_item_tree_changes().
 
511
  rollback by Session::change_item_tree() and is rolled back at the end
 
512
  of execution by Session::rollback_item_tree_changes().
505
513
 
506
514
  Therefore:
507
515
  - this function can not be used at prepared statement prepare
508
516
  (in particular, in fix_fields!), as only permanent
509
517
  transformation of Item trees are allowed at prepare.
510
518
  - the transformer function shall allocate new Items in execution
511
 
  memory root (thd->mem_root) and not anywhere else: allocated
 
519
  memory root (session->mem_root) and not anywhere else: allocated
512
520
  items will be gone in the end of execution.
513
521
 
514
522
  If you don't need to transform an item tree, but only traverse
519
527
  @param arg            opaque argument passed to the functor
520
528
 
521
529
  @return
522
 
    Returns pointer to the new subtree root.  THD::change_item_tree()
 
530
    Returns pointer to the new subtree root.  Session::change_item_tree()
523
531
    should be called for it if transformation took place, i.e. if a
524
532
    pointer to newly allocated item is returned.
525
533
*/
526
534
 
527
 
Item* Item::transform(Item_transformer transformer, uchar *arg)
 
535
Item* Item::transform(Item_transformer transformer, unsigned char *arg)
528
536
{
529
537
  return (this->*transformer)(arg);
530
538
}
548
556
  Constructor used by Item_field & Item_*_ref (see Item comment)
549
557
*/
550
558
 
551
 
Item_ident::Item_ident(THD *thd, Item_ident *item)
552
 
  :Item(thd, item),
 
559
Item_ident::Item_ident(Session *session, Item_ident *item)
 
560
  :Item(session, item),
553
561
   orig_db_name(item->orig_db_name),
554
562
   orig_table_name(item->orig_table_name), 
555
563
   orig_field_name(item->orig_field_name),
581
589
  return;
582
590
}
583
591
 
584
 
bool Item_ident::remove_dependence_processor(uchar * arg)
 
592
bool Item_ident::remove_dependence_processor(unsigned char * arg)
585
593
{
586
594
  if (depended_from == (st_select_lex *) arg)
587
595
    depended_from= 0;
607
615
    for the subsequent items.
608
616
*/
609
617
 
610
 
bool Item_field::collect_item_field_processor(uchar *arg)
 
618
bool Item_field::collect_item_field_processor(unsigned char *arg)
611
619
{
612
620
  List<Item_field> *item_list= (List<Item_field>*) arg;
613
621
  List_iterator<Item_field> item_list_it(*item_list);
638
646
    false otherwise
639
647
*/
640
648
 
641
 
bool Item_field::find_item_in_field_list_processor(uchar *arg)
 
649
bool Item_field::find_item_in_field_list_processor(unsigned char *arg)
642
650
{
643
651
  KEY_PART_INFO *first_non_group_part= *((KEY_PART_INFO **) arg);
644
652
  KEY_PART_INFO *last_part= *(((KEY_PART_INFO **) arg) + 1);
661
669
    column read set or to register used fields in a view
662
670
*/
663
671
 
664
 
bool Item_field::register_field_in_read_map(uchar *arg)
 
672
bool Item_field::register_field_in_read_map(unsigned char *arg)
665
673
{
666
674
  Table *table= (Table *) arg;
667
675
  if (field->table == table || !table)
668
676
    bitmap_set_bit(field->table->read_set, field->field_index);
 
677
  if (field->vcol_info && field->vcol_info->expr_item)
 
678
    return field->vcol_info->expr_item->walk(&Item::register_field_in_read_map, 
 
679
                                             1, arg);
669
680
  return 0;
670
681
}
671
682
 
672
 
 
673
 
bool Item::check_cols(uint c)
 
683
/*
 
684
  Mark field in bitmap supplied as *arg
 
685
 
 
686
*/
 
687
 
 
688
bool Item_field::register_field_in_bitmap(unsigned char *arg)
 
689
{
 
690
  MY_BITMAP *bitmap= (MY_BITMAP *) arg;
 
691
  assert(bitmap);
 
692
  bitmap_set_bit(bitmap, field->field_index);
 
693
  return false;
 
694
}
 
695
 
 
696
 
 
697
bool Item::check_cols(uint32_t c)
674
698
{
675
699
  if (c != 1)
676
700
  {
681
705
}
682
706
 
683
707
 
684
 
void Item::set_name(const char *str, uint length, const CHARSET_INFO * const cs)
 
708
void Item::set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs)
685
709
{
686
710
  if (!length)
687
711
  {
692
716
  }
693
717
  if (cs->ctype)
694
718
  {
695
 
    uint orig_len= length;
 
719
    uint32_t orig_len= length;
696
720
    /*
697
721
      This will probably need a better implementation in the future:
698
722
      a function in CHARSET_INFO structure.
705
729
    if (orig_len != length && !is_autogenerated_name)
706
730
    {
707
731
      if (length == 0)
708
 
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
732
        push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
709
733
                            ER_NAME_BECOMES_EMPTY, ER(ER_NAME_BECOMES_EMPTY),
710
734
                            str + length - orig_len);
711
735
      else
712
 
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
736
        push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
713
737
                            ER_REMOVED_SPACES, ER(ER_REMOVED_SPACES),
714
738
                            str + length - orig_len);
715
739
    }
722
746
                                   &res_length);
723
747
  }
724
748
  else
725
 
    name= sql_strmake(str, (name_length= min(length,(unsigned int)MAX_ALIAS_NAME)));
 
749
    name= sql_strmake(str, (name_length= cmin(length,(unsigned int)MAX_ALIAS_NAME)));
726
750
}
727
751
 
728
752
 
733
757
  - When trying to find an order_st BY/GROUP BY item in the SELECT part
734
758
*/
735
759
 
736
 
bool Item::eq(const Item *item, bool binary_cmp __attribute__((unused))) const
 
760
bool Item::eq(const Item *item, bool) const
737
761
{
738
762
  /*
739
763
    Note, that this is never true if item is a Item_param:
763
787
  the latter returns a non-fixed Item, so val_str() crashes afterwards.
764
788
  Override Item_num method, to return a fixed item.
765
789
*/
766
 
Item *Item_num::safe_charset_converter(const CHARSET_INFO * const tocs __attribute__((unused)))
 
790
Item *Item_num::safe_charset_converter(const CHARSET_INFO * const)
767
791
{
768
792
  Item_string *conv;
769
793
  char buf[64];
778
802
}
779
803
 
780
804
 
781
 
Item *Item_static_float_func::safe_charset_converter(const CHARSET_INFO * const tocs __attribute__((unused)))
 
805
Item *Item_static_float_func::safe_charset_converter(const CHARSET_INFO * const)
782
806
{
783
807
  Item_string *conv;
784
808
  char buf[64];
797
821
Item *Item_string::safe_charset_converter(const CHARSET_INFO * const tocs)
798
822
{
799
823
  Item_string *conv;
800
 
  uint conv_errors;
 
824
  uint32_t conv_errors;
801
825
  char *ptr;
802
826
  String tmp, cstr, *ostr= val_str(&tmp);
803
827
  cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
813
837
    */
814
838
    return NULL;
815
839
  }
816
 
  if (!(ptr= current_thd->strmake(cstr.ptr(), cstr.length())))
 
840
  if (!(ptr= current_session->strmake(cstr.ptr(), cstr.length())))
817
841
    return NULL;
818
842
  conv->str_value.set(ptr, cstr.length(), cstr.charset());
819
843
  /* Ensure that no one is going to change the result string */
826
850
{
827
851
  if (const_item())
828
852
  {
829
 
    uint cnv_errors;
 
853
    uint32_t cnv_errors;
830
854
    String *ostr= val_str(&cnvstr);
831
855
    cnvitem->str_value.copy(ostr->ptr(), ostr->length(),
832
856
                            ostr->charset(), tocs, &cnv_errors);
843
867
Item *Item_static_string_func::safe_charset_converter(const CHARSET_INFO * const tocs)
844
868
{
845
869
  Item_string *conv;
846
 
  uint conv_errors;
 
870
  uint32_t conv_errors;
847
871
  String tmp, cstr, *ostr= val_str(&tmp);
848
872
  cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
849
873
  if (conv_errors ||
885
909
  As a extra convenience the time structure is reset on error!
886
910
*/
887
911
 
888
 
bool Item::get_date(DRIZZLE_TIME *ltime,uint fuzzydate)
 
912
bool Item::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
889
913
{
890
914
  if (result_type() == STRING_RESULT)
891
915
  {
900
924
  {
901
925
    int64_t value= val_int();
902
926
    int was_cut;
903
 
    if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1LL)
 
927
    if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1L)
904
928
    {
905
929
      char buff[22], *end;
906
930
      end= int64_t10_to_str(value, buff, -10);
907
 
      make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
931
      make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
908
932
                                   buff, (int) (end-buff), DRIZZLE_TIMESTAMP_NONE,
909
 
                                   NullS);
 
933
                                   NULL);
910
934
      goto err;
911
935
    }
912
936
  }
938
962
 
939
963
const CHARSET_INFO *Item::default_charset()
940
964
{
941
 
  return current_thd->variables.collation_connection;
 
965
  return current_session->variables.collation_connection;
942
966
}
943
967
 
944
968
 
954
978
{
955
979
  int res;
956
980
  Table *table= field->table;
957
 
  THD *thd= table->in_use;
958
 
  enum_check_fields tmp= thd->count_cuted_fields;
959
 
  ulong sql_mode= thd->variables.sql_mode;
960
 
  thd->variables.sql_mode&= ~(MODE_NO_ZERO_DATE);
961
 
  thd->count_cuted_fields= CHECK_FIELD_IGNORE;
 
981
  Session *session= table->in_use;
 
982
  enum_check_fields tmp= session->count_cuted_fields;
 
983
  ulong sql_mode= session->variables.sql_mode;
 
984
  session->variables.sql_mode&= ~(MODE_NO_ZERO_DATE);
 
985
  session->count_cuted_fields= CHECK_FIELD_IGNORE;
962
986
  res= save_in_field(field, no_conversions);
963
 
  thd->count_cuted_fields= tmp;
964
 
  thd->variables.sql_mode= sql_mode;
 
987
  session->count_cuted_fields= tmp;
 
988
  session->variables.sql_mode= sql_mode;
965
989
  return res;
966
990
}
967
991
 
991
1015
/**
992
1016
  Move SUM items out from item tree and replace with reference.
993
1017
 
994
 
  @param thd                    Thread handler
 
1018
  @param session                        Thread handler
995
1019
  @param ref_pointer_array      Pointer to array of reference fields
996
1020
  @param fields         All fields in select
997
1021
  @param ref                    Pointer to item
1004
1028
    All found SUM items are added FIRST in the fields list and
1005
1029
    we replace the item with a reference.
1006
1030
 
1007
 
    thd->fatal_error() may be called if we are out of memory
 
1031
    session->fatal_error() may be called if we are out of memory
1008
1032
*/
1009
1033
 
1010
 
void Item::split_sum_func2(THD *thd, Item **ref_pointer_array,
 
1034
void Item::split_sum_func2(Session *session, Item **ref_pointer_array,
1011
1035
                           List<Item> &fields, Item **ref, 
1012
1036
                           bool skip_registered)
1013
1037
{
1021
1045
        ((Item_func *) this)->functype() == Item_func::TRIG_COND_FUNC)))
1022
1046
  {
1023
1047
    /* Will split complicated items and ignore simple ones */
1024
 
    split_sum_func(thd, ref_pointer_array, fields);
 
1048
    split_sum_func(session, ref_pointer_array, fields);
1025
1049
  }
1026
1050
  else if ((type() == SUM_FUNC_ITEM || (used_tables() & ~PARAM_TABLE_BIT)) &&
1027
1051
           type() != SUBSELECT_ITEM &&
1039
1063
      Item_ref to allow fields from view being stored in tmp table.
1040
1064
    */
1041
1065
    Item_aggregate_ref *item_ref;
1042
 
    uint el= fields.elements;
 
1066
    uint32_t el= fields.elements;
1043
1067
    Item *real_itm= real_item();
1044
1068
 
1045
1069
    ref_pointer_array[el]= real_itm;
1046
 
    if (!(item_ref= new Item_aggregate_ref(&thd->lex->current_select->context,
 
1070
    if (!(item_ref= new Item_aggregate_ref(&session->lex->current_select->context,
1047
1071
                                           ref_pointer_array + el, 0, name)))
1048
1072
      return;                                   // fatal_error is set
1049
1073
    if (type() == SUM_FUNC_ITEM)
1050
1074
      item_ref->depended_from= ((Item_sum *) this)->depended_from(); 
1051
1075
    fields.push_front(real_itm);
1052
 
    thd->change_item_tree(ref, item_ref);
 
1076
    session->change_item_tree(ref, item_ref);
1053
1077
  }
1054
1078
}
1055
1079
 
1109
1133
  @endcode
1110
1134
*/
1111
1135
 
1112
 
bool DTCollation::aggregate(DTCollation &dt, uint flags)
 
1136
bool DTCollation::aggregate(DTCollation &dt, uint32_t flags)
1113
1137
{
1114
1138
  if (!my_charset_same(collation, dt.collation))
1115
1139
  {
1229
1253
 
1230
1254
 
1231
1255
static
1232
 
void my_coll_agg_error(Item** args, uint count, const char *fname,
 
1256
void my_coll_agg_error(Item** args, uint32_t count, const char *fname,
1233
1257
                       int item_sep)
1234
1258
{
1235
1259
  if (count == 2)
1243
1267
 
1244
1268
 
1245
1269
bool agg_item_collations(DTCollation &c, const char *fname,
1246
 
                         Item **av, uint count, uint flags, int item_sep)
 
1270
                         Item **av, uint32_t count, uint32_t flags, int item_sep)
1247
1271
{
1248
 
  uint i;
 
1272
  uint32_t i;
1249
1273
  Item **arg;
1250
1274
  c.set(av[0]->collation);
1251
1275
  for (i= 1, arg= &av[item_sep]; i < count; i++, arg++)
1267
1291
 
1268
1292
 
1269
1293
bool agg_item_collations_for_comparison(DTCollation &c, const char *fname,
1270
 
                                        Item **av, uint count, uint flags)
 
1294
                                        Item **av, uint32_t count, uint32_t flags)
1271
1295
{
1272
1296
  return (agg_item_collations(c, fname, av, count,
1273
1297
                              flags | MY_COLL_DISALLOW_NONE, 1));
1295
1319
  @code
1296
1320
    collect(A,B,C) ::= collect(collect(A,B),C)
1297
1321
  @endcode
1298
 
  Since this function calls THD::change_item_tree() on the passed Item **
 
1322
  Since this function calls Session::change_item_tree() on the passed Item **
1299
1323
  pointers, it is necessary to pass the original Item **'s, not copies.
1300
1324
  Otherwise their values will not be properly restored (see BUG#20769).
1301
1325
  If the items are not consecutive (eg. args[2] and args[5]), use the
1306
1330
*/
1307
1331
 
1308
1332
bool agg_item_charsets(DTCollation &coll, const char *fname,
1309
 
                       Item **args, uint nargs, uint flags, int item_sep)
 
1333
                       Item **args, uint32_t nargs, uint32_t flags, int item_sep)
1310
1334
{
1311
1335
  Item **arg, *safe_args[2];
1312
1336
 
1328
1352
    safe_args[1]= args[item_sep];
1329
1353
  }
1330
1354
 
1331
 
  THD *thd= current_thd;
1332
 
  Query_arena *arena, backup;
 
1355
  Session *session= current_session;
1333
1356
  bool res= false;
1334
 
  uint i;
1335
 
  /*
1336
 
    In case we're in statement prepare, create conversion item
1337
 
    in its memory: it will be reused on each execute.
1338
 
  */
1339
 
  arena= NULL;
 
1357
  uint32_t i;
1340
1358
 
1341
1359
  for (i= 0, arg= args; i < nargs; i++, arg+= item_sep)
1342
1360
  {
1375
1393
      been created in prepare. In this case register the change for
1376
1394
      rollback.
1377
1395
    */
1378
 
    thd->change_item_tree(arg, conv);
 
1396
    session->change_item_tree(arg, conv);
1379
1397
    /*
1380
1398
      We do not check conv->fixed, because Item_func_conv_charset which can
1381
1399
      be return by safe_charset_converter can't be fixed at creation
1382
1400
    */
1383
 
    conv->fix_fields(thd, arg);
 
1401
    conv->fix_fields(session, arg);
1384
1402
  }
1385
 
  if (arena)
1386
 
    thd->restore_active_arena(arena, &backup);
 
1403
 
1387
1404
  return res;
1388
1405
}
1389
1406
 
1404
1421
/**********************************************/
1405
1422
 
1406
1423
Item_field::Item_field(Field *f)
1407
 
  :Item_ident(0, NullS, *f->table_name, f->field_name),
 
1424
  :Item_ident(0, NULL, *f->table_name, f->field_name),
1408
1425
   item_equal(0), no_const_subst(0),
1409
1426
   have_privileges(0), any_privileges(0)
1410
1427
{
1424
1441
  Item_field (this is important in prepared statements).
1425
1442
*/
1426
1443
 
1427
 
Item_field::Item_field(THD *thd __attribute__((unused)),
1428
 
                       Name_resolution_context *context_arg,
 
1444
Item_field::Item_field(Session *, Name_resolution_context *context_arg,
1429
1445
                       Field *f)
1430
1446
  :Item_ident(context_arg, f->table->s->db.str, *f->table_name, f->field_name),
1431
1447
   item_equal(0), no_const_subst(0),
1442
1458
   field(0), result_field(0), item_equal(0), no_const_subst(0),
1443
1459
   have_privileges(0), any_privileges(0)
1444
1460
{
1445
 
  SELECT_LEX *select= current_thd->lex->current_select;
 
1461
  SELECT_LEX *select= current_session->lex->current_select;
1446
1462
  collation.set(DERIVATION_IMPLICIT);
1447
1463
  if (select && select->parsing_place != IN_HAVING)
1448
1464
      select->select_n_where_fields++;
1452
1468
  Constructor need to process subselect with temporary tables (see Item)
1453
1469
*/
1454
1470
 
1455
 
Item_field::Item_field(THD *thd, Item_field *item)
1456
 
  :Item_ident(thd, item),
 
1471
Item_field::Item_field(Session *session, Item_field *item)
 
1472
  :Item_ident(session, item),
1457
1473
   field(item->field),
1458
1474
   result_field(item->result_field),
1459
1475
   item_equal(item->item_equal),
1504
1520
  {
1505
1521
    tmp=(char*) sql_alloc((uint) strlen(db_name)+(uint) strlen(table_name)+
1506
1522
                          (uint) strlen(field_name)+3);
1507
 
    strxmov(tmp,db_name,".",table_name,".",field_name,NullS);
 
1523
    strxmov(tmp,db_name,".",table_name,".",field_name,NULL);
1508
1524
  }
1509
1525
  else
1510
1526
  {
1512
1528
    {
1513
1529
      tmp= (char*) sql_alloc((uint) strlen(table_name) +
1514
1530
                             (uint) strlen(field_name) + 2);
1515
 
      strxmov(tmp, table_name, ".", field_name, NullS);
 
1531
      strxmov(tmp, table_name, ".", field_name, NULL);
1516
1532
    }
1517
1533
    else
1518
1534
      tmp= (char*) field_name;
1521
1537
}
1522
1538
 
1523
1539
void Item_ident::print(String *str,
1524
 
                       enum_query_type query_type __attribute__((unused)))
 
1540
                       enum_query_type)
1525
1541
{
1526
 
  THD *thd= current_thd;
 
1542
  Session *session= current_session;
1527
1543
  char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
1528
1544
  const char *d_name= db_name, *t_name= table_name;
1529
1545
  if (lower_case_table_names== 1 ||
1531
1547
  {
1532
1548
    if (table_name && table_name[0])
1533
1549
    {
1534
 
      stpcpy(t_name_buff, table_name);
 
1550
      my_stpcpy(t_name_buff, table_name);
1535
1551
      my_casedn_str(files_charset_info, t_name_buff);
1536
1552
      t_name= t_name_buff;
1537
1553
    }
1538
1554
    if (db_name && db_name[0])
1539
1555
    {
1540
 
      stpcpy(d_name_buff, db_name);
 
1556
      my_stpcpy(d_name_buff, db_name);
1541
1557
      my_casedn_str(files_charset_info, d_name_buff);
1542
1558
      d_name= d_name_buff;
1543
1559
    }
1547
1563
  {
1548
1564
    const char *nm= (field_name && field_name[0]) ?
1549
1565
                      field_name : name ? name : "tmp_field";
1550
 
    append_identifier(thd, str, nm, (uint) strlen(nm));
 
1566
    append_identifier(session, str, nm, (uint) strlen(nm));
1551
1567
    return;
1552
1568
  }
1553
1569
  if (db_name && db_name[0] && !alias_name_used)
1554
1570
  {
1555
1571
    {
1556
 
      append_identifier(thd, str, d_name, (uint)strlen(d_name));
 
1572
      append_identifier(session, str, d_name, (uint)strlen(d_name));
1557
1573
      str->append('.');
1558
1574
    }
1559
 
    append_identifier(thd, str, t_name, (uint)strlen(t_name));
 
1575
    append_identifier(session, str, t_name, (uint)strlen(t_name));
1560
1576
    str->append('.');
1561
 
    append_identifier(thd, str, field_name, (uint)strlen(field_name));
 
1577
    append_identifier(session, str, field_name, (uint)strlen(field_name));
1562
1578
  }
1563
1579
  else
1564
1580
  {
1565
1581
    if (table_name[0])
1566
1582
    {
1567
 
      append_identifier(thd, str, t_name, (uint) strlen(t_name));
 
1583
      append_identifier(session, str, t_name, (uint) strlen(t_name));
1568
1584
      str->append('.');
1569
 
      append_identifier(thd, str, field_name, (uint) strlen(field_name));
 
1585
      append_identifier(session, str, field_name, (uint) strlen(field_name));
1570
1586
    }
1571
1587
    else
1572
 
      append_identifier(thd, str, field_name, (uint) strlen(field_name));
 
1588
      append_identifier(session, str, field_name, (uint) strlen(field_name));
1573
1589
  }
1574
1590
}
1575
1591
 
1618
1634
  return result_field->val_str(str,&str_value);
1619
1635
}
1620
1636
 
1621
 
bool Item_field::get_date(DRIZZLE_TIME *ltime,uint fuzzydate)
 
1637
bool Item_field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
1622
1638
{
1623
1639
  if ((null_value=field->is_null()) || field->get_date(ltime,fuzzydate))
1624
1640
  {
1628
1644
  return 0;
1629
1645
}
1630
1646
 
1631
 
bool Item_field::get_date_result(DRIZZLE_TIME *ltime,uint fuzzydate)
 
1647
bool Item_field::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
1632
1648
{
1633
1649
  if ((null_value=result_field->is_null()) ||
1634
1650
      result_field->get_date(ltime,fuzzydate))
1698
1714
}
1699
1715
 
1700
1716
 
1701
 
bool Item_field::eq(const Item *item,
1702
 
                    bool binary_cmp __attribute__((unused))) const
 
1717
bool Item_field::eq(const Item *item, bool) const
1703
1718
{
1704
1719
  Item *real_item= ((Item *) item)->real_item();
1705
1720
  if (real_item->type() != FIELD_ITEM)
1737
1752
}
1738
1753
 
1739
1754
 
1740
 
void Item_field::fix_after_pullout(st_select_lex *new_parent,
1741
 
                                   Item **ref __attribute__((unused)))
 
1755
void Item_field::fix_after_pullout(st_select_lex *new_parent, Item **)
1742
1756
{
1743
1757
  if (new_parent == depended_from)
1744
1758
    depended_from= NULL;
1751
1765
}
1752
1766
 
1753
1767
 
1754
 
Item *Item_field::get_tmp_table_item(THD *thd)
 
1768
Item *Item_field::get_tmp_table_item(Session *session)
1755
1769
{
1756
 
  Item_field *new_item= new Item_field(thd, this);
 
1770
  Item_field *new_item= new Item_field(session, this);
1757
1771
  if (new_item)
1758
1772
    new_item->field= new_item->result_field;
1759
1773
  return new_item;
1760
1774
}
1761
1775
 
1762
 
int64_t Item_field::val_int_endpoint(bool left_endp __attribute__((unused)),
1763
 
                                      bool *incl_endp __attribute__((unused)))
 
1776
int64_t Item_field::val_int_endpoint(bool, bool *)
1764
1777
{
1765
1778
  int64_t res= val_int();
1766
1779
  return null_value? INT64_MIN : res;
1772
1785
  This is always 'signed'. Unsigned values are created with Item_uint()
1773
1786
*/
1774
1787
 
1775
 
Item_int::Item_int(const char *str_arg, uint length)
 
1788
Item_int::Item_int(const char *str_arg, uint32_t length)
1776
1789
{
1777
1790
  char *end_ptr= (char*) str_arg + length;
1778
1791
  int error;
1797
1810
  return str;
1798
1811
}
1799
1812
 
1800
 
void Item_int::print(String *str,
1801
 
                     enum_query_type query_type __attribute__((unused)))
 
1813
void Item_int::print(String *str, enum_query_type)
1802
1814
{
1803
1815
  // my_charset_bin is good enough for numbers
1804
1816
  str_value.set(value, &my_charset_bin);
1806
1818
}
1807
1819
 
1808
1820
 
1809
 
Item_uint::Item_uint(const char *str_arg, uint length):
 
1821
Item_uint::Item_uint(const char *str_arg, uint32_t length):
1810
1822
  Item_int(str_arg, length)
1811
1823
{
1812
1824
  unsigned_flag= 1;
1813
1825
}
1814
1826
 
1815
1827
 
1816
 
Item_uint::Item_uint(const char *str_arg, int64_t i, uint length):
 
1828
Item_uint::Item_uint(const char *str_arg, int64_t i, uint32_t length):
1817
1829
  Item_int(str_arg, i, length)
1818
1830
{
1819
1831
  unsigned_flag= 1;
1829
1841
}
1830
1842
 
1831
1843
 
1832
 
void Item_uint::print(String *str,
1833
 
                      enum_query_type query_type __attribute__((unused)))
 
1844
void Item_uint::print(String *str, enum_query_type)
1834
1845
{
1835
1846
  // latin1 is good enough for numbers
1836
1847
  str_value.set((uint64_t) value, default_charset());
1838
1849
}
1839
1850
 
1840
1851
 
1841
 
Item_decimal::Item_decimal(const char *str_arg, uint length,
 
1852
Item_decimal::Item_decimal(const char *str_arg, uint32_t length,
1842
1853
                           const CHARSET_INFO * const charset)
1843
1854
{
1844
1855
  str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
1859
1870
}
1860
1871
 
1861
1872
 
1862
 
Item_decimal::Item_decimal(double val,
1863
 
                           int precision __attribute__((unused)),
1864
 
                           int scale __attribute__((unused)))
 
1873
Item_decimal::Item_decimal(double val, int, int)
1865
1874
{
1866
1875
  double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
1867
1876
  decimals= (uint8_t) decimal_value.frac;
1872
1881
 
1873
1882
 
1874
1883
Item_decimal::Item_decimal(const char *str, const my_decimal *val_arg,
1875
 
                           uint decimal_par, uint length)
 
1884
                           uint32_t decimal_par, uint32_t length)
1876
1885
{
1877
1886
  my_decimal2decimal(val_arg, &decimal_value);
1878
1887
  name= (char*) str;
1892
1901
}
1893
1902
 
1894
1903
 
1895
 
Item_decimal::Item_decimal(const uchar *bin, int precision, int scale)
 
1904
Item_decimal::Item_decimal(const unsigned char *bin, int precision, int scale)
1896
1905
{
1897
1906
  binary2my_decimal(E_DEC_FATAL_ERROR, bin,
1898
1907
                    &decimal_value, precision, scale);
1924
1933
  return result;
1925
1934
}
1926
1935
 
1927
 
void Item_decimal::print(String *str,
1928
 
                         enum_query_type query_type __attribute__((unused)))
 
1936
void Item_decimal::print(String *str, enum_query_type)
1929
1937
{
1930
1938
  my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, &str_value);
1931
1939
  str->append(str_value);
1932
1940
}
1933
1941
 
1934
1942
 
1935
 
bool Item_decimal::eq(const Item *item,
1936
 
                      bool binary_cmp __attribute__((unused))) const
 
1943
bool Item_decimal::eq(const Item *item, bool) const
1937
1944
{
1938
1945
  if (type() == item->type() && item->basic_const_item())
1939
1946
  {
1970
1977
}
1971
1978
 
1972
1979
 
 
1980
int64_t Item_float::val_int()
 
1981
{
 
1982
  assert(fixed == 1);
 
1983
  if (value <= (double) INT64_MIN)
 
1984
  {
 
1985
     return INT64_MIN;
 
1986
  }
 
1987
  else if (value >= (double) (uint64_t) INT64_MAX)
 
1988
  {
 
1989
    return INT64_MAX;
 
1990
  }
 
1991
  return (int64_t) rint(value);
 
1992
}
 
1993
 
1973
1994
my_decimal *Item_float::val_decimal(my_decimal *decimal_value)
1974
1995
{
1975
1996
  // following assert is redundant, because fixed=1 assigned in constructor
1996
2017
  }
1997
2018
  else
1998
2019
  {
1999
 
    THD *thd= current_thd;
 
2020
    Session *session= current_session;
2000
2021
    LEX_STRING utf8_lex_str;
2001
2022
 
2002
 
    thd->convert_string(&utf8_lex_str,
 
2023
    session->convert_string(&utf8_lex_str,
2003
2024
                        system_charset_info,
2004
2025
                        str_value.c_ptr_safe(),
2005
2026
                        str_value.length(),
2033
2054
      We can use str_value.ptr() here as Item_string is gurantee to put an
2034
2055
      end \0 here.
2035
2056
    */
2036
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2057
    push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2037
2058
                        ER_TRUNCATED_WRONG_VALUE,
2038
2059
                        ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE",
2039
2060
                        str_value.ptr());
2063
2084
  if (err > 0 ||
2064
2085
      (end != org_end && !check_if_only_end_space(cs, end, org_end)))
2065
2086
  {
2066
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2087
    push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2067
2088
                        ER_TRUNCATED_WRONG_VALUE,
2068
2089
                        ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
2069
2090
                        str_value.ptr());
2078
2099
}
2079
2100
 
2080
2101
 
2081
 
bool Item_null::eq(const Item *item,
2082
 
                   bool binary_cmp __attribute__((unused))) const
 
2102
bool Item_null::eq(const Item *item, bool) const
2083
2103
{ return item->type() == type(); }
2084
2104
 
2085
2105
 
2098
2118
  return 0;
2099
2119
}
2100
2120
/* ARGSUSED */
2101
 
String *Item_null::val_str(String *str __attribute__((unused)))
 
2121
String *Item_null::val_str(String *)
2102
2122
{
2103
2123
  // following assert is redundant, because fixed=1 assigned in constructor
2104
2124
  assert(fixed == 1);
2106
2126
  return 0;
2107
2127
}
2108
2128
 
2109
 
my_decimal *Item_null::val_decimal(my_decimal *decimal_value __attribute__((unused)))
 
2129
my_decimal *Item_null::val_decimal(my_decimal *)
2110
2130
{
2111
2131
  return 0;
2112
2132
}
2126
2146
*/
2127
2147
 
2128
2148
static void
2129
 
default_set_param_func(Item_param *param,
2130
 
                       uchar **pos __attribute__((unused)),
2131
 
                       ulong len __attribute__((unused)))
 
2149
default_set_param_func(Item_param *param, unsigned char **, ulong)
2132
2150
{
2133
2151
  param->set_null();
2134
2152
}
2135
2153
 
2136
2154
 
2137
 
Item_param::Item_param(uint pos_in_query_arg) :
 
2155
Item_param::Item_param(uint32_t pos_in_query_arg) :
2138
2156
  state(NO_VALUE),
2139
2157
  item_result_type(STRING_RESULT),
2140
2158
  /* Don't pretend to be a literal unless value for this item is set. */
2233
2251
    the fact that even wrong value sent over binary protocol fits into
2234
2252
    MAX_DATE_STRING_REP_LENGTH buffer.
2235
2253
*/
2236
 
void Item_param::set_time(DRIZZLE_TIME *tm, timestamp_type time_type,
 
2254
void Item_param::set_time(DRIZZLE_TIME *tm,
 
2255
                          enum enum_drizzle_timestamp_type time_type,
2237
2256
                          uint32_t max_length_arg)
2238
2257
2239
2258
  value.time= *tm;
2245
2264
      value.time.minute > 59 || value.time.second > 59)
2246
2265
  {
2247
2266
    char buff[MAX_DATE_STRING_REP_LENGTH];
2248
 
    uint length= my_TIME_to_str(&value.time, buff);
2249
 
    make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2267
    uint32_t length= my_TIME_to_str(&value.time, buff);
 
2268
    make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2250
2269
                                 buff, length, time_type, 0);
2251
2270
    set_zero_time(&value.time, DRIZZLE_TIMESTAMP_ERROR);
2252
2271
  }
2265
2284
    Assign string with no conversion: data is converted only after it's
2266
2285
    been written to the binary log.
2267
2286
  */
2268
 
  uint dummy_errors;
 
2287
  uint32_t dummy_errors;
2269
2288
  if (str_value.copy(str, length, &my_charset_bin, &my_charset_bin,
2270
2289
                     &dummy_errors))
2271
2290
    return(true);
2301
2320
/**
2302
2321
  Set parameter value from user variable value.
2303
2322
 
2304
 
  @param thd   Current thread
 
2323
  @param session   Current thread
2305
2324
  @param entry User variable structure (NULL means use NULL value)
2306
2325
 
2307
2326
  @retval
2310
2329
    1 Out of memory
2311
2330
*/
2312
2331
 
2313
 
bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry)
 
2332
bool Item_param::set_from_user_var(Session *session, const user_var_entry *entry)
2314
2333
{
2315
2334
  if (entry && entry->value)
2316
2335
  {
2335
2354
    case STRING_RESULT:
2336
2355
    {
2337
2356
      const CHARSET_INFO * const fromcs= entry->collation.collation;
2338
 
      const CHARSET_INFO * const tocs= thd->variables.collation_connection;
 
2357
      const CHARSET_INFO * const tocs= session->variables.collation_connection;
2339
2358
      uint32_t dummy_offset;
2340
2359
 
2341
2360
      value.cs_info.character_set_of_placeholder= 
2461
2480
}
2462
2481
 
2463
2482
 
2464
 
bool Item_param::get_date(DRIZZLE_TIME *res, uint fuzzydate)
 
2483
bool Item_param::get_date(DRIZZLE_TIME *res, uint32_t fuzzydate)
2465
2484
{
2466
2485
  if (state == TIME_VALUE)
2467
2486
  {
2668
2687
  connection.
2669
2688
*/
2670
2689
 
2671
 
bool Item_param::convert_str_value(THD *thd)
 
2690
bool Item_param::convert_str_value(Session *session)
2672
2691
{
2673
2692
  bool rc= false;
2674
2693
  if (state == STRING_VALUE || state == LONG_DATA_VALUE)
2682
2701
    if (value.cs_info.final_character_set_of_str_value !=
2683
2702
        value.cs_info.character_set_of_placeholder)
2684
2703
    {
2685
 
      rc= thd->convert_string(&str_value,
 
2704
      rc= session->convert_string(&str_value,
2686
2705
                              value.cs_info.character_set_of_placeholder,
2687
2706
                              value.cs_info.final_character_set_of_str_value);
2688
2707
    }
2773
2792
 
2774
2793
/* End of Item_param related */
2775
2794
 
2776
 
void Item_param::print(String *str,
2777
 
                       enum_query_type query_type __attribute__((unused)))
 
2795
void Item_param::print(String *str, enum_query_type)
2778
2796
{
2779
2797
  if (state == NO_VALUE)
2780
2798
  {
2804
2822
}
2805
2823
 
2806
2824
/* ARGSUSED */
2807
 
String *Item_copy_string::val_str(String *str __attribute__((unused)))
 
2825
String *Item_copy_string::val_str(String *)
2808
2826
{
2809
2827
  // Item_copy_string is used without fix_fields call
2810
2828
  if (null_value)
2828
2846
*/
2829
2847
 
2830
2848
/* ARGSUSED */
2831
 
bool Item::fix_fields(THD *thd __attribute__((unused)),
2832
 
                      Item **ref __attribute__((unused)))
 
2849
bool Item::fix_fields(Session *, Item **)
2833
2850
{
2834
2851
 
2835
2852
  // We do not check fields which are fixed during construction
2883
2900
}
2884
2901
 
2885
2902
 
2886
 
bool Item_ref_null_helper::get_date(DRIZZLE_TIME *ltime, uint fuzzydate)
 
2903
bool Item_ref_null_helper::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate)
2887
2904
{  
2888
2905
  return (owner->was_null|= null_value= (*ref)->get_date(ltime, fuzzydate));
2889
2906
}
2893
2910
  Mark item and SELECT_LEXs as dependent if item was resolved in
2894
2911
  outer SELECT.
2895
2912
 
2896
 
  @param thd             thread handler
 
2913
  @param session             thread handler
2897
2914
  @param last            select from which current item depend
2898
2915
  @param current         current select
2899
2916
  @param resolved_item   item which was resolved in outer SELECT(for warning)
2901
2918
                         substitution)
2902
2919
*/
2903
2920
 
2904
 
static void mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current,
 
2921
static void mark_as_dependent(Session *session, SELECT_LEX *last, SELECT_LEX *current,
2905
2922
                              Item_ident *resolved_item,
2906
2923
                              Item_ident *mark_item)
2907
2924
{
2913
2930
  if (mark_item)
2914
2931
    mark_item->depended_from= last;
2915
2932
  current->mark_as_dependent(last);
2916
 
  if (thd->lex->describe & DESCRIBE_EXTENDED)
 
2933
  if (session->lex->describe & DESCRIBE_EXTENDED)
2917
2934
  {
2918
2935
    char warn_buff[DRIZZLE_ERRMSG_SIZE];
2919
2936
    sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED),
2921
2938
            table_name, (table_name [0] ? "." : ""),
2922
2939
            resolved_item->field_name,
2923
2940
            current->select_number, last->select_number);
2924
 
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
 
2941
    push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2925
2942
                 ER_WARN_FIELD_RESOLVED, warn_buff);
2926
2943
  }
2927
2944
}
2931
2948
  Mark range of selects and resolved identifier (field/reference)
2932
2949
  item as dependent.
2933
2950
 
2934
 
  @param thd             thread handler
 
2951
  @param session             thread handler
2935
2952
  @param last_select     select where resolved_item was resolved
2936
2953
  @param current_sel     current select (select where resolved_item was placed)
2937
2954
  @param found_field     field which was found during resolving
2947
2964
    resolved identifier.
2948
2965
*/
2949
2966
 
2950
 
void mark_select_range_as_dependent(THD *thd,
 
2967
void mark_select_range_as_dependent(Session *session,
2951
2968
                                    SELECT_LEX *last_select,
2952
2969
                                    SELECT_LEX *current_sel,
2953
2970
                                    Field *found_field, Item *found_item,
2985
3002
      prev_subselect_item->used_tables_cache|=
2986
3003
        found_field->table->map;
2987
3004
    prev_subselect_item->const_item_cache= 0;
2988
 
    mark_as_dependent(thd, last_select, current_sel, resolved_item,
 
3005
    mark_as_dependent(session, last_select, current_sel, resolved_item,
2989
3006
                      dependent);
2990
3007
  }
2991
3008
}
3084
3101
          is ambiguous.
3085
3102
        */
3086
3103
        my_error(ER_NON_UNIQ_ERROR, MYF(0),
3087
 
                 find_item->full_name(), current_thd->where);
 
3104
                 find_item->full_name(), current_session->where);
3088
3105
        return NULL;
3089
3106
      }
3090
3107
    }
3110
3127
  derived SELECT column. This extension is allowed only if the
3111
3128
  MODE_ONLY_FULL_GROUP_BY sql mode isn't enabled.
3112
3129
 
3113
 
  @param thd     current thread
 
3130
  @param session     current thread
3114
3131
  @param ref     column reference being resolved
3115
3132
  @param select  the select that ref is resolved against
3116
3133
 
3134
3151
*/
3135
3152
 
3136
3153
static Item**
3137
 
resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select)
 
3154
resolve_ref_in_select_and_group(Session *session, Item_ident *ref, SELECT_LEX *select)
3138
3155
{
3139
3156
  Item **group_by_ref= NULL;
3140
3157
  Item **select_ref= NULL;
3141
3158
  order_st *group_list= (order_st*) select->group_list.first;
3142
3159
  bool ambiguous_fields= false;
3143
 
  uint counter;
 
3160
  uint32_t counter;
3144
3161
  enum_resolution_type resolution;
3145
3162
 
3146
3163
  /*
3164
3181
        !((*group_by_ref)->eq(*select_ref, 0)))
3165
3182
    {
3166
3183
      ambiguous_fields= true;
3167
 
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
 
3184
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
3168
3185
                          ER(ER_NON_UNIQ_ERROR), ref->full_name(),
3169
 
                          current_thd->where);
 
3186
                          current_session->where);
3170
3187
 
3171
3188
    }
3172
3189
  }
3207
3224
  current select as dependent. The found reference of field should be
3208
3225
  provided in 'from_field'.
3209
3226
 
3210
 
  @param[in] thd             current thread
 
3227
  @param[in] session             current thread
3211
3228
  @param[in,out] from_field  found field reference or (Field*)not_found_field
3212
3229
  @param[in,out] reference   view column if this item was resolved to a
3213
3230
    view column
3235
3252
*/
3236
3253
 
3237
3254
int
3238
 
Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
 
3255
Item_field::fix_outer_field(Session *session, Field **from_field, Item **reference)
3239
3256
{
3240
3257
  enum_parsing_place place= NO_MATTER;
3241
3258
  bool field_found= (*from_field != not_found_field);
3252
3269
  */
3253
3270
  Name_resolution_context *last_checked_context= context;
3254
3271
  Item **ref= (Item **) not_found_item;
3255
 
  SELECT_LEX *current_sel= (SELECT_LEX *) thd->lex->current_select;
 
3272
  SELECT_LEX *current_sel= (SELECT_LEX *) session->lex->current_select;
3256
3273
  Name_resolution_context *outer_context= 0;
3257
3274
  SELECT_LEX *select= 0;
3258
3275
  /* Currently derived tables cannot be correlated */
3282
3299
      the found view field into '*reference', in other words, it
3283
3300
      substitutes this Item_field with the found expression.
3284
3301
    */
3285
 
    if (field_found || (*from_field= find_field_in_tables(thd, this,
 
3302
    if (field_found || (*from_field= find_field_in_tables(session, this,
3286
3303
                                          outer_context->
3287
3304
                                            first_name_resolution_table,
3288
3305
                                          outer_context->
3316
3333
            ;
3317
3334
            if (!(rf= new Item_outer_ref(context, this)))
3318
3335
              return -1;
3319
 
            thd->change_item_tree(reference, rf);
 
3336
            session->change_item_tree(reference, rf);
3320
3337
            select->inner_refs_list.push_back(rf);
3321
 
            rf->in_sum_func= thd->lex->in_sum_func;
 
3338
            rf->in_sum_func= session->lex->in_sum_func;
3322
3339
          }
3323
3340
          /*
3324
3341
            A reference is resolved to a nest level that's outer or the same as
3325
3342
            the nest level of the enclosing set function : adjust the value of
3326
3343
            max_arg_level for the function if it's needed.
3327
3344
          */
3328
 
          if (thd->lex->in_sum_func &&
3329
 
              thd->lex->in_sum_func->nest_level >= select->nest_level)
 
3345
          if (session->lex->in_sum_func &&
 
3346
              session->lex->in_sum_func->nest_level >= select->nest_level)
3330
3347
          {
3331
3348
            Item::Type ref_type= (*reference)->type();
3332
 
            set_if_bigger(thd->lex->in_sum_func->max_arg_level,
 
3349
            set_if_bigger(session->lex->in_sum_func->max_arg_level,
3333
3350
                          select->nest_level);
3334
3351
            set_field(*from_field);
3335
3352
            fixed= 1;
3336
 
            mark_as_dependent(thd, last_checked_context->select_lex,
 
3353
            mark_as_dependent(session, last_checked_context->select_lex,
3337
3354
                              context->select_lex, this,
3338
3355
                              ((ref_type == REF_ITEM ||
3339
3356
                                ref_type == FIELD_ITEM) ?
3348
3365
            (*reference)->used_tables();
3349
3366
          prev_subselect_item->const_item_cache&=
3350
3367
            (*reference)->const_item();
3351
 
          mark_as_dependent(thd, last_checked_context->select_lex,
 
3368
          mark_as_dependent(session, last_checked_context->select_lex,
3352
3369
                            context->select_lex, this,
3353
3370
                            ((ref_type == REF_ITEM || ref_type == FIELD_ITEM) ?
3354
3371
                             (Item_ident*) (*reference) :
3368
3385
    /* Search in SELECT and GROUP lists of the outer select. */
3369
3386
    if (place != IN_WHERE && place != IN_ON)
3370
3387
    {
3371
 
      if (!(ref= resolve_ref_in_select_and_group(thd, this, select)))
 
3388
      if (!(ref= resolve_ref_in_select_and_group(session, this, select)))
3372
3389
        return -1; /* Some error occurred (e.g. ambiguous names). */
3373
3390
      if (ref != not_found_item)
3374
3391
      {
3396
3413
    if (upward_lookup)
3397
3414
    {
3398
3415
      // We can't say exactly what absent table or field
3399
 
      my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), thd->where);
 
3416
      my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), session->where);
3400
3417
    }
3401
3418
    else
3402
3419
    {
3403
3420
      /* Call find_field_in_tables only to report the error */
3404
 
      find_field_in_tables(thd, this,
 
3421
      find_field_in_tables(session, this,
3405
3422
                           context->first_name_resolution_table,
3406
3423
                           context->last_name_resolution_table,
3407
3424
                           reference, REPORT_ALL_ERRORS,
3440
3457
    if (place != IN_HAVING && select->group_list.elements)
3441
3458
    {
3442
3459
      outer_context->select_lex->inner_refs_list.push_back((Item_outer_ref*)rf);
3443
 
      ((Item_outer_ref*)rf)->in_sum_func= thd->lex->in_sum_func;
 
3460
      ((Item_outer_ref*)rf)->in_sum_func= session->lex->in_sum_func;
3444
3461
    }
3445
 
    thd->change_item_tree(reference, rf);
 
3462
    session->change_item_tree(reference, rf);
3446
3463
    /*
3447
3464
      rf is Item_ref => never substitute other items (in this case)
3448
3465
      during fix_fields() => we can use rf after fix_fields()
3449
3466
    */
3450
3467
    assert(!rf->fixed);                // Assured by Item_ref()
3451
 
    if (rf->fix_fields(thd, reference) || rf->check_cols(1))
 
3468
    if (rf->fix_fields(session, reference) || rf->check_cols(1))
3452
3469
      return -1;
3453
3470
 
3454
 
    mark_as_dependent(thd, last_checked_context->select_lex,
 
3471
    mark_as_dependent(session, last_checked_context->select_lex,
3455
3472
                      context->select_lex, this,
3456
3473
                      rf);
3457
3474
    return 0;
3458
3475
  }
3459
3476
  else
3460
3477
  {
3461
 
    mark_as_dependent(thd, last_checked_context->select_lex,
 
3478
    mark_as_dependent(session, last_checked_context->select_lex,
3462
3479
                      context->select_lex,
3463
3480
                      this, (Item_ident*)*reference);
3464
3481
    if (last_checked_context->select_lex->having_fix_field)
3469
3486
                       (char*) cached_table->alias, (char*) field_name);
3470
3487
      if (!rf)
3471
3488
        return -1;
3472
 
      thd->change_item_tree(reference, rf);
 
3489
      session->change_item_tree(reference, rf);
3473
3490
      /*
3474
3491
        rf is Item_ref => never substitute other items (in this case)
3475
3492
        during fix_fields() => we can use rf after fix_fields()
3476
3493
      */
3477
3494
      assert(!rf->fixed);                // Assured by Item_ref()
3478
 
      if (rf->fix_fields(thd, reference) || rf->check_cols(1))
 
3495
      if (rf->fix_fields(session, reference) || rf->check_cols(1))
3479
3496
        return -1;
3480
3497
      return 0;
3481
3498
    }
3519
3536
    Notice that compared to Item_ref::fix_fields, here we first search the FROM
3520
3537
    clause, and then we search the SELECT and GROUP BY clauses.
3521
3538
 
3522
 
  @param[in]     thd        current thread
 
3539
  @param[in]     session        current thread
3523
3540
  @param[in,out] reference  view column if this item was resolved to a
3524
3541
    view column
3525
3542
 
3529
3546
    false on success
3530
3547
*/
3531
3548
 
3532
 
bool Item_field::fix_fields(THD *thd, Item **reference)
 
3549
bool Item_field::fix_fields(Session *session, Item **reference)
3533
3550
{
3534
3551
  assert(fixed == 0);
3535
3552
  Field *from_field= (Field *)not_found_field;
3542
3559
      expression to 'reference', i.e. it substitute that expression instead
3543
3560
      of this Item_field
3544
3561
    */
3545
 
    if ((from_field= find_field_in_tables(thd, this,
 
3562
    if ((from_field= find_field_in_tables(session, this,
3546
3563
                                          context->first_name_resolution_table,
3547
3564
                                          context->last_name_resolution_table,
3548
3565
                                          reference,
3549
 
                                          thd->lex->use_only_table_context ?
 
3566
                                          session->lex->use_only_table_context ?
3550
3567
                                            REPORT_ALL_ERRORS : 
3551
3568
                                            IGNORE_EXCEPT_NON_UNIQUE,
3552
3569
                                          !any_privileges,
3555
3572
    {
3556
3573
      int ret;
3557
3574
      /* Look up in current select's item_list to find aliased fields */
3558
 
      if (thd->lex->current_select->is_item_list_lookup)
 
3575
      if (session->lex->current_select->is_item_list_lookup)
3559
3576
      {
3560
 
        uint counter;
 
3577
        uint32_t counter;
3561
3578
        enum_resolution_type resolution;
3562
 
        Item** res= find_item_in_list(this, thd->lex->current_select->item_list,
 
3579
        Item** res= find_item_in_list(this, session->lex->current_select->item_list,
3563
3580
                                      &counter, REPORT_EXCEPT_NOT_FOUND,
3564
3581
                                      &resolution);
3565
3582
        if (!res)
3583
3600
            {
3584
3601
              /* The column to which we link isn't valid. */
3585
3602
              my_error(ER_BAD_FIELD_ERROR, MYF(0), (*res)->name, 
3586
 
                       current_thd->where);
 
3603
                       current_session->where);
3587
3604
              return(1);
3588
3605
            }
3589
3606
 
3600
3617
            Item_ref *rf= new Item_ref(context, db_name,table_name,field_name);
3601
3618
            if (!rf)
3602
3619
              return 1;
3603
 
            thd->change_item_tree(reference, rf);
 
3620
            session->change_item_tree(reference, rf);
3604
3621
            /*
3605
3622
              Because Item_ref never substitutes itself with other items 
3606
3623
              in Item_ref::fix_fields(), we can safely use the original 
3607
3624
              pointer to it even after fix_fields()
3608
3625
             */
3609
 
            return rf->fix_fields(thd, reference) ||  rf->check_cols(1);
 
3626
            return rf->fix_fields(session, reference) ||  rf->check_cols(1);
3610
3627
          }
3611
3628
        }
3612
3629
      }
3613
 
      if ((ret= fix_outer_field(thd, &from_field, reference)) < 0)
 
3630
      if ((ret= fix_outer_field(session, &from_field, reference)) < 0)
3614
3631
        goto error;
3615
3632
      outer_fixed= true;
3616
3633
      if (!ret)
3624
3641
        cached_table->select_lex != context->select_lex)
3625
3642
    {
3626
3643
      int ret;
3627
 
      if ((ret= fix_outer_field(thd, &from_field, reference)) < 0)
 
3644
      if ((ret= fix_outer_field(session, &from_field, reference)) < 0)
3628
3645
        goto error;
3629
3646
      outer_fixed= 1;
3630
3647
      if (!ret)
3647
3664
      return false;
3648
3665
 
3649
3666
    set_field(from_field);
3650
 
    if (thd->lex->in_sum_func &&
3651
 
        thd->lex->in_sum_func->nest_level == 
3652
 
        thd->lex->current_select->nest_level)
3653
 
      set_if_bigger(thd->lex->in_sum_func->max_arg_level,
3654
 
                    thd->lex->current_select->nest_level);
 
3667
    if (session->lex->in_sum_func &&
 
3668
        session->lex->in_sum_func->nest_level == 
 
3669
        session->lex->current_select->nest_level)
 
3670
      set_if_bigger(session->lex->in_sum_func->max_arg_level,
 
3671
                    session->lex->current_select->nest_level);
3655
3672
  }
3656
 
  else if (thd->mark_used_columns != MARK_COLUMNS_NONE)
 
3673
  else if (session->mark_used_columns != MARK_COLUMNS_NONE)
3657
3674
  {
3658
3675
    Table *table= field->table;
3659
3676
    MY_BITMAP *current_bitmap, *other_bitmap;
3660
 
    if (thd->mark_used_columns == MARK_COLUMNS_READ)
 
3677
    if (session->mark_used_columns == MARK_COLUMNS_READ)
3661
3678
    {
3662
3679
      current_bitmap= table->read_set;
3663
3680
      other_bitmap=   table->write_set;
3684
3701
  return false;
3685
3702
 
3686
3703
error:
3687
 
  context->process_error(thd);
 
3704
  context->process_error(session);
3688
3705
  return true;
3689
3706
}
3690
3707
 
3777
3794
    false  otherwise
3778
3795
*/
3779
3796
 
3780
 
bool Item_field::subst_argument_checker(uchar **arg)
 
3797
bool Item_field::subst_argument_checker(unsigned char **arg)
3781
3798
{
3782
3799
  return (result_type() != STRING_RESULT) || (*arg);
3783
3800
}
3807
3824
    - pointer to the field item, otherwise.
3808
3825
*/
3809
3826
 
3810
 
Item *Item_field::equal_fields_propagator(uchar *arg)
 
3827
Item *Item_field::equal_fields_propagator(unsigned char *arg)
3811
3828
{
3812
3829
  if (no_const_subst)
3813
3830
    return this;
3840
3857
  See comments in Arg_comparator::set_compare_func() for details.
3841
3858
*/
3842
3859
 
3843
 
bool Item_field::set_no_const_sub(uchar *arg __attribute__((unused)))
 
3860
bool Item_field::set_no_const_sub(unsigned char *)
3844
3861
{
3845
3862
  if (field->charset() != &my_charset_bin)
3846
3863
    no_const_subst=1;
3873
3890
    - this - otherwise.
3874
3891
*/
3875
3892
 
3876
 
Item *Item_field::replace_equal_field(uchar *arg __attribute__((unused)))
 
3893
Item *Item_field::replace_equal_field(unsigned char *)
3877
3894
{
3878
3895
  if (item_equal)
3879
3896
  {
3909
3926
  tmp_field->type=              field_type_arg;
3910
3927
  tmp_field->length=max_length;
3911
3928
  tmp_field->decimals=decimals;
3912
 
  if (unsigned_flag)
3913
 
    tmp_field->flags |= UNSIGNED_FLAG;
3914
3929
}
3915
3930
 
3916
3931
void Item::make_field(Send_field *tmp_field)
3969
3984
  /* Check whether we got a well-formed string */
3970
3985
  const CHARSET_INFO * const cs= str->charset();
3971
3986
  int well_formed_error;
3972
 
  uint wlen= cs->cset->well_formed_len(cs,
 
3987
  uint32_t wlen= cs->cset->well_formed_len(cs,
3973
3988
                                       str->ptr(), str->ptr() + str->length(),
3974
3989
                                       str->length(), &well_formed_error);
3975
3990
  if (wlen < str->length())
3976
3991
  {
3977
 
    THD *thd= current_thd;
 
3992
    Session *session= current_session;
3978
3993
    char hexbuf[7];
3979
3994
    enum DRIZZLE_ERROR::enum_warning_level level;
3980
 
    uint diff= str->length() - wlen;
 
3995
    uint32_t diff= str->length() - wlen;
3981
3996
    set_if_smaller(diff, 3);
3982
3997
    octet2hex(hexbuf, str->ptr() + wlen, diff);
3983
3998
    if (send_error)
3991
4006
      null_value= 1;
3992
4007
      str= 0;
3993
4008
    }
3994
 
    push_warning_printf(thd, level, ER_INVALID_CHARACTER_STRING,
 
4009
    push_warning_printf(session, level, ER_INVALID_CHARACTER_STRING,
3995
4010
                        ER(ER_INVALID_CHARACTER_STRING), cs->csname, hexbuf);
3996
4011
  }
3997
4012
  return str;
4080
4095
    \#    Created field
4081
4096
*/
4082
4097
 
4083
 
Field *Item::tmp_table_field_from_field_type(Table *table, bool fixed_length __attribute__((unused)))
 
4098
Field *Item::tmp_table_field_from_field_type(Table *table, bool)
4084
4099
{
4085
4100
  /*
4086
4101
    The field functions defines a field to be not null if null_ptr is not 0
4087
4102
  */
4088
 
  uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
 
4103
  unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
4089
4104
  Field *field;
4090
4105
 
4091
4106
  switch (field_type()) {
4092
4107
  case DRIZZLE_TYPE_NEWDECIMAL:
4093
 
    field= new Field_new_decimal((uchar*) 0, max_length, null_ptr, 0,
 
4108
    field= new Field_new_decimal((unsigned char*) 0, max_length, null_ptr, 0,
4094
4109
                                 Field::NONE, name, decimals, 0,
4095
4110
                                 unsigned_flag);
4096
4111
    break;
4097
 
  case DRIZZLE_TYPE_TINY:
4098
 
    field= new Field_tiny((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4099
 
                          name, 0, unsigned_flag);
4100
 
    break;
4101
 
  case DRIZZLE_TYPE_SHORT:
4102
 
    field= new Field_short((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4103
 
                           name, 0, unsigned_flag);
4104
 
    break;
4105
4112
  case DRIZZLE_TYPE_LONG:
4106
 
    field= new Field_long((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4113
    field= new Field_long((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4107
4114
                          name, 0, unsigned_flag);
4108
4115
    break;
4109
4116
  case DRIZZLE_TYPE_LONGLONG:
4110
 
    field= new Field_int64_t((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4117
    field= new Field_int64_t((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4111
4118
                              name, 0, unsigned_flag);
4112
4119
    break;
4113
4120
  case DRIZZLE_TYPE_DOUBLE:
4114
 
    field= new Field_double((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4121
    field= new Field_double((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4115
4122
                            name, decimals, 0, unsigned_flag);
4116
4123
    break;
4117
4124
  case DRIZZLE_TYPE_NULL:
4118
 
    field= new Field_null((uchar*) 0, max_length, Field::NONE,
 
4125
    field= new Field_null((unsigned char*) 0, max_length, Field::NONE,
4119
4126
                          name, &my_charset_bin);
4120
4127
    break;
4121
4128
  case DRIZZLE_TYPE_NEWDATE:
4305
4312
}
4306
4313
 
4307
4314
 
4308
 
int Item_string::save_in_field(Field *field,
4309
 
                               bool no_conversions __attribute__((unused)))
 
4315
int Item_string::save_in_field(Field *field, bool)
4310
4316
{
4311
4317
  String *result;
4312
4318
  result=val_str(&str_value);
4321
4327
}
4322
4328
 
4323
4329
 
4324
 
int Item_int::save_in_field(Field *field,
4325
 
                            bool no_conversions __attribute__((unused)))
 
4330
int Item_int::save_in_field(Field *field, bool)
4326
4331
{
4327
4332
  int64_t nr=val_int();
4328
4333
  if (null_value)
4332
4337
}
4333
4338
 
4334
4339
 
4335
 
int Item_decimal::save_in_field(Field *field,
4336
 
                                bool no_conversions __attribute__((unused)))
 
4340
int Item_decimal::save_in_field(Field *field, bool)
4337
4341
{
4338
4342
  field->set_notnull();
4339
4343
  return field->store_decimal(&decimal_value);
4340
4344
}
4341
4345
 
4342
4346
 
4343
 
bool Item_int::eq(const Item *arg,
4344
 
                  bool binary_cmp __attribute__((unused))) const
 
4347
bool Item_int::eq(const Item *arg, bool) const
4345
4348
{
4346
4349
  /* No need to check for null value as basic constant can't be NULL */
4347
4350
  if (arg->basic_const_item() && arg->type() == type())
4377
4380
}
4378
4381
 
4379
4382
 
4380
 
static uint nr_of_decimals(const char *str, const char *end)
 
4383
static uint32_t nr_of_decimals(const char *str, const char *end)
4381
4384
{
4382
4385
  const char *decimal_point;
4383
4386
 
4405
4408
  value is not a true double value (overflow)
4406
4409
*/
4407
4410
 
4408
 
Item_float::Item_float(const char *str_arg, uint length)
 
4411
Item_float::Item_float(const char *str_arg, uint32_t length)
4409
4412
{
4410
4413
  int error;
4411
4414
  char *end_not_used;
4427
4430
}
4428
4431
 
4429
4432
 
4430
 
int Item_float::save_in_field(Field *field,
4431
 
                              bool no_conversions __attribute__((unused)))
 
4433
int Item_float::save_in_field(Field *field, bool)
4432
4434
{
4433
4435
  double nr= val_real();
4434
4436
  if (null_value)
4438
4440
}
4439
4441
 
4440
4442
 
4441
 
void Item_float::print(String *str,
4442
 
                       enum_query_type query_type __attribute__((unused)))
 
4443
void Item_float::print(String *str, enum_query_type)
4443
4444
{
4444
4445
  if (presentation)
4445
4446
  {
4459
4460
  In number context this is a int64_t value.
4460
4461
*/
4461
4462
 
4462
 
bool Item_float::eq(const Item *arg,
4463
 
                    bool binary_cmp __attribute__((unused))) const
 
4463
bool Item_float::eq(const Item *arg, bool) const
4464
4464
{
4465
4465
  if (arg->basic_const_item() && arg->type() == type())
4466
4466
  {
4475
4475
}
4476
4476
 
4477
4477
 
4478
 
inline uint char_val(char X)
 
4478
inline uint32_t char_val(char X)
4479
4479
{
4480
4480
  return (uint) (X >= '0' && X <= '9' ? X-'0' :
4481
4481
                 X >= 'A' && X <= 'Z' ? X-'A'+10 :
4483
4483
}
4484
4484
 
4485
4485
 
4486
 
Item_hex_string::Item_hex_string(const char *str, uint str_length)
 
4486
Item_hex_string::Item_hex_string(const char *str, uint32_t str_length)
4487
4487
{
4488
4488
  max_length=(str_length+1)/2;
4489
4489
  char *ptr=(char*) sql_alloc(max_length+1);
4509
4509
  // following assert is redundant, because fixed=1 assigned in constructor
4510
4510
  assert(fixed == 1);
4511
4511
  char *end=(char*) str_value.ptr()+str_value.length(),
4512
 
       *ptr=end-min(str_value.length(),(uint32_t)sizeof(int64_t));
 
4512
       *ptr=end-cmin(str_value.length(),(uint32_t)sizeof(int64_t));
4513
4513
 
4514
4514
  uint64_t value=0;
4515
4515
  for (; ptr != end ; ptr++)
4516
 
    value=(value << 8)+ (uint64_t) (uchar) *ptr;
 
4516
    value=(value << 8)+ (uint64_t) (unsigned char) *ptr;
4517
4517
  return (int64_t) value;
4518
4518
}
4519
4519
 
4528
4528
}
4529
4529
 
4530
4530
 
4531
 
int Item_hex_string::save_in_field(Field *field,
4532
 
                                   bool no_conversions __attribute__((unused)))
 
4531
int Item_hex_string::save_in_field(Field *field, bool)
4533
4532
{
4534
4533
  field->set_notnull();
4535
4534
  if (field->result_type() == STRING_RESULT)
4536
 
    return field->store(str_value.ptr(), str_value.length(), 
 
4535
    return field->store(str_value.ptr(), str_value.length(),
4537
4536
                        collation.collation);
4538
4537
 
4539
4538
  uint64_t nr;
4559
4558
}
4560
4559
 
4561
4560
 
4562
 
void Item_hex_string::print(String *str,
4563
 
                            enum_query_type query_type __attribute__((unused)))
 
4561
void Item_hex_string::print(String *str, enum_query_type)
4564
4562
{
4565
4563
  char *end= (char*) str_value.ptr() + str_value.length(),
4566
 
       *ptr= end - min(str_value.length(), (uint32_t)sizeof(int64_t));
 
4564
       *ptr= end - cmin(str_value.length(), (uint32_t)sizeof(int64_t));
4567
4565
  str->append("0x");
4568
4566
  for (; ptr != end ; ptr++)
4569
4567
  {
4570
 
    str->append(_dig_vec_lower[((uchar) *ptr) >> 4]);
4571
 
    str->append(_dig_vec_lower[((uchar) *ptr) & 0x0F]);
 
4568
    str->append(_dig_vec_lower[((unsigned char) *ptr) >> 4]);
 
4569
    str->append(_dig_vec_lower[((unsigned char) *ptr) & 0x0F]);
4572
4570
  }
4573
4571
}
4574
4572
 
4604
4602
  In number context this is a int64_t value.
4605
4603
*/
4606
4604
  
4607
 
Item_bin_string::Item_bin_string(const char *str, uint str_length)
 
4605
Item_bin_string::Item_bin_string(const char *str, uint32_t str_length)
4608
4606
{
4609
4607
  const char *end= str + str_length - 1;
4610
 
  uchar bits= 0;
4611
 
  uint power= 1;
 
4608
  unsigned char bits= 0;
 
4609
  uint32_t power= 1;
4612
4610
 
4613
4611
  max_length= (str_length + 7) >> 3;
4614
4612
  char *ptr= (char*) sql_alloc(max_length + 1);
4640
4638
*/
4641
4639
 
4642
4640
bool Item_null::send(Protocol *protocol,
4643
 
                     String *packet __attribute__((unused)))
 
4641
                     String *)
4644
4642
{
4645
4643
  return protocol->store_null();
4646
4644
}
4667
4665
      result= protocol->store(res->ptr(),res->length(),res->charset());
4668
4666
    break;
4669
4667
  }
4670
 
  case DRIZZLE_TYPE_TINY:
4671
 
  {
4672
 
    int64_t nr;
4673
 
    nr= val_int();
4674
 
    if (!null_value)
4675
 
      result= protocol->store_tiny(nr);
4676
 
    break;
4677
 
  }
4678
 
  case DRIZZLE_TYPE_SHORT:
4679
 
  {
4680
 
    int64_t nr;
4681
 
    nr= val_int();
4682
 
    if (!null_value)
4683
 
      result= protocol->store_short(nr);
4684
 
    break;
4685
 
  }
4686
4668
  case DRIZZLE_TYPE_LONG:
4687
4669
  {
4688
4670
    int64_t nr;
4735
4717
}
4736
4718
 
4737
4719
 
4738
 
bool Item_field::send(Protocol *protocol,
4739
 
                      String *buffer __attribute__((unused)))
 
4720
bool Item_field::send(Protocol *protocol, String *)
4740
4721
{
4741
4722
  return protocol->store(result_field);
4742
4723
}
4748
4729
    need to set no_errors to prevent warnings about type conversion
4749
4730
    popping up.
4750
4731
  */
4751
 
  THD *thd= field->table->in_use;
 
4732
  Session *session= field->table->in_use;
4752
4733
  int no_errors;
4753
4734
 
4754
 
  no_errors= thd->no_errors;
4755
 
  thd->no_errors= 1;
 
4735
  no_errors= session->no_errors;
 
4736
  session->no_errors= 1;
4756
4737
  Item::update_null_value();
4757
 
  thd->no_errors= no_errors;
 
4738
  session->no_errors= no_errors;
4758
4739
}
4759
4740
 
4760
4741
 
4780
4761
    this field    otherwise
4781
4762
*/
4782
4763
 
4783
 
Item *Item_field::update_value_transformer(uchar *select_arg)
 
4764
Item *Item_field::update_value_transformer(unsigned char *select_arg)
4784
4765
{
4785
4766
  SELECT_LEX *select= (SELECT_LEX*)select_arg;
4786
4767
  assert(fixed);
4822
4803
                   Item **item, const char *table_name_arg,
4823
4804
                   const char *field_name_arg,
4824
4805
                   bool alias_name_used_arg)
4825
 
  :Item_ident(context_arg, NullS, table_name_arg, field_name_arg),
 
4806
  :Item_ident(context_arg, NULL, table_name_arg, field_name_arg),
4826
4807
   result_field(0), ref(item)
4827
4808
{
4828
4809
  alias_name_used= alias_name_used_arg;
4882
4863
    Item_field::fix_fields, here we first search the SELECT and GROUP BY
4883
4864
    clauses, and then we search the FROM clause.
4884
4865
 
4885
 
  @param[in]     thd        current thread
 
4866
  @param[in]     session        current thread
4886
4867
  @param[in,out] reference  view column if this item was resolved to a
4887
4868
    view column
4888
4869
 
4898
4879
    false on success
4899
4880
*/
4900
4881
 
4901
 
bool Item_ref::fix_fields(THD *thd, Item **reference)
 
4882
bool Item_ref::fix_fields(Session *session, Item **reference)
4902
4883
{
4903
4884
  enum_parsing_place place= NO_MATTER;
4904
4885
  assert(fixed == 0);
4905
 
  SELECT_LEX *current_sel= thd->lex->current_select;
 
4886
  SELECT_LEX *current_sel= session->lex->current_select;
4906
4887
 
4907
4888
  if (!ref || ref == not_found_item)
4908
4889
  {
4909
 
    if (!(ref= resolve_ref_in_select_and_group(thd, this,
 
4890
    if (!(ref= resolve_ref_in_select_and_group(session, this,
4910
4891
                                               context->select_lex)))
4911
4892
      goto error;             /* Some error occurred (e.g. ambiguous names). */
4912
4893
 
4921
4902
      {
4922
4903
        /* The current reference cannot be resolved in this query. */
4923
4904
        my_error(ER_BAD_FIELD_ERROR,MYF(0),
4924
 
                 this->full_name(), current_thd->where);
 
4905
                 this->full_name(), current_session->where);
4925
4906
        goto error;
4926
4907
      }
4927
4908
 
4946
4927
        /* Search in the SELECT and GROUP lists of the outer select. */
4947
4928
        if (outer_context->resolve_in_select_list)
4948
4929
        {
4949
 
          if (!(ref= resolve_ref_in_select_and_group(thd, this, select)))
 
4930
          if (!(ref= resolve_ref_in_select_and_group(session, this, select)))
4950
4931
            goto error; /* Some error occurred (e.g. ambiguous names). */
4951
4932
          if (ref != not_found_item)
4952
4933
          {
4983
4964
            field expression to 'reference', i.e. it substitute that
4984
4965
            expression instead of this Item_ref
4985
4966
          */
4986
 
          from_field= find_field_in_tables(thd, this,
 
4967
          from_field= find_field_in_tables(session, this,
4987
4968
                                           outer_context->
4988
4969
                                             first_name_resolution_table,
4989
4970
                                           outer_context->
5001
4982
            prev_subselect_item->const_item_cache&=
5002
4983
              (*reference)->const_item();
5003
4984
            assert((*reference)->type() == REF_ITEM);
5004
 
            mark_as_dependent(thd, last_checked_context->select_lex,
 
4985
            mark_as_dependent(session, last_checked_context->select_lex,
5005
4986
                              context->select_lex, this,
5006
4987
                              ((refer_type == REF_ITEM ||
5007
4988
                                refer_type == FIELD_ITEM) ?
5054
5035
        Item_field* fld;
5055
5036
        if (!(fld= new Item_field(from_field)))
5056
5037
          goto error;
5057
 
        thd->change_item_tree(reference, fld);
5058
 
        mark_as_dependent(thd, last_checked_context->select_lex,
5059
 
                          thd->lex->current_select, this, fld);
 
5038
        session->change_item_tree(reference, fld);
 
5039
        mark_as_dependent(session, last_checked_context->select_lex,
 
5040
                          session->lex->current_select, this, fld);
5060
5041
        /*
5061
5042
          A reference is resolved to a nest level that's outer or the same as
5062
5043
          the nest level of the enclosing set function : adjust the value of
5063
5044
          max_arg_level for the function if it's needed.
5064
5045
        */
5065
 
        if (thd->lex->in_sum_func &&
5066
 
            thd->lex->in_sum_func->nest_level >= 
 
5046
        if (session->lex->in_sum_func &&
 
5047
            session->lex->in_sum_func->nest_level >= 
5067
5048
            last_checked_context->select_lex->nest_level)
5068
 
          set_if_bigger(thd->lex->in_sum_func->max_arg_level,
 
5049
          set_if_bigger(session->lex->in_sum_func->max_arg_level,
5069
5050
                        last_checked_context->select_lex->nest_level);
5070
5051
        return false;
5071
5052
      }
5073
5054
      {
5074
5055
        /* The item was not a table field and not a reference */
5075
5056
        my_error(ER_BAD_FIELD_ERROR, MYF(0),
5076
 
                 this->full_name(), current_thd->where);
 
5057
                 this->full_name(), current_session->where);
5077
5058
        goto error;
5078
5059
      }
5079
5060
      /* Should be checked in resolve_ref_in_select_and_group(). */
5080
5061
      assert(*ref && (*ref)->fixed);
5081
 
      mark_as_dependent(thd, last_checked_context->select_lex,
 
5062
      mark_as_dependent(session, last_checked_context->select_lex,
5082
5063
                        context->select_lex, this, this);
5083
5064
      /*
5084
5065
        A reference is resolved to a nest level that's outer or the same as
5085
5066
        the nest level of the enclosing set function : adjust the value of
5086
5067
        max_arg_level for the function if it's needed.
5087
5068
      */
5088
 
      if (thd->lex->in_sum_func &&
5089
 
          thd->lex->in_sum_func->nest_level >= 
 
5069
      if (session->lex->in_sum_func &&
 
5070
          session->lex->in_sum_func->nest_level >= 
5090
5071
          last_checked_context->select_lex->nest_level)
5091
 
        set_if_bigger(thd->lex->in_sum_func->max_arg_level,
 
5072
        set_if_bigger(session->lex->in_sum_func->max_arg_level,
5092
5073
                      last_checked_context->select_lex->nest_level);
5093
5074
    }
5094
5075
  }
5121
5102
  return false;
5122
5103
 
5123
5104
error:
5124
 
  context->process_error(thd);
 
5105
  context->process_error(session);
5125
5106
  return true;
5126
5107
}
5127
5108
 
5163
5144
    if ((*ref)->type() != Item::CACHE_ITEM && ref_type() != VIEW_REF &&
5164
5145
        !table_name && name && alias_name_used)
5165
5146
    {
5166
 
      THD *thd= current_thd;
5167
 
      append_identifier(thd, str, name, (uint) strlen(name));
 
5147
      Session *session= current_session;
 
5148
      append_identifier(session, str, name, (uint) strlen(name));
5168
5149
    }
5169
5150
    else
5170
5151
      (*ref)->print(str, query_type);
5303
5284
}
5304
5285
 
5305
5286
 
5306
 
bool Item_ref::get_date(DRIZZLE_TIME *ltime,uint fuzzydate)
 
5287
bool Item_ref::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
5307
5288
{
5308
5289
  return (null_value=(*ref)->get_date_result(ltime,fuzzydate));
5309
5290
}
5345
5326
}
5346
5327
 
5347
5328
 
5348
 
Item *Item_ref::get_tmp_table_item(THD *thd)
 
5329
Item *Item_ref::get_tmp_table_item(Session *session)
5349
5330
{
5350
5331
  if (!result_field)
5351
 
    return (*ref)->get_tmp_table_item(thd);
 
5332
    return (*ref)->get_tmp_table_item(session);
5352
5333
 
5353
5334
  Item_field *item= new Item_field(result_field);
5354
5335
  if (item)
5417
5398
}
5418
5399
 
5419
5400
 
5420
 
bool Item_direct_ref::get_date(DRIZZLE_TIME *ltime,uint fuzzydate)
 
5401
bool Item_direct_ref::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
5421
5402
{
5422
5403
  return (null_value=(*ref)->get_date(ltime,fuzzydate));
5423
5404
}
5426
5407
/**
5427
5408
  Prepare referenced field then call usual Item_direct_ref::fix_fields .
5428
5409
 
5429
 
  @param thd         thread handler
 
5410
  @param session         thread handler
5430
5411
  @param reference   reference on reference where this item stored
5431
5412
 
5432
5413
  @retval
5435
5416
    true    Error
5436
5417
*/
5437
5418
 
5438
 
bool Item_direct_view_ref::fix_fields(THD *thd, Item **reference)
 
5419
bool Item_direct_view_ref::fix_fields(Session *session, Item **reference)
5439
5420
{
5440
5421
  /* view fild reference must be defined */
5441
5422
  assert(*ref);
5442
5423
  /* (*ref)->check_cols() will be made in Item_direct_ref::fix_fields */
5443
5424
  if (!(*ref)->fixed &&
5444
 
      ((*ref)->fix_fields(thd, ref)))
 
5425
      ((*ref)->fix_fields(session, ref)))
5445
5426
    return true;
5446
 
  return Item_direct_ref::fix_fields(thd, reference);
 
5427
  return Item_direct_ref::fix_fields(session, reference);
5447
5428
}
5448
5429
 
5449
5430
/*
5451
5432
 
5452
5433
  SYNOPSIS
5453
5434
    Item_outer_ref::fix_fields()
5454
 
    thd         thread handler
 
5435
    session         thread handler
5455
5436
    reference   reference on reference where this item stored
5456
5437
 
5457
5438
  RETURN
5459
5440
    true    Error
5460
5441
*/
5461
5442
 
5462
 
bool Item_outer_ref::fix_fields(THD *thd, Item **reference)
 
5443
bool Item_outer_ref::fix_fields(Session *session, Item **reference)
5463
5444
{
5464
5445
  bool err;
5465
5446
  /* outer_ref->check_cols() will be made in Item_direct_ref::fix_fields */
5466
 
  if ((*ref) && !(*ref)->fixed && ((*ref)->fix_fields(thd, reference)))
 
5447
  if ((*ref) && !(*ref)->fixed && ((*ref)->fix_fields(session, reference)))
5467
5448
    return true;
5468
 
  err= Item_direct_ref::fix_fields(thd, reference);
 
5449
  err= Item_direct_ref::fix_fields(session, reference);
5469
5450
  if (!outer_ref)
5470
5451
    outer_ref= *ref;
5471
5452
  if ((*ref)->type() == Item::FIELD_ITEM)
5482
5463
  }
5483
5464
}
5484
5465
 
5485
 
void Item_ref::fix_after_pullout(st_select_lex *new_parent,
5486
 
                                 Item **refptr __attribute__((unused)))
 
5466
void Item_ref::fix_after_pullout(st_select_lex *new_parent, Item **)
5487
5467
{
5488
5468
  if (depended_from == new_parent)
5489
5469
  {
5509
5489
    false   otherwise
5510
5490
*/
5511
5491
 
5512
 
bool Item_direct_view_ref::eq(const Item *item,
5513
 
                              bool binary_cmp __attribute__((unused))) const
 
5492
bool Item_direct_view_ref::eq(const Item *item, bool) const
5514
5493
{
5515
5494
  if (item->type() == REF_ITEM)
5516
5495
  {
5531
5510
}
5532
5511
 
5533
5512
 
5534
 
bool Item_default_value::fix_fields(THD *thd,
5535
 
                                    Item **items __attribute__((unused)))
 
5513
bool Item_default_value::fix_fields(Session *session, Item **)
5536
5514
{
5537
5515
  Item *real_arg;
5538
5516
  Item_field *field_arg;
5544
5522
    fixed= 1;
5545
5523
    return false;
5546
5524
  }
5547
 
  if (!arg->fixed && arg->fix_fields(thd, &arg))
 
5525
  if (!arg->fixed && arg->fix_fields(session, &arg))
5548
5526
    goto error;
5549
5527
 
5550
5528
 
5571
5549
  return false;
5572
5550
 
5573
5551
error:
5574
 
  context->process_error(thd);
 
5552
  context->process_error(session);
5575
5553
  return true;
5576
5554
}
5577
5555
 
5623
5601
  same time it can replace some nodes in the tree.
5624
5602
*/ 
5625
5603
 
5626
 
Item *Item_default_value::transform(Item_transformer transformer, uchar *args)
 
5604
Item *Item_default_value::transform(Item_transformer transformer, unsigned char *args)
5627
5605
{
5628
5606
  Item *new_item= arg->transform(transformer, args);
5629
5607
  if (!new_item)
5630
5608
    return 0;
5631
5609
 
5632
5610
  /*
5633
 
    THD::change_item_tree() should be called only if the tree was
 
5611
    Session::change_item_tree() should be called only if the tree was
5634
5612
    really transformed, i.e. when a new item has been created.
5635
5613
    Otherwise we'll be allocating a lot of unnecessary memory for
5636
5614
    change records at each execution.
5637
5615
  */
5638
5616
  if (arg != new_item)
5639
 
    current_thd->change_item_tree(&arg, new_item);
 
5617
    current_session->change_item_tree(&arg, new_item);
5640
5618
  return (this->*transformer)(args);
5641
5619
}
5642
5620
 
5648
5626
}
5649
5627
 
5650
5628
 
5651
 
bool Item_insert_value::fix_fields(THD *thd,
5652
 
                                   Item **items __attribute__((unused)))
 
5629
bool Item_insert_value::fix_fields(Session *session, Item **)
5653
5630
{
5654
5631
  assert(fixed == 0);
5655
5632
  /* We should only check that arg is in first table */
5658
5635
    bool res;
5659
5636
    TableList *orig_next_table= context->last_name_resolution_table;
5660
5637
    context->last_name_resolution_table= context->first_name_resolution_table;
5661
 
    res= arg->fix_fields(thd, &arg);
 
5638
    res= arg->fix_fields(session, &arg);
5662
5639
    context->last_name_resolution_table= orig_next_table;
5663
5640
    if (res)
5664
5641
      return true;
5731
5708
}
5732
5709
 
5733
5710
 
5734
 
void resolve_const_item(THD *thd, Item **ref, Item *comp_item)
 
5711
void resolve_const_item(Session *session, Item **ref, Item *comp_item)
5735
5712
{
5736
5713
  Item *item= *ref;
5737
5714
  Item *new_item= NULL;
5751
5728
      new_item= new Item_null(name);
5752
5729
    else
5753
5730
    {
5754
 
      uint length= result->length();
 
5731
      uint32_t length= result->length();
5755
5732
      char *tmp_str= sql_strmake(result->ptr(), length);
5756
5733
      new_item= new Item_string(name, tmp_str, length, result->charset());
5757
5734
    }
5760
5737
  case INT_RESULT:
5761
5738
  {
5762
5739
    int64_t result=item->val_int();
5763
 
    uint length=item->max_length;
 
5740
    uint32_t length=item->max_length;
5764
5741
    bool null_value=item->null_value;
5765
5742
    new_item= (null_value ? (Item*) new Item_null(name) :
5766
5743
               (Item*) new Item_int(name, result, length));
5779
5756
    */
5780
5757
    Item_row *item_row= (Item_row*) item;
5781
5758
    Item_row *comp_item_row= (Item_row*) comp_item;
5782
 
    uint col;
 
5759
    uint32_t col;
5783
5760
    new_item= 0;
5784
5761
    /*
5785
5762
      If item and comp_item are both Item_rows and have same number of cols
5791
5768
    assert(item_row->cols() == comp_item_row->cols());
5792
5769
    col= item_row->cols();
5793
5770
    while (col-- > 0)
5794
 
      resolve_const_item(thd, item_row->addr(col),
 
5771
      resolve_const_item(session, item_row->addr(col),
5795
5772
                         comp_item_row->element_index(col));
5796
5773
    break;
5797
5774
  }
5799
5776
  case REAL_RESULT:
5800
5777
  {                                             // It must REAL_RESULT
5801
5778
    double result= item->val_real();
5802
 
    uint length=item->max_length,decimals=item->decimals;
 
5779
    uint32_t length=item->max_length,decimals=item->decimals;
5803
5780
    bool null_value=item->null_value;
5804
5781
    new_item= (null_value ? (Item*) new Item_null(name) : (Item*)
5805
5782
               new Item_float(name, result, decimals, length));
5809
5786
  {
5810
5787
    my_decimal decimal_value;
5811
5788
    my_decimal *result= item->val_decimal(&decimal_value);
5812
 
    uint length= item->max_length, decimals= item->decimals;
 
5789
    uint32_t length= item->max_length, decimals= item->decimals;
5813
5790
    bool null_value= item->null_value;
5814
5791
    new_item= (null_value ?
5815
5792
               (Item*) new Item_null(name) :
5820
5797
    assert(0);
5821
5798
  }
5822
5799
  if (new_item)
5823
 
    thd->change_item_tree(ref, new_item);
 
5800
    session->change_item_tree(ref, new_item);
5824
5801
}
5825
5802
 
5826
5803
/**
5992
5969
  return str;
5993
5970
}
5994
5971
 
5995
 
my_decimal *Item_cache_decimal::val_decimal(my_decimal *val __attribute__((unused)))
 
5972
my_decimal *Item_cache_decimal::val_decimal(my_decimal *)
5996
5973
{
5997
5974
  assert(fixed);
5998
5975
  return &decimal_value;
6062
6039
}
6063
6040
 
6064
6041
 
6065
 
bool Item_cache_row::allocate(uint num)
 
6042
bool Item_cache_row::allocate(uint32_t num)
6066
6043
{
6067
6044
  item_count= num;
6068
 
  THD *thd= current_thd;
 
6045
  Session *session= current_session;
6069
6046
  return (!(values= 
6070
 
            (Item_cache **) thd->calloc(sizeof(Item_cache *)*item_count)));
 
6047
            (Item_cache **) session->calloc(sizeof(Item_cache *)*item_count)));
6071
6048
}
6072
6049
 
6073
6050
 
6076
6053
  example= item;
6077
6054
  if (!values && allocate(item->cols()))
6078
6055
    return 1;
6079
 
  for (uint i= 0; i < item_count; i++)
 
6056
  for (uint32_t i= 0; i < item_count; i++)
6080
6057
  {
6081
6058
    Item *el= item->element_index(i);
6082
6059
    Item_cache *tmp;
6092
6069
{
6093
6070
  null_value= 0;
6094
6071
  item->bring_value();
6095
 
  for (uint i= 0; i < item_count; i++)
 
6072
  for (uint32_t i= 0; i < item_count; i++)
6096
6073
  {
6097
6074
    values[i]->store(item->element_index(i));
6098
6075
    null_value|= values[i]->null_value;
6100
6077
}
6101
6078
 
6102
6079
 
6103
 
void Item_cache_row::illegal_method_call(const char *method __attribute__((unused)))
 
6080
void Item_cache_row::illegal_method_call(const char *)
6104
6081
{
6105
6082
  assert(0);
6106
6083
  my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
6108
6085
}
6109
6086
 
6110
6087
 
6111
 
bool Item_cache_row::check_cols(uint c)
 
6088
bool Item_cache_row::check_cols(uint32_t c)
6112
6089
{
6113
6090
  if (c != item_count)
6114
6091
  {
6121
6098
 
6122
6099
bool Item_cache_row::null_inside()
6123
6100
{
6124
 
  for (uint i= 0; i < item_count; i++)
 
6101
  for (uint32_t i= 0; i < item_count; i++)
6125
6102
  {
6126
6103
    if (values[i]->cols() > 1)
6127
6104
    {
6141
6118
 
6142
6119
void Item_cache_row::bring_value()
6143
6120
{
6144
 
  for (uint i= 0; i < item_count; i++)
 
6121
  for (uint32_t i= 0; i < item_count; i++)
6145
6122
    values[i]->bring_value();
6146
6123
  return;
6147
6124
}
6148
6125
 
6149
6126
 
6150
 
Item_type_holder::Item_type_holder(THD *thd, Item *item)
6151
 
  :Item(thd, item), enum_set_typelib(0), fld_type(get_real_type(item))
 
6127
Item_type_holder::Item_type_holder(Session *session, Item *item)
 
6128
  :Item(session, item), enum_set_typelib(0), fld_type(get_real_type(item))
6152
6129
{
6153
6130
  assert(item->fixed);
6154
6131
  maybe_null= item->maybe_null;
6243
6220
  Find field type which can carry current Item_type_holder type and
6244
6221
  type of given Item.
6245
6222
 
6246
 
  @param thd     thread handler
 
6223
  @param session     thread handler
6247
6224
  @param item    given item to join its parameters with this item ones
6248
6225
 
6249
6226
  @retval
6252
6229
    false  OK
6253
6230
*/
6254
6231
 
6255
 
bool Item_type_holder::join_types(THD *thd __attribute__((unused)),
6256
 
                                  Item *item)
 
6232
bool Item_type_holder::join_types(Session *, Item *item)
6257
6233
{
6258
 
  uint max_length_orig= max_length;
6259
 
  uint decimals_orig= decimals;
 
6234
  uint32_t max_length_orig= max_length;
 
6235
  uint32_t decimals_orig= decimals;
6260
6236
  fld_type= Field::field_type_merge(fld_type, get_real_type(item));
6261
6237
  {
6262
6238
    int item_decimals= item->decimals;
6263
6239
    /* fix variable decimals which always is NOT_FIXED_DEC */
6264
6240
    if (Field::result_merge_type(fld_type) == INT_RESULT)
6265
6241
      item_decimals= 0;
6266
 
    decimals= max((int)decimals, item_decimals);
 
6242
    decimals= cmax((int)decimals, item_decimals);
6267
6243
  }
6268
6244
  if (Field::result_merge_type(fld_type) == DECIMAL_RESULT)
6269
6245
  {
6270
 
    decimals= min((int)max(decimals, item->decimals), DECIMAL_MAX_SCALE);
6271
 
    int precision= min(max(prev_decimal_int_part, item->decimal_int_part())
 
6246
    decimals= cmin((int)cmax(decimals, item->decimals), DECIMAL_MAX_SCALE);
 
6247
    int precision= cmin(cmax(prev_decimal_int_part, item->decimal_int_part())
6272
6248
                       + decimals, DECIMAL_MAX_PRECISION);
6273
6249
    unsigned_flag&= item->unsigned_flag;
6274
6250
    max_length= my_decimal_precision_to_length(precision, decimals,
6299
6275
     */
6300
6276
    if (collation.collation != &my_charset_bin)
6301
6277
    {
6302
 
      max_length= max(old_max_chars * collation.collation->mbmaxlen,
 
6278
      max_length= cmax(old_max_chars * collation.collation->mbmaxlen,
6303
6279
                      display_length(item) /
6304
6280
                      item->collation.collation->mbmaxlen *
6305
6281
                      collation.collation->mbmaxlen);
6314
6290
    {
6315
6291
      int delta1= max_length_orig - decimals_orig;
6316
6292
      int delta2= item->max_length - item->decimals;
6317
 
      max_length= max(delta1, delta2) + decimals;
 
6293
      max_length= cmax(delta1, delta2) + decimals;
6318
6294
      if (fld_type == DRIZZLE_TYPE_DOUBLE && max_length > DBL_DIG + 2) 
6319
6295
      {
6320
6296
        max_length= DBL_DIG + 7;
6326
6302
    break;
6327
6303
  }
6328
6304
  default:
6329
 
    max_length= max(max_length, display_length(item));
 
6305
    max_length= cmax(max_length, display_length(item));
6330
6306
  };
6331
6307
  maybe_null|= item->maybe_null;
6332
6308
  get_full_info(item);
6360
6336
  case DRIZZLE_TYPE_NEWDECIMAL:
6361
6337
  case DRIZZLE_TYPE_ENUM:
6362
6338
  case DRIZZLE_TYPE_BLOB:
6363
 
  case DRIZZLE_TYPE_TINY:
6364
6339
    return 4;
6365
 
  case DRIZZLE_TYPE_SHORT:
6366
 
    return 6;
6367
6340
  case DRIZZLE_TYPE_LONG:
6368
6341
    return MY_INT32_NUM_DECIMAL_DIGITS;
6369
6342
  case DRIZZLE_TYPE_DOUBLE:
6394
6367
  /*
6395
6368
    The field functions defines a field to be not null if null_ptr is not 0
6396
6369
  */
6397
 
  uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
 
6370
  unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
6398
6371
  Field *field;
6399
6372
 
6400
6373
  switch (fld_type) {
6401
6374
  case DRIZZLE_TYPE_ENUM:
6402
6375
    assert(enum_set_typelib);
6403
 
    field= new Field_enum((uchar *) 0, max_length, null_ptr, 0,
 
6376
    field= new Field_enum((unsigned char *) 0, max_length, null_ptr, 0,
6404
6377
                          Field::NONE, name,
6405
6378
                          get_enum_pack_length(enum_set_typelib->count),
6406
6379
                          enum_set_typelib, collation.collation);
6487
6460
    do nothing
6488
6461
*/
6489
6462
 
6490
 
void dummy_error_processor(THD *thd __attribute__((unused)),
6491
 
                           void *data __attribute__((unused)))
 
6463
void dummy_error_processor(Session *, void *)
6492
6464
{}
6493
6465
 
6494
6466
/**