~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_index.cc

  • Committer: Olaf van der Spek
  • Date: 2011-07-07 13:41:07 UTC
  • mto: This revision was merged to the branch mainline in revision 2385.
  • Revision ID: olafvdspek@gmail.com-20110707134107-6mi7pauiatxtf4oe
Rename strmake to strdup (standard name)

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
 
#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"
 
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>
 
28
#include <drizzled/open_tables_state.h>
27
29
 
28
30
namespace drizzled
29
31
{
30
32
 
 
33
namespace statement
 
34
{
 
35
 
 
36
CreateIndex::CreateIndex(Session *in_session) :
 
37
  CreateTable(in_session)
 
38
  {
 
39
    set_command(SQLCOM_CREATE_INDEX);
 
40
    alter_info.flags.set(ALTER_ADD_INDEX);
 
41
    lex().col_list.clear();
 
42
  }
 
43
 
31
44
bool statement::CreateIndex::execute()
32
45
{
33
 
  TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
34
 
  TableList *all_tables= session->lex->query_tables;
 
46
  TableList *first_table= (TableList *) lex().select_lex.table_list.first;
 
47
  TableList *all_tables= lex().query_tables;
35
48
 
36
49
  /* 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
50
  message::table::shared_ptr original_table_message;
38
51
  {
39
 
    TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName());
40
 
    if (plugin::StorageEngine::getTableDefinition(*session, identifier, original_table_message) != EEXIST)
 
52
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
 
53
    if (not (original_table_message= plugin::StorageEngine::getTableMessage(session(), identifier)))
41
54
    {
42
 
      std::string path;
43
 
      identifier.getSQLPath(path);
44
 
      my_error(ER_BAD_TABLE_ERROR, MYF(0), path.c_str());
 
55
      my_error(ER_BAD_TABLE_ERROR, identifier);
45
56
      return true;
46
57
    }
47
58
  }
56
67
  */
57
68
 
58
69
  assert(first_table == all_tables && first_table != 0);
59
 
  if (! session->endActiveTransaction())
 
70
  if (session().inTransaction())
60
71
  {
 
72
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
61
73
    return true;
62
74
  }
63
75
 
64
76
  bool res;
65
77
  if (original_table_message->type() == message::Table::STANDARD )
66
78
  {
67
 
    TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName());
68
 
    create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
 
79
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
 
80
    create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
69
81
 
70
 
    res= alter_table(session, 
71
 
                     identifier,
72
 
                     identifier,
73
 
                     &create_info, 
 
82
    res= alter_table(&session(), 
 
83
                     identifier,
 
84
                     identifier,
 
85
                     &create_info(), 
74
86
                     *original_table_message,
75
 
                     create_table_message, 
 
87
                     createTableMessage(), 
76
88
                     first_table,
77
89
                     &alter_info,
78
90
                     0, (Order*) 0, 0);
79
91
  }
80
92
  else
81
93
  {
82
 
    TableIdentifier catch22(first_table->getSchemaName(), first_table->getTableName());
83
 
    Table *table= session->find_temporary_table(catch22);
 
94
    identifier::Table catch22(first_table->getSchemaName(), first_table->getTableName());
 
95
    Table *table= session().open_tables.find_temporary_table(catch22);
84
96
    assert(table);
85
97
    {
86
 
      TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
87
 
      create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
 
98
      identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
 
99
      create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
88
100
 
89
 
      res= alter_table(session, 
90
 
                       identifier,
91
 
                       identifier,
92
 
                       &create_info, 
 
101
      res= alter_table(&session(), 
 
102
                       identifier,
 
103
                       identifier,
 
104
                       &create_info(), 
93
105
                       *original_table_message,
94
 
                       create_table_message, 
 
106
                       createTableMessage(), 
95
107
                       first_table,
96
108
                       &alter_info,
97
109
                       0, (Order*) 0, 0);
101
113
  return res;
102
114
}
103
115
 
 
116
} /* namespace statement */
104
117
} /* namespace drizzled */