~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_index.cc

  • Committer: Stewart Smith
  • Date: 2011-01-14 05:13:33 UTC
  • mto: (2086.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 2087.
  • Revision ID: stewart@flamingspork.com-20110114051333-pz1xy0f1dyc4jfms
talk about statement rollback (briefly) in replication docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
#include "config.h"
22
 
 
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"
29
27
 
30
28
namespace drizzled
31
29
{
32
30
 
33
 
namespace statement
34
 
{
35
 
 
36
 
CreateIndex::CreateIndex(Session *in_session, const drizzled::ha_build_method method_arg) :
37
 
  CreateTable(in_session)
38
 
  {
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();
43
 
  }
44
 
 
45
31
bool statement::CreateIndex::execute()
46
32
{
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;
49
35
 
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
37
  message::table::shared_ptr original_table_message;
52
38
  {
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->getSchemaName(), first_table->getTableName());
 
40
    if (plugin::StorageEngine::getTableDefinition(*session, identifier, original_table_message) != EEXIST)
55
41
    {
56
 
      my_error(ER_BAD_TABLE_ERROR, identifier);
 
42
      std::string path;
 
43
      identifier.getSQLPath(path);
 
44
      my_error(ER_BAD_TABLE_ERROR, MYF(0), path.c_str());
57
45
      return true;
58
46
    }
59
47
  }
68
56
  */
69
57
 
70
58
  assert(first_table == all_tables && first_table != 0);
71
 
  if (getSession()->inTransaction())
 
59
  if (! session->endActiveTransaction())
72
60
  {
73
 
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
74
61
    return true;
75
62
  }
76
63
 
77
64
  bool res;
78
65
  if (original_table_message->type() == message::Table::STANDARD )
79
66
  {
80
 
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
 
67
    TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName());
81
68
    create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
82
69
 
83
 
    res= alter_table(getSession(), 
 
70
    res= alter_table(session, 
84
71
                     identifier,
85
72
                     identifier,
86
73
                     &create_info(), 
92
79
  }
93
80
  else
94
81
  {
95
 
    identifier::Table catch22(first_table->getSchemaName(), first_table->getTableName());
96
 
    Table *table= getSession()->find_temporary_table(catch22);
 
82
    TableIdentifier catch22(first_table->getSchemaName(), first_table->getTableName());
 
83
    Table *table= session->find_temporary_table(catch22);
97
84
    assert(table);
98
85
    {
99
 
      identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
 
86
      TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
100
87
      create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
101
88
 
102
 
      res= alter_table(getSession(), 
 
89
      res= alter_table(session, 
103
90
                       identifier,
104
91
                       identifier,
105
92
                       &create_info(), 
114
101
  return res;
115
102
}
116
103
 
117
 
} /* namespace statement */
118
104
} /* namespace drizzled */