~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.cc

Merged uint fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
670
670
}
671
671
 
672
672
 
673
 
bool Item::check_cols(uint c)
 
673
bool Item::check_cols(uint32_t c)
674
674
{
675
675
  if (c != 1)
676
676
  {
681
681
}
682
682
 
683
683
 
684
 
void Item::set_name(const char *str, uint length, const CHARSET_INFO * const cs)
 
684
void Item::set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs)
685
685
{
686
686
  if (!length)
687
687
  {
692
692
  }
693
693
  if (cs->ctype)
694
694
  {
695
 
    uint orig_len= length;
 
695
    uint32_t orig_len= length;
696
696
    /*
697
697
      This will probably need a better implementation in the future:
698
698
      a function in CHARSET_INFO structure.
797
797
Item *Item_string::safe_charset_converter(const CHARSET_INFO * const tocs)
798
798
{
799
799
  Item_string *conv;
800
 
  uint conv_errors;
 
800
  uint32_t conv_errors;
801
801
  char *ptr;
802
802
  String tmp, cstr, *ostr= val_str(&tmp);
803
803
  cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
826
826
{
827
827
  if (const_item())
828
828
  {
829
 
    uint cnv_errors;
 
829
    uint32_t cnv_errors;
830
830
    String *ostr= val_str(&cnvstr);
831
831
    cnvitem->str_value.copy(ostr->ptr(), ostr->length(),
832
832
                            ostr->charset(), tocs, &cnv_errors);
843
843
Item *Item_static_string_func::safe_charset_converter(const CHARSET_INFO * const tocs)
844
844
{
845
845
  Item_string *conv;
846
 
  uint conv_errors;
 
846
  uint32_t conv_errors;
847
847
  String tmp, cstr, *ostr= val_str(&tmp);
848
848
  cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
849
849
  if (conv_errors ||
885
885
  As a extra convenience the time structure is reset on error!
886
886
*/
887
887
 
888
 
bool Item::get_date(DRIZZLE_TIME *ltime,uint fuzzydate)
 
888
bool Item::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
889
889
{
890
890
  if (result_type() == STRING_RESULT)
891
891
  {
1039
1039
      Item_ref to allow fields from view being stored in tmp table.
1040
1040
    */
1041
1041
    Item_aggregate_ref *item_ref;
1042
 
    uint el= fields.elements;
 
1042
    uint32_t el= fields.elements;
1043
1043
    Item *real_itm= real_item();
1044
1044
 
1045
1045
    ref_pointer_array[el]= real_itm;
1109
1109
  @endcode
1110
1110
*/
1111
1111
 
1112
 
bool DTCollation::aggregate(DTCollation &dt, uint flags)
 
1112
bool DTCollation::aggregate(DTCollation &dt, uint32_t flags)
1113
1113
{
1114
1114
  if (!my_charset_same(collation, dt.collation))
1115
1115
  {
1229
1229
 
1230
1230
 
1231
1231
static
1232
 
void my_coll_agg_error(Item** args, uint count, const char *fname,
 
1232
void my_coll_agg_error(Item** args, uint32_t count, const char *fname,
1233
1233
                       int item_sep)
1234
1234
{
1235
1235
  if (count == 2)
1243
1243
 
1244
1244
 
1245
1245
bool agg_item_collations(DTCollation &c, const char *fname,
1246
 
                         Item **av, uint count, uint flags, int item_sep)
 
1246
                         Item **av, uint32_t count, uint32_t flags, int item_sep)
1247
1247
{
1248
 
  uint i;
 
1248
  uint32_t i;
1249
1249
  Item **arg;
1250
1250
  c.set(av[0]->collation);
1251
1251
  for (i= 1, arg= &av[item_sep]; i < count; i++, arg++)
1267
1267
 
1268
1268
 
1269
1269
bool agg_item_collations_for_comparison(DTCollation &c, const char *fname,
1270
 
                                        Item **av, uint count, uint flags)
 
1270
                                        Item **av, uint32_t count, uint32_t flags)
1271
1271
{
1272
1272
  return (agg_item_collations(c, fname, av, count,
1273
1273
                              flags | MY_COLL_DISALLOW_NONE, 1));
1306
1306
*/
1307
1307
 
1308
1308
bool agg_item_charsets(DTCollation &coll, const char *fname,
1309
 
                       Item **args, uint nargs, uint flags, int item_sep)
 
1309
                       Item **args, uint32_t nargs, uint32_t flags, int item_sep)
1310
1310
{
1311
1311
  Item **arg, *safe_args[2];
1312
1312
 
1330
1330
 
1331
1331
  THD *thd= current_thd;
1332
1332
  bool res= false;
1333
 
  uint i;
 
1333
  uint32_t i;
1334
1334
 
1335
1335
  for (i= 0, arg= args; i < nargs; i++, arg+= item_sep)
1336
1336
  {
1611
1611
  return result_field->val_str(str,&str_value);
1612
1612
}
1613
1613
 
1614
 
bool Item_field::get_date(DRIZZLE_TIME *ltime,uint fuzzydate)
 
1614
bool Item_field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
1615
1615
{
1616
1616
  if ((null_value=field->is_null()) || field->get_date(ltime,fuzzydate))
1617
1617
  {
1621
1621
  return 0;
1622
1622
}
1623
1623
 
1624
 
bool Item_field::get_date_result(DRIZZLE_TIME *ltime,uint fuzzydate)
 
1624
bool Item_field::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
1625
1625
{
1626
1626
  if ((null_value=result_field->is_null()) ||
1627
1627
      result_field->get_date(ltime,fuzzydate))
1765
1765
  This is always 'signed'. Unsigned values are created with Item_uint()
1766
1766
*/
1767
1767
 
1768
 
Item_int::Item_int(const char *str_arg, uint length)
 
1768
Item_int::Item_int(const char *str_arg, uint32_t length)
1769
1769
{
1770
1770
  char *end_ptr= (char*) str_arg + length;
1771
1771
  int error;
1799
1799
}
1800
1800
 
1801
1801
 
1802
 
Item_uint::Item_uint(const char *str_arg, uint length):
 
1802
Item_uint::Item_uint(const char *str_arg, uint32_t length):
1803
1803
  Item_int(str_arg, length)
1804
1804
{
1805
1805
  unsigned_flag= 1;
1806
1806
}
1807
1807
 
1808
1808
 
1809
 
Item_uint::Item_uint(const char *str_arg, int64_t i, uint length):
 
1809
Item_uint::Item_uint(const char *str_arg, int64_t i, uint32_t length):
1810
1810
  Item_int(str_arg, i, length)
1811
1811
{
1812
1812
  unsigned_flag= 1;
1831
1831
}
1832
1832
 
1833
1833
 
1834
 
Item_decimal::Item_decimal(const char *str_arg, uint length,
 
1834
Item_decimal::Item_decimal(const char *str_arg, uint32_t length,
1835
1835
                           const CHARSET_INFO * const charset)
1836
1836
{
1837
1837
  str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
1865
1865
 
1866
1866
 
1867
1867
Item_decimal::Item_decimal(const char *str, const my_decimal *val_arg,
1868
 
                           uint decimal_par, uint length)
 
1868
                           uint32_t decimal_par, uint32_t length)
1869
1869
{
1870
1870
  my_decimal2decimal(val_arg, &decimal_value);
1871
1871
  name= (char*) str;
2127
2127
}
2128
2128
 
2129
2129
 
2130
 
Item_param::Item_param(uint pos_in_query_arg) :
 
2130
Item_param::Item_param(uint32_t pos_in_query_arg) :
2131
2131
  state(NO_VALUE),
2132
2132
  item_result_type(STRING_RESULT),
2133
2133
  /* Don't pretend to be a literal unless value for this item is set. */
2239
2239
      value.time.minute > 59 || value.time.second > 59)
2240
2240
  {
2241
2241
    char buff[MAX_DATE_STRING_REP_LENGTH];
2242
 
    uint length= my_TIME_to_str(&value.time, buff);
 
2242
    uint32_t length= my_TIME_to_str(&value.time, buff);
2243
2243
    make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2244
2244
                                 buff, length, time_type, 0);
2245
2245
    set_zero_time(&value.time, DRIZZLE_TIMESTAMP_ERROR);
2259
2259
    Assign string with no conversion: data is converted only after it's
2260
2260
    been written to the binary log.
2261
2261
  */
2262
 
  uint dummy_errors;
 
2262
  uint32_t dummy_errors;
2263
2263
  if (str_value.copy(str, length, &my_charset_bin, &my_charset_bin,
2264
2264
                     &dummy_errors))
2265
2265
    return(true);
2455
2455
}
2456
2456
 
2457
2457
 
2458
 
bool Item_param::get_date(DRIZZLE_TIME *res, uint fuzzydate)
 
2458
bool Item_param::get_date(DRIZZLE_TIME *res, uint32_t fuzzydate)
2459
2459
{
2460
2460
  if (state == TIME_VALUE)
2461
2461
  {
2877
2877
}
2878
2878
 
2879
2879
 
2880
 
bool Item_ref_null_helper::get_date(DRIZZLE_TIME *ltime, uint fuzzydate)
 
2880
bool Item_ref_null_helper::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate)
2881
2881
{  
2882
2882
  return (owner->was_null|= null_value= (*ref)->get_date(ltime, fuzzydate));
2883
2883
}
3134
3134
  Item **select_ref= NULL;
3135
3135
  order_st *group_list= (order_st*) select->group_list.first;
3136
3136
  bool ambiguous_fields= false;
3137
 
  uint counter;
 
3137
  uint32_t counter;
3138
3138
  enum_resolution_type resolution;
3139
3139
 
3140
3140
  /*
3551
3551
      /* Look up in current select's item_list to find aliased fields */
3552
3552
      if (thd->lex->current_select->is_item_list_lookup)
3553
3553
      {
3554
 
        uint counter;
 
3554
        uint32_t counter;
3555
3555
        enum_resolution_type resolution;
3556
3556
        Item** res= find_item_in_list(this, thd->lex->current_select->item_list,
3557
3557
                                      &counter, REPORT_EXCEPT_NOT_FOUND,
3963
3963
  /* Check whether we got a well-formed string */
3964
3964
  const CHARSET_INFO * const cs= str->charset();
3965
3965
  int well_formed_error;
3966
 
  uint wlen= cs->cset->well_formed_len(cs,
 
3966
  uint32_t wlen= cs->cset->well_formed_len(cs,
3967
3967
                                       str->ptr(), str->ptr() + str->length(),
3968
3968
                                       str->length(), &well_formed_error);
3969
3969
  if (wlen < str->length())
3971
3971
    THD *thd= current_thd;
3972
3972
    char hexbuf[7];
3973
3973
    enum DRIZZLE_ERROR::enum_warning_level level;
3974
 
    uint diff= str->length() - wlen;
 
3974
    uint32_t diff= str->length() - wlen;
3975
3975
    set_if_smaller(diff, 3);
3976
3976
    octet2hex(hexbuf, str->ptr() + wlen, diff);
3977
3977
    if (send_error)
4367
4367
}
4368
4368
 
4369
4369
 
4370
 
static uint nr_of_decimals(const char *str, const char *end)
 
4370
static uint32_t nr_of_decimals(const char *str, const char *end)
4371
4371
{
4372
4372
  const char *decimal_point;
4373
4373
 
4395
4395
  value is not a true double value (overflow)
4396
4396
*/
4397
4397
 
4398
 
Item_float::Item_float(const char *str_arg, uint length)
 
4398
Item_float::Item_float(const char *str_arg, uint32_t length)
4399
4399
{
4400
4400
  int error;
4401
4401
  char *end_not_used;
4465
4465
}
4466
4466
 
4467
4467
 
4468
 
inline uint char_val(char X)
 
4468
inline uint32_t char_val(char X)
4469
4469
{
4470
4470
  return (uint) (X >= '0' && X <= '9' ? X-'0' :
4471
4471
                 X >= 'A' && X <= 'Z' ? X-'A'+10 :
4473
4473
}
4474
4474
 
4475
4475
 
4476
 
Item_hex_string::Item_hex_string(const char *str, uint str_length)
 
4476
Item_hex_string::Item_hex_string(const char *str, uint32_t str_length)
4477
4477
{
4478
4478
  max_length=(str_length+1)/2;
4479
4479
  char *ptr=(char*) sql_alloc(max_length+1);
4594
4594
  In number context this is a int64_t value.
4595
4595
*/
4596
4596
  
4597
 
Item_bin_string::Item_bin_string(const char *str, uint str_length)
 
4597
Item_bin_string::Item_bin_string(const char *str, uint32_t str_length)
4598
4598
{
4599
4599
  const char *end= str + str_length - 1;
4600
4600
  unsigned char bits= 0;
4601
 
  uint power= 1;
 
4601
  uint32_t power= 1;
4602
4602
 
4603
4603
  max_length= (str_length + 7) >> 3;
4604
4604
  char *ptr= (char*) sql_alloc(max_length + 1);
5285
5285
}
5286
5286
 
5287
5287
 
5288
 
bool Item_ref::get_date(DRIZZLE_TIME *ltime,uint fuzzydate)
 
5288
bool Item_ref::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
5289
5289
{
5290
5290
  return (null_value=(*ref)->get_date_result(ltime,fuzzydate));
5291
5291
}
5399
5399
}
5400
5400
 
5401
5401
 
5402
 
bool Item_direct_ref::get_date(DRIZZLE_TIME *ltime,uint fuzzydate)
 
5402
bool Item_direct_ref::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
5403
5403
{
5404
5404
  return (null_value=(*ref)->get_date(ltime,fuzzydate));
5405
5405
}
5733
5733
      new_item= new Item_null(name);
5734
5734
    else
5735
5735
    {
5736
 
      uint length= result->length();
 
5736
      uint32_t length= result->length();
5737
5737
      char *tmp_str= sql_strmake(result->ptr(), length);
5738
5738
      new_item= new Item_string(name, tmp_str, length, result->charset());
5739
5739
    }
5742
5742
  case INT_RESULT:
5743
5743
  {
5744
5744
    int64_t result=item->val_int();
5745
 
    uint length=item->max_length;
 
5745
    uint32_t length=item->max_length;
5746
5746
    bool null_value=item->null_value;
5747
5747
    new_item= (null_value ? (Item*) new Item_null(name) :
5748
5748
               (Item*) new Item_int(name, result, length));
5761
5761
    */
5762
5762
    Item_row *item_row= (Item_row*) item;
5763
5763
    Item_row *comp_item_row= (Item_row*) comp_item;
5764
 
    uint col;
 
5764
    uint32_t col;
5765
5765
    new_item= 0;
5766
5766
    /*
5767
5767
      If item and comp_item are both Item_rows and have same number of cols
5781
5781
  case REAL_RESULT:
5782
5782
  {                                             // It must REAL_RESULT
5783
5783
    double result= item->val_real();
5784
 
    uint length=item->max_length,decimals=item->decimals;
 
5784
    uint32_t length=item->max_length,decimals=item->decimals;
5785
5785
    bool null_value=item->null_value;
5786
5786
    new_item= (null_value ? (Item*) new Item_null(name) : (Item*)
5787
5787
               new Item_float(name, result, decimals, length));
5791
5791
  {
5792
5792
    my_decimal decimal_value;
5793
5793
    my_decimal *result= item->val_decimal(&decimal_value);
5794
 
    uint length= item->max_length, decimals= item->decimals;
 
5794
    uint32_t length= item->max_length, decimals= item->decimals;
5795
5795
    bool null_value= item->null_value;
5796
5796
    new_item= (null_value ?
5797
5797
               (Item*) new Item_null(name) :
6044
6044
}
6045
6045
 
6046
6046
 
6047
 
bool Item_cache_row::allocate(uint num)
 
6047
bool Item_cache_row::allocate(uint32_t num)
6048
6048
{
6049
6049
  item_count= num;
6050
6050
  THD *thd= current_thd;
6058
6058
  example= item;
6059
6059
  if (!values && allocate(item->cols()))
6060
6060
    return 1;
6061
 
  for (uint i= 0; i < item_count; i++)
 
6061
  for (uint32_t i= 0; i < item_count; i++)
6062
6062
  {
6063
6063
    Item *el= item->element_index(i);
6064
6064
    Item_cache *tmp;
6074
6074
{
6075
6075
  null_value= 0;
6076
6076
  item->bring_value();
6077
 
  for (uint i= 0; i < item_count; i++)
 
6077
  for (uint32_t i= 0; i < item_count; i++)
6078
6078
  {
6079
6079
    values[i]->store(item->element_index(i));
6080
6080
    null_value|= values[i]->null_value;
6090
6090
}
6091
6091
 
6092
6092
 
6093
 
bool Item_cache_row::check_cols(uint c)
 
6093
bool Item_cache_row::check_cols(uint32_t c)
6094
6094
{
6095
6095
  if (c != item_count)
6096
6096
  {
6103
6103
 
6104
6104
bool Item_cache_row::null_inside()
6105
6105
{
6106
 
  for (uint i= 0; i < item_count; i++)
 
6106
  for (uint32_t i= 0; i < item_count; i++)
6107
6107
  {
6108
6108
    if (values[i]->cols() > 1)
6109
6109
    {
6123
6123
 
6124
6124
void Item_cache_row::bring_value()
6125
6125
{
6126
 
  for (uint i= 0; i < item_count; i++)
 
6126
  for (uint32_t i= 0; i < item_count; i++)
6127
6127
    values[i]->bring_value();
6128
6128
  return;
6129
6129
}
6237
6237
bool Item_type_holder::join_types(THD *thd __attribute__((unused)),
6238
6238
                                  Item *item)
6239
6239
{
6240
 
  uint max_length_orig= max_length;
6241
 
  uint decimals_orig= decimals;
 
6240
  uint32_t max_length_orig= max_length;
 
6241
  uint32_t decimals_orig= decimals;
6242
6242
  fld_type= Field::field_type_merge(fld_type, get_real_type(item));
6243
6243
  {
6244
6244
    int item_decimals= item->decimals;