~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

merge for-brian work

Show diffs side-by-side

added added

removed removed

Lines of Context:
124
124
                    system_charset_info,  to, to_length, &errors);
125
125
    if (errors) // Old 5.0 name
126
126
    {
127
 
      strcpy(to, MYSQL50_TABLE_NAME_PREFIX);
128
 
      strncat(to, from, to_length-MYSQL50_TABLE_NAME_PREFIX_LENGTH-1);
 
127
      to[0]='\0';
 
128
      strncat(to, from, to_length-1);
129
129
      res= strlen(to);
130
130
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid (old?) table or database name '%s'"), from);
131
131
    }
151
151
{
152
152
  uint32_t errors, length;
153
153
 
154
 
  if (from[0] == '#' && !strncmp(from, MYSQL50_TABLE_NAME_PREFIX,
155
 
                                 MYSQL50_TABLE_NAME_PREFIX_LENGTH))
156
 
    return((uint32_t) (strncpy(to, from+MYSQL50_TABLE_NAME_PREFIX_LENGTH,
157
 
                           to_length-1) -
158
 
                           (from + MYSQL50_TABLE_NAME_PREFIX_LENGTH)));
159
154
  length= strconvert(system_charset_info, from,
160
155
                     &my_charset_filename, to, to_length, &errors);
161
156
  if (check_if_legal_tablename(to) &&
268
263
 
269
264
  path_str << drizzle_tmpdir;
270
265
  post_tmpdir_str << "/" << TMP_FILE_PREFIX << current_pid;
271
 
  post_tmpdir_str << session->thread_id << session->tmp_table++ << reg_ext;
 
266
  post_tmpdir_str << session->thread_id << session->tmp_table++;
272
267
  tmp= post_tmpdir_str.str();
273
268
 
274
269
  if (lower_case_table_names)
510
505
      }
511
506
      alias= (lower_case_table_names == 2) ? table->alias : table->table_name;
512
507
      /* remove .frm file and engine files */
513
 
      path_length= build_table_filename(path, sizeof(path), db, alias, reg_ext,
 
508
      path_length= build_table_filename(path, sizeof(path), db, alias, "",
514
509
                                        table->internal_tmp_table ?
515
510
                                        FN_IS_TMP : 0);
516
511
    }
517
512
    if (drop_temporary ||
518
 
        ((table_type == NULL && (access(path, F_OK))))
519
 
        )
 
513
        ((table_type == NULL && (table_proto_exists(path)!=EEXIST))))
520
514
    {
521
515
      // Table was not found on disk and table can't be created from engine
522
516
      if (if_exists)
528
522
    }
529
523
    else
530
524
    {
531
 
      char *end;
532
 
      // Remove extension for delete
533
 
      *(end= path + path_length - reg_ext_length)= '\0';
534
525
      error= ha_delete_table(session, path, db, table->table_name,
535
526
                             !dont_log_query);
536
527
      if ((error == ENOENT || error == HA_ERR_NO_SUCH_TABLE) &&
548
539
      {
549
540
        int new_error;
550
541
 
551
 
        /* for some weird-ass reason, we ignore the return code here
552
 
           and things work. */
553
 
        delete_table_proto_file(path);
554
 
 
555
 
        /* Delete the table definition file */
556
 
        strcpy(end,reg_ext);
557
 
        if (!(new_error=my_delete(path,MYF(MY_WME))))
 
542
        if (!(new_error= delete_table_proto_file(path)))
558
543
        {
559
544
          some_tables_deleted=1;
560
545
          new_error= 0;
662
647
  char path[FN_REFLEN];
663
648
  bool error= 0;
664
649
 
665
 
  uint32_t path_length= build_table_filename(path, sizeof(path),
666
 
                                         db, table_name, reg_ext, flags);
667
 
  if (my_delete(path,MYF(0)))
668
 
    error= 1; /* purecov: inspected */
669
 
 
670
 
  path[path_length - reg_ext_length]= '\0'; // Remove reg_ext
671
 
 
672
 
  error|= delete_table_proto_file(path);
 
650
  build_table_filename(path, sizeof(path), db, table_name, "", flags);
 
651
 
 
652
  error= delete_table_proto_file(path);
673
653
 
674
654
  return(ha_delete_table(current_session, path, db, table_name, 0) ||
675
655
              error);
1785
1765
      return(true);
1786
1766
    }
1787
1767
#endif
1788
 
    path_length= build_table_filename(path, sizeof(path), db, alias, reg_ext,
 
1768
    path_length= build_table_filename(path, sizeof(path), db, alias, "",
1789
1769
                                      internal_tmp_table ? FN_IS_TMP : 0);
1790
1770
  }
1791
1771
 
1810
1790
    pthread_mutex_lock(&LOCK_open);
1811
1791
  if (!internal_tmp_table && !(create_info->options & HA_LEX_CREATE_TMP_TABLE))
1812
1792
  {
1813
 
    if (!access(path,F_OK))
 
1793
    if (table_proto_exists(path)==EEXIST)
1814
1794
    {
1815
1795
      if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
1816
1796
        goto warn;
1891
1871
  }
1892
1872
  create_info->table_options=db_options;
1893
1873
 
1894
 
  path[path_length - reg_ext_length]= '\0'; // Remove .frm extension
1895
1874
  if (rea_create_table(session, path, db, table_name,
1896
1875
                       create_info, alter_info->create_list,
1897
1876
                       key_count, key_info_buffer, file, false))
2123
2102
  }
2124
2103
  if (!file || !(error=file->ha_rename_table(from_base, to_base)))
2125
2104
  {
2126
 
    if (!(flags & NO_FRM_RENAME) && rename_file_ext(from,to,reg_ext))
2127
 
    {
2128
 
      error=my_errno;
2129
 
      /* Restore old file name */
2130
 
      if (file)
2131
 
        file->ha_rename_table(to_base, from_base);
2132
 
    }
2133
 
 
2134
2105
    if(!(flags & NO_FRM_RENAME)
2135
2106
       && rename_table_proto_file(from_base, to_base))
2136
2107
    {
2137
 
      error= errno;
2138
 
      rename_file_ext(to, from, reg_ext);
 
2108
      error= my_errno;
2139
2109
      if (file)
2140
2110
        file->ha_rename_table(to_base, from_base);
2141
2111
    }
2941
2911
  if (open_tables(session, &src_table, &not_used, 0))
2942
2912
    return(true);
2943
2913
 
2944
 
  sprintf(src_path,"%s%s",src_table->table->s->path.str, reg_ext);
 
2914
  strncpy(src_path, src_table->table->s->path.str, sizeof(src_path));
2945
2915
 
2946
2916
  /*
2947
2917
    Check that destination tables does not exist. Note that its name
2961
2931
    if (!name_lock)
2962
2932
      goto table_exists;
2963
2933
    dst_path_length= build_table_filename(dst_path, sizeof(dst_path),
2964
 
                                          db, table_name, reg_ext, 0);
2965
 
    if (!access(dst_path, F_OK))
 
2934
                                          db, table_name, "", 0);
 
2935
    if (table_proto_exists(dst_path)==EEXIST)
2966
2936
      goto table_exists;
2967
2937
  }
2968
2938
 
2990
2960
  }
2991
2961
  else
2992
2962
  {
2993
 
    int frmcopyr= my_copy(src_path, dst_path, MYF(MY_DONT_OVERWRITE_FILE));
2994
 
 
2995
 
    string dfesrc(src_path);
2996
 
    string dfedst(dst_path);
2997
 
 
2998
 
    dfesrc.replace(dfesrc.find(".frm"), 4, ".dfe" );
2999
 
    dfedst.replace(dfedst.find(".frm"), 4, ".dfe" );
3000
 
 
3001
 
    int dfecopyr= my_copy(dfesrc.c_str(), dfedst.c_str(),
3002
 
                          MYF(MY_DONT_OVERWRITE_FILE));
3003
 
 
3004
 
    if(frmcopyr || dfecopyr) // FIXME: should handle only one fail.
 
2963
    int dfecopyr= copy_table_proto_file(src_path, dst_path);
 
2964
 
 
2965
    if(dfecopyr)
3005
2966
    {
3006
2967
      if (my_errno == ENOENT)
3007
2968
        my_error(ER_BAD_DB_ERROR,MYF(0),db);
3017
2978
    creation, instead create the table directly (for both normal
3018
2979
    and temporary tables).
3019
2980
  */
3020
 
  dst_path[dst_path_length - reg_ext_length]= '\0';  // Remove .frm
 
2981
 
3021
2982
  if (session->variables.keep_files_on_create)
3022
2983
    create_info->options|= HA_CREATE_KEEP_FILES;
3023
2984
  err= ha_create_table(session, dst_path, db, table_name, create_info, 1);
4419
4380
    return(mysql_discard_or_import_tablespace(session,table_list,
4420
4381
                                              alter_info->tablespace_op));
4421
4382
  ostringstream oss;
4422
 
  oss << drizzle_data_home << "/" << db << "/" << table_name << reg_ext;
 
4383
  oss << drizzle_data_home << "/" << db << "/" << table_name;
4423
4384
 
4424
4385
  (void) unpack_filename(new_name_buff, oss.str().c_str());
4425
4386
  /*
4484
4445
        }
4485
4446
 
4486
4447
        build_table_filename(new_name_buff, sizeof(new_name_buff),
4487
 
                             new_db, new_name_buff, reg_ext, 0);
4488
 
        if (!access(new_name_buff, F_OK))
 
4448
                             new_db, new_name_buff, "", 0);
 
4449
        if (table_proto_exists(new_name_buff)==EEXIST)
4489
4450
        {
4490
4451
          /* Table will be closed in do_command() */
4491
4452
          my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
4597
4558
        we don't take this name-lock and where this order really matters.
4598
4559
        TODO: Investigate if we need this access() check at all.
4599
4560
      */
4600
 
      if (!access(new_name_buff,F_OK))
 
4561
      if (table_proto_exists(new_name)==EEXIST)
4601
4562
      {
4602
4563
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_name);
4603
4564
        error= -1;