1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems, Inc.
4
* Copyright (C) 2009 Sun Microsystems
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
21
21
#include "config.h"
23
22
#include "drizzled/show.h"
24
23
#include "drizzled/session.h"
25
24
#include "drizzled/statement/create_index.h"
26
25
#include "drizzled/statement/alter_table.h"
27
26
#include "drizzled/db.h"
28
#include "drizzled/plugin/storage_engine.h"
36
CreateIndex::CreateIndex(Session *in_session, const drizzled::ha_build_method method_arg) :
37
CreateTable(in_session)
39
getSession()->getLex()->sql_command= SQLCOM_CREATE_INDEX;
40
alter_info.flags.set(ALTER_ADD_INDEX);
41
alter_info.build_method= method_arg;
42
getSession()->getLex()->col_list.empty();
45
31
bool statement::CreateIndex::execute()
47
TableList *first_table= (TableList *) getSession()->lex->select_lex.table_list.first;
48
TableList *all_tables= getSession()->lex->query_tables;
33
TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
34
TableList *all_tables= session->lex->query_tables;
50
36
/* Chicken/Egg... we need to search for the table, to know if the table exists, so we can build a full identifier from it */
51
message::table::shared_ptr original_table_message;
37
message::Table original_table_message;
53
identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
54
if (plugin::StorageEngine::getTableDefinition(*getSession(), identifier, original_table_message) != EEXIST)
39
TableIdentifier identifier(first_table->db, first_table->table_name);
40
if (plugin::StorageEngine::getTableDefinition(*session, identifier, original_table_message) != EEXIST)
56
my_error(ER_BAD_TABLE_ERROR, identifier);
42
my_error(ER_BAD_TABLE_ERROR, MYF(0), identifier.getSQLPath().c_str());
70
56
assert(first_table == all_tables && first_table != 0);
71
if (getSession()->inTransaction())
57
if (! session->endActiveTransaction())
73
my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
78
if (original_table_message->type() == message::Table::STANDARD )
63
if (original_table_message.type() == message::Table::STANDARD )
80
identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
81
create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
65
TableIdentifier identifier(first_table->db, first_table->table_name);
66
create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
83
res= alter_table(getSession(),
87
*original_table_message,
68
res= alter_table(session,
72
original_table_message,
95
identifier::Table catch22(first_table->getSchemaName(), first_table->getTableName());
96
Table *table= getSession()->find_temporary_table(catch22);
80
Table *table= session->find_temporary_table(first_table);
99
identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
100
create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
83
TableIdentifier identifier(first_table->db, first_table->table_name, table->getMutableShare()->getPath());
84
create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
102
res= alter_table(getSession(),
106
*original_table_message,
107
createTableMessage(),
86
res= alter_table(session,
90
original_table_message,
117
} /* namespace statement */
118
101
} /* namespace drizzled */