~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_index.cc

  • Committer: patrick crews
  • Date: 2010-09-29 15:15:19 UTC
  • mfrom: (1099.4.188 drizzle)
  • Revision ID: gleebix@gmail.com-20100929151519-6mrmzd1ciw2p9nws
Tags: 2010.09.1802
Update translations

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