~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_index.cc

  • Committer: Stewart Smith
  • Date: 2010-11-03 03:30:27 UTC
  • mto: (1902.1.1 build) (1910.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1903.
  • Revision ID: stewart@flamingspork.com-20101103033027-lskb6gxwwforfz71
fix docs warning: underline/overline too short for replace.rst

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2009 Sun Microsystems
5
5
 *
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
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
 
  message::table::shared_ptr original_table_message;
 
37
  message::Table original_table_message;
51
38
  {
52
 
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
53
 
    if (not (original_table_message= plugin::StorageEngine::getTableMessage(*getSession(), identifier)))
 
39
    TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName());
 
40
    if (plugin::StorageEngine::getTableDefinition(*session, identifier, original_table_message) != EEXIST)
54
41
    {
55
 
      my_error(ER_BAD_TABLE_ERROR, identifier);
 
42
      my_error(ER_BAD_TABLE_ERROR, MYF(0), identifier.getSQLPath().c_str());
56
43
      return true;
57
44
    }
58
45
  }
67
54
  */
68
55
 
69
56
  assert(first_table == all_tables && first_table != 0);
70
 
  if (getSession()->inTransaction())
 
57
  if (! session->endActiveTransaction())
71
58
  {
72
 
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
73
59
    return true;
74
60
  }
75
61
 
76
62
  bool res;
77
 
  if (original_table_message->type() == message::Table::STANDARD )
 
63
  if (original_table_message.type() == message::Table::STANDARD )
78
64
  {
79
 
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
80
 
    create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
 
65
    TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName());
 
66
    create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
81
67
 
82
 
    res= alter_table(getSession(), 
83
 
                     identifier,
84
 
                     identifier,
85
 
                     &create_info(), 
86
 
                     *original_table_message,
87
 
                     createTableMessage(), 
 
68
    res= alter_table(session, 
 
69
                     identifier,
 
70
                     identifier,
 
71
                     &create_info, 
 
72
                     original_table_message,
 
73
                     create_table_message, 
88
74
                     first_table,
89
75
                     &alter_info,
90
76
                     0, (Order*) 0, 0);
91
77
  }
92
78
  else
93
79
  {
94
 
    identifier::Table catch22(first_table->getSchemaName(), first_table->getTableName());
95
 
    Table *table= getSession()->find_temporary_table(catch22);
 
80
    TableIdentifier catch22(first_table->getSchemaName(), first_table->getTableName());
 
81
    Table *table= session->find_temporary_table(catch22);
96
82
    assert(table);
97
83
    {
98
 
      identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
99
 
      create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
 
84
      TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
 
85
      create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
100
86
 
101
 
      res= alter_table(getSession(), 
102
 
                       identifier,
103
 
                       identifier,
104
 
                       &create_info(), 
105
 
                       *original_table_message,
106
 
                       createTableMessage(), 
 
87
      res= alter_table(session, 
 
88
                       identifier,
 
89
                       identifier,
 
90
                       &create_info, 
 
91
                       original_table_message,
 
92
                       create_table_message, 
107
93
                       first_table,
108
94
                       &alter_info,
109
95
                       0, (Order*) 0, 0);
113
99
  return res;
114
100
}
115
101
 
116
 
} /* namespace statement */
117
102
} /* namespace drizzled */