~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Brian Aker
  • Date: 2009-08-18 07:20:29 UTC
  • mfrom: (1117.1.9 merge)
  • Revision ID: brian@gaz-20090818072029-s9ch5lcmltxwidn7
Merge of Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
static bool
78
78
mysql_prepare_alter_table(Session *session, Table *table,
79
79
                          HA_CREATE_INFO *create_info,
 
80
                          drizzled::message::Table *table_proto,
80
81
                          Alter_info *alter_info);
81
82
 
82
83
static void set_table_default_charset(HA_CREATE_INFO *create_info, char *db)
1755
1756
  if (create_info->options & HA_LEX_CREATE_TMP_TABLE)
1756
1757
  {
1757
1758
    path_length= build_tmptable_filename(session, path, sizeof(path));
1758
 
    create_info->table_options|=HA_CREATE_DELAY_KEY_WRITE;
1759
1759
  }
1760
1760
  else
1761
1761
  {
2563
2563
  alter_info.flags.set(ALTER_RECREATE);
2564
2564
  schema_table->table->use_all_columns();
2565
2565
  if (mysql_prepare_alter_table(session, schema_table->table,
2566
 
                                &local_create_info, &alter_info))
 
2566
                                &local_create_info, table_proto, &alter_info))
2567
2567
    return true;
2568
2568
 
 
2569
  /* I_S tables are created with MAX_ROWS for some efficiency drive.
 
2570
     When CREATE LIKE, we don't want to keep it coming across */
 
2571
  drizzled::message::Table::TableOptions *table_options;
 
2572
  table_options= table_proto->mutable_options();
 
2573
  table_options->clear_max_rows();
 
2574
 
2569
2575
  if (mysql_prepare_create_table(session, &local_create_info, &alter_info,
2570
2576
                                 tmp_table, &db_options,
2571
2577
                                 schema_table->table->file,
2572
2578
                                 &schema_table->table->s->key_info, &keys, 0))
2573
2579
    return true;
2574
2580
 
2575
 
  local_create_info.max_rows= 0;
2576
 
 
2577
2581
  table_proto->set_name("system_stupid_i_s_fix_nonsense");
2578
2582
  if(tmp_table)
2579
2583
    table_proto->set_type(drizzled::message::Table::TEMPORARY);
2648
2652
    if (session->find_temporary_table(db, table_name))
2649
2653
      goto table_exists;
2650
2654
    dst_path_length= build_tmptable_filename(session, dst_path, sizeof(dst_path));
2651
 
    create_info->table_options|= HA_CREATE_DELAY_KEY_WRITE;
2652
2655
  }
2653
2656
  else
2654
2657
  {
2952
2955
  return(error);
2953
2956
}
2954
2957
 
2955
 
static int 
 
2958
static int
2956
2959
create_temporary_table(Session *session,
2957
2960
                       Table *table,
2958
2961
                       char *new_db,
2959
2962
                       char *tmp_name,
2960
2963
                       HA_CREATE_INFO *create_info,
 
2964
                       drizzled::message::Table *create_proto,
2961
2965
                       Alter_info *alter_info,
2962
2966
                       bool db_changed)
2963
2967
{
3016
3020
    Create a table with a temporary name.
3017
3021
    We don't log the statement, it will be logged later.
3018
3022
  */
3019
 
  drizzled::message::Table table_proto;
3020
 
  table_proto.set_name(tmp_name);
3021
 
  table_proto.set_type(drizzled::message::Table::TEMPORARY);
 
3023
  create_proto->set_name(tmp_name);
 
3024
  create_proto->set_type(drizzled::message::Table::TEMPORARY);
3022
3025
 
3023
3026
  drizzled::message::Table::StorageEngine *protoengine;
3024
 
  protoengine= table_proto.mutable_engine();
 
3027
  protoengine= create_proto->mutable_engine();
3025
3028
  protoengine->set_name(new_db_type->getName());
3026
3029
 
3027
3030
  error= mysql_create_table(session, new_db, tmp_name,
3028
 
                            create_info, &table_proto, alter_info, 1, 0);
 
3031
                            create_info, create_proto, alter_info, 1, 0);
3029
3032
 
3030
3033
  return(error);
3031
3034
}
3075
3078
static bool
3076
3079
mysql_prepare_alter_table(Session *session, Table *table,
3077
3080
                          HA_CREATE_INFO *create_info,
 
3081
                          drizzled::message::Table *table_proto,
3078
3082
                          Alter_info *alter_info)
3079
3083
{
3080
3084
  /* New column definitions are added here */
3088
3092
  List_iterator<CreateField> find_it(new_create_list);
3089
3093
  List_iterator<CreateField> field_it(new_create_list);
3090
3094
  List<Key_part_spec> key_parts;
3091
 
  uint32_t db_create_options= (table->s->db_create_options
3092
 
                           & ~(HA_OPTION_PACK_RECORD));
3093
3095
  uint32_t used_fields= create_info->used_fields;
3094
3096
  KEY *key_info=table->key_info;
3095
3097
  bool rc= true;
3097
3099
 
3098
3100
  create_info->varchar= false;
3099
3101
  /* Let new create options override the old ones */
3100
 
  if (!(used_fields & HA_CREATE_USED_MIN_ROWS))
3101
 
    create_info->min_rows= table->s->min_rows;
3102
 
  if (!(used_fields & HA_CREATE_USED_MAX_ROWS))
3103
 
    create_info->max_rows= table->s->max_rows;
3104
 
  if (!(used_fields & HA_CREATE_USED_AVG_ROW_LENGTH))
3105
 
    create_info->avg_row_length= table->s->avg_row_length;
 
3102
  drizzled::message::Table::TableOptions *table_options;
 
3103
  table_options= table_proto->mutable_options();
 
3104
 
3106
3105
  if (!(used_fields & HA_CREATE_USED_BLOCK_SIZE))
3107
3106
    create_info->block_size= table->s->block_size;
3108
3107
  if (!(used_fields & HA_CREATE_USED_DEFAULT_CHARSET))
3406
3405
    goto err;
3407
3406
  }
3408
3407
 
3409
 
  if (!create_info->comment.str)
3410
 
  {
3411
 
    create_info->comment.str= table->s->comment.str;
3412
 
    create_info->comment.length= table->s->comment.length;
3413
 
  }
3414
 
 
3415
 
  table->file->update_create_info(create_info);
3416
 
  if ((create_info->table_options &
3417
 
       (HA_OPTION_PACK_KEYS | HA_OPTION_NO_PACK_KEYS)) ||
3418
 
      (used_fields & HA_CREATE_USED_PACK_KEYS))
3419
 
    db_create_options&= ~(HA_OPTION_PACK_KEYS | HA_OPTION_NO_PACK_KEYS);
3420
 
  if (create_info->table_options &
3421
 
      (HA_OPTION_CHECKSUM | HA_OPTION_NO_CHECKSUM))
3422
 
    db_create_options&= ~(HA_OPTION_CHECKSUM | HA_OPTION_NO_CHECKSUM);
3423
 
  if (create_info->table_options &
3424
 
      (HA_OPTION_DELAY_KEY_WRITE | HA_OPTION_NO_DELAY_KEY_WRITE))
3425
 
    db_create_options&= ~(HA_OPTION_DELAY_KEY_WRITE |
3426
 
                          HA_OPTION_NO_DELAY_KEY_WRITE);
3427
 
  create_info->table_options|= db_create_options;
 
3408
  if (! table_proto->options().has_comment()
 
3409
      && table->s->hasComment())
 
3410
    table_options->set_comment(table->s->getComment());
3428
3411
 
3429
3412
  if (table->s->tmp_table)
3430
3413
    create_info->options|=HA_LEX_CREATE_TMP_TABLE;
3483
3466
                       char *new_db, 
3484
3467
                       char *new_name,
3485
3468
                       HA_CREATE_INFO *create_info,
 
3469
                       drizzled::message::Table *create_proto,
3486
3470
                       TableList *table_list,
3487
3471
                       Alter_info *alter_info,
3488
3472
                       uint32_t order_num, 
3786
3770
  */
3787
3771
  new_db_type= create_info->db_type;
3788
3772
 
3789
 
  if (mysql_prepare_alter_table(session, table, create_info, alter_info))
3790
 
    goto err;
 
3773
  if (mysql_prepare_alter_table(session, table, create_info, create_proto,
 
3774
                                alter_info))
 
3775
      goto err;
3791
3776
 
3792
3777
  set_table_default_charset(create_info, db);
3793
3778
 
3799
3784
  my_casedn_str(files_charset_info, tmp_name);
3800
3785
 
3801
3786
  /* Create a temporary table with the new format */
3802
 
  error= create_temporary_table(session, table, new_db, tmp_name, create_info, alter_info, ! strcmp(db, new_db));
3803
 
 
 
3787
  error= create_temporary_table(session, table, new_db, tmp_name, create_info, create_proto, alter_info, !strcmp(db, new_db));
3804
3788
  if (error != 0)
3805
3789
    goto err;
3806
3790
 
4294
4278
{
4295
4279
  HA_CREATE_INFO create_info;
4296
4280
  Alter_info alter_info;
 
4281
  drizzled::message::Table table_proto;
4297
4282
 
4298
4283
  assert(!table_list->next_global);
4299
4284
  /*
4308
4293
  /* Force alter table to recreate table */
4309
4294
  alter_info.flags.set(ALTER_CHANGE_COLUMN);
4310
4295
  alter_info.flags.set(ALTER_RECREATE);
4311
 
  return(mysql_alter_table(session, NULL, NULL, &create_info,
4312
 
                                table_list, &alter_info, 0,
4313
 
                                (order_st *) 0, 0));
 
4296
  return(mysql_alter_table(session, NULL, NULL, &create_info, &table_proto,
 
4297
                           table_list, &alter_info, 0,
 
4298
                           (order_st *) 0, 0));
4314
4299
}
4315
4300
 
4316
4301