~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

  • Committer: Brian Aker
  • Date: 2008-10-06 03:55:31 UTC
  • mto: This revision was merged to the branch mainline in revision 479.
  • Revision ID: brian@gir.tangent.org-20081006035531-ade3cc3kfwutd35g
uint cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
587
587
    1   error
588
588
*/
589
589
 
590
 
bool Field_num::get_int(const CHARSET_INFO * const cs, const char *from, uint len,
 
590
bool Field_num::get_int(const CHARSET_INFO * const cs, const char *from, uint32_t len,
591
591
                        int64_t *rnd, uint64_t unsigned_max, 
592
592
                        int64_t signed_min, int64_t signed_max)
593
593
{
721
721
String *Field::val_int_as_str(String *val_buffer, bool unsigned_val)
722
722
{
723
723
  const CHARSET_INFO * const cs= &my_charset_bin;
724
 
  uint length;
 
724
  uint32_t length;
725
725
  int64_t value= val_int();
726
726
 
727
727
  if (val_buffer->alloc(MY_INT64_NUM_DECIMAL_DIGITS))
728
728
    return 0;
729
 
  length= (uint) (*cs->cset->int64_t10_to_str)(cs, (char*) val_buffer->ptr(),
 
729
  length= (uint32_t) (*cs->cset->int64_t10_to_str)(cs, (char*) val_buffer->ptr(),
730
730
                                                MY_INT64_NUM_DECIMAL_DIGITS,
731
731
                                                unsigned_val ? 10 : -10,
732
732
                                                value);
762
762
  }
763
763
  else
764
764
  {
765
 
    uint len= pack_length();
 
765
    uint32_t len= pack_length();
766
766
    const CHARSET_INFO * const cs= charset();
767
767
    cs->coll->hash_sort(cs, ptr, len, nr, nr2);
768
768
  }
783
783
  memcpy(ptr,ptr+row_offset,pack_length());
784
784
  if (null_ptr)
785
785
  {
786
 
    *null_ptr= (uchar) ((null_ptr[0] & (uchar) ~(uint) null_bit) | (null_ptr[row_offset] & (uchar) null_bit));
 
786
    *null_ptr= (uchar) ((null_ptr[0] & (uchar) ~(uint32_t) null_bit) | (null_ptr[row_offset] & (uchar) null_bit));
787
787
  }
788
788
}
789
789
 
810
810
   @retval 0 if this field's size is < the source field's size
811
811
   @retval 1 if this field's size is >= the source field's size
812
812
*/
813
 
int Field::compatible_field_size(uint field_metadata)
 
813
int Field::compatible_field_size(uint32_t field_metadata)
814
814
{
815
 
  uint const source_size= pack_length_from_metadata(field_metadata);
816
 
  uint const destination_size= row_pack_length();
 
815
  uint32_t const source_size= pack_length_from_metadata(field_metadata);
 
816
  uint32_t const destination_size= row_pack_length();
817
817
  return (source_size <= destination_size);
818
818
}
819
819
 
820
820
 
821
 
int Field::store(const char *to, uint length, const CHARSET_INFO * const cs,
 
821
int Field::store(const char *to, uint32_t length, const CHARSET_INFO * const cs,
822
822
                 enum_check_fields check_level)
823
823
{
824
824
  int res;
868
868
   little-endian.
869
869
*/
870
870
uchar *
871
 
Field::pack(uchar *to, const uchar *from, uint max_length,
 
871
Field::pack(uchar *to, const uchar *from, uint32_t max_length,
872
872
            bool low_byte_first __attribute__((unused)))
873
873
{
874
874
  uint32_t length= pack_length();
908
908
   @return  New pointer into memory based on from + length of the data
909
909
*/
910
910
const uchar *
911
 
Field::unpack(uchar* to, const uchar *from, uint param_data,
 
911
Field::unpack(uchar* to, const uchar *from, uint32_t param_data,
912
912
              bool low_byte_first __attribute__((unused)))
913
913
{
914
 
  uint length=pack_length();
 
914
  uint32_t length=pack_length();
915
915
  int from_type= 0;
916
916
  /*
917
917
    If from length is > 255, it has encoded data in the upper bits. Need
931
931
    return from+length;
932
932
  }
933
933
 
934
 
  uint len= (param_data && (param_data < length)) ?
 
934
  uint32_t len= (param_data && (param_data < length)) ?
935
935
            param_data : length;
936
936
 
937
937
  memcpy(to, from, param_data > length ? length : len);
1126
1126
}
1127
1127
 
1128
1128
 
1129
 
uint Field::fill_cache_field(CACHE_FIELD *copy)
 
1129
uint32_t Field::fill_cache_field(CACHE_FIELD *copy)
1130
1130
{
1131
 
  uint store_length;
 
1131
  uint32_t store_length;
1132
1132
  copy->str=ptr;
1133
1133
  copy->length=pack_length();
1134
1134
  copy->blob_field=0;
1148
1148
}
1149
1149
 
1150
1150
 
1151
 
bool Field::get_date(DRIZZLE_TIME *ltime,uint fuzzydate)
 
1151
bool Field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
1152
1152
{
1153
1153
  char buff[40];
1154
1154
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1180
1180
                      enum enum_drizzle_timestamp_type type_arg __attribute__((unused)))
1181
1181
{
1182
1182
  char buff[MAX_DATE_STRING_REP_LENGTH];
1183
 
  uint length= (uint) my_TIME_to_str(ltime, buff);
 
1183
  uint32_t length= (uint32_t) my_TIME_to_str(ltime, buff);
1184
1184
  return store(buff, length, &my_charset_bin);
1185
1185
}
1186
1186
 
1187
1187
 
1188
 
bool Field::optimize_range(uint idx, uint part)
 
1188
bool Field::optimize_range(uint32_t idx, uint32_t part)
1189
1189
{
1190
1190
  return test(table->file->index_flags(idx, part, 1) & HA_READ_RANGE);
1191
1191
}
1213
1213
 
1214
1214
Field *Field::new_key_field(MEM_ROOT *root, Table *new_table,
1215
1215
                            uchar *new_ptr, uchar *new_null_ptr,
1216
 
                            uint new_null_bit)
 
1216
                            uint32_t new_null_bit)
1217
1217
{
1218
1218
  Field *tmp;
1219
1219
  if ((tmp= new_field(root, new_table, table == new_table)))
1245
1245
** tiny int
1246
1246
****************************************************************************/
1247
1247
 
1248
 
int Field_tiny::store(const char *from,uint len, const CHARSET_INFO * const cs)
 
1248
int Field_tiny::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
1249
1249
{
1250
1250
  int error;
1251
1251
  int64_t rnd;
1362
1362
                            String *val_ptr __attribute__((unused)))
1363
1363
{
1364
1364
  const CHARSET_INFO * const cs= &my_charset_bin;
1365
 
  uint length;
1366
 
  uint mlength=cmax(field_length+1,5*cs->mbmaxlen);
 
1365
  uint32_t length;
 
1366
  uint32_t mlength=cmax(field_length+1,5*cs->mbmaxlen);
1367
1367
  val_buffer->alloc(mlength);
1368
1368
  char *to=(char*) val_buffer->ptr();
1369
1369
 
1370
1370
  if (unsigned_flag)
1371
 
    length= (uint) cs->cset->long10_to_str(cs,to,mlength, 10,
 
1371
    length= (uint32_t) cs->cset->long10_to_str(cs,to,mlength, 10,
1372
1372
                                           (long) *ptr);
1373
1373
  else
1374
 
    length= (uint) cs->cset->long10_to_str(cs,to,mlength,-10,
 
1374
    length= (uint32_t) cs->cset->long10_to_str(cs,to,mlength,-10,
1375
1375
                                           (long) *((signed char*) ptr));
1376
1376
  
1377
1377
  val_buffer->length(length);
1393
1393
  return (a < b) ? -1 : (a > b) ? 1 : 0;
1394
1394
}
1395
1395
 
1396
 
void Field_tiny::sort_string(uchar *to,uint length __attribute__((unused)))
 
1396
void Field_tiny::sort_string(uchar *to,uint32_t length __attribute__((unused)))
1397
1397
{
1398
1398
  if (unsigned_flag)
1399
1399
    *to= *ptr;
1546
1546
int Field_str::store(double nr)
1547
1547
{
1548
1548
  char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
1549
 
  uint local_char_length= field_length / charset()->mbmaxlen;
 
1549
  uint32_t local_char_length= field_length / charset()->mbmaxlen;
1550
1550
  size_t length;
1551
1551
  bool error;
1552
1552
 
1562
1562
}
1563
1563
 
1564
1564
 
1565
 
uint Field::is_equal(Create_field *new_field)
 
1565
uint32_t Field::is_equal(Create_field *new_field)
1566
1566
{
1567
1567
  return (new_field->sql_type == real_type());
1568
1568
}
1579
1579
}
1580
1580
 
1581
1581
 
1582
 
uint Field_str::is_equal(Create_field *new_field)
 
1582
uint32_t Field_str::is_equal(Create_field *new_field)
1583
1583
{
1584
1584
  if (compare_str_field_flags(new_field, flags))
1585
1585
    return 0;
1631
1631
 
1632
1632
  if (typelib->count < from_lib->count)
1633
1633
    return 0;
1634
 
  for (uint i=0 ; i < from_lib->count ; i++)
 
1634
  for (uint32_t i=0 ; i < from_lib->count ; i++)
1635
1635
    if (my_strnncoll(field_charset,
1636
1636
                     (const uchar*)typelib->type_names[i],
1637
1637
                     strlen(typelib->type_names[i]),
1658
1658
}
1659
1659
 
1660
1660
 
1661
 
uint Field_num::is_equal(Create_field *new_field)
 
1661
uint32_t Field_num::is_equal(Create_field *new_field)
1662
1662
{
1663
1663
  return ((new_field->sql_type == real_type()) &&
1664
 
          ((new_field->flags & UNSIGNED_FLAG) == (uint) (flags &
 
1664
          ((new_field->flags & UNSIGNED_FLAG) == (uint32_t) (flags &
1665
1665
                                                         UNSIGNED_FLAG)) &&
1666
1666
          ((new_field->flags & AUTO_INCREMENT_FLAG) ==
1667
 
           (uint) (flags & AUTO_INCREMENT_FLAG)) &&
 
1667
           (uint32_t) (flags & AUTO_INCREMENT_FLAG)) &&
1668
1668
          (new_field->length <= max_display_length()));
1669
1669
}
1670
1670
 
1750
1750
 
1751
1751
bool Create_field::init(THD *thd __attribute__((unused)), char *fld_name, enum_field_types fld_type,
1752
1752
                        char *fld_length, char *fld_decimals,
1753
 
                        uint fld_type_modifier, Item *fld_default_value,
 
1753
                        uint32_t fld_type_modifier, Item *fld_default_value,
1754
1754
                        Item *fld_on_update_value, LEX_STRING *fld_comment,
1755
1755
                        char *fld_change, List<String> *fld_interval_list,
1756
1756
                        const CHARSET_INFO * const fld_charset,
1757
 
                        uint fld_geom_type __attribute__((unused)),
 
1757
                        uint32_t fld_geom_type __attribute__((unused)),
1758
1758
                        enum column_format_type column_format)
1759
1759
{
1760
 
  uint sign_len, allowed_type_modifier= 0;
 
1760
  uint32_t sign_len, allowed_type_modifier= 0;
1761
1761
  uint32_t max_field_charlength= MAX_FIELD_CHARLENGTH;
1762
1762
 
1763
1763
  field= 0;
1764
1764
  field_name= fld_name;
1765
1765
  def= fld_default_value;
1766
1766
  flags= fld_type_modifier;
1767
 
  flags|= (((uint)column_format & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
 
1767
  flags|= (((uint32_t)column_format & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
1768
1768
  unireg_check= (fld_type_modifier & AUTO_INCREMENT_FLAG ?
1769
1769
                 Field::NEXT_NUMBER : Field::NONE);
1770
 
  decimals= fld_decimals ? (uint)atoi(fld_decimals) : 0;
 
1770
  decimals= fld_decimals ? (uint32_t)atoi(fld_decimals) : 0;
1771
1771
  if (decimals >= NOT_FIXED_DEC)
1772
1772
  {
1773
1773
    my_error(ER_TOO_BIG_SCALE, MYF(0), decimals, fld_name,
1792
1792
      (fld_type_modifier & NOT_NULL_FLAG) && fld_type != DRIZZLE_TYPE_TIMESTAMP)
1793
1793
    flags|= NO_DEFAULT_VALUE_FLAG;
1794
1794
 
1795
 
  if (fld_length && !(length= (uint) atoi(fld_length)))
 
1795
  if (fld_length && !(length= (uint32_t) atoi(fld_length)))
1796
1796
    fld_length= 0; /* purecov: inspected */
1797
1797
  sign_len= fld_type_modifier & UNSIGNED_FLAG ? 0 : 1;
1798
1798
 
2001
2001
}
2002
2002
 
2003
2003
 
2004
 
uint pack_length_to_packflag(uint type)
 
2004
uint32_t pack_length_to_packflag(uint32_t type)
2005
2005
{
2006
2006
  switch (type) {
2007
 
    case 1: return f_settype((uint) DRIZZLE_TYPE_TINY);
 
2007
    case 1: return f_settype((uint32_t) DRIZZLE_TYPE_TINY);
2008
2008
    case 2: assert(1);
2009
2009
    case 3: assert(1);
2010
 
    case 4: return f_settype((uint) DRIZZLE_TYPE_LONG);
2011
 
    case 8: return f_settype((uint) DRIZZLE_TYPE_LONGLONG);
 
2010
    case 4: return f_settype((uint32_t) DRIZZLE_TYPE_LONG);
 
2011
    case 8: return f_settype((uint32_t) DRIZZLE_TYPE_LONGLONG);
2012
2012
  }
2013
2013
  return 0;                                     // This shouldn't happen
2014
2014
}
2016
2016
 
2017
2017
Field *make_field(TABLE_SHARE *share, uchar *ptr, uint32_t field_length,
2018
2018
                  uchar *null_pos, uchar null_bit,
2019
 
                  uint pack_flag,
 
2019
                  uint32_t pack_flag,
2020
2020
                  enum_field_types field_type,
2021
2021
                  const CHARSET_INFO * field_charset,
2022
2022
                  Field::utype unireg_check,
2056
2056
      return 0;                                 // Error
2057
2057
    }
2058
2058
 
2059
 
    uint pack_length=calc_pack_length((enum_field_types)
 
2059
    uint32_t pack_length=calc_pack_length((enum_field_types)
2060
2060
                                      f_packtype(pack_flag),
2061
2061
                                      field_length);
2062
2062
 
2220
2220
*/
2221
2221
 
2222
2222
bool 
2223
 
Field::set_warning(DRIZZLE_ERROR::enum_warning_level level, uint code,
 
2223
Field::set_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
2224
2224
                   int cuted_increment)
2225
2225
{
2226
2226
  /*
2258
2258
void 
2259
2259
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, 
2260
2260
                            unsigned int code, 
2261
 
                            const char *str, uint str_length, 
 
2261
                            const char *str, uint32_t str_length, 
2262
2262
                            enum enum_drizzle_timestamp_type ts_type, int cuted_increment)
2263
2263
{
2264
2264
  THD *thd= table ? table->in_use : current_thd;
2286
2286
*/
2287
2287
 
2288
2288
void 
2289
 
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint code, 
 
2289
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code, 
2290
2290
                            int64_t nr, enum enum_drizzle_timestamp_type ts_type,
2291
2291
                            int cuted_increment)
2292
2292
{
2296
2296
  {
2297
2297
    char str_nr[22];
2298
2298
    char *str_end= int64_t10_to_str(nr, str_nr, -10);
2299
 
    make_truncated_value_warning(thd, level, str_nr, (uint) (str_end - str_nr), 
 
2299
    make_truncated_value_warning(thd, level, str_nr, (uint32_t) (str_end - str_nr), 
2300
2300
                                 ts_type, field_name);
2301
2301
  }
2302
2302
}
2317
2317
*/
2318
2318
 
2319
2319
void 
2320
 
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint code, 
 
2320
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code, 
2321
2321
                            double nr, enum enum_drizzle_timestamp_type ts_type)
2322
2322
{
2323
2323
  THD *thd= table ? table->in_use : current_thd;
2326
2326
  {
2327
2327
    /* DBL_DIG is enough to print '-[digits].E+###' */
2328
2328
    char str_nr[DBL_DIG + 8];
2329
 
    uint str_len= sprintf(str_nr, "%g", nr);
 
2329
    uint32_t str_len= sprintf(str_nr, "%g", nr);
2330
2330
    make_truncated_value_warning(thd, level, str_nr, str_len, ts_type,
2331
2331
                                 field_name);
2332
2332
  }