~drizzle-developers/ubuntu/natty/drizzle/natty

« back to all changes in this revision

Viewing changes to drizzled/statement/alter_table.cc

  • Committer: Monty Taylor
  • Date: 2010-03-03 19:27:30 UTC
  • mto: (1308.1.2 trunk)
  • mto: This revision was merged to the branch mainline in revision 1278.
  • Revision ID: mordred@inaugust.com-20100303192730-o2o3nmp0lzhuatbe
Tags: upstream-2010.03.1317
ImportĀ upstreamĀ versionĀ 2010.03.1317

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include "drizzled/data_home.h"
36
36
#include "drizzled/sql_table.h"
37
37
#include "drizzled/table_proto.h"
38
 
#include "drizzled/plugin/info_schema_table.h"
39
38
#include "drizzled/optimizer/range.h"
40
39
#include "drizzled/time_functions.h"
41
40
#include "drizzled/records.h"
43
42
#include "drizzled/internal/my_sys.h"
44
43
#include "drizzled/internal/iocache.h"
45
44
 
46
 
extern pid_t current_pid;
 
45
#include "drizzled/transaction_services.h"
47
46
 
48
47
using namespace std;
49
48
 
50
49
namespace drizzled
51
50
{
52
51
 
 
52
extern pid_t current_pid;
 
53
 
53
54
static int copy_data_between_tables(Table *from,Table *to,
54
55
                                    List<CreateField> &create,
55
56
                                    bool ignore,
355
356
      */
356
357
      if (alter_info->build_method == HA_BUILD_ONLINE)
357
358
      {
358
 
        my_error(ER_NOT_SUPPORTED_YET, MYF(0), session->query);
 
359
        my_error(ER_NOT_SUPPORTED_YET, MYF(0), session->query.c_str());
359
360
        goto err;
360
361
      }
361
362
      alter_info->build_method= HA_BUILD_OFFLINE;
544
545
    ALTER Table
545
546
  */
546
547
 
 
548
  TransactionServices &transaction_services= TransactionServices::singleton();
547
549
  session->set_proc_info("discard_or_import_tablespace");
548
550
 
549
551
  discard= test(tablespace_op == DISCARD_TABLESPACE);
567
569
    goto err;
568
570
 
569
571
  /* The ALTER Table is always in its own transaction */
570
 
  error = ha_autocommit_or_rollback(session, 0);
 
572
  error= transaction_services.ha_autocommit_or_rollback(session, false);
571
573
  if (! session->endActiveTransaction())
572
574
    error=1;
573
575
  if (error)
574
576
    goto err;
575
 
  write_bin_log(session, session->query, session->query_length);
 
577
  write_bin_log(session, session->query.c_str());
576
578
 
577
579
err:
578
 
  ha_autocommit_or_rollback(session, error);
 
580
  (void) transaction_services.ha_autocommit_or_rollback(session, error);
579
581
  session->tablespace_op=false;
580
582
 
581
583
  if (error == 0)
644
646
      table_list       The table to change.
645
647
      alter_info       Lists of fields, keys to be changed, added
646
648
                       or dropped.
647
 
      order_num        How many order_st BY fields has been specified.
 
649
      order_num        How many ORDER BY fields has been specified.
648
650
      order            List of fields to order_st BY.
649
651
      ignore           Whether we have ALTER IGNORE Table
650
652
 
704
706
 
705
707
  new_name_buff[0]= '\0';
706
708
 
707
 
  /**
708
 
   * @todo this is a result of retaining the behavior that was here before. This should be removed
709
 
   * and the correct error handling should be done in doDropTable for the I_S engine.
710
 
   */
711
 
  plugin::InfoSchemaTable *sch_table= plugin::InfoSchemaTable::getTable(table_list->table_name);
712
 
  if (sch_table)
713
 
  {
714
 
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.c_str());
715
 
    return true;
716
 
  }
717
 
 
718
709
  session->set_proc_info("init");
719
710
 
720
711
  /*
736
727
  ostringstream oss;
737
728
  oss << drizzle_data_home << "/" << db << "/" << table_name;
738
729
 
739
 
  (void) unpack_filename(new_name_buff, oss.str().c_str());
 
730
  (void) internal::unpack_filename(new_name_buff, oss.str().c_str());
740
731
 
741
732
  /*
742
733
    If this is just a rename of a view, short cut to the
792
783
        if (session->lock_table_name_if_not_cached(new_db, new_name, &name_lock))
793
784
          return true;
794
785
 
795
 
        if (! name_lock)
 
786
        if (not name_lock)
796
787
        {
797
788
          my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
798
789
          return true;
799
790
        }
800
791
 
801
 
        build_table_filename(new_name_buff, sizeof(new_name_buff), new_db, new_name_buff, false);
 
792
        TableIdentifier identifier(new_db, new_name_buff);
802
793
 
803
 
        if (plugin::StorageEngine::getTableDefinition(*session, new_name_buff, new_db, new_name_buff, false) == EEXIST)
 
794
        if (plugin::StorageEngine::getTableDefinition(*session, identifier) == EEXIST)
804
795
        {
805
796
          /* Table will be closed by Session::executeCommand() */
806
797
          my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
846
837
    table_options= create_proto->mutable_options();
847
838
 
848
839
    create_info->row_type= table->s->row_type;
849
 
    table_options->set_row_type((drizzled::message::Table_TableOptions_RowType)table->s->row_type);
 
840
    table_options->set_row_type((message::Table_TableOptions_RowType)table->s->row_type);
850
841
  }
851
842
 
852
843
  if (old_db_type->check_flag(HTON_BIT_ALTER_NOT_SUPPORTED) ||
943
934
      }
944
935
      else
945
936
      {
946
 
        *fn_ext(new_name)= 0;
 
937
        *internal::fn_ext(new_name)= 0;
947
938
        if (mysql_rename_table(old_db_type, db, table_name, new_db, new_alias, 0))
948
939
          error= -1;
949
940
      }
959
950
 
960
951
    if (error == 0)
961
952
    {
962
 
      write_bin_log(session, session->query, session->query_length);
 
953
      write_bin_log(session, session->query.c_str());
963
954
      session->my_ok();
964
955
    }
965
956
    else if (error > 0)
1160
1151
 
1161
1152
  session->set_proc_info("end");
1162
1153
 
1163
 
  write_bin_log(session, session->query, session->query_length);
 
1154
  write_bin_log(session, session->query.c_str());
1164
1155
  table_list->table= NULL;
1165
1156
 
1166
1157
end_temporary:
1224
1215
    bool save_abort_on_warning= session->abort_on_warning;
1225
1216
    session->abort_on_warning= true;
1226
1217
    make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
1227
 
                                 f_val, strlength(f_val), t_type,
 
1218
                                 f_val, internal::strlength(f_val), t_type,
1228
1219
                                 alter_info->datetime_field->field_name);
1229
1220
    session->abort_on_warning= save_abort_on_warning;
1230
1221
  }
1260
1251
                         enum enum_enable_or_disable keys_onoff,
1261
1252
                         bool error_if_not_empty)
1262
1253
{
1263
 
  int error;
 
1254
  int error= 0;
1264
1255
  CopyField *copy,*copy_end;
1265
1256
  ulong found_count,delete_count;
1266
1257
  Session *session= current_session;
1280
1271
 
1281
1272
    This needs to be done before external_lock
1282
1273
  */
1283
 
  error= ha_enable_transaction(session, false);
1284
 
  if (error)
1285
 
    return -1;
 
1274
  TransactionServices &transaction_services= TransactionServices::singleton();
1286
1275
 
1287
1276
  if (!(copy= new CopyField[to->s->fields]))
1288
1277
    return -1;
1331
1320
    }
1332
1321
    else
1333
1322
    {
1334
 
      from->sort.io_cache= new IO_CACHE;
1335
 
      memset(from->sort.io_cache, 0, sizeof(IO_CACHE));
 
1323
      from->sort.io_cache= new internal::IO_CACHE;
 
1324
      memset(from->sort.io_cache, 0, sizeof(internal::IO_CACHE));
1336
1325
 
1337
1326
      memset(&tables, 0, sizeof(tables));
1338
1327
      tables.table= from;
1414
1403
  }
1415
1404
  to->cursor->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
1416
1405
 
1417
 
  if (ha_enable_transaction(session, true))
1418
 
  {
1419
 
    error= 1;
1420
 
    goto err;
1421
 
  }
1422
 
 
1423
1406
  /*
1424
1407
    Ensure that the new table is saved properly to disk so that we
1425
1408
    can do a rename
1426
1409
  */
1427
 
  if (ha_autocommit_or_rollback(session, 0))
 
1410
  if (transaction_services.ha_autocommit_or_rollback(session, false))
1428
1411
    error=1;
1429
1412
  if (! session->endActiveTransaction())
1430
1413
    error=1;