~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_index.cc

new functions

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <config.h>
22
 
 
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>
 
21
#include "config.h"
 
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"
28
27
 
29
28
namespace drizzled
30
29
{
31
30
 
32
 
namespace statement
33
 
{
34
 
 
35
 
CreateIndex::CreateIndex(Session *in_session, const drizzled::ha_build_method method_arg) :
36
 
  CreateTable(in_session)
37
 
  {
38
 
    getSession()->getLex()->sql_command= SQLCOM_CREATE_INDEX;
39
 
    alter_info.flags.set(ALTER_ADD_INDEX);
40
 
    alter_info.build_method= method_arg;
41
 
    getSession()->getLex()->col_list.clear();
42
 
  }
43
 
 
44
31
bool statement::CreateIndex::execute()
45
32
{
46
 
  TableList *first_table= (TableList *) getSession()->getLex()->select_lex.table_list.first;
47
 
  TableList *all_tables= getSession()->getLex()->query_tables;
 
33
  TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
 
34
  TableList *all_tables= session->lex->query_tables;
48
35
 
49
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 */
50
37
  message::table::shared_ptr original_table_message;
51
38
  {
52
39
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
53
 
    if (not (original_table_message= plugin::StorageEngine::getTableMessage(*getSession(), identifier)))
 
40
    if (plugin::StorageEngine::getTableDefinition(*session, identifier, original_table_message) != EEXIST)
54
41
    {
55
 
      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());
56
45
      return true;
57
46
    }
58
47
  }
67
56
  */
68
57
 
69
58
  assert(first_table == all_tables && first_table != 0);
70
 
  if (getSession()->inTransaction())
 
59
  if (! session->endActiveTransaction())
71
60
  {
72
 
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
73
61
    return true;
74
62
  }
75
63
 
79
67
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
80
68
    create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
81
69
 
82
 
    res= alter_table(getSession(), 
 
70
    res= alter_table(session, 
83
71
                     identifier,
84
72
                     identifier,
85
73
                     &create_info(), 
92
80
  else
93
81
  {
94
82
    identifier::Table catch22(first_table->getSchemaName(), first_table->getTableName());
95
 
    Table *table= getSession()->find_temporary_table(catch22);
 
83
    Table *table= session->find_temporary_table(catch22);
96
84
    assert(table);
97
85
    {
98
86
      identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
99
87
      create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
100
88
 
101
 
      res= alter_table(getSession(), 
 
89
      res= alter_table(session, 
102
90
                       identifier,
103
91
                       identifier,
104
92
                       &create_info(), 
113
101
  return res;
114
102
}
115
103
 
116
 
} /* namespace statement */
117
104
} /* namespace drizzled */