~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/alter_table.cc

  • Committer: Andrew Hutchings
  • Date: 2010-10-27 06:36:38 UTC
  • mto: (1883.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1884.
  • Revision ID: andrew@linuxjedi.co.uk-20101027063638-08d33sknkd691zz2
Fix min() usage for 32bit
Fix Solaris doesn't follow POSIX standard for send()

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
 
45
45
#include "drizzled/transaction_services.h"
46
46
 
47
 
#include "drizzled/filesort.h"
48
 
 
49
47
#include "drizzled/message.h"
50
48
 
51
49
using namespace std;
60
58
                                    List<CreateField> &create,
61
59
                                    bool ignore,
62
60
                                    uint32_t order_num,
63
 
                                    Order *order,
 
61
                                    order_st *order,
64
62
                                    ha_rows *copied,
65
63
                                    ha_rows *deleted,
66
64
                                    enum enum_enable_or_disable keys_onoff,
107
105
  assert(select_lex->db);
108
106
 
109
107
  /* Chicken/Egg... we need to search for the table, to know if the table exists, so we can build a full identifier from it */
110
 
  message::table::shared_ptr original_table_message;
 
108
  message::Table original_table_message;
111
109
  {
112
110
    TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName());
113
111
    if (plugin::StorageEngine::getTableDefinition(*session, identifier, original_table_message) != EEXIST)
114
112
    {
115
 
      std::string path;
116
 
      identifier.getSQLPath(path);
117
 
      my_error(ER_BAD_TABLE_ERROR, MYF(0), path.c_str());
 
113
      my_error(ER_BAD_TABLE_ERROR, MYF(0), identifier.getSQLPath().c_str());
118
114
      return true;
119
115
    }
120
116
 
121
117
    if (not  create_info.db_type)
122
118
    {
123
119
      create_info.db_type= 
124
 
        plugin::StorageEngine::findByName(*session, original_table_message->engine().name());
 
120
        plugin::StorageEngine::findByName(*session, original_table_message.engine().name());
125
121
 
126
122
      if (not create_info.db_type)
127
123
      {
128
 
        std::string path;
129
 
        identifier.getSQLPath(path);
130
 
        my_error(ER_BAD_TABLE_ERROR, MYF(0), path.c_str());
 
124
        my_error(ER_BAD_TABLE_ERROR, MYF(0), identifier.getSQLPath().c_str());
131
125
        return true;
132
126
      }
133
127
    }
134
128
  }
135
129
 
136
130
  if (not validateCreateTableOption())
 
131
  {
137
132
    return true;
 
133
  }
138
134
 
139
135
  /* ALTER TABLE ends previous transaction */
140
136
  if (not session->endActiveTransaction())
 
137
  {
141
138
    return true;
 
139
  }
142
140
 
143
 
  if (not (need_start_waiting= not session->wait_if_global_read_lock(0, 1)))
 
141
  if (not (need_start_waiting= ! wait_if_global_read_lock(session, 0, 1)))
 
142
  {
144
143
    return true;
 
144
  }
145
145
 
146
146
  bool res;
147
 
  if (original_table_message->type() == message::Table::STANDARD )
 
147
  if (original_table_message.type() == message::Table::STANDARD )
148
148
  {
149
149
    TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName());
150
150
    TableIdentifier new_identifier(select_lex->db ? select_lex->db : first_table->getSchemaName(),
154
154
                     identifier,
155
155
                     new_identifier,
156
156
                     &create_info,
157
 
                     *original_table_message,
 
157
                     original_table_message,
158
158
                     create_table_message,
159
159
                     first_table,
160
160
                     &alter_info,
161
161
                     select_lex->order_list.elements,
162
 
                     (Order *) select_lex->order_list.first,
 
162
                     (order_st *) select_lex->order_list.first,
163
163
                     session->lex->ignore);
164
164
  }
165
165
  else
177
177
                       identifier,
178
178
                       new_identifier,
179
179
                       &create_info,
180
 
                       *original_table_message,
 
180
                       original_table_message,
181
181
                       create_table_message,
182
182
                       first_table,
183
183
                       &alter_info,
184
184
                       select_lex->order_list.elements,
185
 
                       (Order *) select_lex->order_list.first,
 
185
                       (order_st *) select_lex->order_list.first,
186
186
                       session->lex->ignore);
187
187
    }
188
188
  }
191
191
     Release the protection against the global read lock and wake
192
192
     everyone, who might want to set a global read lock.
193
193
   */
194
 
  session->startWaitingGlobalReadLock();
195
 
 
 
194
  start_waiting_global_read_lock(session);
196
195
  return res;
197
196
}
198
197
 
347
346
        if (def->sql_type == DRIZZLE_TYPE_BLOB)
348
347
        {
349
348
          my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), def->change);
350
 
          return true;
 
349
                goto err;
351
350
        }
352
351
        if ((def->def= alter->def))
353
352
        {
355
354
          def->flags&= ~NO_DEFAULT_VALUE_FLAG;
356
355
        }
357
356
        else
358
 
        {
359
357
          def->flags|= NO_DEFAULT_VALUE_FLAG;
360
 
        }
361
358
        alter_it.remove();
362
359
      }
363
360
    }
368
365
    if (def->change && ! def->field)
369
366
    {
370
367
      my_error(ER_BAD_FIELD_ERROR, MYF(0), def->change, table->getMutableShare()->getTableName());
371
 
      return true;
 
368
      goto err;
372
369
    }
373
370
    /*
374
 
      If we have been given a field which has no default value, and is not null then we need to bail.
 
371
      Check that the DATE/DATETIME not null field we are going to add is
 
372
      either has a default value or the '0000-00-00' is allowed by the
 
373
      set sql mode.
 
374
      If the '0000-00-00' value isn't allowed then raise the error_if_not_empty
 
375
      flag to allow ALTER Table only if the table to be altered is empty.
375
376
    */
376
 
    if (not (~def->flags & (NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG)) and not def->change)
 
377
    if ((def->sql_type == DRIZZLE_TYPE_DATE ||
 
378
         def->sql_type == DRIZZLE_TYPE_DATETIME) &&
 
379
        ! alter_info->datetime_field &&
 
380
        ! (~def->flags & (NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG)))
377
381
    {
 
382
      alter_info->datetime_field= def;
378
383
      alter_info->error_if_not_empty= true;
379
384
    }
380
385
    if (! def->after)
381
 
    {
382
386
      new_create_list.push_back(def);
383
 
    }
384
387
    else if (def->after == first_keyword)
385
 
    {
386
388
      new_create_list.push_front(def);
387
 
    }
388
389
    else
389
390
    {
390
391
      CreateField *find;
397
398
      if (! find)
398
399
      {
399
400
        my_error(ER_BAD_FIELD_ERROR, MYF(0), def->after, table->getMutableShare()->getTableName());
400
 
        return true;
 
401
        goto err;
401
402
      }
402
403
      find_it.after(def); /* Put element after this */
403
404
      /*
412
413
      */
413
414
      if (alter_info->build_method == HA_BUILD_ONLINE)
414
415
      {
415
 
        my_error(ER_NOT_SUPPORTED_YET, MYF(0), session->getQueryString()->c_str());
416
 
        return true;
 
416
        my_error(ER_NOT_SUPPORTED_YET, MYF(0), session->query.c_str());
 
417
        goto err;
417
418
      }
418
419
      alter_info->build_method= HA_BUILD_OFFLINE;
419
420
    }
424
425
             MYF(0),
425
426
             alter_info->alter_list.head()->name,
426
427
             table->getMutableShare()->getTableName());
427
 
    return true;
 
428
    goto err;
428
429
  }
429
430
  if (! new_create_list.elements)
430
431
  {
431
432
    my_message(ER_CANT_REMOVE_ALL_FIELDS,
432
433
               ER(ER_CANT_REMOVE_ALL_FIELDS),
433
434
               MYF(0));
434
 
    return true;
 
435
    goto err;
435
436
  }
436
437
 
437
438
  /*
568
569
      if (key->type == Key::FOREIGN_KEY)
569
570
      {
570
571
        if (((Foreign_key *)key)->validate(new_create_list))
571
 
        {
572
 
          return true;
573
 
        }
 
572
          goto err;
574
573
 
575
574
        Foreign_key *fkey= (Foreign_key*)key;
576
575
        add_foreign_key_to_table_message(&table_message,
591
590
        my_error(ER_WRONG_NAME_FOR_INDEX,
592
591
                 MYF(0),
593
592
                 key->name.str);
594
 
        return true;
 
593
        goto err;
595
594
      }
596
595
    }
597
596
  }
618
617
    my_error(ER_CANT_DROP_FIELD_OR_KEY,
619
618
             MYF(0),
620
619
             alter_info->drop_list.head()->name);
621
 
    return true;
 
620
    goto err;
622
621
  }
623
622
  if (alter_info->alter_list.elements)
624
623
  {
625
624
    my_error(ER_CANT_DROP_FIELD_OR_KEY,
626
625
             MYF(0),
627
626
             alter_info->alter_list.head()->name);
628
 
    return true;
 
627
    goto err;
629
628
  }
630
629
 
631
630
  if (not table_message.options().has_comment()
644
643
  rc= false;
645
644
  alter_info->create_list.swap(new_create_list);
646
645
  alter_info->key_list.swap(new_key_list);
 
646
err:
647
647
 
648
648
  size_t num_engine_options= table_message.engine().options_size();
649
649
  size_t original_num_engine_options= original_proto.engine().options_size();
670
670
 
671
671
  drizzled::message::update(table_message);
672
672
 
673
 
  return false;
 
673
  return rc;
674
674
}
675
675
 
676
676
/* table_list should contain just one table */
712
712
 
713
713
  /* The ALTER Table is always in its own transaction */
714
714
  error= transaction_services.autocommitOrRollback(session, false);
715
 
  if (not session->endActiveTransaction())
 
715
  if (! session->endActiveTransaction())
716
716
    error=1;
717
 
 
718
717
  if (error)
719
718
    goto err;
720
 
 
721
 
  write_bin_log(session, *session->getQueryString());
 
719
  write_bin_log(session, session->query.c_str());
722
720
 
723
721
err:
724
722
  (void) transaction_services.autocommitOrRollback(session, error);
791
789
 
792
790
      if (session.find_temporary_table(new_table_identifier))
793
791
      {
794
 
        std::string path;
795
 
        new_table_identifier.getSQLPath(path);
796
 
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), path.c_str());
 
792
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_table_identifier.getSQLPath().c_str());
797
793
        return false;
798
794
      }
799
795
    }
806
802
 
807
803
      if (not name_lock)
808
804
      {
809
 
        std::string path;
810
 
        new_table_identifier.getSQLPath(path);
811
 
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), path.c_str());
 
805
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_table_identifier.getSQLPath().c_str());
812
806
        return false;
813
807
      }
814
808
 
815
809
      if (plugin::StorageEngine::doesTableExist(session, new_table_identifier))
816
810
      {
817
 
        std::string path;
818
 
        new_table_identifier.getSQLPath(path);
819
 
 
820
811
        /* Table will be closed by Session::executeCommand() */
821
 
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), path.c_str());
 
812
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_table_identifier.getSQLPath().c_str());
822
813
 
823
 
        table::Cache::singleton().mutex().lock(); /* ALTER TABLe */
 
814
        LOCK_open.lock(); /* ALTER TABLe */
824
815
        session.unlink_open_table(name_lock);
825
 
        table::Cache::singleton().mutex().unlock();
 
816
        LOCK_open.unlock();
826
817
 
827
818
        return false;
828
819
      }
884
875
                                 TableList *table_list,
885
876
                                 AlterInfo *alter_info,
886
877
                                 uint32_t order_num,
887
 
                                 Order *order,
 
878
                                 order_st *order,
888
879
                                 bool ignore)
889
880
{
890
881
  int error= 0;
893
884
  ha_rows copied= 0;
894
885
  ha_rows deleted= 0;
895
886
 
896
 
  if (not original_table_identifier.isValid())
897
 
    return true;
898
 
 
899
 
  if (not new_table_identifier.isValid())
900
 
    return true;
901
 
 
902
887
  session->set_proc_info("init");
903
888
 
904
889
  table->use_all_columns();
934
919
  if (original_engine->check_flag(HTON_BIT_ALTER_NOT_SUPPORTED) ||
935
920
      new_engine->check_flag(HTON_BIT_ALTER_NOT_SUPPORTED))
936
921
  {
937
 
    std::string path;
938
 
    new_table_identifier.getSQLPath(path);
939
 
    my_error(ER_ILLEGAL_HA, MYF(0), path.c_str());
 
922
    my_error(ER_ILLEGAL_HA, MYF(0), new_table_identifier.getSQLPath().c_str());
940
923
 
941
924
    return true;
942
925
  }
970
953
          while the fact that the table is still open gives us protection
971
954
          from concurrent DDL statements.
972
955
        */
973
 
        table::Cache::singleton().mutex().lock(); /* DDL wait for/blocker */
 
956
        LOCK_open.lock(); /* DDL wait for/blocker */
974
957
        wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
975
 
        table::Cache::singleton().mutex().unlock();
 
958
        LOCK_open.unlock();
976
959
        error= table->cursor->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
977
960
        /* COND_refresh will be signaled in close_thread_tables() */
978
961
        break;
979
962
      case DISABLE:
980
 
        table::Cache::singleton().mutex().lock(); /* DDL wait for/blocker */
 
963
        LOCK_open.lock(); /* DDL wait for/blocker */
981
964
        wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
982
 
        table::Cache::singleton().mutex().unlock();
 
965
        LOCK_open.unlock();
983
966
        error=table->cursor->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
984
967
        /* COND_refresh will be signaled in close_thread_tables() */
985
968
        break;
997
980
                            table->getAlias());
998
981
      }
999
982
 
1000
 
      table::Cache::singleton().mutex().lock(); /* Lock to remove all instances of table from table cache before ALTER */
 
983
      LOCK_open.lock(); /* Lock to remove all instances of table from table cache before ALTER */
1001
984
      /*
1002
985
        Unlike to the above case close_cached_table() below will remove ALL
1003
986
        instances of Table from table cache (it will also remove table lock
1004
987
        held by this thread). So to make actual table renaming and writing
1005
988
        to binlog atomic we have to put them into the same critical section
1006
 
        protected by table::Cache::singleton().mutex() mutex. This also removes gap for races between
 
989
        protected by LOCK_open mutex. This also removes gap for races between
1007
990
        access() and mysql_rename_table() calls.
1008
991
      */
1009
992
 
1025
1008
        */
1026
1009
        if (plugin::StorageEngine::doesTableExist(*session, new_table_identifier))
1027
1010
        {
1028
 
          std::string path;
1029
 
          new_table_identifier.getSQLPath(path);
1030
 
          my_error(ER_TABLE_EXISTS_ERROR, MYF(0), path.c_str());
 
1011
          my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_table_identifier.getSQLPath().c_str());
1031
1012
          error= -1;
1032
1013
        }
1033
1014
        else
1049
1030
 
1050
1031
      if (error == 0)
1051
1032
      {
1052
 
        TransactionServices &transaction_services= TransactionServices::singleton();
1053
 
        transaction_services.allocateNewTransactionId();
1054
 
        write_bin_log(session, *session->getQueryString());
 
1033
        write_bin_log(session, session->query.c_str());
1055
1034
        session->my_ok();
1056
1035
      }
1057
1036
      else if (error > 0)
1060
1039
        error= -1;
1061
1040
      }
1062
1041
 
1063
 
      table::Cache::singleton().mutex().unlock();
 
1042
      LOCK_open.unlock();
1064
1043
      table_list->table= NULL;
1065
1044
 
1066
1045
      return error;
1105
1084
 
1106
1085
  if (not new_table)
1107
1086
  {
1108
 
    plugin::StorageEngine::dropTable(*session, new_table_as_temporary);
 
1087
    quick_rm_table(*session, new_table_as_temporary);
1109
1088
    return true;
1110
1089
  }
1111
1090
 
1149
1128
    */
1150
1129
    if (alter_info->error_if_not_empty && session->row_count)
1151
1130
    {
1152
 
      my_error(ER_INVALID_ALTER_TABLE_FOR_NOT_NULL, MYF(0));
 
1131
      const char *f_val= 0;
 
1132
      enum enum_drizzle_timestamp_type t_type= DRIZZLE_TIMESTAMP_DATE;
 
1133
 
 
1134
      switch (alter_info->datetime_field->sql_type)
 
1135
      {
 
1136
      case DRIZZLE_TYPE_DATE:
 
1137
        f_val= "0000-00-00";
 
1138
        t_type= DRIZZLE_TIMESTAMP_DATE;
 
1139
        break;
 
1140
      case DRIZZLE_TYPE_DATETIME:
 
1141
        f_val= "0000-00-00 00:00:00";
 
1142
        t_type= DRIZZLE_TIMESTAMP_DATETIME;
 
1143
        break;
 
1144
      default:
 
1145
        /* Shouldn't get here. */
 
1146
        assert(0);
 
1147
      }
 
1148
      bool save_abort_on_warning= session->abort_on_warning;
 
1149
      session->abort_on_warning= true;
 
1150
      make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
1151
                                   f_val, internal::strlength(f_val), t_type,
 
1152
                                   alter_info->datetime_field->field_name);
 
1153
      session->abort_on_warning= save_abort_on_warning;
1153
1154
    }
1154
1155
 
1155
1156
    if (original_table_identifier.isTmp())
1161
1162
      }
1162
1163
      else
1163
1164
      {
1164
 
        plugin::StorageEngine::dropTable(*session, new_table_as_temporary);
 
1165
        quick_rm_table(*session, new_table_as_temporary);
1165
1166
      }
1166
1167
 
1167
1168
      return true;
1183
1184
        delete new_table;
1184
1185
      }
1185
1186
 
1186
 
      table::Cache::singleton().mutex().lock(); /* ALTER TABLE */
 
1187
      LOCK_open.lock(); /* ALTER TABLE */
1187
1188
 
1188
 
      plugin::StorageEngine::dropTable(*session, new_table_as_temporary);
1189
 
      table::Cache::singleton().mutex().unlock();
 
1189
      quick_rm_table(*session, new_table_as_temporary);
 
1190
      LOCK_open.unlock();
1190
1191
 
1191
1192
      return true;
1192
1193
    }
1197
1198
    /* Close lock if this is a transactional table */
1198
1199
    if (session->lock)
1199
1200
    {
1200
 
      session->unlockTables(session->lock);
 
1201
      mysql_unlock_tables(session, session->lock);
1201
1202
      session->lock= 0;
1202
1203
    }
1203
1204
 
1233
1234
      delete new_table;
1234
1235
    }
1235
1236
 
1236
 
    table::Cache::singleton().mutex().lock(); /* ALTER TABLE */
 
1237
    LOCK_open.lock(); /* ALTER TABLE */
1237
1238
 
1238
1239
    /*
1239
1240
      Data is copied. Now we:
1278
1279
    if (mysql_rename_table(*session, original_engine, original_table_identifier, original_table_to_drop))
1279
1280
    {
1280
1281
      error= 1;
1281
 
      plugin::StorageEngine::dropTable(*session, new_table_as_temporary);
 
1282
      quick_rm_table(*session, new_table_as_temporary);
1282
1283
    }
1283
1284
    else
1284
1285
    {
1287
1288
        /* Try to get everything back. */
1288
1289
        error= 1;
1289
1290
 
1290
 
        plugin::StorageEngine::dropTable(*session, new_table_identifier);
 
1291
        quick_rm_table(*session, new_table_identifier);
1291
1292
 
1292
 
        plugin::StorageEngine::dropTable(*session, new_table_as_temporary);
 
1293
        quick_rm_table(*session, new_table_as_temporary);
1293
1294
 
1294
1295
        mysql_rename_table(*session, original_engine, original_table_to_drop, original_table_identifier);
1295
1296
      }
1296
1297
      else
1297
1298
      {
1298
 
        plugin::StorageEngine::dropTable(*session, original_table_to_drop);
 
1299
        quick_rm_table(*session, original_table_to_drop);
1299
1300
      }
1300
1301
    }
1301
1302
 
1307
1308
        from list of open tables list and table cache.
1308
1309
      */
1309
1310
      session->unlink_open_table(table);
1310
 
      table::Cache::singleton().mutex().unlock();
 
1311
      LOCK_open.unlock();
1311
1312
 
1312
1313
      return true;
1313
1314
    }
1314
1315
 
1315
 
    table::Cache::singleton().mutex().unlock();
 
1316
    LOCK_open.unlock();
1316
1317
 
1317
1318
    session->set_proc_info("end");
1318
1319
 
1319
 
    write_bin_log(session, *session->getQueryString());
 
1320
    write_bin_log(session, session->query.c_str());
1320
1321
    table_list->table= NULL;
1321
1322
  }
1322
1323
 
1349
1350
                 TableList *table_list,
1350
1351
                 AlterInfo *alter_info,
1351
1352
                 uint32_t order_num,
1352
 
                 Order *order,
 
1353
                 order_st *order,
1353
1354
                 bool ignore)
1354
1355
{
1355
1356
  bool error;
1395
1396
 
1396
1397
    if (name_lock)
1397
1398
    {
1398
 
      table::Cache::singleton().mutex().lock(); /* ALTER TABLe */
 
1399
      LOCK_open.lock(); /* ALTER TABLe */
1399
1400
      session->unlink_open_table(name_lock);
1400
 
      table::Cache::singleton().mutex().unlock();
 
1401
      LOCK_open.unlock();
1401
1402
    }
1402
1403
  }
1403
1404
 
1410
1411
                         Table *from, Table *to,
1411
1412
                         List<CreateField> &create,
1412
1413
                         bool ignore,
1413
 
                         uint32_t order_num, Order *order,
 
1414
                         uint32_t order_num, order_st *order,
1414
1415
                         ha_rows *copied,
1415
1416
                         ha_rows *deleted,
1416
1417
                         enum enum_enable_or_disable keys_onoff,
1440
1441
  /* 
1441
1442
   * LP Bug #552420 
1442
1443
   *
1443
 
   * Since open_temporary_table() doesn't invoke lockTables(), we
 
1444
   * Since open_temporary_table() doesn't invoke mysql_lock_tables(), we
1444
1445
   * don't get the usual automatic call to StorageEngine::startStatement(), so
1445
1446
   * we manually call it here...
1446
1447
   */
1493
1494
    }
1494
1495
    else
1495
1496
    {
1496
 
      FileSort filesort(*session);
1497
1497
      from->sort.io_cache= new internal::IO_CACHE;
1498
1498
 
1499
1499
      memset(&tables, 0, sizeof(tables));
1507
1507
          setup_order(session, session->lex->select_lex.ref_pointer_array,
1508
1508
                      &tables, fields, all_fields, order) ||
1509
1509
          !(sortorder= make_unireg_sortorder(order, &length, NULL)) ||
1510
 
          (from->sort.found_records= filesort.run(from, sortorder, length,
1511
 
                                                  (optimizer::SqlSelect *) 0, HA_POS_ERROR,
1512
 
                                                  1, examined_rows)) == HA_POS_ERROR)
 
1510
          (from->sort.found_records= filesort(session, from, sortorder, length,
 
1511
                                              (optimizer::SqlSelect *) 0, HA_POS_ERROR,
 
1512
                                              1, &examined_rows)) ==
 
1513
          HA_POS_ERROR)
1513
1514
      {
1514
1515
        goto err;
1515
1516
      }
1525
1526
  to->restoreRecordAsDefault();        // Create empty record
1526
1527
  while (!(error=info.read_record(&info)))
1527
1528
  {
1528
 
    if (session->getKilled())
 
1529
    if (session->killed)
1529
1530
    {
1530
1531
      session->send_kill_message();
1531
1532
      error= 1;
1546
1547
        to->next_number_field->reset();
1547
1548
    }
1548
1549
 
1549
 
    for (CopyField *copy_ptr= copy; copy_ptr != copy_end ; copy_ptr++)
 
1550
    for (CopyField *copy_ptr=copy ; copy_ptr != copy_end ; copy_ptr++)
1550
1551
    {
1551
 
      if (not copy->to_field->hasDefault() and copy->from_null_ptr and  *copy->from_null_ptr & copy->from_bit)
1552
 
      {
1553
 
        copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
1554
 
                                    ER_WARN_DATA_TRUNCATED, 1);
1555
 
        copy->to_field->reset();
1556
 
        error= 1;
1557
 
        break;
1558
 
      }
1559
 
 
1560
1552
      copy_ptr->do_copy(copy_ptr);
1561
1553
    }
1562
 
 
1563
 
    if (error)
1564
 
    {
1565
 
      break;
1566
 
    }
1567
 
 
1568
1554
    prev_insert_id= to->cursor->next_insert_id;
1569
1555
    error= to->cursor->insertRecord(to->record[0]);
1570
1556
    to->auto_increment_field_not_null= false;
1571
1557
 
1572
1558
    if (error)
1573
1559
    { 
1574
 
      if (!ignore || to->cursor->is_fatal_error(error, HA_CHECK_DUP))
 
1560
      if (!ignore ||
 
1561
          to->cursor->is_fatal_error(error, HA_CHECK_DUP))
1575
1562
      { 
1576
1563
        to->print_error(error, MYF(0));
1577
1564
        break;