18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include "drizzled/show.h"
23
#include "drizzled/session.h"
24
#include "drizzled/statement/create_index.h"
25
#include "drizzled/statement/alter_table.h"
26
#include "drizzled/db.h"
23
#include <drizzled/show.h>
24
#include <drizzled/session.h>
25
#include <drizzled/statement/create_index.h>
26
#include <drizzled/statement/alter_table.h>
27
#include <drizzled/plugin/storage_engine.h>
35
CreateIndex::CreateIndex(Session *in_session) :
36
CreateTable(in_session)
38
set_command(SQLCOM_CREATE_INDEX);
39
alter_info.flags.set(ALTER_ADD_INDEX);
40
lex().col_list.clear();
31
43
bool statement::CreateIndex::execute()
33
TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
34
TableList *all_tables= session->lex->query_tables;
45
TableList *first_table= (TableList *) lex().select_lex.table_list.first;
46
TableList *all_tables= lex().query_tables;
36
48
/* Chicken/Egg... we need to search for the table, to know if the table exists, so we can build a full identifier from it */
37
49
message::table::shared_ptr original_table_message;
39
TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName());
40
if (plugin::StorageEngine::getTableDefinition(*session, identifier, original_table_message) != EEXIST)
51
identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
52
if (not (original_table_message= plugin::StorageEngine::getTableMessage(session(), identifier)))
43
identifier.getSQLPath(path);
44
my_error(ER_BAD_TABLE_ERROR, MYF(0), path.c_str());
54
my_error(ER_BAD_TABLE_ERROR, identifier);
58
68
assert(first_table == all_tables && first_table != 0);
59
if (! session->endActiveTransaction())
69
if (session().inTransaction())
71
my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
65
76
if (original_table_message->type() == message::Table::STANDARD )
67
TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName());
68
create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
78
identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
79
create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
70
res= alter_table(session,
81
res= alter_table(&session(),
74
85
*original_table_message,
82
TableIdentifier catch22(first_table->getSchemaName(), first_table->getTableName());
83
Table *table= session->find_temporary_table(catch22);
93
identifier::Table catch22(first_table->getSchemaName(), first_table->getTableName());
94
Table *table= session().find_temporary_table(catch22);
86
TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
87
create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
97
identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
98
create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
89
res= alter_table(session,
100
res= alter_table(&session(),
93
104
*original_table_message,
105
createTableMessage(),
97
108
0, (Order*) 0, 0);