~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/alter_table.cc

MergedĀ fromĀ me.

Show diffs side-by-side

added added

removed removed

Lines of Context:
564
564
    return 0;
565
565
  }
566
566
 
567
 
  table->cursor->print_error(error, MYF(0));
 
567
  table->print_error(error, MYF(0));
568
568
 
569
569
  return -1;
570
570
}
606
606
                        table->s->table_name.str);
607
607
    error= 0;
608
608
  } else if (error)
609
 
    table->cursor->print_error(error, MYF(0));
 
609
    table->print_error(error, MYF(0));
610
610
 
611
611
  return(error);
612
612
}
933
933
    }
934
934
    else if (error > 0)
935
935
    {
936
 
      table->cursor->print_error(error, MYF(0));
 
936
      table->print_error(error, MYF(0));
937
937
      error= -1;
938
938
    }
939
939
 
1040
1040
    }
1041
1041
 
1042
1042
    /* Remove link to old table and rename the new one */
1043
 
    session->close_temporary_table(table, true, true);
 
1043
    session->close_temporary_table(table);
1044
1044
 
1045
1045
    /* Should pass the 'new_name' as we store table name in the cache */
1046
1046
    if (new_table->rename_temporary_table(new_db, new_name))
1139
1139
  session->set_proc_info("end");
1140
1140
 
1141
1141
  write_bin_log(session, session->query, session->query_length);
1142
 
 
1143
 
  if (old_db_type->check_flag(HTON_BIT_FLUSH_AFTER_RENAME))
1144
 
  {
1145
 
    /*
1146
 
      For the alter table to be properly flushed to the logs, we
1147
 
      have to open the new table.  If not, we get a problem on server
1148
 
      shutdown. But we do not need to attach MERGE children.
1149
 
    */
1150
 
    char table_path[FN_REFLEN];
1151
 
    Table *t_table;
1152
 
    build_table_filename(table_path, sizeof(table_path), new_db, table_name, false);
1153
 
    t_table= session->open_temporary_table(table_path, new_db, tmp_name, false);
1154
 
    if (t_table)
1155
 
    {
1156
 
      t_table->intern_close_table();
1157
 
      free(t_table);
1158
 
    }
1159
 
    else
1160
 
      errmsg_printf(ERRMSG_LVL_WARN, _("Could not open table %s.%s after rename\n"), new_db, table_name);
1161
 
 
1162
 
    plugin::StorageEngine::flushLogs(old_db_type);
1163
 
  }
1164
1142
  table_list->table= NULL;
1165
1143
 
1166
1144
end_temporary:
1188
1166
  if (new_table)
1189
1167
  {
1190
1168
    /* close_temporary_table() frees the new_table pointer. */
1191
 
    session->close_temporary_table(new_table, true, true);
 
1169
    session->close_temporary_table(new_table);
1192
1170
  }
1193
1171
  else
1194
1172
    quick_rm_table(*session, new_db, tmp_name, true);
1248
1226
/* alter_table */
1249
1227
 
1250
1228
static int
1251
 
copy_data_between_tables(Table *from,Table *to,
1252
 
                         List<CreateField> &create,
 
1229
copy_data_between_tables(Table *from, Table *to,
 
1230
                         List<CreateField> &create,
1253
1231
                         bool ignore,
1254
 
                         uint32_t order_num, order_st *order,
1255
 
                         ha_rows *copied,
1256
 
                         ha_rows *deleted,
 
1232
                         uint32_t order_num, order_st *order,
 
1233
                         ha_rows *copied,
 
1234
                         ha_rows *deleted,
1257
1235
                         enum enum_enable_or_disable keys_onoff,
1258
1236
                         bool error_if_not_empty)
1259
1237
{
1387
1365
    error= to->cursor->ha_write_row(to->record[0]);
1388
1366
    to->auto_increment_field_not_null= false;
1389
1367
    if (error)
1390
 
    {
 
1368
    { 
1391
1369
      if (!ignore ||
1392
1370
          to->cursor->is_fatal_error(error, HA_CHECK_DUP))
1393
 
      {
1394
 
        if (!to->cursor->is_fatal_error(error, HA_CHECK_DUP))
1395
 
        {
1396
 
          uint32_t key_nr= to->cursor->get_dup_key(error);
1397
 
          if ((int) key_nr >= 0)
1398
 
          {
1399
 
            const char *err_msg= ER(ER_DUP_ENTRY_WITH_KEY_NAME);
1400
 
            if (key_nr == 0 &&
1401
 
                (to->key_info[0].key_part[0].field->flags &
1402
 
                 AUTO_INCREMENT_FLAG))
1403
 
              err_msg= ER(ER_DUP_ENTRY_AUTOINCREMENT_CASE);
1404
 
            to->cursor->print_keydup_error(key_nr, err_msg);
1405
 
            break;
1406
 
          }
1407
 
        }
1408
 
 
1409
 
        to->cursor->print_error(error,MYF(0));
 
1371
      { 
 
1372
        to->print_error(error, MYF(0));
1410
1373
        break;
1411
1374
      }
1412
1375
      to->cursor->restore_auto_increment(prev_insert_id);
1421
1384
 
1422
1385
  if (to->cursor->ha_end_bulk_insert() && error <= 0)
1423
1386
  {
1424
 
    to->cursor->print_error(my_errno,MYF(0));
 
1387
    to->print_error(my_errno, MYF(0));
1425
1388
    error=1;
1426
1389
  }
1427
1390
  to->cursor->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);