~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.cc

Merged in changes from Andrey.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
Hybrid_type_traits_decimal::fix_length_and_dec(Item *item, Item *arg) const
68
68
{
69
69
  item->decimals= arg->decimals;
70
 
  item->max_length= min(arg->max_length + DECIMAL_LONGLONG_DIGITS,
 
70
  item->max_length= cmin(arg->max_length + DECIMAL_LONGLONG_DIGITS,
71
71
                        (unsigned int)DECIMAL_MAX_STR_LENGTH);
72
72
}
73
73
 
429
429
}
430
430
 
431
431
 
432
 
uint Item::decimal_precision() const
 
432
uint32_t Item::decimal_precision() const
433
433
{
434
434
  Item_result restype= result_type();
435
435
 
436
436
  if ((restype == DECIMAL_RESULT) || (restype == INT_RESULT))
437
 
    return min(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
 
437
    return cmin(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
438
438
               (unsigned int)DECIMAL_MAX_PRECISION);
439
 
  return min(max_length, (uint32_t)DECIMAL_MAX_PRECISION);
 
439
  return cmin(max_length, (uint32_t)DECIMAL_MAX_PRECISION);
440
440
}
441
441
 
442
442
 
469
469
  @param arg   a dummy parameter, is not used here
470
470
*/
471
471
 
472
 
bool Item::cleanup_processor(uchar *arg __attribute__((unused)))
 
472
bool Item::cleanup_processor(unsigned char *arg __attribute__((unused)))
473
473
{
474
474
  if (fixed)
475
475
    cleanup();
524
524
    pointer to newly allocated item is returned.
525
525
*/
526
526
 
527
 
Item* Item::transform(Item_transformer transformer, uchar *arg)
 
527
Item* Item::transform(Item_transformer transformer, unsigned char *arg)
528
528
{
529
529
  return (this->*transformer)(arg);
530
530
}
581
581
  return;
582
582
}
583
583
 
584
 
bool Item_ident::remove_dependence_processor(uchar * arg)
 
584
bool Item_ident::remove_dependence_processor(unsigned char * arg)
585
585
{
586
586
  if (depended_from == (st_select_lex *) arg)
587
587
    depended_from= 0;
607
607
    for the subsequent items.
608
608
*/
609
609
 
610
 
bool Item_field::collect_item_field_processor(uchar *arg)
 
610
bool Item_field::collect_item_field_processor(unsigned char *arg)
611
611
{
612
612
  List<Item_field> *item_list= (List<Item_field>*) arg;
613
613
  List_iterator<Item_field> item_list_it(*item_list);
638
638
    false otherwise
639
639
*/
640
640
 
641
 
bool Item_field::find_item_in_field_list_processor(uchar *arg)
 
641
bool Item_field::find_item_in_field_list_processor(unsigned char *arg)
642
642
{
643
643
  KEY_PART_INFO *first_non_group_part= *((KEY_PART_INFO **) arg);
644
644
  KEY_PART_INFO *last_part= *(((KEY_PART_INFO **) arg) + 1);
661
661
    column read set or to register used fields in a view
662
662
*/
663
663
 
664
 
bool Item_field::register_field_in_read_map(uchar *arg)
 
664
bool Item_field::register_field_in_read_map(unsigned char *arg)
665
665
{
666
666
  Table *table= (Table *) arg;
667
667
  if (field->table == table || !table)
677
677
 
678
678
*/
679
679
 
680
 
bool Item_field::register_field_in_bitmap(uchar *arg)
 
680
bool Item_field::register_field_in_bitmap(unsigned char *arg)
681
681
{
682
682
  MY_BITMAP *bitmap= (MY_BITMAP *) arg;
683
683
  assert(bitmap);
686
686
}
687
687
 
688
688
 
689
 
bool Item::check_cols(uint c)
 
689
bool Item::check_cols(uint32_t c)
690
690
{
691
691
  if (c != 1)
692
692
  {
697
697
}
698
698
 
699
699
 
700
 
void Item::set_name(const char *str, uint length, const CHARSET_INFO * const cs)
 
700
void Item::set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs)
701
701
{
702
702
  if (!length)
703
703
  {
708
708
  }
709
709
  if (cs->ctype)
710
710
  {
711
 
    uint orig_len= length;
 
711
    uint32_t orig_len= length;
712
712
    /*
713
713
      This will probably need a better implementation in the future:
714
714
      a function in CHARSET_INFO structure.
738
738
                                   &res_length);
739
739
  }
740
740
  else
741
 
    name= sql_strmake(str, (name_length= min(length,(unsigned int)MAX_ALIAS_NAME)));
 
741
    name= sql_strmake(str, (name_length= cmin(length,(unsigned int)MAX_ALIAS_NAME)));
742
742
}
743
743
 
744
744
 
813
813
Item *Item_string::safe_charset_converter(const CHARSET_INFO * const tocs)
814
814
{
815
815
  Item_string *conv;
816
 
  uint conv_errors;
 
816
  uint32_t conv_errors;
817
817
  char *ptr;
818
818
  String tmp, cstr, *ostr= val_str(&tmp);
819
819
  cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
842
842
{
843
843
  if (const_item())
844
844
  {
845
 
    uint cnv_errors;
 
845
    uint32_t cnv_errors;
846
846
    String *ostr= val_str(&cnvstr);
847
847
    cnvitem->str_value.copy(ostr->ptr(), ostr->length(),
848
848
                            ostr->charset(), tocs, &cnv_errors);
859
859
Item *Item_static_string_func::safe_charset_converter(const CHARSET_INFO * const tocs)
860
860
{
861
861
  Item_string *conv;
862
 
  uint conv_errors;
 
862
  uint32_t conv_errors;
863
863
  String tmp, cstr, *ostr= val_str(&tmp);
864
864
  cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
865
865
  if (conv_errors ||
901
901
  As a extra convenience the time structure is reset on error!
902
902
*/
903
903
 
904
 
bool Item::get_date(DRIZZLE_TIME *ltime,uint fuzzydate)
 
904
bool Item::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
905
905
{
906
906
  if (result_type() == STRING_RESULT)
907
907
  {
916
916
  {
917
917
    int64_t value= val_int();
918
918
    int was_cut;
919
 
    if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1LL)
 
919
    if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1L)
920
920
    {
921
921
      char buff[22], *end;
922
922
      end= int64_t10_to_str(value, buff, -10);
923
923
      make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
924
924
                                   buff, (int) (end-buff), DRIZZLE_TIMESTAMP_NONE,
925
 
                                   NullS);
 
925
                                   NULL);
926
926
      goto err;
927
927
    }
928
928
  }
1055
1055
      Item_ref to allow fields from view being stored in tmp table.
1056
1056
    */
1057
1057
    Item_aggregate_ref *item_ref;
1058
 
    uint el= fields.elements;
 
1058
    uint32_t el= fields.elements;
1059
1059
    Item *real_itm= real_item();
1060
1060
 
1061
1061
    ref_pointer_array[el]= real_itm;
1125
1125
  @endcode
1126
1126
*/
1127
1127
 
1128
 
bool DTCollation::aggregate(DTCollation &dt, uint flags)
 
1128
bool DTCollation::aggregate(DTCollation &dt, uint32_t flags)
1129
1129
{
1130
1130
  if (!my_charset_same(collation, dt.collation))
1131
1131
  {
1245
1245
 
1246
1246
 
1247
1247
static
1248
 
void my_coll_agg_error(Item** args, uint count, const char *fname,
 
1248
void my_coll_agg_error(Item** args, uint32_t count, const char *fname,
1249
1249
                       int item_sep)
1250
1250
{
1251
1251
  if (count == 2)
1259
1259
 
1260
1260
 
1261
1261
bool agg_item_collations(DTCollation &c, const char *fname,
1262
 
                         Item **av, uint count, uint flags, int item_sep)
 
1262
                         Item **av, uint32_t count, uint32_t flags, int item_sep)
1263
1263
{
1264
 
  uint i;
 
1264
  uint32_t i;
1265
1265
  Item **arg;
1266
1266
  c.set(av[0]->collation);
1267
1267
  for (i= 1, arg= &av[item_sep]; i < count; i++, arg++)
1283
1283
 
1284
1284
 
1285
1285
bool agg_item_collations_for_comparison(DTCollation &c, const char *fname,
1286
 
                                        Item **av, uint count, uint flags)
 
1286
                                        Item **av, uint32_t count, uint32_t flags)
1287
1287
{
1288
1288
  return (agg_item_collations(c, fname, av, count,
1289
1289
                              flags | MY_COLL_DISALLOW_NONE, 1));
1322
1322
*/
1323
1323
 
1324
1324
bool agg_item_charsets(DTCollation &coll, const char *fname,
1325
 
                       Item **args, uint nargs, uint flags, int item_sep)
 
1325
                       Item **args, uint32_t nargs, uint32_t flags, int item_sep)
1326
1326
{
1327
1327
  Item **arg, *safe_args[2];
1328
1328
 
1345
1345
  }
1346
1346
 
1347
1347
  THD *thd= current_thd;
1348
 
  Query_arena *arena, backup;
1349
1348
  bool res= false;
1350
 
  uint i;
1351
 
  /*
1352
 
    In case we're in statement prepare, create conversion item
1353
 
    in its memory: it will be reused on each execute.
1354
 
  */
1355
 
  arena= NULL;
 
1349
  uint32_t i;
1356
1350
 
1357
1351
  for (i= 0, arg= args; i < nargs; i++, arg+= item_sep)
1358
1352
  {
1398
1392
    */
1399
1393
    conv->fix_fields(thd, arg);
1400
1394
  }
1401
 
  if (arena)
1402
 
    thd->restore_active_arena(arena, &backup);
 
1395
 
1403
1396
  return res;
1404
1397
}
1405
1398
 
1420
1413
/**********************************************/
1421
1414
 
1422
1415
Item_field::Item_field(Field *f)
1423
 
  :Item_ident(0, NullS, *f->table_name, f->field_name),
 
1416
  :Item_ident(0, NULL, *f->table_name, f->field_name),
1424
1417
   item_equal(0), no_const_subst(0),
1425
1418
   have_privileges(0), any_privileges(0)
1426
1419
{
1520
1513
  {
1521
1514
    tmp=(char*) sql_alloc((uint) strlen(db_name)+(uint) strlen(table_name)+
1522
1515
                          (uint) strlen(field_name)+3);
1523
 
    strxmov(tmp,db_name,".",table_name,".",field_name,NullS);
 
1516
    strxmov(tmp,db_name,".",table_name,".",field_name,NULL);
1524
1517
  }
1525
1518
  else
1526
1519
  {
1528
1521
    {
1529
1522
      tmp= (char*) sql_alloc((uint) strlen(table_name) +
1530
1523
                             (uint) strlen(field_name) + 2);
1531
 
      strxmov(tmp, table_name, ".", field_name, NullS);
 
1524
      strxmov(tmp, table_name, ".", field_name, NULL);
1532
1525
    }
1533
1526
    else
1534
1527
      tmp= (char*) field_name;
1547
1540
  {
1548
1541
    if (table_name && table_name[0])
1549
1542
    {
1550
 
      stpcpy(t_name_buff, table_name);
 
1543
      my_stpcpy(t_name_buff, table_name);
1551
1544
      my_casedn_str(files_charset_info, t_name_buff);
1552
1545
      t_name= t_name_buff;
1553
1546
    }
1554
1547
    if (db_name && db_name[0])
1555
1548
    {
1556
 
      stpcpy(d_name_buff, db_name);
 
1549
      my_stpcpy(d_name_buff, db_name);
1557
1550
      my_casedn_str(files_charset_info, d_name_buff);
1558
1551
      d_name= d_name_buff;
1559
1552
    }
1634
1627
  return result_field->val_str(str,&str_value);
1635
1628
}
1636
1629
 
1637
 
bool Item_field::get_date(DRIZZLE_TIME *ltime,uint fuzzydate)
 
1630
bool Item_field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
1638
1631
{
1639
1632
  if ((null_value=field->is_null()) || field->get_date(ltime,fuzzydate))
1640
1633
  {
1644
1637
  return 0;
1645
1638
}
1646
1639
 
1647
 
bool Item_field::get_date_result(DRIZZLE_TIME *ltime,uint fuzzydate)
 
1640
bool Item_field::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
1648
1641
{
1649
1642
  if ((null_value=result_field->is_null()) ||
1650
1643
      result_field->get_date(ltime,fuzzydate))
1788
1781
  This is always 'signed'. Unsigned values are created with Item_uint()
1789
1782
*/
1790
1783
 
1791
 
Item_int::Item_int(const char *str_arg, uint length)
 
1784
Item_int::Item_int(const char *str_arg, uint32_t length)
1792
1785
{
1793
1786
  char *end_ptr= (char*) str_arg + length;
1794
1787
  int error;
1822
1815
}
1823
1816
 
1824
1817
 
1825
 
Item_uint::Item_uint(const char *str_arg, uint length):
 
1818
Item_uint::Item_uint(const char *str_arg, uint32_t length):
1826
1819
  Item_int(str_arg, length)
1827
1820
{
1828
1821
  unsigned_flag= 1;
1829
1822
}
1830
1823
 
1831
1824
 
1832
 
Item_uint::Item_uint(const char *str_arg, int64_t i, uint length):
 
1825
Item_uint::Item_uint(const char *str_arg, int64_t i, uint32_t length):
1833
1826
  Item_int(str_arg, i, length)
1834
1827
{
1835
1828
  unsigned_flag= 1;
1854
1847
}
1855
1848
 
1856
1849
 
1857
 
Item_decimal::Item_decimal(const char *str_arg, uint length,
 
1850
Item_decimal::Item_decimal(const char *str_arg, uint32_t length,
1858
1851
                           const CHARSET_INFO * const charset)
1859
1852
{
1860
1853
  str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
1888
1881
 
1889
1882
 
1890
1883
Item_decimal::Item_decimal(const char *str, const my_decimal *val_arg,
1891
 
                           uint decimal_par, uint length)
 
1884
                           uint32_t decimal_par, uint32_t length)
1892
1885
{
1893
1886
  my_decimal2decimal(val_arg, &decimal_value);
1894
1887
  name= (char*) str;
1908
1901
}
1909
1902
 
1910
1903
 
1911
 
Item_decimal::Item_decimal(const uchar *bin, int precision, int scale)
 
1904
Item_decimal::Item_decimal(const unsigned char *bin, int precision, int scale)
1912
1905
{
1913
1906
  binary2my_decimal(E_DEC_FATAL_ERROR, bin,
1914
1907
                    &decimal_value, precision, scale);
2143
2136
 
2144
2137
static void
2145
2138
default_set_param_func(Item_param *param,
2146
 
                       uchar **pos __attribute__((unused)),
 
2139
                       unsigned char **pos __attribute__((unused)),
2147
2140
                       ulong len __attribute__((unused)))
2148
2141
{
2149
2142
  param->set_null();
2150
2143
}
2151
2144
 
2152
2145
 
2153
 
Item_param::Item_param(uint pos_in_query_arg) :
 
2146
Item_param::Item_param(uint32_t pos_in_query_arg) :
2154
2147
  state(NO_VALUE),
2155
2148
  item_result_type(STRING_RESULT),
2156
2149
  /* Don't pretend to be a literal unless value for this item is set. */
2249
2242
    the fact that even wrong value sent over binary protocol fits into
2250
2243
    MAX_DATE_STRING_REP_LENGTH buffer.
2251
2244
*/
2252
 
void Item_param::set_time(DRIZZLE_TIME *tm, timestamp_type time_type,
 
2245
void Item_param::set_time(DRIZZLE_TIME *tm,
 
2246
                          enum enum_drizzle_timestamp_type time_type,
2253
2247
                          uint32_t max_length_arg)
2254
2248
2255
2249
  value.time= *tm;
2261
2255
      value.time.minute > 59 || value.time.second > 59)
2262
2256
  {
2263
2257
    char buff[MAX_DATE_STRING_REP_LENGTH];
2264
 
    uint length= my_TIME_to_str(&value.time, buff);
 
2258
    uint32_t length= my_TIME_to_str(&value.time, buff);
2265
2259
    make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2266
2260
                                 buff, length, time_type, 0);
2267
2261
    set_zero_time(&value.time, DRIZZLE_TIMESTAMP_ERROR);
2281
2275
    Assign string with no conversion: data is converted only after it's
2282
2276
    been written to the binary log.
2283
2277
  */
2284
 
  uint dummy_errors;
 
2278
  uint32_t dummy_errors;
2285
2279
  if (str_value.copy(str, length, &my_charset_bin, &my_charset_bin,
2286
2280
                     &dummy_errors))
2287
2281
    return(true);
2477
2471
}
2478
2472
 
2479
2473
 
2480
 
bool Item_param::get_date(DRIZZLE_TIME *res, uint fuzzydate)
 
2474
bool Item_param::get_date(DRIZZLE_TIME *res, uint32_t fuzzydate)
2481
2475
{
2482
2476
  if (state == TIME_VALUE)
2483
2477
  {
2899
2893
}
2900
2894
 
2901
2895
 
2902
 
bool Item_ref_null_helper::get_date(DRIZZLE_TIME *ltime, uint fuzzydate)
 
2896
bool Item_ref_null_helper::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate)
2903
2897
{  
2904
2898
  return (owner->was_null|= null_value= (*ref)->get_date(ltime, fuzzydate));
2905
2899
}
3156
3150
  Item **select_ref= NULL;
3157
3151
  order_st *group_list= (order_st*) select->group_list.first;
3158
3152
  bool ambiguous_fields= false;
3159
 
  uint counter;
 
3153
  uint32_t counter;
3160
3154
  enum_resolution_type resolution;
3161
3155
 
3162
3156
  /*
3573
3567
      /* Look up in current select's item_list to find aliased fields */
3574
3568
      if (thd->lex->current_select->is_item_list_lookup)
3575
3569
      {
3576
 
        uint counter;
 
3570
        uint32_t counter;
3577
3571
        enum_resolution_type resolution;
3578
3572
        Item** res= find_item_in_list(this, thd->lex->current_select->item_list,
3579
3573
                                      &counter, REPORT_EXCEPT_NOT_FOUND,
3793
3787
    false  otherwise
3794
3788
*/
3795
3789
 
3796
 
bool Item_field::subst_argument_checker(uchar **arg)
 
3790
bool Item_field::subst_argument_checker(unsigned char **arg)
3797
3791
{
3798
3792
  return (result_type() != STRING_RESULT) || (*arg);
3799
3793
}
3823
3817
    - pointer to the field item, otherwise.
3824
3818
*/
3825
3819
 
3826
 
Item *Item_field::equal_fields_propagator(uchar *arg)
 
3820
Item *Item_field::equal_fields_propagator(unsigned char *arg)
3827
3821
{
3828
3822
  if (no_const_subst)
3829
3823
    return this;
3856
3850
  See comments in Arg_comparator::set_compare_func() for details.
3857
3851
*/
3858
3852
 
3859
 
bool Item_field::set_no_const_sub(uchar *arg __attribute__((unused)))
 
3853
bool Item_field::set_no_const_sub(unsigned char *arg __attribute__((unused)))
3860
3854
{
3861
3855
  if (field->charset() != &my_charset_bin)
3862
3856
    no_const_subst=1;
3889
3883
    - this - otherwise.
3890
3884
*/
3891
3885
 
3892
 
Item *Item_field::replace_equal_field(uchar *arg __attribute__((unused)))
 
3886
Item *Item_field::replace_equal_field(unsigned char *arg __attribute__((unused)))
3893
3887
{
3894
3888
  if (item_equal)
3895
3889
  {
3985
3979
  /* Check whether we got a well-formed string */
3986
3980
  const CHARSET_INFO * const cs= str->charset();
3987
3981
  int well_formed_error;
3988
 
  uint wlen= cs->cset->well_formed_len(cs,
 
3982
  uint32_t wlen= cs->cset->well_formed_len(cs,
3989
3983
                                       str->ptr(), str->ptr() + str->length(),
3990
3984
                                       str->length(), &well_formed_error);
3991
3985
  if (wlen < str->length())
3993
3987
    THD *thd= current_thd;
3994
3988
    char hexbuf[7];
3995
3989
    enum DRIZZLE_ERROR::enum_warning_level level;
3996
 
    uint diff= str->length() - wlen;
 
3990
    uint32_t diff= str->length() - wlen;
3997
3991
    set_if_smaller(diff, 3);
3998
3992
    octet2hex(hexbuf, str->ptr() + wlen, diff);
3999
3993
    if (send_error)
4101
4095
  /*
4102
4096
    The field functions defines a field to be not null if null_ptr is not 0
4103
4097
  */
4104
 
  uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
 
4098
  unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
4105
4099
  Field *field;
4106
4100
 
4107
4101
  switch (field_type()) {
4108
4102
  case DRIZZLE_TYPE_NEWDECIMAL:
4109
 
    field= new Field_new_decimal((uchar*) 0, max_length, null_ptr, 0,
 
4103
    field= new Field_new_decimal((unsigned char*) 0, max_length, null_ptr, 0,
4110
4104
                                 Field::NONE, name, decimals, 0,
4111
4105
                                 unsigned_flag);
4112
4106
    break;
4113
4107
  case DRIZZLE_TYPE_TINY:
4114
 
    field= new Field_tiny((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4108
    field= new Field_tiny((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4115
4109
                          name, 0, unsigned_flag);
4116
4110
    break;
4117
 
  case DRIZZLE_TYPE_SHORT:
4118
 
    field= new Field_short((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
4119
 
                           name, 0, unsigned_flag);
4120
 
    break;
4121
4111
  case DRIZZLE_TYPE_LONG:
4122
 
    field= new Field_long((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4112
    field= new Field_long((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4123
4113
                          name, 0, unsigned_flag);
4124
4114
    break;
4125
4115
  case DRIZZLE_TYPE_LONGLONG:
4126
 
    field= new Field_int64_t((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4116
    field= new Field_int64_t((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4127
4117
                              name, 0, unsigned_flag);
4128
4118
    break;
4129
4119
  case DRIZZLE_TYPE_DOUBLE:
4130
 
    field= new Field_double((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
 
4120
    field= new Field_double((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE,
4131
4121
                            name, decimals, 0, unsigned_flag);
4132
4122
    break;
4133
4123
  case DRIZZLE_TYPE_NULL:
4134
 
    field= new Field_null((uchar*) 0, max_length, Field::NONE,
 
4124
    field= new Field_null((unsigned char*) 0, max_length, Field::NONE,
4135
4125
                          name, &my_charset_bin);
4136
4126
    break;
4137
4127
  case DRIZZLE_TYPE_NEWDATE:
4393
4383
}
4394
4384
 
4395
4385
 
4396
 
static uint nr_of_decimals(const char *str, const char *end)
 
4386
static uint32_t nr_of_decimals(const char *str, const char *end)
4397
4387
{
4398
4388
  const char *decimal_point;
4399
4389
 
4421
4411
  value is not a true double value (overflow)
4422
4412
*/
4423
4413
 
4424
 
Item_float::Item_float(const char *str_arg, uint length)
 
4414
Item_float::Item_float(const char *str_arg, uint32_t length)
4425
4415
{
4426
4416
  int error;
4427
4417
  char *end_not_used;
4491
4481
}
4492
4482
 
4493
4483
 
4494
 
inline uint char_val(char X)
 
4484
inline uint32_t char_val(char X)
4495
4485
{
4496
4486
  return (uint) (X >= '0' && X <= '9' ? X-'0' :
4497
4487
                 X >= 'A' && X <= 'Z' ? X-'A'+10 :
4499
4489
}
4500
4490
 
4501
4491
 
4502
 
Item_hex_string::Item_hex_string(const char *str, uint str_length)
 
4492
Item_hex_string::Item_hex_string(const char *str, uint32_t str_length)
4503
4493
{
4504
4494
  max_length=(str_length+1)/2;
4505
4495
  char *ptr=(char*) sql_alloc(max_length+1);
4525
4515
  // following assert is redundant, because fixed=1 assigned in constructor
4526
4516
  assert(fixed == 1);
4527
4517
  char *end=(char*) str_value.ptr()+str_value.length(),
4528
 
       *ptr=end-min(str_value.length(),(uint32_t)sizeof(int64_t));
 
4518
       *ptr=end-cmin(str_value.length(),(uint32_t)sizeof(int64_t));
4529
4519
 
4530
4520
  uint64_t value=0;
4531
4521
  for (; ptr != end ; ptr++)
4532
 
    value=(value << 8)+ (uint64_t) (uchar) *ptr;
 
4522
    value=(value << 8)+ (uint64_t) (unsigned char) *ptr;
4533
4523
  return (int64_t) value;
4534
4524
}
4535
4525
 
4579
4569
                            enum_query_type query_type __attribute__((unused)))
4580
4570
{
4581
4571
  char *end= (char*) str_value.ptr() + str_value.length(),
4582
 
       *ptr= end - min(str_value.length(), (uint32_t)sizeof(int64_t));
 
4572
       *ptr= end - cmin(str_value.length(), (uint32_t)sizeof(int64_t));
4583
4573
  str->append("0x");
4584
4574
  for (; ptr != end ; ptr++)
4585
4575
  {
4586
 
    str->append(_dig_vec_lower[((uchar) *ptr) >> 4]);
4587
 
    str->append(_dig_vec_lower[((uchar) *ptr) & 0x0F]);
 
4576
    str->append(_dig_vec_lower[((unsigned char) *ptr) >> 4]);
 
4577
    str->append(_dig_vec_lower[((unsigned char) *ptr) & 0x0F]);
4588
4578
  }
4589
4579
}
4590
4580
 
4620
4610
  In number context this is a int64_t value.
4621
4611
*/
4622
4612
  
4623
 
Item_bin_string::Item_bin_string(const char *str, uint str_length)
 
4613
Item_bin_string::Item_bin_string(const char *str, uint32_t str_length)
4624
4614
{
4625
4615
  const char *end= str + str_length - 1;
4626
 
  uchar bits= 0;
4627
 
  uint power= 1;
 
4616
  unsigned char bits= 0;
 
4617
  uint32_t power= 1;
4628
4618
 
4629
4619
  max_length= (str_length + 7) >> 3;
4630
4620
  char *ptr= (char*) sql_alloc(max_length + 1);
4691
4681
      result= protocol->store_tiny(nr);
4692
4682
    break;
4693
4683
  }
4694
 
  case DRIZZLE_TYPE_SHORT:
4695
 
  {
4696
 
    int64_t nr;
4697
 
    nr= val_int();
4698
 
    if (!null_value)
4699
 
      result= protocol->store_short(nr);
4700
 
    break;
4701
 
  }
4702
4684
  case DRIZZLE_TYPE_LONG:
4703
4685
  {
4704
4686
    int64_t nr;
4796
4778
    this field    otherwise
4797
4779
*/
4798
4780
 
4799
 
Item *Item_field::update_value_transformer(uchar *select_arg)
 
4781
Item *Item_field::update_value_transformer(unsigned char *select_arg)
4800
4782
{
4801
4783
  SELECT_LEX *select= (SELECT_LEX*)select_arg;
4802
4784
  assert(fixed);
4838
4820
                   Item **item, const char *table_name_arg,
4839
4821
                   const char *field_name_arg,
4840
4822
                   bool alias_name_used_arg)
4841
 
  :Item_ident(context_arg, NullS, table_name_arg, field_name_arg),
 
4823
  :Item_ident(context_arg, NULL, table_name_arg, field_name_arg),
4842
4824
   result_field(0), ref(item)
4843
4825
{
4844
4826
  alias_name_used= alias_name_used_arg;
5319
5301
}
5320
5302
 
5321
5303
 
5322
 
bool Item_ref::get_date(DRIZZLE_TIME *ltime,uint fuzzydate)
 
5304
bool Item_ref::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
5323
5305
{
5324
5306
  return (null_value=(*ref)->get_date_result(ltime,fuzzydate));
5325
5307
}
5433
5415
}
5434
5416
 
5435
5417
 
5436
 
bool Item_direct_ref::get_date(DRIZZLE_TIME *ltime,uint fuzzydate)
 
5418
bool Item_direct_ref::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
5437
5419
{
5438
5420
  return (null_value=(*ref)->get_date(ltime,fuzzydate));
5439
5421
}
5639
5621
  same time it can replace some nodes in the tree.
5640
5622
*/ 
5641
5623
 
5642
 
Item *Item_default_value::transform(Item_transformer transformer, uchar *args)
 
5624
Item *Item_default_value::transform(Item_transformer transformer, unsigned char *args)
5643
5625
{
5644
5626
  Item *new_item= arg->transform(transformer, args);
5645
5627
  if (!new_item)
5767
5749
      new_item= new Item_null(name);
5768
5750
    else
5769
5751
    {
5770
 
      uint length= result->length();
 
5752
      uint32_t length= result->length();
5771
5753
      char *tmp_str= sql_strmake(result->ptr(), length);
5772
5754
      new_item= new Item_string(name, tmp_str, length, result->charset());
5773
5755
    }
5776
5758
  case INT_RESULT:
5777
5759
  {
5778
5760
    int64_t result=item->val_int();
5779
 
    uint length=item->max_length;
 
5761
    uint32_t length=item->max_length;
5780
5762
    bool null_value=item->null_value;
5781
5763
    new_item= (null_value ? (Item*) new Item_null(name) :
5782
5764
               (Item*) new Item_int(name, result, length));
5795
5777
    */
5796
5778
    Item_row *item_row= (Item_row*) item;
5797
5779
    Item_row *comp_item_row= (Item_row*) comp_item;
5798
 
    uint col;
 
5780
    uint32_t col;
5799
5781
    new_item= 0;
5800
5782
    /*
5801
5783
      If item and comp_item are both Item_rows and have same number of cols
5815
5797
  case REAL_RESULT:
5816
5798
  {                                             // It must REAL_RESULT
5817
5799
    double result= item->val_real();
5818
 
    uint length=item->max_length,decimals=item->decimals;
 
5800
    uint32_t length=item->max_length,decimals=item->decimals;
5819
5801
    bool null_value=item->null_value;
5820
5802
    new_item= (null_value ? (Item*) new Item_null(name) : (Item*)
5821
5803
               new Item_float(name, result, decimals, length));
5825
5807
  {
5826
5808
    my_decimal decimal_value;
5827
5809
    my_decimal *result= item->val_decimal(&decimal_value);
5828
 
    uint length= item->max_length, decimals= item->decimals;
 
5810
    uint32_t length= item->max_length, decimals= item->decimals;
5829
5811
    bool null_value= item->null_value;
5830
5812
    new_item= (null_value ?
5831
5813
               (Item*) new Item_null(name) :
6078
6060
}
6079
6061
 
6080
6062
 
6081
 
bool Item_cache_row::allocate(uint num)
 
6063
bool Item_cache_row::allocate(uint32_t num)
6082
6064
{
6083
6065
  item_count= num;
6084
6066
  THD *thd= current_thd;
6092
6074
  example= item;
6093
6075
  if (!values && allocate(item->cols()))
6094
6076
    return 1;
6095
 
  for (uint i= 0; i < item_count; i++)
 
6077
  for (uint32_t i= 0; i < item_count; i++)
6096
6078
  {
6097
6079
    Item *el= item->element_index(i);
6098
6080
    Item_cache *tmp;
6108
6090
{
6109
6091
  null_value= 0;
6110
6092
  item->bring_value();
6111
 
  for (uint i= 0; i < item_count; i++)
 
6093
  for (uint32_t i= 0; i < item_count; i++)
6112
6094
  {
6113
6095
    values[i]->store(item->element_index(i));
6114
6096
    null_value|= values[i]->null_value;
6124
6106
}
6125
6107
 
6126
6108
 
6127
 
bool Item_cache_row::check_cols(uint c)
 
6109
bool Item_cache_row::check_cols(uint32_t c)
6128
6110
{
6129
6111
  if (c != item_count)
6130
6112
  {
6137
6119
 
6138
6120
bool Item_cache_row::null_inside()
6139
6121
{
6140
 
  for (uint i= 0; i < item_count; i++)
 
6122
  for (uint32_t i= 0; i < item_count; i++)
6141
6123
  {
6142
6124
    if (values[i]->cols() > 1)
6143
6125
    {
6157
6139
 
6158
6140
void Item_cache_row::bring_value()
6159
6141
{
6160
 
  for (uint i= 0; i < item_count; i++)
 
6142
  for (uint32_t i= 0; i < item_count; i++)
6161
6143
    values[i]->bring_value();
6162
6144
  return;
6163
6145
}
6271
6253
bool Item_type_holder::join_types(THD *thd __attribute__((unused)),
6272
6254
                                  Item *item)
6273
6255
{
6274
 
  uint max_length_orig= max_length;
6275
 
  uint decimals_orig= decimals;
 
6256
  uint32_t max_length_orig= max_length;
 
6257
  uint32_t decimals_orig= decimals;
6276
6258
  fld_type= Field::field_type_merge(fld_type, get_real_type(item));
6277
6259
  {
6278
6260
    int item_decimals= item->decimals;
6279
6261
    /* fix variable decimals which always is NOT_FIXED_DEC */
6280
6262
    if (Field::result_merge_type(fld_type) == INT_RESULT)
6281
6263
      item_decimals= 0;
6282
 
    decimals= max((int)decimals, item_decimals);
 
6264
    decimals= cmax((int)decimals, item_decimals);
6283
6265
  }
6284
6266
  if (Field::result_merge_type(fld_type) == DECIMAL_RESULT)
6285
6267
  {
6286
 
    decimals= min((int)max(decimals, item->decimals), DECIMAL_MAX_SCALE);
6287
 
    int precision= min(max(prev_decimal_int_part, item->decimal_int_part())
 
6268
    decimals= cmin((int)cmax(decimals, item->decimals), DECIMAL_MAX_SCALE);
 
6269
    int precision= cmin(cmax(prev_decimal_int_part, item->decimal_int_part())
6288
6270
                       + decimals, DECIMAL_MAX_PRECISION);
6289
6271
    unsigned_flag&= item->unsigned_flag;
6290
6272
    max_length= my_decimal_precision_to_length(precision, decimals,
6315
6297
     */
6316
6298
    if (collation.collation != &my_charset_bin)
6317
6299
    {
6318
 
      max_length= max(old_max_chars * collation.collation->mbmaxlen,
 
6300
      max_length= cmax(old_max_chars * collation.collation->mbmaxlen,
6319
6301
                      display_length(item) /
6320
6302
                      item->collation.collation->mbmaxlen *
6321
6303
                      collation.collation->mbmaxlen);
6330
6312
    {
6331
6313
      int delta1= max_length_orig - decimals_orig;
6332
6314
      int delta2= item->max_length - item->decimals;
6333
 
      max_length= max(delta1, delta2) + decimals;
 
6315
      max_length= cmax(delta1, delta2) + decimals;
6334
6316
      if (fld_type == DRIZZLE_TYPE_DOUBLE && max_length > DBL_DIG + 2) 
6335
6317
      {
6336
6318
        max_length= DBL_DIG + 7;
6342
6324
    break;
6343
6325
  }
6344
6326
  default:
6345
 
    max_length= max(max_length, display_length(item));
 
6327
    max_length= cmax(max_length, display_length(item));
6346
6328
  };
6347
6329
  maybe_null|= item->maybe_null;
6348
6330
  get_full_info(item);
6378
6360
  case DRIZZLE_TYPE_BLOB:
6379
6361
  case DRIZZLE_TYPE_TINY:
6380
6362
    return 4;
6381
 
  case DRIZZLE_TYPE_SHORT:
6382
 
    return 6;
6383
6363
  case DRIZZLE_TYPE_LONG:
6384
6364
    return MY_INT32_NUM_DECIMAL_DIGITS;
6385
6365
  case DRIZZLE_TYPE_DOUBLE:
6410
6390
  /*
6411
6391
    The field functions defines a field to be not null if null_ptr is not 0
6412
6392
  */
6413
 
  uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
 
6393
  unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0;
6414
6394
  Field *field;
6415
6395
 
6416
6396
  switch (fld_type) {
6417
6397
  case DRIZZLE_TYPE_ENUM:
6418
6398
    assert(enum_set_typelib);
6419
 
    field= new Field_enum((uchar *) 0, max_length, null_ptr, 0,
 
6399
    field= new Field_enum((unsigned char *) 0, max_length, null_ptr, 0,
6420
6400
                          Field::NONE, name,
6421
6401
                          get_enum_pack_length(enum_set_typelib->count),
6422
6402
                          enum_set_typelib, collation.collation);