~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_index.cc

  • Committer: Brian Aker
  • Date: 2010-12-08 18:53:46 UTC
  • mto: This revision was merged to the branch mainline in revision 1983.
  • Revision ID: brian@tangent.org-20101208185346-89uak2ofyivk1yss
Update schema, make sure that it always ruturns a valid string (it just
makes the entire interface simpler to use).

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
37
  message::table::shared_ptr 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
      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
 
76
64
  bool res;
77
65
  if (original_table_message->type() == message::Table::STANDARD )
78
66
  {
79
 
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
80
 
    create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
 
67
    TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName());
 
68
    create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
81
69
 
82
 
    res= alter_table(getSession(), 
83
 
                     identifier,
84
 
                     identifier,
85
 
                     &create_info(), 
 
70
    res= alter_table(session, 
 
71
                     identifier,
 
72
                     identifier,
 
73
                     &create_info, 
86
74
                     *original_table_message,
87
 
                     createTableMessage(), 
 
75
                     create_table_message, 
88
76
                     first_table,
89
77
                     &alter_info,
90
78
                     0, (Order*) 0, 0);
91
79
  }
92
80
  else
93
81
  {
94
 
    identifier::Table catch22(first_table->getSchemaName(), first_table->getTableName());
95
 
    Table *table= getSession()->find_temporary_table(catch22);
 
82
    TableIdentifier catch22(first_table->getSchemaName(), first_table->getTableName());
 
83
    Table *table= session->find_temporary_table(catch22);
96
84
    assert(table);
97
85
    {
98
 
      identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
99
 
      create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
 
86
      TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
 
87
      create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
100
88
 
101
 
      res= alter_table(getSession(), 
102
 
                       identifier,
103
 
                       identifier,
104
 
                       &create_info(), 
 
89
      res= alter_table(session, 
 
90
                       identifier,
 
91
                       identifier,
 
92
                       &create_info, 
105
93
                       *original_table_message,
106
 
                       createTableMessage(), 
 
94
                       create_table_message, 
107
95
                       first_table,
108
96
                       &alter_info,
109
97
                       0, (Order*) 0, 0);
113
101
  return res;
114
102
}
115
103
 
116
 
} /* namespace statement */
117
104
} /* namespace drizzled */