~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_index.cc

  • Committer: Mark Atwood
  • Date: 2011-08-11 03:05:03 UTC
  • mfrom: (2385.1.12 refactor4)
  • Revision ID: me@mark.atwood.name-20110811030503-rp9xjihc5x3y0x4q
merge lp:~olafvdspek/drizzle/refactor4

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"
 
21
#include <config.h>
22
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/db.h"
28
 
#include "drizzled/plugin/storage_engine.h"
 
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>
29
29
 
30
30
namespace drizzled
31
31
{
33
33
namespace statement
34
34
{
35
35
 
36
 
CreateIndex::CreateIndex(Session *in_session, const drizzled::ha_build_method method_arg) :
 
36
CreateIndex::CreateIndex(Session *in_session) :
37
37
  CreateTable(in_session)
38
38
  {
39
 
    getSession()->getLex()->sql_command= SQLCOM_CREATE_INDEX;
 
39
    set_command(SQLCOM_CREATE_INDEX);
40
40
    alter_info.flags.set(ALTER_ADD_INDEX);
41
 
    alter_info.build_method= method_arg;
42
 
    getSession()->getLex()->col_list.empty();
 
41
    lex().col_list.clear();
43
42
  }
44
43
 
45
44
bool statement::CreateIndex::execute()
46
45
{
47
 
  TableList *first_table= (TableList *) getSession()->lex->select_lex.table_list.first;
48
 
  TableList *all_tables= getSession()->lex->query_tables;
 
46
  TableList *first_table= (TableList *) lex().select_lex.table_list.first;
 
47
  TableList *all_tables= lex().query_tables;
49
48
 
50
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 */
51
50
  message::table::shared_ptr original_table_message;
52
51
  {
53
52
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
54
 
    if (plugin::StorageEngine::getTableDefinition(*getSession(), identifier, original_table_message) != EEXIST)
 
53
    if (not (original_table_message= plugin::StorageEngine::getTableMessage(session(), identifier)))
55
54
    {
56
55
      my_error(ER_BAD_TABLE_ERROR, identifier);
57
56
      return true;
68
67
  */
69
68
 
70
69
  assert(first_table == all_tables && first_table != 0);
71
 
  if (getSession()->inTransaction())
 
70
  if (session().inTransaction())
72
71
  {
73
72
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
74
73
    return true;
80
79
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
81
80
    create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
82
81
 
83
 
    res= alter_table(getSession(), 
 
82
    res= alter_table(&session(), 
84
83
                     identifier,
85
84
                     identifier,
86
85
                     &create_info(), 
93
92
  else
94
93
  {
95
94
    identifier::Table catch22(first_table->getSchemaName(), first_table->getTableName());
96
 
    Table *table= getSession()->find_temporary_table(catch22);
 
95
    Table *table= session().open_tables.find_temporary_table(catch22);
97
96
    assert(table);
98
97
    {
99
98
      identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
100
99
      create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
101
100
 
102
 
      res= alter_table(getSession(), 
 
101
      res= alter_table(&session(), 
103
102
                       identifier,
104
103
                       identifier,
105
104
                       &create_info(),