~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Brian Aker
  • Date: 2009-08-24 19:19:39 UTC
  • mfrom: (1121.1.6 merge)
  • Revision ID: brian@gaz-20090824191939-xcn528r7gwjc48h3
Merge Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
966
966
 
967
967
  select_field_pos= alter_info->create_list.elements - select_field_count;
968
968
  null_fields=blob_columns=0;
969
 
  create_info->varchar= 0;
970
969
  max_key_length= file->max_key_length();
971
970
 
972
971
  for (field_no=0; (sql_field=it++) ; field_no++)
1193
1192
                             &timestamps, &timestamps_with_niladic,
1194
1193
                             file->ha_table_flags()))
1195
1194
      return(true);
1196
 
    if (sql_field->sql_type == DRIZZLE_TYPE_VARCHAR)
1197
 
      create_info->varchar= true;
1198
1195
    sql_field->offset= record_offset;
1199
1196
    if (MTYP_TYPENR(sql_field->unireg_check) == Field::NEXT_NUMBER)
1200
1197
      auto_increment++;
1605
1602
  /* Sort keys in optimized order */
1606
1603
  my_qsort((unsigned char*) *key_info_buffer, *key_count, sizeof(KEY),
1607
1604
           (qsort_cmp) sort_keys);
1608
 
  create_info->null_bits= null_fields;
1609
1605
 
1610
1606
  /* Check fields. */
1611
1607
  it.rewind();
1770
1766
    path_length= build_table_filename(path, sizeof(path), db, table_name, internal_tmp_table);
1771
1767
  }
1772
1768
 
1773
 
  /*
1774
 
   * If the DATA DIRECTORY or INDEX DIRECTORY options are specified in the
1775
 
   * create table statement, check whether the storage engine supports those
1776
 
   * options. If not, return an appropriate error.
1777
 
   */
1778
 
  if (create_info->data_file_name &&
1779
 
      ! create_info->db_type->check_flag(HTON_BIT_DATA_DIR))
1780
 
  {
1781
 
    my_error(ER_ILLEGAL_HA_CREATE_OPTION, MYF(0),
1782
 
             create_info->db_type->getName().c_str(), 
1783
 
             "DATA DIRECTORY");
1784
 
    goto err;
1785
 
  }
1786
 
 
1787
 
  if (create_info->index_file_name &&
1788
 
      ! create_info->db_type->check_flag(HTON_BIT_INDEX_DIR))
1789
 
  {
1790
 
    my_error(ER_ILLEGAL_HA_CREATE_OPTION, MYF(0),
1791
 
             create_info->db_type->getName().c_str(), 
1792
 
             "INDEX DIRECTORY");
1793
 
    goto err;
1794
 
  }
1795
 
 
1796
1769
  /* Check if table already exists */
1797
1770
  if ((create_info->options & HA_LEX_CREATE_TMP_TABLE) &&
1798
1771
      session->find_temporary_table(db, table_name))
1890
1863
  session->set_proc_info("creating table");
1891
1864
  create_info->table_existed= 0;                // Mark that table is created
1892
1865
 
1893
 
#ifdef HAVE_READLINK
1894
 
  if (test_if_data_home_dir(create_info->data_file_name))
1895
 
  {
1896
 
    my_error(ER_WRONG_ARGUMENTS, MYF(0), "DATA DIRECTORY");
1897
 
    goto unlock_and_end;
1898
 
  }
1899
 
  if (test_if_data_home_dir(create_info->index_file_name))
1900
 
  {
1901
 
    my_error(ER_WRONG_ARGUMENTS, MYF(0), "INDEX DIRECTORY");
1902
 
    goto unlock_and_end;
1903
 
  }
1904
 
 
1905
 
  if (!my_use_symdir)
1906
 
#endif /* HAVE_READLINK */
1907
 
  {
1908
 
    if (create_info->data_file_name)
1909
 
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1910
 
                   "DATA DIRECTORY option ignored");
1911
 
    if (create_info->index_file_name)
1912
 
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1913
 
                   "INDEX DIRECTORY option ignored");
1914
 
    create_info->data_file_name= create_info->index_file_name= 0;
1915
 
  }
1916
1866
  create_info->table_options=db_options;
1917
1867
 
1918
1868
  if (rea_create_table(session, path, db, table_name,
2962
2912
                       char *tmp_name,
2963
2913
                       HA_CREATE_INFO *create_info,
2964
2914
                       drizzled::message::Table *create_proto,
2965
 
                       Alter_info *alter_info,
2966
 
                       bool db_changed)
 
2915
                       Alter_info *alter_info)
2967
2916
{
2968
2917
  int error;
2969
 
  char index_file[FN_REFLEN], data_file[FN_REFLEN];
2970
2918
  StorageEngine *old_db_type, *new_db_type;
2971
2919
  old_db_type= table->s->db_type();
2972
2920
  new_db_type= create_info->db_type;
2973
2921
  /*
2974
 
    Handling of symlinked tables:
2975
 
    If no rename:
2976
 
      Create new data file and index file on the same disk as the
2977
 
      old data and index files.
2978
 
      Copy data.
2979
 
      Rename new data file over old data file and new index file over
2980
 
      old index file.
2981
 
      Symlinks are not changed.
2982
 
 
2983
 
   If rename:
2984
 
      Create new data file and index file on the same disk as the
2985
 
      old data and index files.  Create also symlinks to point at
2986
 
      the new tables.
2987
 
      Copy data.
2988
 
      At end, rename intermediate tables, and symlinks to intermediate
2989
 
      table, to final table name.
2990
 
      Remove old table and old symlinks
2991
 
 
2992
 
    If rename is made to another database:
2993
 
      Create new tables in new database.
2994
 
      Copy data.
2995
 
      Remove old table and symlinks.
2996
 
  */
2997
 
  if (db_changed)               // Ignore symlink if db changed
2998
 
  {
2999
 
    if (create_info->index_file_name)
3000
 
    {
3001
 
      /* Fix index_file_name to have 'tmp_name' as basename */
3002
 
      strcpy(index_file, tmp_name);
3003
 
      create_info->index_file_name=fn_same(index_file,
3004
 
                                           create_info->index_file_name,
3005
 
                                           1);
3006
 
    }
3007
 
    if (create_info->data_file_name)
3008
 
    {
3009
 
      /* Fix data_file_name to have 'tmp_name' as basename */
3010
 
      strcpy(data_file, tmp_name);
3011
 
      create_info->data_file_name=fn_same(data_file,
3012
 
                                          create_info->data_file_name,
3013
 
                                          1);
3014
 
    }
3015
 
  }
3016
 
  else
3017
 
    create_info->data_file_name=create_info->index_file_name=0;
3018
 
 
3019
 
  /*
3020
2922
    Create a table with a temporary name.
3021
2923
    We don't log the statement, it will be logged later.
3022
2924
  */
3097
2999
  bool rc= true;
3098
3000
 
3099
3001
 
3100
 
  create_info->varchar= false;
3101
3002
  /* Let new create options override the old ones */
3102
3003
  drizzled::message::Table::TableOptions *table_options;
3103
3004
  table_options= table_proto->mutable_options();
3784
3685
  my_casedn_str(files_charset_info, tmp_name);
3785
3686
 
3786
3687
  /* Create a temporary table with the new format */
3787
 
  error= create_temporary_table(session, table, new_db, tmp_name, create_info, create_proto, alter_info, !strcmp(db, new_db));
 
3688
  error= create_temporary_table(session, table, new_db, tmp_name, create_info, create_proto, alter_info);
3788
3689
  if (error != 0)
3789
3690
    goto err;
3790
3691