~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
static char *make_unique_key_name(const char *field_name,KEY *start,KEY *end);
30
30
static int copy_data_between_tables(Table *from,Table *to,
31
31
                                    List<Create_field> &create, bool ignore,
32
 
                                    uint order_num, order_st *order,
 
32
                                    uint32_t order_num, order_st *order,
33
33
                                    ha_rows *copied,ha_rows *deleted,
34
34
                                    enum enum_enable_or_disable keys_onoff,
35
35
                                    bool error_if_not_empty);
40
40
mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
41
41
                           Alter_info *alter_info,
42
42
                           bool tmp_table,
43
 
                               uint *db_options,
 
43
                               uint32_t *db_options,
44
44
                               handler *file, KEY **key_info_buffer,
45
 
                               uint *key_count, int select_field_count);
 
45
                               uint32_t *key_count, int select_field_count);
46
46
static bool
47
47
mysql_prepare_alter_table(THD *thd, Table *table,
48
48
                          HA_CREATE_INFO *create_info,
60
60
  RETURN
61
61
    Table name length.
62
62
*/
63
 
uint filename_to_tablename(const char *from, char *to, uint to_length)
 
63
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length)
64
64
{
65
 
  uint errors;
66
 
  uint res;
 
65
  uint32_t errors;
 
66
  uint32_t res;
67
67
 
68
68
  if (!memcmp(from, tmp_file_prefix, tmp_file_prefix_length))
69
69
  {
99
99
    File name length.
100
100
*/
101
101
 
102
 
uint tablename_to_filename(const char *from, char *to, uint to_length)
 
102
uint32_t tablename_to_filename(const char *from, char *to, uint32_t to_length)
103
103
{
104
 
  uint errors, length;
 
104
  uint32_t errors, length;
105
105
 
106
106
  if (from[0] == '#' && !strncmp(from, MYSQL50_TABLE_NAME_PREFIX,
107
107
                                 MYSQL50_TABLE_NAME_PREFIX_LENGTH))
153
153
    path length
154
154
*/
155
155
 
156
 
uint build_table_filename(char *buff, size_t bufflen, const char *db,
157
 
                          const char *table_name, const char *ext, uint flags)
 
156
uint32_t build_table_filename(char *buff, size_t bufflen, const char *db,
 
157
                          const char *table_name, const char *ext, uint32_t flags)
158
158
{
159
159
  char dbbuff[FN_REFLEN];
160
160
  char tbbuff[FN_REFLEN];
202
202
    path length
203
203
*/
204
204
 
205
 
uint build_tmptable_filename(THD* thd, char *buff, size_t bufflen)
 
205
uint32_t build_tmptable_filename(THD* thd, char *buff, size_t bufflen)
206
206
{
207
207
 
208
208
  char *p= my_stpncpy(buff, mysql_tmpdir, bufflen);
216
216
    my_casedn_str(files_charset_info, p);
217
217
  }
218
218
 
219
 
  uint length= unpack_filename(buff, buff);
 
219
  uint32_t length= unpack_filename(buff, buff);
220
220
  return(length);
221
221
}
222
222
 
344
344
{
345
345
  TableList *table;
346
346
  char path[FN_REFLEN], *alias;
347
 
  uint path_length;
 
347
  uint32_t path_length;
348
348
  String wrong_tables;
349
349
  int error= 0;
350
350
  int non_temp_tables_count= 0;
605
605
*/
606
606
 
607
607
bool quick_rm_table(handlerton *base,const char *db,
608
 
                    const char *table_name, uint flags)
 
608
                    const char *table_name, uint32_t flags)
609
609
{
610
610
  char path[FN_REFLEN];
611
611
  bool error= 0;
612
612
 
613
 
  uint path_length= build_table_filename(path, sizeof(path),
 
613
  uint32_t path_length= build_table_filename(path, sizeof(path),
614
614
                                         db, table_name, reg_ext, flags);
615
615
  if (my_delete(path,MYF(0)))
616
616
    error= 1; /* purecov: inspected */
731
731
                                uint32_t *max_length, uint32_t *tot_length)
732
732
{
733
733
  const char **pos;
734
 
  uint *len;
 
734
  uint32_t *len;
735
735
  *max_length= *tot_length= 0;
736
736
  for (pos= interval->type_names, len= interval->type_lengths;
737
737
       *pos ; pos++, len++)
738
738
  {
739
 
    uint length= cs->cset->numchars(cs, *pos, *pos + *len);
 
739
    uint32_t length= cs->cset->numchars(cs, *pos, *pos + *len);
740
740
    *tot_length+= length;
741
741
    set_if_bigger(*max_length, (uint32_t)length);
742
742
  }
763
763
*/
764
764
 
765
765
int prepare_create_field(Create_field *sql_field, 
766
 
                         uint *blob_columns,
 
766
                         uint32_t *blob_columns,
767
767
                         int *timestamps, int *timestamps_with_niladic,
768
768
                         int64_t table_flags __attribute__((unused)))
769
769
{
877
877
mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
878
878
                           Alter_info *alter_info,
879
879
                           bool tmp_table,
880
 
                               uint *db_options,
 
880
                               uint32_t *db_options,
881
881
                               handler *file, KEY **key_info_buffer,
882
 
                               uint *key_count, int select_field_count)
 
882
                               uint32_t *key_count, int select_field_count)
883
883
{
884
884
  const char    *key_name;
885
885
  Create_field  *sql_field,*dup_field;
892
892
  int           select_field_pos,auto_increment=0;
893
893
  List_iterator<Create_field> it(alter_info->create_list);
894
894
  List_iterator<Create_field> it2(alter_info->create_list);
895
 
  uint total_uneven_bit_length= 0;
 
895
  uint32_t total_uneven_bit_length= 0;
896
896
 
897
897
  select_field_pos= alter_info->create_list.elements - select_field_count;
898
898
  null_fields=blob_columns=0;
987
987
                                          (unsigned char*) comma_buf + 
988
988
                                          sizeof(comma_buf));
989
989
        assert(comma_length > 0);
990
 
        for (uint i= 0; (tmp= int_it++); i++)
 
990
        for (uint32_t i= 0; (tmp= int_it++); i++)
991
991
        {
992
 
          uint lengthsp;
 
992
          uint32_t lengthsp;
993
993
          if (String::needs_conversion(tmp->length(), tmp->charset(),
994
994
                                       cs, &dummy))
995
995
          {
996
 
            uint cnv_errs;
 
996
            uint32_t cnv_errs;
997
997
            conv.copy(tmp->ptr(), tmp->length(), tmp->charset(), cs, &cnv_errs);
998
998
            interval->type_names[i]= strmake_root(thd->mem_root, conv.ptr(),
999
999
                                                  conv.length());
1157
1157
 
1158
1158
  List_iterator<Key> key_iterator(alter_info->key_list);
1159
1159
  List_iterator<Key> key_iterator2(alter_info->key_list);
1160
 
  uint key_parts=0, fk_key_count=0;
 
1160
  uint32_t key_parts=0, fk_key_count=0;
1161
1161
  bool primary_key=0,unique_key=0;
1162
1162
  Key *key, *key2;
1163
 
  uint tmp, key_number;
 
1163
  uint32_t tmp, key_number;
1164
1164
  /* special marker for keys to be ignored */
1165
1165
  static char ignore_key[1];
1166
1166
 
1250
1250
  key_number=0;
1251
1251
  for (; (key=key_iterator++) ; key_number++)
1252
1252
  {
1253
 
    uint key_length=0;
 
1253
    uint32_t key_length=0;
1254
1254
    Key_part_spec *column;
1255
1255
 
1256
1256
    if (key->name.str == ignore_key)
1294
1294
    if (key_info->block_size)
1295
1295
      key_info->flags|= HA_USES_BLOCK_SIZE;
1296
1296
 
1297
 
    uint tmp_len= system_charset_info->cset->charpos(system_charset_info,
 
1297
    uint32_t tmp_len= system_charset_info->cset->charpos(system_charset_info,
1298
1298
                                           key->key_create_info.comment.str,
1299
1299
                                           key->key_create_info.comment.str +
1300
1300
                                           key->key_create_info.comment.length,
1316
1316
    }
1317
1317
 
1318
1318
    List_iterator<Key_part_spec> cols(key->columns), cols2(key->columns);
1319
 
    for (uint column_nr=0 ; (column=cols++) ; column_nr++)
 
1319
    for (uint32_t column_nr=0 ; (column=cols++) ; column_nr++)
1320
1320
    {
1321
 
      uint length;
 
1321
      uint32_t length;
1322
1322
      Key_part_spec *dup_column;
1323
1323
 
1324
1324
      it.rewind();
1713
1713
                                HA_CREATE_INFO *create_info,
1714
1714
                                Alter_info *alter_info,
1715
1715
                                bool internal_tmp_table,
1716
 
                                uint select_field_count)
 
1716
                                uint32_t select_field_count)
1717
1717
{
1718
1718
  char          path[FN_REFLEN];
1719
 
  uint          path_length;
 
1719
  uint32_t          path_length;
1720
1720
  const char    *alias;
1721
1721
  uint          db_options, key_count;
1722
1722
  KEY           *key_info_buffer;
1929
1929
                        HA_CREATE_INFO *create_info,
1930
1930
                        Alter_info *alter_info,
1931
1931
                        bool internal_tmp_table,
1932
 
                        uint select_field_count)
 
1932
                        uint32_t select_field_count)
1933
1933
{
1934
1934
  Table *name_lock= 0;
1935
1935
  bool result;
2025
2025
    Only 3 chars + '\0' left, so need to limit to 2 digit
2026
2026
    This is ok as we can't have more than 100 keys anyway
2027
2027
  */
2028
 
  for (uint i=2 ; i< 100; i++)
 
2028
  for (uint32_t i=2 ; i< 100; i++)
2029
2029
  {
2030
2030
    *buff_end= '_';
2031
2031
    int10_to_str(i, buff_end+1, 10);
2065
2065
bool
2066
2066
mysql_rename_table(handlerton *base, const char *old_db,
2067
2067
                   const char *old_name, const char *new_db,
2068
 
                   const char *new_name, uint flags)
 
2068
                   const char *new_name, uint32_t flags)
2069
2069
{
2070
2070
  THD *thd= current_thd;
2071
2071
  char from[FN_REFLEN], to[FN_REFLEN], lc_from[FN_REFLEN], lc_to[FN_REFLEN];
2225
2225
  if (!(table= table_list->table))              /* if open_ltable failed */
2226
2226
  {
2227
2227
    char key[MAX_DBKEY_LENGTH];
2228
 
    uint key_length;
 
2228
    uint32_t key_length;
2229
2229
 
2230
2230
    key_length= create_table_def_key(thd, key, table_list, 0);
2231
2231
    pthread_mutex_lock(&LOCK_open);
2363
2363
                              thr_lock_type lock_type,
2364
2364
                              bool open_for_modify,
2365
2365
                              bool no_warnings_for_error,
2366
 
                              uint extra_open_options,
 
2366
                              uint32_t extra_open_options,
2367
2367
                              int (*prepare_func)(THD *, TableList *,
2368
2368
                                                  HA_CHECK_OPT *),
2369
2369
                              int (handler::*operator_func)(THD *,
2468
2468
    {
2469
2469
      /* purecov: begin inspected */
2470
2470
      char buff[FN_REFLEN + DRIZZLE_ERRMSG_SIZE];
2471
 
      uint length;
 
2471
      uint32_t length;
2472
2472
      protocol->prepare_for_resend();
2473
2473
      protocol->store(table_name, system_charset_info);
2474
2474
      protocol->store(operator_name, system_charset_info);
2575
2575
    case HA_ADMIN_NOT_IMPLEMENTED:
2576
2576
      {
2577
2577
        char buf[ERRMSGSIZE+20];
2578
 
        uint length=snprintf(buf, ERRMSGSIZE,
 
2578
        uint32_t length=snprintf(buf, ERRMSGSIZE,
2579
2579
                             ER(ER_CHECK_NOT_IMPLEMENTED), operator_name);
2580
2580
        protocol->store(STRING_WITH_LEN("note"), system_charset_info);
2581
2581
        protocol->store(buf, length, system_charset_info);
2585
2585
    case HA_ADMIN_NOT_BASE_TABLE:
2586
2586
      {
2587
2587
        char buf[ERRMSGSIZE+20];
2588
 
        uint length= snprintf(buf, ERRMSGSIZE,
 
2588
        uint32_t length= snprintf(buf, ERRMSGSIZE,
2589
2589
                              ER(ER_BAD_TABLE_ERROR), table_name);
2590
2590
        protocol->store(STRING_WITH_LEN("note"), system_charset_info);
2591
2591
        protocol->store(buf, length, system_charset_info);
2700
2700
    case HA_ADMIN_NEEDS_ALTER:
2701
2701
    {
2702
2702
      char buf[ERRMSGSIZE];
2703
 
      uint length;
 
2703
      uint32_t length;
2704
2704
 
2705
2705
      protocol->store(STRING_WITH_LEN("error"), system_charset_info);
2706
2706
      length=snprintf(buf, ERRMSGSIZE, ER(ER_TABLE_NEEDS_UPGRADE), table->table_name);
2712
2712
    default:                            // Probably HA_ADMIN_INTERNAL_ERROR
2713
2713
      {
2714
2714
        char buf[ERRMSGSIZE+20];
2715
 
        uint length=snprintf(buf, ERRMSGSIZE,
 
2715
        uint32_t length=snprintf(buf, ERRMSGSIZE,
2716
2716
                             _("Unknown - internal error %d during operation"),
2717
2717
                             result_code);
2718
2718
        protocol->store(STRING_WITH_LEN("error"), system_charset_info);
2868
2868
  HA_CREATE_INFO local_create_info;
2869
2869
  Alter_info alter_info;
2870
2870
  bool tmp_table= (create_info->options & HA_LEX_CREATE_TMP_TABLE);
2871
 
  uint keys= schema_table->table->s->keys;
2872
 
  uint db_options= 0;
 
2871
  uint32_t keys= schema_table->table->s->keys;
 
2872
  uint32_t db_options= 0;
2873
2873
 
2874
2874
  memset(&local_create_info, 0, sizeof(local_create_info));
2875
2875
  local_create_info.db_type= schema_table->table->s->db_type();
2915
2915
{
2916
2916
  Table *name_lock= 0;
2917
2917
  char src_path[FN_REFLEN], dst_path[FN_REFLEN];
2918
 
  uint dst_path_length;
 
2918
  uint32_t dst_path_length;
2919
2919
  char *db= table->db;
2920
2920
  char *table_name= table->table_name;
2921
2921
  int  err;
2922
2922
  bool res= true;
2923
 
  uint not_used;
 
2923
  uint32_t not_used;
2924
2924
 
2925
2925
  /*
2926
2926
    By opening source table we guarantee that it exists and no concurrent
3193
3193
 
3194
3194
void setup_ha_alter_flags(Alter_info *alter_info, HA_ALTER_FLAGS *alter_flags)
3195
3195
{
3196
 
  uint flags= alter_info->flags;
 
3196
  uint32_t flags= alter_info->flags;
3197
3197
 
3198
3198
  if (ALTER_ADD_COLUMN & flags)
3199
3199
    *alter_flags|= HA_ADD_COLUMN;
3259
3259
               Table *table,
3260
3260
               Alter_info *alter_info,
3261
3261
                           HA_CREATE_INFO *create_info,
3262
 
               uint order_num,
 
3262
               uint32_t order_num,
3263
3263
               HA_ALTER_FLAGS *alter_flags,
3264
3264
               HA_ALTER_INFO *ha_alter_info,
3265
 
               uint *table_changes)
 
3265
               uint32_t *table_changes)
3266
3266
{
3267
3267
  Field **f_ptr, *field;
3268
 
  uint table_changes_local= 0;
 
3268
  uint32_t table_changes_local= 0;
3269
3269
  List_iterator_fast<Create_field> new_field_it(alter_info->create_list);
3270
3270
  Create_field *new_field;
3271
3271
  KEY_PART_INFO *key_part;
3294
3294
    */
3295
3295
    Alter_info tmp_alter_info(*alter_info, thd->mem_root);
3296
3296
    THD *thd= table->in_use;
3297
 
    uint db_options= 0; /* not used */
 
3297
    uint32_t db_options= 0; /* not used */
3298
3298
    /* Create the prepared information. */
3299
3299
    if (mysql_prepare_create_table(thd, create_info,
3300
3300
                                   &tmp_alter_info,
3973
3973
  List_iterator<Create_field> find_it(new_create_list);
3974
3974
  List_iterator<Create_field> field_it(new_create_list);
3975
3975
  List<Key_part_spec> key_parts;
3976
 
  uint db_create_options= (table->s->db_create_options
 
3976
  uint32_t db_create_options= (table->s->db_create_options
3977
3977
                           & ~(HA_OPTION_PACK_RECORD));
3978
 
  uint used_fields= create_info->used_fields;
 
3978
  uint32_t used_fields= create_info->used_fields;
3979
3979
  KEY *key_info=table->key_info;
3980
3980
  bool rc= true;
3981
3981
 
4159
4159
    for which some fields exists.
4160
4160
    */
4161
4161
 
4162
 
  for (uint i=0 ; i < table->s->keys ; i++,key_info++)
 
4162
  for (uint32_t i=0 ; i < table->s->keys ; i++,key_info++)
4163
4163
    {
4164
4164
    char *key_name= key_info->name;
4165
4165
    Alter_drop *drop;
4178
4178
 
4179
4179
    KEY_PART_INFO *key_part= key_info->key_part;
4180
4180
    key_parts.empty();
4181
 
    for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
 
4181
    for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
4182
4182
    {
4183
4183
      if (!key_part->field)
4184
4184
        continue;                               // Wrong field (from UNIREG)
4199
4199
      }
4200
4200
      if (!cfield)
4201
4201
        continue;                               // Field is removed
4202
 
      uint key_part_length=key_part->length;
 
4202
      uint32_t key_part_length=key_part->length;
4203
4203
      if (cfield->field)                        // Not new field
4204
4204
      {
4205
4205
        /*
4362
4362
                       HA_CREATE_INFO *create_info,
4363
4363
                       TableList *table_list,
4364
4364
                       Alter_info *alter_info,
4365
 
                       uint order_num, order_st *order, bool ignore)
 
4365
                       uint32_t order_num, order_st *order, bool ignore)
4366
4366
{
4367
4367
  Table *table, *new_table=0, *name_lock= 0;;
4368
4368
  int error= 0;
4660
4660
    Table *altered_table= 0;
4661
4661
    HA_ALTER_INFO ha_alter_info;
4662
4662
    HA_ALTER_FLAGS ha_alter_flags;
4663
 
    uint table_changes= IS_EQUAL_YES;
 
4663
    uint32_t table_changes= IS_EQUAL_YES;
4664
4664
    bool need_copy_table= true;
4665
4665
    /* Check how much the tables differ. */
4666
4666
    if (compare_tables(thd, table, alter_info,
5078
5078
copy_data_between_tables(Table *from,Table *to,
5079
5079
                         List<Create_field> &create,
5080
5080
                         bool ignore,
5081
 
                         uint order_num, order_st *order,
 
5081
                         uint32_t order_num, order_st *order,
5082
5082
                         ha_rows *copied,
5083
5083
                         ha_rows *deleted,
5084
5084
                         enum enum_enable_or_disable keys_onoff,
5088
5088
  Copy_field *copy,*copy_end;
5089
5089
  ulong found_count,delete_count;
5090
5090
  THD *thd= current_thd;
5091
 
  uint length= 0;
 
5091
  uint32_t length= 0;
5092
5092
  SORT_FIELD *sortorder;
5093
5093
  READ_RECORD info;
5094
5094
  TableList   tables;
5222
5222
      {
5223
5223
         if (!to->file->is_fatal_error(error, HA_CHECK_DUP))
5224
5224
         {
5225
 
           uint key_nr= to->file->get_dup_key(error);
 
5225
           uint32_t key_nr= to->file->get_dup_key(error);
5226
5226
           if ((int) key_nr >= 0)
5227
5227
           {
5228
5228
             const char *err_msg= ER(ER_DUP_ENTRY_WITH_KEY_NAME);
5394
5394
              row_crc= my_checksum(row_crc, t->record[0], t->s->null_bytes);
5395
5395
            }
5396
5396
 
5397
 
            for (uint i= 0; i < t->s->fields; i++ )
 
5397
            for (uint32_t i= 0; i < t->s->fields; i++ )
5398
5398
            {
5399
5399
              Field *f= t->field[i];
5400
5400
              if ((f->type() == DRIZZLE_TYPE_BLOB) ||