~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Brian Aker
  • Date: 2009-02-27 21:38:40 UTC
  • Revision ID: brian@tangent.org-20090227213840-r9hq3sfk8d8qrg72
Code cleanup in signal_handler.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
#include <drizzled/server_includes.h>
19
19
#include <storage/myisam/myisam.h>
20
 
#include <drizzled/sql_show.h>
 
20
#include <drizzled/show.h>
21
21
#include <drizzled/error.h>
22
22
#include <drizzled/gettext.h>
23
23
#include <drizzled/data_home.h>
24
24
#include <drizzled/sql_parse.h>
 
25
#include <mysys/hash.h>
 
26
#include <drizzled/sql_lex.h>
 
27
#include <drizzled/session.h>
 
28
#include <drizzled/sql_base.h>
 
29
#include <drizzled/db.h>
 
30
#include <drizzled/lock.h>
 
31
#include <drizzled/unireg.h>
 
32
#include <drizzled/item/int.h>
 
33
#include <drizzled/item/empty_string.h>
 
34
#include <drizzled/replicator.h>
 
35
 
 
36
using namespace std;
 
37
 
 
38
extern HASH lock_db_cache;
25
39
 
26
40
int creating_table= 0;        // How many mysql_create_table are running
27
41
 
28
 
const char * primary_key_name="PRIMARY";
 
42
 
 
43
bool is_primary_key(KEY *key_info)
 
44
{
 
45
  static const char * primary_key_name="PRIMARY";
 
46
  return (strcmp(key_info->name, primary_key_name)==0);
 
47
}
 
48
 
 
49
const char* is_primary_key_name(const char* key_name)
 
50
{
 
51
  static const char * primary_key_name="PRIMARY";
 
52
  if (strcmp(key_name, primary_key_name)==0)
 
53
    return key_name;
 
54
  else
 
55
    return NULL;
 
56
}
29
57
 
30
58
static bool check_if_keyname_exists(const char *name,KEY *start, KEY *end);
31
59
static char *make_unique_key_name(const char *field_name,KEY *start,KEY *end);
50
78
                          HA_CREATE_INFO *create_info,
51
79
                          Alter_info *alter_info);
52
80
 
 
81
static void set_table_default_charset(Session *session,
 
82
                                      HA_CREATE_INFO *create_info, char *db)
 
83
{
 
84
  /*
 
85
    If the table character set was not given explicitly,
 
86
    let's fetch the database default character set and
 
87
    apply it to the table.
 
88
  */
 
89
  if (!create_info->default_table_charset)
 
90
  {
 
91
    HA_CREATE_INFO db_info;
 
92
 
 
93
    load_db_opt_by_name(session, db, &db_info);
 
94
 
 
95
    create_info->default_table_charset= db_info.default_table_charset;
 
96
  }
 
97
}
 
98
 
53
99
/*
54
100
  Translate a file name to a table name (WL #1324).
55
101
 
67
113
  uint32_t errors;
68
114
  uint32_t res;
69
115
 
70
 
  if (!memcmp(from, tmp_file_prefix, tmp_file_prefix_length))
 
116
  if (!memcmp(from, TMP_FILE_PREFIX, TMP_FILE_PREFIX_LENGTH))
71
117
  {
72
118
    /* Temporary table name. */
73
 
    res= (my_stpncpy(to, from, to_length) - to);
 
119
    res= strlen(strncpy(to, from, to_length));
74
120
  }
75
121
  else
76
122
  {
81
127
      strcpy(to, MYSQL50_TABLE_NAME_PREFIX);
82
128
      strncat(to, from, to_length-MYSQL50_TABLE_NAME_PREFIX_LENGTH-1);
83
129
      res= strlen(to);
84
 
      sql_print_error(_("Invalid (old?) table or database name '%s'"), from);
 
130
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid (old?) table or database name '%s'"), from);
85
131
    }
86
132
  }
87
133
 
107
153
 
108
154
  if (from[0] == '#' && !strncmp(from, MYSQL50_TABLE_NAME_PREFIX,
109
155
                                 MYSQL50_TABLE_NAME_PREFIX_LENGTH))
110
 
    return((uint) (strmake(to, from+MYSQL50_TABLE_NAME_PREFIX_LENGTH,
111
 
                                to_length-1) -
112
 
                        (from + 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)));
113
159
  length= strconvert(system_charset_info, from,
114
160
                     &my_charset_filename, to, to_length, &errors);
115
161
  if (check_if_legal_tablename(to) &&
152
198
    build_tmptable_filename() for them.
153
199
 
154
200
  RETURN
155
 
    path length
 
201
    path length on success, 0 on failure
156
202
*/
157
203
 
158
204
uint32_t build_table_filename(char *buff, size_t bufflen, const char *db,
159
205
                          const char *table_name, const char *ext, uint32_t flags)
160
206
{
 
207
  string table_path;
161
208
  char dbbuff[FN_REFLEN];
162
209
  char tbbuff[FN_REFLEN];
 
210
  int rootdir_len= strlen(FN_ROOTDIR);
163
211
 
164
212
  if (flags & FN_IS_TMP) // FN_FROM_IS_TMP | FN_TO_IS_TMP
165
 
    my_stpncpy(tbbuff, table_name, sizeof(tbbuff));
 
213
    strncpy(tbbuff, table_name, sizeof(tbbuff));
166
214
  else
167
215
    tablename_to_filename(table_name, tbbuff, sizeof(tbbuff));
168
216
 
169
217
  tablename_to_filename(db, dbbuff, sizeof(dbbuff));
 
218
  table_path= drizzle_data_home;
 
219
  int without_rootdir= table_path.length()-rootdir_len;
170
220
 
171
 
  char *end = buff + bufflen;
172
221
  /* Don't add FN_ROOTDIR if dirzzle_data_home already includes it */
173
 
  char *pos = my_stpncpy(buff, drizzle_data_home, bufflen);
174
 
  int rootdir_len= strlen(FN_ROOTDIR);
175
 
  if (pos - rootdir_len >= buff &&
176
 
      memcmp(pos - rootdir_len, FN_ROOTDIR, rootdir_len) != 0)
177
 
    pos= my_stpncpy(pos, FN_ROOTDIR, end - pos);
178
 
  pos= my_stpncpy(pos, dbbuff, end-pos);
179
 
  pos= my_stpncpy(pos, FN_ROOTDIR, end-pos);
 
222
  if (without_rootdir >= 0)
 
223
  {
 
224
    char *tmp= (char*)table_path.c_str()+without_rootdir;
 
225
    if (memcmp(tmp, FN_ROOTDIR, rootdir_len) != 0)
 
226
      table_path.append(FN_ROOTDIR);
 
227
  }
 
228
 
 
229
  table_path.append(dbbuff);
 
230
  table_path.append(FN_ROOTDIR);
180
231
#ifdef USE_SYMDIR
181
 
  unpack_dirname(buff, buff);
182
 
  pos= strend(buff);
 
232
  table_path.clear();
183
233
#endif
184
 
  pos= my_stpncpy(pos, tbbuff, end - pos);
185
 
  pos= my_stpncpy(pos, ext, end - pos);
186
 
 
187
 
  return(pos - buff);
 
234
  table_path.append(tbbuff);
 
235
  table_path.append(ext);
 
236
 
 
237
  if (bufflen < table_path.length())
 
238
    return 0;
 
239
 
 
240
  strcpy(buff, table_path.c_str());
 
241
  return table_path.length();
188
242
}
189
243
 
190
244
 
191
245
/*
192
 
  Creates path to a file: mysql_tmpdir/#sql1234_12_1.ext
 
246
  Creates path to a file: drizzle_tmpdir/#sql1234_12_1.ext
193
247
 
194
248
  SYNOPSIS
195
249
   build_tmptable_filename()
196
 
     session                        The thread handle.
 
250
     session                    The thread handle.
197
251
     buff                       Where to write result in my_charset_filename.
198
252
     bufflen                    buff size
199
253
 
200
254
  NOTES
201
255
 
202
256
    Uses current_pid, thread_id, and tmp_table counter to create
203
 
    a file name in mysql_tmpdir.
 
257
    a file name in drizzle_tmpdir.
204
258
 
205
259
  RETURN
206
 
    path length
 
260
    path length on success, 0 on failure
207
261
*/
208
262
 
209
263
uint32_t build_tmptable_filename(Session* session, char *buff, size_t bufflen)
210
264
{
 
265
  uint32_t length;
 
266
  ostringstream path_str, post_tmpdir_str;
 
267
  string tmp;
211
268
 
212
 
  char *p= my_stpncpy(buff, mysql_tmpdir, bufflen);
213
 
  snprintf(p, bufflen - (p - buff), "/%s%lx_%"PRIx64"_%x%s",
214
 
              tmp_file_prefix, current_pid,
215
 
              session->thread_id, session->tmp_table++, reg_ext);
 
269
  path_str << drizzle_tmpdir;
 
270
  post_tmpdir_str << "/" << TMP_FILE_PREFIX << current_pid;
 
271
  post_tmpdir_str << session->thread_id << session->tmp_table++ << reg_ext;
 
272
  tmp= post_tmpdir_str.str();
216
273
 
217
274
  if (lower_case_table_names)
218
 
  {
219
 
    /* Convert all except tmpdir to lower case */
220
 
    my_casedn_str(files_charset_info, p);
221
 
  }
222
 
 
223
 
  uint32_t length= unpack_filename(buff, buff);
224
 
  return(length);
 
275
    transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
 
276
 
 
277
  path_str << tmp;
 
278
 
 
279
  if (bufflen < path_str.str().length())
 
280
    length= 0;
 
281
  else
 
282
    length= unpack_filename(buff, path_str.str().c_str());
 
283
 
 
284
  return length;
225
285
}
226
286
 
227
287
/*
240
300
    file
241
301
*/
242
302
 
243
 
void write_bin_log(Session *session, bool clear_error,
244
 
                   char const *query, ulong query_length)
 
303
void write_bin_log(Session *session, bool,
 
304
                   char const *query, size_t query_length)
245
305
{
246
 
  if (mysql_bin_log.is_open())
247
 
  {
248
 
    if (clear_error)
249
 
      session->clear_error();
250
 
    session->binlog_query(Session::STMT_QUERY_TYPE,
251
 
                      query, query_length, false, false);
252
 
  }
 
306
  (void)replicator_statement(session, query, query_length);
253
307
}
254
308
 
255
309
 
283
337
 
284
338
  if (tables && tables->schema_table)
285
339
  {
286
 
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.str);
 
340
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.c_str());
287
341
    return(true);
288
342
  }
289
343
 
301
355
    LOCK_open during wait_if_global_read_lock(), other threads could not
302
356
    close their tables. This would make a pretty deadlock.
303
357
  */
304
 
  error= mysql_rm_table_part2(session, tables, if_exists, drop_temporary, 0, 0);
 
358
  error= mysql_rm_table_part2(session, tables, if_exists, drop_temporary, 0);
305
359
 
306
360
  if (need_start_waiting)
307
361
    start_waiting_global_read_lock(session);
308
362
 
309
363
  if (error)
310
364
    return(true);
311
 
  my_ok(session);
 
365
  session->my_ok();
312
366
  return(false);
313
367
}
314
368
 
324
378
    drop_temporary      Only drop temporary tables
325
379
    drop_view           Allow to delete VIEW .frm
326
380
    dont_log_query      Don't write query to log files. This will also not
327
 
                        generate warnings if the handler files doesn't exists  
 
381
                        generate warnings if the handler files doesn't exists
328
382
 
329
383
  TODO:
330
384
    When logging to the binary log, we should log
343
397
*/
344
398
 
345
399
int mysql_rm_table_part2(Session *session, TableList *tables, bool if_exists,
346
 
                         bool drop_temporary, bool drop_view,
347
 
                         bool dont_log_query)
 
400
                         bool drop_temporary, bool dont_log_query)
348
401
{
349
402
  TableList *table;
350
403
  char path[FN_REFLEN], *alias;
351
 
  uint32_t path_length;
 
404
  uint32_t path_length= 0;
352
405
  String wrong_tables;
353
406
  int error= 0;
354
407
  int non_temp_tables_count= 0;
395
448
  {
396
449
    char *db=table->db;
397
450
    handlerton *table_type;
398
 
    enum legacy_db_type frm_db_type;
399
 
 
400
451
 
401
452
    error= drop_temporary_table(session, table);
402
453
 
464
515
                                        FN_IS_TMP : 0);
465
516
    }
466
517
    if (drop_temporary ||
467
 
        ((table_type == NULL && (access(path, F_OK) && ha_create_table_from_engine(session, db, alias))) ||
468
 
         (!drop_view && mysql_frm_type(session, path, &frm_db_type) != true)))
 
518
        ((table_type == NULL && (access(path, F_OK))))
 
519
        )
469
520
    {
470
521
      // Table was not found on disk and table can't be created from engine
471
522
      if (if_exists)
478
529
    else
479
530
    {
480
531
      char *end;
481
 
      if (table_type == NULL)
482
 
      {
483
 
        mysql_frm_type(session, path, &frm_db_type);
484
 
        table_type= ha_resolve_by_legacy_type(session, frm_db_type);
485
 
      }
486
532
      // Remove extension for delete
487
533
      *(end= path + path_length - reg_ext_length)= '\0';
488
 
      error= ha_delete_table(session, table_type, path, db, table->table_name,
 
534
      error= ha_delete_table(session, path, db, table->table_name,
489
535
                             !dont_log_query);
490
 
      if ((error == ENOENT || error == HA_ERR_NO_SUCH_TABLE) && 
491
 
          (if_exists || table_type == NULL))
 
536
      if ((error == ENOENT || error == HA_ERR_NO_SUCH_TABLE) &&
 
537
          if_exists)
492
538
      {
493
539
        error= 0;
494
540
        session->clear_error();
501
547
      if (!error || error == ENOENT || error == HA_ERR_NO_SUCH_TABLE)
502
548
      {
503
549
        int new_error;
 
550
 
 
551
        /* for some weird-ass reason, we ignore the return code here
 
552
           and things work. */
 
553
        delete_table_proto_file(path);
 
554
 
504
555
        /* Delete the table definition file */
505
 
        my_stpcpy(end,reg_ext);
 
556
        strcpy(end,reg_ext);
506
557
        if (!(new_error=my_delete(path,MYF(MY_WME))))
507
558
        {
508
559
          some_tables_deleted=1;
605
656
    != 0        Error
606
657
*/
607
658
 
608
 
bool quick_rm_table(handlerton *base,const char *db,
 
659
bool quick_rm_table(handlerton *,const char *db,
609
660
                    const char *table_name, uint32_t flags)
610
661
{
611
662
  char path[FN_REFLEN];
615
666
                                         db, table_name, reg_ext, flags);
616
667
  if (my_delete(path,MYF(0)))
617
668
    error= 1; /* purecov: inspected */
 
669
 
618
670
  path[path_length - reg_ext_length]= '\0'; // Remove reg_ext
619
 
  return(ha_delete_table(current_session, base, path, db, table_name, 0) ||
 
671
 
 
672
  error|= delete_table_proto_file(path);
 
673
 
 
674
  return(ha_delete_table(current_session, path, db, table_name, 0) ||
620
675
              error);
621
676
}
622
677
 
636
691
static int sort_keys(KEY *a, KEY *b)
637
692
{
638
693
  ulong a_flags= a->flags, b_flags= b->flags;
639
 
  
 
694
 
640
695
  if (a_flags & HA_NOSAME)
641
696
  {
642
697
    if (!(b_flags & HA_NOSAME))
646
701
      /* Sort NOT NULL keys before other keys */
647
702
      return (a_flags & (HA_NULL_PART_KEY)) ? 1 : -1;
648
703
    }
649
 
    if (a->name == primary_key_name)
 
704
    if (is_primary_key(a))
650
705
      return -1;
651
 
    if (b->name == primary_key_name)
 
706
    if (is_primary_key(b))
652
707
      return 1;
653
708
    /* Sort keys don't containing partial segments before others */
654
709
    if ((a_flags ^ b_flags) & HA_KEY_HAS_PART_KEY_SEG)
692
747
  TYPELIB tmp= *typelib;
693
748
  const char **cur_value= typelib->type_names;
694
749
  unsigned int *cur_length= typelib->type_lengths;
695
 
  *dup_val_count= 0;  
696
 
  
 
750
  *dup_val_count= 0;
 
751
 
697
752
  for ( ; tmp.count > 1; cur_value++, cur_length++)
698
753
  {
699
754
    tmp.type_names++;
763
818
   1    Error
764
819
*/
765
820
 
766
 
int prepare_create_field(Create_field *sql_field, 
 
821
int prepare_create_field(Create_field *sql_field,
767
822
                         uint32_t *blob_columns,
768
823
                         int *timestamps, int *timestamps_with_niladic,
769
 
                         int64_t table_flags __attribute__((unused)))
 
824
                         int64_t )
770
825
{
771
826
  unsigned int dup_val_count;
772
827
 
784
839
    if (sql_field->charset->state & MY_CS_BINSORT)
785
840
      sql_field->pack_flag|=FIELDFLAG_BINARY;
786
841
    sql_field->length=8;                        // Unireg field length
787
 
    sql_field->unireg_check=Field::BLOB_FIELD;
788
842
    (*blob_columns)++;
789
843
    break;
790
844
  case DRIZZLE_TYPE_VARCHAR:
797
851
      FIELDFLAG_INTERVAL;
798
852
    if (sql_field->charset->state & MY_CS_BINSORT)
799
853
      sql_field->pack_flag|=FIELDFLAG_BINARY;
800
 
    sql_field->unireg_check=Field::INTERVAL_FIELD;
801
854
    if (check_duplicates_in_interval("ENUM",sql_field->field_name,
802
855
                                 sql_field->interval,
803
856
                                     sql_field->charset, &dup_val_count))
804
857
      return(1);
805
858
    break;
806
 
  case DRIZZLE_TYPE_NEWDATE:  // Rest of string types
 
859
  case DRIZZLE_TYPE_DATE:  // Rest of string types
807
860
  case DRIZZLE_TYPE_TIME:
808
861
  case DRIZZLE_TYPE_DATETIME:
809
862
  case DRIZZLE_TYPE_NULL:
810
 
    sql_field->pack_flag=f_settype((uint) sql_field->sql_type);
 
863
    sql_field->pack_flag=f_settype((uint32_t) sql_field->sql_type);
811
864
    break;
812
865
  case DRIZZLE_TYPE_NEWDECIMAL:
813
866
    sql_field->pack_flag=(FIELDFLAG_NUMBER |
837
890
    sql_field->pack_flag=(FIELDFLAG_NUMBER |
838
891
                          (sql_field->flags & UNSIGNED_FLAG ? 0 :
839
892
                           FIELDFLAG_DECIMAL) |
840
 
                          f_settype((uint) sql_field->sql_type) |
 
893
                          f_settype((uint32_t) sql_field->sql_type) |
841
894
                          (sql_field->decimals << FIELDFLAG_DEC_SHIFT));
842
895
    break;
843
896
  }
924
977
 
925
978
    save_cs= sql_field->charset;
926
979
    if ((sql_field->flags & BINCMP_FLAG) &&
927
 
        !(sql_field->charset= get_charset_by_csname(sql_field->charset->csname,
928
 
                                                    MY_CS_BINSORT,MYF(0))))
 
980
        !(sql_field->charset= get_charset_by_csname(sql_field->charset->csname, MY_CS_BINSORT)))
929
981
    {
930
982
      char tmp[64];
931
 
      strmake(strmake(tmp, save_cs->csname, sizeof(tmp)-4),
932
 
              STRING_WITH_LEN("_bin"));
 
983
      char *tmp_pos= tmp;
 
984
      strncpy(tmp_pos, save_cs->csname, sizeof(tmp)-4);
 
985
      tmp_pos+= strlen(tmp);
 
986
      strncpy(tmp_pos, STRING_WITH_LEN("_bin"));
933
987
      my_error(ER_UNKNOWN_COLLATION, MYF(0), tmp);
934
988
      return(true);
935
989
    }
938
992
      Convert the default value from client character
939
993
      set into the column character set if necessary.
940
994
    */
941
 
    if (sql_field->def && 
 
995
    if (sql_field->def &&
942
996
        save_cs != sql_field->def->collation.collation &&
943
997
        (sql_field->sql_type == DRIZZLE_TYPE_ENUM))
944
998
    {
986
1040
        String conv, *tmp;
987
1041
        char comma_buf[4];
988
1042
        int comma_length= cs->cset->wc_mb(cs, ',', (unsigned char*) comma_buf,
989
 
                                          (unsigned char*) comma_buf + 
 
1043
                                          (unsigned char*) comma_buf +
990
1044
                                          sizeof(comma_buf));
991
1045
        assert(comma_length > 0);
992
1046
        for (uint32_t i= 0; (tmp= int_it++); i++)
1027
1081
            }
1028
1082
 
1029
1083
            /* else, the defaults yield the correct length for NULLs. */
1030
 
          } 
 
1084
          }
1031
1085
          else /* not NULL */
1032
1086
          {
1033
1087
            def->length(cs->cset->lengthsp(cs, def->ptr(), def->length()));
1087
1141
          sql_field->decimals=          dup_field->decimals;
1088
1142
          sql_field->create_length_to_internal_length();
1089
1143
          sql_field->unireg_check=      dup_field->unireg_check;
1090
 
          /* 
 
1144
          /*
1091
1145
            We're making one field from two, the result field will have
1092
1146
            dup_field->flags as flags. If we've incremented null_fields
1093
1147
            because of sql_field->flags, decrement it back.
1120
1174
  {
1121
1175
    assert(sql_field->charset != 0);
1122
1176
 
1123
 
    if (prepare_create_field(sql_field, &blob_columns, 
 
1177
    if (prepare_create_field(sql_field, &blob_columns,
1124
1178
                             &timestamps, &timestamps_with_niladic,
1125
1179
                             file->ha_table_flags()))
1126
1180
      return(true);
1131
1185
      auto_increment++;
1132
1186
    /*
1133
1187
          For now skip fields that are not physically stored in the database
1134
 
          (virtual fields) and update their offset later 
 
1188
          (virtual fields) and update their offset later
1135
1189
          (see the next loop).
1136
1190
        */
1137
1191
    if (sql_field->is_stored)
1250
1304
    else
1251
1305
      (*key_count)--;
1252
1306
    if (key->name.str && !tmp_table && (key->type != Key::PRIMARY) &&
1253
 
        !my_strcasecmp(system_charset_info,key->name.str, primary_key_name))
 
1307
        is_primary_key_name(key->name.str))
1254
1308
    {
1255
1309
      my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name.str);
1256
1310
      return(true);
1326
1380
    {
1327
1381
      my_error(ER_WRONG_STRING_LENGTH, MYF(0),
1328
1382
               key->key_create_info.comment.str,"INDEX COMMENT",
1329
 
               (uint) INDEX_COMMENT_MAXLEN);
 
1383
               (uint32_t) INDEX_COMMENT_MAXLEN);
1330
1384
      return(-1);
1331
1385
    }
1332
1386
 
1520
1574
                       MYF(0));
1521
1575
            return(true);
1522
1576
          }
1523
 
          key_name=primary_key_name;
 
1577
          static const char pkey_name[]= "PRIMARY";
 
1578
          key_name=pkey_name;
1524
1579
          primary_key=1;
1525
1580
        }
1526
1581
        else if (!(key_name= key->name.str))
1599
1654
  return(false);
1600
1655
}
1601
1656
 
1602
 
 
1603
 
/*
1604
 
  Set table default charset, if not set
1605
 
 
1606
 
  SYNOPSIS
1607
 
    set_table_default_charset()
1608
 
    create_info        Table create information
1609
 
 
1610
 
  DESCRIPTION
1611
 
    If the table character set was not given explicitely,
1612
 
    let's fetch the database default character set and
1613
 
    apply it to the table.
1614
 
*/
1615
 
 
1616
 
static void set_table_default_charset(Session *session,
1617
 
                                      HA_CREATE_INFO *create_info, char *db)
1618
 
{
1619
 
  /*
1620
 
    If the table character set was not given explicitly,
1621
 
    let's fetch the database default character set and
1622
 
    apply it to the table.
1623
 
  */
1624
 
  if (!create_info->default_table_charset)
1625
 
  {
1626
 
    HA_CREATE_INFO db_info;
1627
 
 
1628
 
    load_db_opt_by_name(session, db, &db_info);
1629
 
 
1630
 
    create_info->default_table_charset= db_info.default_table_charset;
1631
 
  }
1632
 
}
1633
 
 
1634
 
 
1635
1657
/*
1636
1658
  Extend long VARCHAR fields to blob & prepare field if it's a blob
1637
1659
 
1645
1667
        In this case the error is given
1646
1668
*/
1647
1669
 
1648
 
static bool prepare_blob_field(Session *session __attribute__((unused)),
 
1670
static bool prepare_blob_field(Session *,
1649
1671
                               Create_field *sql_field)
1650
1672
{
1651
1673
 
1656
1678
             MAX_FIELD_VARCHARLENGTH / sql_field->charset->mbmaxlen);
1657
1679
    return(1);
1658
1680
  }
1659
 
    
 
1681
 
1660
1682
  if ((sql_field->flags & BLOB_FLAG) && sql_field->length)
1661
1683
  {
1662
1684
    if (sql_field->sql_type == DRIZZLE_TYPE_BLOB)
1684
1706
    keys                List of keys to create
1685
1707
    internal_tmp_table  Set to 1 if this is an internal temporary table
1686
1708
                        (From ALTER Table)
1687
 
    select_field_count  
 
1709
    select_field_count
1688
1710
 
1689
1711
  DESCRIPTION
1690
1712
    If one creates a temporary table, this is automatically opened
1754
1776
    path_length= build_tmptable_filename(session, path, sizeof(path));
1755
1777
    create_info->table_options|=HA_CREATE_DELAY_KEY_WRITE;
1756
1778
  }
1757
 
  else  
 
1779
  else
1758
1780
  {
1759
1781
 #ifdef FN_DEVCHAR
1760
1782
    /* check if the table name contains FN_DEVCHAR when defined */
1832
1854
        break;
1833
1855
      case HA_ERR_TABLE_EXIST:
1834
1856
 
1835
 
      if (create_if_not_exists)
1836
 
        goto warn;
1837
 
      my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
1838
 
      goto unlock_and_end;
1839
 
        break;
 
1857
        if (create_if_not_exists)
 
1858
          goto warn;
 
1859
        my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
 
1860
        goto unlock_and_end;
1840
1861
      default:
1841
1862
        my_error(retcode, MYF(0),table_name);
1842
1863
        goto unlock_and_end;
1874
1895
  path[path_length - reg_ext_length]= '\0'; // Remove .frm extension
1875
1896
  if (rea_create_table(session, path, db, table_name,
1876
1897
                       create_info, alter_info->create_list,
1877
 
                       key_count, key_info_buffer, file))
 
1898
                       key_count, key_info_buffer, file, false))
1878
1899
    goto unlock_and_end;
1879
1900
 
1880
1901
  if (create_info->options & HA_LEX_CREATE_TMP_TABLE)
1882
1903
    /* Open table and put in temporary table list */
1883
1904
    if (!(open_temporary_table(session, path, db, table_name, 1, OTM_OPEN)))
1884
1905
    {
1885
 
      (void) rm_temporary_table(create_info->db_type, path, false);
 
1906
      (void) rm_temporary_table(create_info->db_type, path);
1886
1907
      goto unlock_and_end;
1887
1908
    }
1888
1909
    session->thread_specific_used= true;
2014
2035
  char buff[MAX_FIELD_NAME],*buff_end;
2015
2036
 
2016
2037
  if (!check_if_keyname_exists(field_name,start,end) &&
2017
 
      my_strcasecmp(system_charset_info,field_name,primary_key_name))
 
2038
      !is_primary_key_name(field_name))
2018
2039
    return (char*) field_name;                  // Use fieldname
2019
 
  buff_end=strmake(buff,field_name, sizeof(buff)-4);
 
2040
 
 
2041
  buff_end= strncpy(buff, field_name, sizeof(buff)-4);
 
2042
  buff_end+= strlen(buff);
2020
2043
 
2021
2044
  /*
2022
2045
    Only 3 chars + '\0' left, so need to limit to 2 digit
2087
2110
  if (lower_case_table_names == 2 && file &&
2088
2111
      !(file->ha_table_flags() & HA_FILE_BASED))
2089
2112
  {
2090
 
    my_stpcpy(tmp_name, old_name);
 
2113
    strcpy(tmp_name, old_name);
2091
2114
    my_casedn_str(files_charset_info, tmp_name);
2092
2115
    build_table_filename(lc_from, sizeof(lc_from), old_db, tmp_name, "",
2093
2116
                         flags & FN_FROM_IS_TMP);
2094
2117
    from_base= lc_from;
2095
2118
 
2096
 
    my_stpcpy(tmp_name, new_name);
 
2119
    strcpy(tmp_name, new_name);
2097
2120
    my_casedn_str(files_charset_info, tmp_name);
2098
2121
    build_table_filename(lc_to, sizeof(lc_to), new_db, tmp_name, "",
2099
2122
                         flags & FN_TO_IS_TMP);
2108
2131
      if (file)
2109
2132
        file->ha_rename_table(to_base, from_base);
2110
2133
    }
 
2134
 
 
2135
    if(!(flags & NO_FRM_RENAME)
 
2136
       && rename_table_proto_file(from_base, to_base))
 
2137
    {
 
2138
      error= errno;
 
2139
      rename_file_ext(to, from, reg_ext);
 
2140
      if (file)
 
2141
        file->ha_rename_table(to_base, from_base);
 
2142
    }
2111
2143
  }
2112
2144
  delete file;
2113
2145
  if (error == HA_ERR_WRONG_COMMAND)
2216
2248
  const char **ext;
2217
2249
  struct stat stat_info;
2218
2250
 
2219
 
  if (!(check_opt->sql_flags & TT_USEFRM))
 
2251
  if (!(check_opt->use_frm))
2220
2252
    return(0);
2221
2253
 
2222
2254
  if (!(table= table_list->table))              /* if open_ltable failed */
2267
2299
    Check if this is a table type that stores index and data separately,
2268
2300
    like ISAM or MyISAM. We assume fixed order of engine file name
2269
2301
    extentions array. First element of engine file name extentions array
2270
 
    is meta/index file extention. Second element - data file extention. 
 
2302
    is meta/index file extention. Second element - data file extention.
2271
2303
  */
2272
2304
  ext= table->file->bas_ext();
2273
2305
  if (!ext[0] || !ext[1])
2274
2306
    goto end;                                   // No data file
2275
2307
 
2276
2308
  // Name of data file
2277
 
  strxmov(from, table->s->normalized_path.str, ext[1], NULL);
 
2309
  sprintf(from,"%s%s", table->s->normalized_path.str, ext[1]);
2278
2310
  if (stat(from, &stat_info))
2279
2311
    goto end;                           // Can't use USE_FRM flag
2280
2312
 
2281
2313
  snprintf(tmp, sizeof(tmp), "%s-%lx_%"PRIx64,
2282
 
           from, current_pid, session->thread_id);
 
2314
           from, (unsigned long)current_pid, session->thread_id);
2283
2315
 
2284
2316
  /* If we could open the table, close it */
2285
2317
  if (table_list->table)
2340
2372
  if (table == &tmp_table)
2341
2373
  {
2342
2374
    pthread_mutex_lock(&LOCK_open);
2343
 
    closefrm(table, 1);                         // Free allocated memory
 
2375
    table->closefrm(true);                              // Free allocated memory
2344
2376
    pthread_mutex_unlock(&LOCK_open);
2345
2377
  }
2346
2378
  return(error);
2351
2383
/*
2352
2384
  RETURN VALUES
2353
2385
    false Message sent to net (admin operation went ok)
2354
 
    true  Message should be sent by caller 
 
2386
    true  Message should be sent by caller
2355
2387
          (admin operation or network communication failed)
2356
2388
*/
2357
2389
static bool mysql_admin_table(Session* session, TableList* tables,
2367
2399
                                                            HA_CHECK_OPT *))
2368
2400
{
2369
2401
  TableList *table;
2370
 
  SELECT_LEX *select= &session->lex->select_lex;
 
2402
  Select_Lex *select= &session->lex->select_lex;
2371
2403
  List<Item> field_list;
2372
2404
  Item *item;
2373
2405
  Protocol *protocol= session->protocol;
2399
2431
    char* db = table->db;
2400
2432
    bool fatal_error=0;
2401
2433
 
2402
 
    strxmov(table_name, db, ".", table->table_name, NULL);
 
2434
    sprintf(table_name,"%s.%s",db,table->table_name);
2403
2435
    session->open_options|= extra_open_options;
2404
2436
    table->lock_type= lock_type;
2405
2437
    /* open only one table from local list of command */
2515
2547
      /* purecov: end */
2516
2548
    }
2517
2549
 
2518
 
    if (operator_func == &handler::ha_repair &&
2519
 
        !(check_opt->sql_flags & TT_USEFRM))
 
2550
    if (operator_func == &handler::ha_repair && !(check_opt->use_frm))
2520
2551
    {
2521
2552
      if ((table->table->file->check_old_types() == HA_ADMIN_NEEDS_ALTER) ||
2522
2553
          (table->table->file->ha_check_for_upgrade(check_opt) ==
2524
2555
      {
2525
2556
        ha_autocommit_or_rollback(session, 1);
2526
2557
        close_thread_tables(session);
2527
 
        tmp_disable_binlog(session); // binlogging is done by caller if wanted
2528
2558
        result_code= mysql_recreate_table(session, table);
2529
 
        reenable_binlog(session);
2530
2559
        /*
2531
2560
          mysql_recreate_table() can push OK or ERROR.
2532
2561
          Clear 'OK' status. If there is an error, keep it:
2533
 
          we will store the error message in a result set row 
 
2562
          we will store the error message in a result set row
2534
2563
          and then clear.
2535
2564
        */
2536
2565
        if (session->main_da.is_ok())
2579
2608
      }
2580
2609
      break;
2581
2610
 
2582
 
    case HA_ADMIN_NOT_BASE_TABLE:
2583
 
      {
2584
 
        char buf[ERRMSGSIZE+20];
2585
 
        uint32_t length= snprintf(buf, ERRMSGSIZE,
2586
 
                              ER(ER_BAD_TABLE_ERROR), table_name);
2587
 
        protocol->store(STRING_WITH_LEN("note"), system_charset_info);
2588
 
        protocol->store(buf, length, system_charset_info);
2589
 
      }
2590
 
      break;
2591
 
 
2592
2611
    case HA_ADMIN_OK:
2593
2612
      protocol->store(STRING_WITH_LEN("status"), system_charset_info);
2594
2613
      protocol->store(STRING_WITH_LEN("OK"), system_charset_info);
2637
2656
      TableList *save_next_local= table->next_local,
2638
2657
                 *save_next_global= table->next_global;
2639
2658
      table->next_local= table->next_global= 0;
2640
 
      tmp_disable_binlog(session); // binlogging is done by caller if wanted
2641
2659
      result_code= mysql_recreate_table(session, table);
2642
 
      reenable_binlog(session);
2643
2660
      /*
2644
2661
        mysql_recreate_table() can push OK or ERROR.
2645
2662
        Clear 'OK' status. If there is an error, keep it:
2646
 
        we will store the error message in a result set row 
 
2663
        we will store the error message in a result set row
2647
2664
        and then clear.
2648
2665
      */
2649
2666
      if (session->main_da.is_ok())
2662
2679
        if (session->is_error())
2663
2680
        {
2664
2681
          const char *err_msg= session->main_da.message();
2665
 
          if (!session->vio_ok())
 
2682
          if (!session->drizzleclient_vio_ok())
2666
2683
          {
2667
 
            sql_print_error("%s",err_msg);
 
2684
            errmsg_printf(ERRMSG_LVL_ERROR, "%s", err_msg);
2668
2685
          }
2669
2686
          else
2670
2687
          {
2685
2702
      table->next_global= save_next_global;
2686
2703
      goto send_result_message;
2687
2704
    }
2688
 
    case HA_ADMIN_WRONG_CHECKSUM:
2689
 
    {
2690
 
      protocol->store(STRING_WITH_LEN("note"), system_charset_info);
2691
 
      protocol->store(ER(ER_VIEW_CHECKSUM), strlen(ER(ER_VIEW_CHECKSUM)),
2692
 
                      system_charset_info);
2693
 
      break;
2694
 
    }
2695
 
 
2696
2705
    case HA_ADMIN_NEEDS_UPGRADE:
2697
2706
    case HA_ADMIN_NEEDS_ALTER:
2698
2707
    {
2743
2752
      goto err;
2744
2753
  }
2745
2754
 
2746
 
  my_eof(session);
 
2755
  session->my_eof();
2747
2756
  return(false);
2748
2757
 
2749
2758
err:
2759
2768
bool mysql_repair_table(Session* session, TableList* tables, HA_CHECK_OPT* check_opt)
2760
2769
{
2761
2770
  return(mysql_admin_table(session, tables, check_opt,
2762
 
                                "repair", TL_WRITE, 1,
2763
 
                                test(check_opt->sql_flags & TT_USEFRM),
2764
 
                                HA_OPEN_FOR_REPAIR,
2765
 
                                &prepare_for_repair,
2766
 
                                &handler::ha_repair));
 
2771
                           "repair", TL_WRITE, 1,
 
2772
                           check_opt->use_frm,
 
2773
                           HA_OPEN_FOR_REPAIR,
 
2774
                           &prepare_for_repair,
 
2775
                           &handler::ha_repair));
2767
2776
}
2768
2777
 
2769
2778
 
2770
2779
bool mysql_optimize_table(Session* session, TableList* tables, HA_CHECK_OPT* check_opt)
2771
2780
{
2772
2781
  return(mysql_admin_table(session, tables, check_opt,
2773
 
                                "optimize", TL_WRITE, 1,0,0,0,
2774
 
                                &handler::ha_optimize));
 
2782
                           "optimize", TL_WRITE, 1,0,0,0,
 
2783
                           &handler::ha_optimize));
2775
2784
}
2776
2785
 
2777
2786
 
2835
2844
    0     ok
2836
2845
*/
2837
2846
 
2838
 
int reassign_keycache_tables(Session *session __attribute__((unused)),
 
2847
int reassign_keycache_tables(Session *,
2839
2848
                             KEY_CACHE *src_cache,
2840
2849
                             KEY_CACHE *dst_cache)
2841
2850
{
2851
2860
  @brief          Create frm file based on I_S table
2852
2861
 
2853
2862
  @param[in]      session                      thread handler
2854
 
  @param[in]      schema_table             I_S table           
 
2863
  @param[in]      schema_table             I_S table
2855
2864
  @param[in]      dst_path                 path where frm should be created
2856
2865
  @param[in]      create_info              Create info
2857
2866
 
2876
2885
  schema_table->table->use_all_columns();
2877
2886
  if (mysql_prepare_alter_table(session, schema_table->table,
2878
2887
                                &local_create_info, &alter_info))
2879
 
    return(1);
 
2888
    return true;
 
2889
 
2880
2890
  if (mysql_prepare_create_table(session, &local_create_info, &alter_info,
2881
2891
                                 tmp_table, &db_options,
2882
2892
                                 schema_table->table->file,
2883
2893
                                 &schema_table->table->s->key_info, &keys, 0))
2884
 
    return(1);
 
2894
    return true;
 
2895
 
2885
2896
  local_create_info.max_rows= 0;
2886
 
  if (mysql_create_frm(session, dst_path, NULL, NULL,
 
2897
  if (rea_create_table(session, dst_path, "system_tmp", "system_stupid_i_s_fix_nonsense",
2887
2898
                       &local_create_info, alter_info.create_list,
2888
2899
                       keys, schema_table->table->s->key_info,
2889
 
                       schema_table->table->file))
2890
 
    return(1);
2891
 
  return(0);
 
2900
                       schema_table->table->file, true))
 
2901
    return true;
 
2902
 
 
2903
  return false;
2892
2904
}
2893
2905
 
2894
 
 
2895
2906
/*
2896
2907
  Create a table identical to the specified table
2897
2908
 
2931
2942
  if (open_tables(session, &src_table, &not_used, 0))
2932
2943
    return(true);
2933
2944
 
2934
 
  strxmov(src_path, src_table->table->s->path.str, reg_ext, NULL);
 
2945
  sprintf(src_path,"%s%s",src_table->table->s->path.str, reg_ext);
2935
2946
 
2936
 
  /* 
 
2947
  /*
2937
2948
    Check that destination tables does not exist. Note that its name
2938
2949
    was already checked when it was added to the table list.
2939
2950
  */
2978
2989
      goto err;
2979
2990
    }
2980
2991
  }
2981
 
  else if (my_copy(src_path, dst_path, MYF(MY_DONT_OVERWRITE_FILE)))
 
2992
  else
2982
2993
  {
2983
 
    if (my_errno == ENOENT)
2984
 
      my_error(ER_BAD_DB_ERROR,MYF(0),db);
2985
 
    else
2986
 
      my_error(ER_CANT_CREATE_FILE,MYF(0),dst_path,my_errno);
2987
 
    pthread_mutex_unlock(&LOCK_open);
2988
 
    goto err;
 
2994
    int frmcopyr= my_copy(src_path, dst_path, MYF(MY_DONT_OVERWRITE_FILE));
 
2995
 
 
2996
    string dfesrc(src_path);
 
2997
    string dfedst(dst_path);
 
2998
 
 
2999
    dfesrc.replace(dfesrc.find(".frm"), 4, ".dfe" );
 
3000
    dfedst.replace(dfedst.find(".frm"), 4, ".dfe" );
 
3001
 
 
3002
    int dfecopyr= my_copy(dfesrc.c_str(), dfedst.c_str(),
 
3003
                          MYF(MY_DONT_OVERWRITE_FILE));
 
3004
 
 
3005
    if(frmcopyr || dfecopyr) // FIXME: should handle only one fail.
 
3006
    {
 
3007
      if (my_errno == ENOENT)
 
3008
        my_error(ER_BAD_DB_ERROR,MYF(0),db);
 
3009
      else
 
3010
        my_error(ER_CANT_CREATE_FILE,MYF(0),dst_path,my_errno);
 
3011
      pthread_mutex_unlock(&LOCK_open);
 
3012
      goto err;
 
3013
    }
2989
3014
  }
2990
3015
 
2991
3016
  /*
3005
3030
                                     OTM_OPEN))
3006
3031
    {
3007
3032
      (void) rm_temporary_table(create_info->db_type,
3008
 
                                dst_path, false); /* purecov: inspected */
 
3033
                                dst_path);
3009
3034
      goto err;     /* purecov: inspected */
3010
3035
    }
3011
3036
  }
3169
3194
err:
3170
3195
  ha_autocommit_or_rollback(session, error);
3171
3196
  session->tablespace_op=false;
3172
 
  
 
3197
 
3173
3198
  if (error == 0)
3174
3199
  {
3175
 
    my_ok(session);
 
3200
    session->my_ok();
3176
3201
    return(0);
3177
3202
  }
3178
3203
 
3179
3204
  table->file->print_error(error, MYF(0));
3180
 
    
 
3205
 
3181
3206
  return(-1);
3182
3207
}
3183
3208
 
3252
3277
compare_tables(Session *session,
3253
3278
               Table *table,
3254
3279
               Alter_info *alter_info,
3255
 
                           HA_CREATE_INFO *create_info,
 
3280
               HA_CREATE_INFO *create_info,
3256
3281
               uint32_t order_num,
3257
3282
               HA_ALTER_FLAGS *alter_flags,
3258
3283
               HA_ALTER_INFO *ha_alter_info,
3264
3289
  Create_field *new_field;
3265
3290
  KEY_PART_INFO *key_part;
3266
3291
  KEY_PART_INFO *end;
3267
 
  /*
3268
 
    Remember if the new definition has new VARCHAR column;
3269
 
    create_info->varchar will be reset in mysql_prepare_create_table.
3270
 
  */
3271
 
  bool varchar= create_info->varchar;
3272
3292
 
3273
3293
  {
3274
3294
    /*
3287
3307
      destroy the copy.
3288
3308
    */
3289
3309
    Alter_info tmp_alter_info(*alter_info, session->mem_root);
3290
 
    Session *session= table->in_use;
 
3310
    session= table->in_use;
3291
3311
    uint32_t db_options= 0; /* not used */
3292
3312
    /* Create the prepared information. */
3293
3313
    if (mysql_prepare_create_table(session, create_info,
3301
3321
      return(true);
3302
3322
    /* Allocate result buffers. */
3303
3323
    if (! (ha_alter_info->index_drop_buffer=
3304
 
           (uint*) session->alloc(sizeof(uint) * table->s->keys)) ||
 
3324
           (uint*) session->alloc(sizeof(uint32_t) * table->s->keys)) ||
3305
3325
        ! (ha_alter_info->index_add_buffer=
3306
 
           (uint*) session->alloc(sizeof(uint) *
 
3326
           (uint*) session->alloc(sizeof(uint32_t) *
3307
3327
                              tmp_alter_info.key_list.elements)))
3308
3328
      return(true);
3309
3329
  }
3349
3369
      create_info->used_fields & HA_CREATE_USED_ROW_FORMAT ||
3350
3370
      (alter_info->flags & (ALTER_RECREATE | ALTER_FOREIGN_KEY)) ||
3351
3371
      order_num ||
3352
 
      !table->s->mysql_version ||
3353
 
      (table->s->frm_version < FRM_VER_TRUE_VARCHAR && varchar))
 
3372
      !table->s->mysql_version)
3354
3373
  {
3355
3374
    *table_changes= IS_EQUAL_NO;
3356
3375
    /*
3372
3391
    /* TODO check for ADD/DROP FOREIGN KEY */
3373
3392
    if (alter_info->flags & ALTER_FOREIGN_KEY)
3374
3393
      *alter_flags|=  HA_ALTER_FOREIGN_KEY;
3375
 
    if (!table->s->mysql_version ||
3376
 
        (table->s->frm_version < FRM_VER_TRUE_VARCHAR && varchar))
3377
 
      *alter_flags|=  HA_ALTER_COLUMN_TYPE;
3378
3394
  }
3379
3395
  /*
3380
3396
    Go through fields and check if the original ones are compatible
3404
3420
      /*
3405
3421
        Check if the altered column is a stored virtual field.
3406
3422
        TODO: Mark such a column with an alter flag only if
3407
 
        the expression functions are not equal. 
 
3423
        the expression functions are not equal.
3408
3424
      */
3409
3425
      if (field->is_stored && field->vcol_info)
3410
3426
        *alter_flags|= HA_ALTER_STORED_VCOL;
3425
3441
 
3426
3442
      /* Check that NULL behavior is same for old and new fields */
3427
3443
      if ((new_field->flags & NOT_NULL_FLAG) !=
3428
 
          (uint) (field->flags & NOT_NULL_FLAG))
 
3444
          (uint32_t) (field->flags & NOT_NULL_FLAG))
3429
3445
      {
3430
3446
        *table_changes= IS_EQUAL_NO;
3431
3447
        *alter_flags|= HA_ALTER_COLUMN_NULLABLE;
3474
3490
      if (table_key->flags & HA_NOSAME)
3475
3491
      {
3476
3492
        /* Unique key. Check for "PRIMARY". */
3477
 
        if (! my_strcasecmp(system_charset_info,
3478
 
                            table_key->name, primary_key_name))
 
3493
        if (is_primary_key(table_key))
3479
3494
          *alter_flags|= HA_DROP_PK_INDEX;
3480
3495
        else
3481
3496
          *alter_flags|= HA_DROP_UNIQUE_INDEX;
3495
3510
      if (table_key->flags & HA_NOSAME)
3496
3511
      {
3497
3512
        // Unique key. Check for "PRIMARY".
3498
 
        if (! my_strcasecmp(system_charset_info,
3499
 
                            table_key->name, primary_key_name))
 
3513
        if (is_primary_key(table_key))
3500
3514
          *alter_flags|= HA_ALTER_PK_INDEX;
3501
3515
        else
3502
3516
          *alter_flags|= HA_ALTER_UNIQUE_INDEX;
3525
3539
        if (table_key->flags & HA_NOSAME)
3526
3540
        {
3527
3541
          /* Unique key. Check for "PRIMARY" */
3528
 
          if (! my_strcasecmp(system_charset_info,
3529
 
                              table_key->name, primary_key_name))
 
3542
          if (is_primary_key(table_key))
3530
3543
            *alter_flags|= HA_ALTER_PK_INDEX;
3531
3544
          else
3532
3545
            *alter_flags|= HA_ALTER_UNIQUE_INDEX;
3588
3601
      if (new_key->flags & HA_NOSAME)
3589
3602
      {
3590
3603
        /* Unique key. Check for "PRIMARY" */
3591
 
        if (! my_strcasecmp(system_charset_info,
3592
 
                            new_key->name, primary_key_name))
 
3604
        if (is_primary_key(new_key))
3593
3605
          *alter_flags|= HA_ADD_PK_INDEX;
3594
3606
        else
3595
3607
        *alter_flags|= HA_ADD_UNIQUE_INDEX;
3690
3702
    if (create_info->index_file_name)
3691
3703
    {
3692
3704
      /* Fix index_file_name to have 'tmp_name' as basename */
3693
 
      my_stpcpy(index_file, tmp_name);
 
3705
      strcpy(index_file, tmp_name);
3694
3706
      create_info->index_file_name=fn_same(index_file,
3695
3707
                                           create_info->index_file_name,
3696
3708
                                           1);
3698
3710
    if (create_info->data_file_name)
3699
3711
    {
3700
3712
      /* Fix data_file_name to have 'tmp_name' as basename */
3701
 
      my_stpcpy(data_file, tmp_name);
 
3713
      strcpy(data_file, tmp_name);
3702
3714
      create_info->data_file_name=fn_same(data_file,
3703
3715
                                          create_info->data_file_name,
3704
3716
                                          1);
3709
3721
 
3710
3722
  /*
3711
3723
    Create a table with a temporary name.
3712
 
    With create_info->frm_only == 1 this creates a .frm file only.
3713
3724
    We don't log the statement, it will be logged later.
3714
3725
  */
3715
 
  tmp_disable_binlog(session);
3716
3726
  error= mysql_create_table(session, new_db, tmp_name,
3717
3727
                            create_info, alter_info, 1, 0);
3718
 
  reenable_binlog(session);
3719
3728
 
3720
3729
  return(error);
3721
3730
}
3754
3763
  char path[FN_REFLEN];
3755
3764
 
3756
3765
  snprintf(tmp_name, sizeof(tmp_name), "%s-%lx_%"PRIx64,
3757
 
           tmp_file_prefix, current_pid, session->thread_id);
 
3766
           TMP_FILE_PREFIX, (unsigned long)current_pid, session->thread_id);
3758
3767
  /* Safety fix for InnoDB */
3759
3768
  if (lower_case_table_names)
3760
3769
    my_casedn_str(files_charset_info, tmp_name);
3761
3770
  altered_create_info.options&= ~HA_LEX_CREATE_TMP_TABLE;
3762
 
  altered_create_info.frm_only= 1;
 
3771
 
3763
3772
  if ((error= create_temporary_table(session, table, new_db, tmp_name,
3764
3773
                                     &altered_create_info,
3765
3774
                                     alter_info, db_change)))
3772
3781
  altered_table= open_temporary_table(session, path, new_db, tmp_name, 1,
3773
3782
                                      OTM_ALTER);
3774
3783
  return(altered_table);
3775
 
 
3776
 
  return(NULL);
3777
3784
}
3778
3785
 
3779
3786
 
3830
3837
 
3831
3838
    /*
3832
3839
       Tell the storage engine to perform the online alter table
3833
 
       TODO: 
 
3840
       TODO:
3834
3841
       if check_if_supported_alter() returned HA_ALTER_SUPPORTED_WAIT_LOCK
3835
3842
       we need to wrap the next call with a DDL lock.
3836
3843
     */
4011
4018
    */
4012
4019
  Field **f_ptr,*field;
4013
4020
  for (f_ptr=table->field ; (field= *f_ptr) ; f_ptr++)
4014
 
    {
 
4021
  {
4015
4022
    /* Check if field should be dropped */
4016
4023
    Alter_drop *drop;
4017
4024
    drop_it.rewind();
4019
4026
    {
4020
4027
      if (drop->type == Alter_drop::COLUMN &&
4021
4028
          !my_strcasecmp(system_charset_info,field->field_name, drop->name))
4022
 
    {
 
4029
      {
4023
4030
        /* Reset auto_increment value if it was dropped */
4024
4031
        if (MTYP_TYPENR(field->unireg_check) == Field::NEXT_NUMBER &&
4025
4032
            !(used_fields & HA_CREATE_USED_AUTO))
4026
 
      {
 
4033
        {
4027
4034
          create_info->auto_increment_value=0;
4028
4035
          create_info->used_fields|=HA_CREATE_USED_AUTO;
 
4036
        }
 
4037
        break;
4029
4038
      }
4030
 
        break;
4031
4039
    }
4032
 
  }
4033
4040
    if (drop)
4034
 
      {
 
4041
    {
4035
4042
      drop_it.remove();
4036
4043
      continue;
4037
4044
    }
4054
4061
        goto err;
4055
4062
      }
4056
4063
      if (!def->after)
4057
 
        {
 
4064
      {
4058
4065
        new_create_list.push_back(def);
4059
4066
        def_it.remove();
4060
 
        }
4061
4067
      }
4062
 
      else
4063
 
      {
 
4068
    }
 
4069
    else
 
4070
    {
4064
4071
      /*
4065
4072
        This field was not dropped and not changed, add it to the list
4066
4073
        for the new table.
4070
4077
      alter_it.rewind();                        // Change default if ALTER
4071
4078
      Alter_column *alter;
4072
4079
      while ((alter=alter_it++))
4073
 
        {
 
4080
      {
4074
4081
        if (!my_strcasecmp(system_charset_info,field->field_name, alter->name))
4075
4082
          break;
4076
 
        }
 
4083
      }
4077
4084
      if (alter)
4078
 
        {
 
4085
      {
4079
4086
        if (def->sql_type == DRIZZLE_TYPE_BLOB)
4080
4087
        {
4081
4088
          my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), def->change);
4097
4104
      my_error(ER_BAD_FIELD_ERROR, MYF(0), def->change, table->s->table_name.str);
4098
4105
      goto err;
4099
4106
    }
4100
 
      /*
 
4107
    /*
4101
4108
      Check that the DATE/DATETIME not null field we are going to add is
4102
4109
      either has a default value or the '0000-00-00' is allowed by the
4103
4110
      set sql mode.
4104
4111
      If the '0000-00-00' value isn't allowed then raise the error_if_not_empty
4105
4112
      flag to allow ALTER Table only if the table to be altered is empty.
4106
 
      */
4107
 
    if ((def->sql_type == DRIZZLE_TYPE_NEWDATE ||
 
4113
    */
 
4114
    if ((def->sql_type == DRIZZLE_TYPE_DATE ||
4108
4115
         def->sql_type == DRIZZLE_TYPE_DATETIME) &&
4109
 
         !alter_info->datetime_field &&
4110
 
         !(~def->flags & (NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG)) &&
4111
 
         session->variables.sql_mode & MODE_NO_ZERO_DATE)
 
4116
        !alter_info->datetime_field &&
 
4117
        !(~def->flags & (NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG)) &&
 
4118
        session->variables.sql_mode & MODE_NO_ZERO_DATE)
4112
4119
    {
4113
 
        alter_info->datetime_field= def;
4114
 
        alter_info->error_if_not_empty= true;
 
4120
      alter_info->datetime_field= def;
 
4121
      alter_info->error_if_not_empty= true;
4115
4122
    }
4116
4123
    if (!def->after)
4117
4124
      new_create_list.push_back(def);
4125
4132
      {
4126
4133
        if (!my_strcasecmp(system_charset_info,def->after, find->field_name))
4127
4134
          break;
4128
 
  }
 
4135
      }
4129
4136
      if (!find)
4130
 
  {
 
4137
      {
4131
4138
        my_error(ER_BAD_FIELD_ERROR, MYF(0), def->after, table->s->table_name.str);
4132
 
    goto err;
4133
 
  }
 
4139
        goto err;
 
4140
      }
4134
4141
      find_it.after(def);                       // Put element after this
4135
4142
      /*
4136
4143
        XXX: hack for Bug#28427.
4155
4162
    my_error(ER_BAD_FIELD_ERROR, MYF(0),
4156
4163
             alter_info->alter_list.head()->name, table->s->table_name.str);
4157
4164
    goto err;
4158
 
    }
 
4165
  }
4159
4166
  if (!new_create_list.elements)
4160
 
    {
 
4167
  {
4161
4168
    my_message(ER_CANT_REMOVE_ALL_FIELDS, ER(ER_CANT_REMOVE_ALL_FIELDS),
4162
4169
               MYF(0));
4163
4170
    goto err;
4164
 
    }
 
4171
  }
4165
4172
 
4166
 
    /*
 
4173
  /*
4167
4174
    Collect all keys which isn't in drop list. Add only those
4168
4175
    for which some fields exists.
4169
 
    */
 
4176
  */
4170
4177
 
4171
4178
  for (uint32_t i=0 ; i < table->s->keys ; i++,key_info++)
4172
 
    {
 
4179
  {
4173
4180
    char *key_name= key_info->name;
4174
4181
    Alter_drop *drop;
4175
4182
    drop_it.rewind();
4176
4183
    while ((drop=drop_it++))
4177
 
      {
 
4184
    {
4178
4185
      if (drop->type == Alter_drop::KEY &&
4179
4186
          !my_strcasecmp(system_charset_info,key_name, drop->name))
4180
4187
        break;
4181
 
      }
 
4188
    }
4182
4189
    if (drop)
4183
 
        {
 
4190
    {
4184
4191
      drop_it.remove();
4185
4192
      continue;
4186
4193
    }
4195
4202
      Create_field *cfield;
4196
4203
      field_it.rewind();
4197
4204
      while ((cfield=field_it++))
4198
 
    {
 
4205
      {
4199
4206
        if (cfield->change)
4200
 
    {
 
4207
        {
4201
4208
          if (!my_strcasecmp(system_charset_info, key_part_name,
4202
4209
                             cfield->change))
4203
4210
            break;
4251
4258
 
4252
4259
      if (key_info->flags & HA_NOSAME)
4253
4260
      {
4254
 
        if (! my_strcasecmp(system_charset_info, key_name, primary_key_name))
 
4261
        if (is_primary_key_name(key_name))
4255
4262
          key_type= Key::PRIMARY;
4256
4263
        else
4257
4264
          key_type= Key::UNIQUE;
4275
4282
        goto err;
4276
4283
      if (key->type != Key::FOREIGN_KEY)
4277
4284
        new_key_list.push_back(key);
4278
 
      if (key->name.str &&
4279
 
          !my_strcasecmp(system_charset_info, key->name.str, primary_key_name))
 
4285
      if (key->name.str && is_primary_key_name(key->name.str))
4280
4286
      {
4281
4287
        my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name.str);
4282
4288
        goto err;
4377
4383
                       uint32_t order_num, order_st *order, bool ignore)
4378
4384
{
4379
4385
  Table *table, *new_table=0, *name_lock= 0;;
 
4386
  string new_name_str;
4380
4387
  int error= 0;
4381
4388
  char tmp_name[80],old_name[32],new_name_buff[FN_REFLEN];
4382
4389
  char new_alias_buff[FN_REFLEN], *table_name, *db, *new_alias, *alias;
4383
4390
  char path[FN_REFLEN];
4384
4391
  ha_rows copied= 0,deleted= 0;
4385
4392
  handlerton *old_db_type, *new_db_type, *save_old_db_type;
4386
 
  legacy_db_type table_type;
 
4393
 
 
4394
  new_name_buff[0]= '\0';
4387
4395
 
4388
4396
  if (table_list && table_list->schema_table)
4389
4397
  {
4390
 
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.str);
 
4398
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.c_str());
4391
4399
    return(true);
4392
4400
  }
4393
4401
 
4411
4419
    /* Conditionally writes to binlog. */
4412
4420
    return(mysql_discard_or_import_tablespace(session,table_list,
4413
4421
                                              alter_info->tablespace_op));
4414
 
  char* pos= new_name_buff;
4415
 
  char* pos_end= pos+strlen(new_name_buff)-1;
4416
 
  pos= my_stpncpy(new_name_buff, drizzle_data_home, pos_end-pos);
4417
 
  pos= my_stpncpy(new_name_buff, "/", pos_end-pos);
4418
 
  pos= my_stpncpy(new_name_buff, db, pos_end-pos);
4419
 
  pos= my_stpncpy(new_name_buff, "/", pos_end-pos);
4420
 
  pos= my_stpncpy(new_name_buff, table_name, pos_end-pos);
4421
 
  pos= my_stpncpy(new_name_buff, reg_ext, pos_end-pos);
 
4422
  ostringstream oss;
 
4423
  oss << drizzle_data_home << "/" << db << "/" << table_name << reg_ext;
4422
4424
 
4423
 
  (void) unpack_filename(new_name_buff, new_name_buff);
 
4425
  (void) unpack_filename(new_name_buff, oss.str().c_str());
4424
4426
  /*
4425
4427
    If this is just a rename of a view, short cut to the
4426
4428
    following scenario: 1) lock LOCK_open 2) do a RENAME
4434
4436
    into the main table list, like open_tables does).
4435
4437
    This code is wrong and will be removed, please do not copy.
4436
4438
  */
4437
 
  (void)mysql_frm_type(session, new_name_buff, &table_type);
4438
4439
 
4439
4440
  if (!(table= open_n_lock_single_table(session, table_list, TL_WRITE_ALLOW_READ)))
4440
4441
    return(true);
4443
4444
  /* Check that we are not trying to rename to an existing table */
4444
4445
  if (new_name)
4445
4446
  {
4446
 
    my_stpcpy(new_name_buff,new_name);
4447
 
    my_stpcpy(new_alias= new_alias_buff, new_name);
 
4447
    strcpy(new_name_buff,new_name);
 
4448
    strcpy(new_alias= new_alias_buff, new_name);
4448
4449
    if (lower_case_table_names)
4449
4450
    {
4450
4451
      if (lower_case_table_names != 2)
4451
4452
      {
4452
 
        my_casedn_str(files_charset_info, new_name_buff);
4453
 
        new_alias= new_name;                    // Create lower case table name
 
4453
        my_casedn_str(files_charset_info, new_name_buff);
 
4454
        new_alias= new_name;                    // Create lower case table name
4454
4455
      }
4455
4456
      my_casedn_str(files_charset_info, new_name);
4456
4457
    }
4521
4522
  if (create_info->row_type == ROW_TYPE_NOT_USED)
4522
4523
    create_info->row_type= table->s->row_type;
4523
4524
 
4524
 
  if (ha_check_storage_engine_flag(old_db_type, HTON_ALTER_NOT_SUPPORTED) ||
4525
 
      ha_check_storage_engine_flag(new_db_type, HTON_ALTER_NOT_SUPPORTED))
 
4525
  if (ha_check_storage_engine_flag(old_db_type, HTON_BIT_ALTER_NOT_SUPPORTED) ||
 
4526
      ha_check_storage_engine_flag(new_db_type, HTON_BIT_ALTER_NOT_SUPPORTED))
4526
4527
  {
4527
4528
    my_error(ER_ILLEGAL_HA, MYF(0), table_name);
4528
4529
    goto err;
4627
4628
    if (!error)
4628
4629
    {
4629
4630
      write_bin_log(session, true, session->query, session->query_length);
4630
 
      my_ok(session);
 
4631
      session->my_ok();
4631
4632
  }
4632
4633
    else if (error > 0)
4633
4634
  {
4661
4662
 
4662
4663
  set_table_default_charset(session, create_info, db);
4663
4664
 
4664
 
 
4665
4665
  if (session->variables.old_alter_table
4666
4666
      || (table->s->db_type() != create_info->db_type)
4667
4667
     )
4792
4792
      close_temporary_table(session, altered_table, 1, 1);
4793
4793
  }
4794
4794
 
4795
 
  snprintf(tmp_name, sizeof(tmp_name), "%s-%lx_%"PRIx64, tmp_file_prefix,
4796
 
           current_pid, session->thread_id);
 
4795
  snprintf(tmp_name, sizeof(tmp_name), "%s-%lx_%"PRIx64, TMP_FILE_PREFIX,
 
4796
           (unsigned long)current_pid, session->thread_id);
4797
4797
  /* Safety fix for innodb */
4798
4798
  if (lower_case_table_names)
4799
4799
    my_casedn_str(files_charset_info, tmp_name);
4800
4800
 
4801
4801
 
4802
4802
  /* Create a temporary table with the new format */
4803
 
  if ((error= create_temporary_table(session, table, new_db, tmp_name, 
4804
 
                                     create_info, alter_info, 
 
4803
  if ((error= create_temporary_table(session, table, new_db, tmp_name,
 
4804
                                     create_info, alter_info,
4805
4805
                                     !strcmp(db, new_db))))
4806
4806
  {
4807
4807
    goto err;
4819
4819
  }
4820
4820
  else
4821
4821
  {
4822
 
    char path[FN_REFLEN];
 
4822
    char tmp_path[FN_REFLEN];
4823
4823
    /* table is a normal table: Create temporary table in same directory */
4824
 
    build_table_filename(path, sizeof(path), new_db, tmp_name, "",
 
4824
    build_table_filename(tmp_path, sizeof(tmp_path), new_db, tmp_name, "",
4825
4825
                         FN_IS_TMP);
4826
4826
    /* Open our intermediate table */
4827
 
    new_table=open_temporary_table(session, path, new_db, tmp_name, 0, OTM_OPEN);
 
4827
    new_table=open_temporary_table(session, tmp_path, new_db, tmp_name, 0, OTM_OPEN);
4828
4828
  }
4829
4829
  if (!new_table)
4830
4830
    goto err1;
4860
4860
    if (end_active_trans(session))
4861
4861
      error= 1;
4862
4862
  }
4863
 
  session->count_cuted_fields= CHECK_FIELD_IGNORE;
 
4863
  /* We must not ignore bad input! */;
 
4864
  session->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
4864
4865
 
4865
4866
  if (table->s->tmp_table != NO_TMP_TABLE)
4866
4867
  {
4915
4916
  */
4916
4917
 
4917
4918
  session->set_proc_info("rename result table");
4918
 
  snprintf(old_name, sizeof(old_name), "%s2-%lx-%"PRIx64, tmp_file_prefix,
4919
 
           current_pid, session->thread_id);
 
4919
  snprintf(old_name, sizeof(old_name), "%s2-%lx-%"PRIx64, TMP_FILE_PREFIX,
 
4920
           (unsigned long)current_pid, session->thread_id);
4920
4921
  if (lower_case_table_names)
4921
4922
    my_casedn_str(files_charset_info, old_name);
4922
4923
 
4977
4978
 
4978
4979
  session->set_proc_info("end");
4979
4980
 
4980
 
  assert(!(mysql_bin_log.is_open() &&
4981
 
                (create_info->options & HA_LEX_CREATE_TMP_TABLE)));
4982
4981
  write_bin_log(session, true, session->query, session->query_length);
4983
4982
 
4984
 
  if (ha_check_storage_engine_flag(old_db_type, HTON_FLUSH_AFTER_RENAME))
 
4983
  if (ha_check_storage_engine_flag(old_db_type, HTON_BIT_FLUSH_AFTER_RENAME))
4985
4984
  {
4986
4985
    /*
4987
4986
      For the alter table to be properly flushed to the logs, we
4988
4987
      have to open the new table.  If not, we get a problem on server
4989
4988
      shutdown. But we do not need to attach MERGE children.
4990
4989
    */
4991
 
    char path[FN_REFLEN];
 
4990
    char table_path[FN_REFLEN];
4992
4991
    Table *t_table;
4993
 
    build_table_filename(path, sizeof(path), new_db, table_name, "", 0);
4994
 
    t_table= open_temporary_table(session, path, new_db, tmp_name, false, OTM_OPEN);
 
4992
    build_table_filename(table_path, sizeof(table_path), new_db, table_name, "", 0);
 
4993
    t_table= open_temporary_table(session, table_path, new_db, tmp_name, false, OTM_OPEN);
4995
4994
    if (t_table)
4996
4995
    {
4997
4996
      intern_close_table(t_table);
4998
4997
      free(t_table);
4999
4998
    }
5000
4999
    else
5001
 
      sql_print_warning(_("Could not open table %s.%s after rename\n"),
5002
 
                        new_db,table_name);
 
5000
      errmsg_printf(ERRMSG_LVL_WARN,
 
5001
                    _("Could not open table %s.%s after rename\n"),
 
5002
                    new_db,table_name);
5003
5003
    ha_flush_logs(old_db_type);
5004
5004
  }
5005
5005
  table_list->table=0;                          // For query cache
5019
5019
  }
5020
5020
 
5021
5021
end_temporary:
5022
 
  snprintf(tmp_name, sizeof(tmp_name), ER(ER_INSERT_INFO),
5023
 
           (ulong) (copied + deleted), (ulong) deleted,
5024
 
           (ulong) session->cuted_fields);
5025
 
  my_ok(session, copied + deleted, 0L, tmp_name);
5026
 
  session->some_tables_deleted=0;
5027
 
  return(false);
 
5022
  /*
 
5023
   * Field::store() may have called my_error().  If this is 
 
5024
   * the case, we must not send an ok packet, since 
 
5025
   * Diagnostics_area::is_set() will fail an assert.
 
5026
   */
 
5027
  if (! session->is_error())
 
5028
  {
 
5029
    snprintf(tmp_name, sizeof(tmp_name), ER(ER_INSERT_INFO),
 
5030
            (ulong) (copied + deleted), (ulong) deleted,
 
5031
            (ulong) session->cuted_fields);
 
5032
    session->my_ok(copied + deleted, 0L, tmp_name);
 
5033
    session->some_tables_deleted=0;
 
5034
    return false;
 
5035
  }
 
5036
  else
 
5037
  {
 
5038
    /* my_error() was called.  Return true (which means error...) */
 
5039
    return true;
 
5040
  }
5028
5041
 
5029
5042
err1:
5030
5043
  if (new_table)
5048
5061
    enum enum_drizzle_timestamp_type t_type= DRIZZLE_TIMESTAMP_DATE;
5049
5062
    switch (alter_info->datetime_field->sql_type)
5050
5063
    {
5051
 
      case DRIZZLE_TYPE_NEWDATE:
 
5064
      case DRIZZLE_TYPE_DATE:
5052
5065
        f_val= "0000-00-00";
5053
5066
        t_type= DRIZZLE_TIMESTAMP_DATE;
5054
5067
        break;
5117
5130
  /*
5118
5131
    Turn off recovery logging since rollback of an alter table is to
5119
5132
    delete the new table so there is no need to log the changes to it.
5120
 
    
 
5133
 
5121
5134
    This needs to be done before external_lock
5122
5135
  */
5123
5136
  error= ha_enable_transaction(session, false);
5124
5137
  if (error)
5125
5138
    return(-1);
5126
 
  
 
5139
 
5127
5140
  if (!(copy= new Copy_field[to->s->fields]))
5128
5141
    return(-1);                         /* purecov: inspected */
5129
5142
 
5164
5177
    if (to->s->primary_key != MAX_KEY && to->file->primary_key_is_clustered())
5165
5178
    {
5166
5179
      char warn_buff[DRIZZLE_ERRMSG_SIZE];
5167
 
      snprintf(warn_buff, sizeof(warn_buff), 
 
5180
      snprintf(warn_buff, sizeof(warn_buff),
5168
5181
               _("order_st BY ignored because there is a user-defined clustered "
5169
5182
                 "index in the table '%-.192s'"),
5170
5183
               from->s->table_name.str);
5173
5186
    }
5174
5187
    else
5175
5188
    {
5176
 
      from->sort.io_cache=(IO_CACHE*) my_malloc(sizeof(IO_CACHE),
5177
 
                                                MYF(MY_FAE | MY_ZEROFILL));
 
5189
      from->sort.io_cache= new IO_CACHE;
 
5190
      memset(from->sort.io_cache, 0, sizeof(IO_CACHE));
 
5191
 
5178
5192
      memset(&tables, 0, sizeof(tables));
5179
5193
      tables.table= from;
5180
5194
      tables.alias= tables.table_name= from->s->table_name.str;
5222
5236
      else
5223
5237
        to->next_number_field->reset();
5224
5238
    }
5225
 
    
 
5239
 
5226
5240
    for (Copy_field *copy_ptr=copy ; copy_ptr != copy_end ; copy_ptr++)
5227
5241
    {
5228
5242
      copy_ptr->do_copy(copy_ptr);
5356
5370
    char table_name[NAME_LEN*2+2];
5357
5371
    Table *t;
5358
5372
 
5359
 
    strxmov(table_name, table->db ,".", table->table_name, NULL);
 
5373
    sprintf(table_name,"%s.%s",table->db,table->table_name);
5360
5374
 
5361
5375
    t= table->table= open_n_lock_single_table(session, table, TL_READ);
5362
5376
    session->clear_error();                     // these errors shouldn't get client
5439
5453
      goto err;
5440
5454
  }
5441
5455
 
5442
 
  my_eof(session);
 
5456
  session->my_eof();
5443
5457
  return(false);
5444
5458
 
5445
5459
 err:
5468
5482
                       table_name);
5469
5483
  }
5470
5484
  if (create_info->options & HA_LEX_CREATE_TMP_TABLE &&
5471
 
      ha_check_storage_engine_flag(*new_engine, HTON_TEMPORARY_NOT_SUPPORTED))
 
5485
      ha_check_storage_engine_flag(*new_engine, HTON_BIT_TEMPORARY_NOT_SUPPORTED))
5472
5486
  {
5473
5487
    if (create_info->used_fields & HA_CREATE_USED_ENGINE)
5474
5488
    {