~drizzle-trunk/drizzle/development

1100.3.62 by Padraig O'Sullivan
Created a CreateIndex class and DropIndex class instead of a
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2009 Sun Microsystems, Inc.
1100.3.62 by Padraig O'Sullivan
Created a CreateIndex class and DropIndex class instead of a
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
21
#include <config.h>
2148.7.12 by Brian Aker
Merge in header fixes.
22
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
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>
1100.3.62 by Padraig O'Sullivan
Created a CreateIndex class and DropIndex class instead of a
28
1130.3.12 by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/
29
namespace drizzled
30
{
1100.3.62 by Padraig O'Sullivan
Created a CreateIndex class and DropIndex class instead of a
31
2096.1.4 by Brian Aker
Clean up errors and pass information in creation of statement.
32
namespace statement
33
{
34
2104.3.12 by Brian Aker
Merge in create index encap from parser.
35
CreateIndex::CreateIndex(Session *in_session, const drizzled::ha_build_method method_arg) :
36
  CreateTable(in_session)
37
  {
2224.2.6 by Olaf van der Spek
Statement::set_command
38
    set_command(SQLCOM_CREATE_INDEX);
2104.3.12 by Brian Aker
Merge in create index encap from parser.
39
    alter_info.flags.set(ALTER_ADD_INDEX);
40
    alter_info.build_method= method_arg;
2224.2.8 by Olaf van der Spek
Statement::lex()
41
    lex().col_list.clear();
2104.3.12 by Brian Aker
Merge in create index encap from parser.
42
  }
2096.1.4 by Brian Aker
Clean up errors and pass information in creation of statement.
43
1100.3.62 by Padraig O'Sullivan
Created a CreateIndex class and DropIndex class instead of a
44
bool statement::CreateIndex::execute()
45
{
2224.2.8 by Olaf van der Spek
Statement::lex()
46
  TableList *first_table= (TableList *) lex().select_lex.table_list.first;
47
  TableList *all_tables= lex().query_tables;
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
48
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 */
1938.4.2 by Brian Aker
Fix style issue around table for message (though this is imperfect,...)
50
  message::table::shared_ptr original_table_message;
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
51
  {
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
52
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
2159.2.4 by Brian Aker
Merge in error wasteful removal.
53
    if (not (original_table_message= plugin::StorageEngine::getTableMessage(*getSession(), identifier)))
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
54
    {
2096.1.6 by Brian Aker
Merge in fixes for error messages.
55
      my_error(ER_BAD_TABLE_ERROR, identifier);
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
56
      return true;
57
    }
58
  }
59
1100.3.62 by Padraig O'Sullivan
Created a CreateIndex class and DropIndex class instead of a
60
  /*
61
    CREATE INDEX and DROP INDEX are implemented by calling ALTER
62
    TABLE with proper arguments.
63
64
    In the future ALTER TABLE will notice that the request is to
65
    only add indexes and create these one by one for the existing
66
    table without having to do a full rebuild.
67
  */
68
69
  assert(first_table == all_tables && first_table != 0);
2104 by Brian Aker
Session encapsulation.
70
  if (getSession()->inTransaction())
1100.3.62 by Padraig O'Sullivan
Created a CreateIndex class and DropIndex class instead of a
71
  {
1890.2.48 by Stewart Smith
error out on CREATE INDEX inside a transaction with ER_TRANSACTIONAL_DDL_NOT_SUPPORTED.
72
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
1100.3.62 by Padraig O'Sullivan
Created a CreateIndex class and DropIndex class instead of a
73
    return true;
74
  }
75
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
76
  bool res;
1910.2.15 by Brian Aker
Update so that we use shared_ptr from the cache throughout more of the
77
  if (original_table_message->type() == message::Table::STANDARD )
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
78
  {
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
79
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
2029.1.2 by Brian Aker
Merge in refactor of LIKE up to its own calling pointer in the parser.
80
    create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
81
2098.4.1 by Brian Aker
Make session encapsulated.
82
    res= alter_table(getSession(), 
1395.1.2 by Brian Aker
More logic pulling from ALTER TABLE
83
                     identifier,
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
84
                     identifier,
2029.1.2 by Brian Aker
Merge in refactor of LIKE up to its own calling pointer in the parser.
85
                     &create_info(), 
1910.2.15 by Brian Aker
Update so that we use shared_ptr from the cache throughout more of the
86
                     *original_table_message,
2029.1.2 by Brian Aker
Merge in refactor of LIKE up to its own calling pointer in the parser.
87
                     createTableMessage(), 
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
88
                     first_table,
89
                     &alter_info,
1892.3.3 by tdavies
struct order_st changed and renamed to c++ class named:Order
90
                     0, (Order*) 0, 0);
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
91
  }
92
  else
93
  {
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
94
    identifier::Table catch22(first_table->getSchemaName(), first_table->getTableName());
2098.4.1 by Brian Aker
Make session encapsulated.
95
    Table *table= getSession()->find_temporary_table(catch22);
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
96
    assert(table);
97
    {
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
98
      identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
2029.1.2 by Brian Aker
Merge in refactor of LIKE up to its own calling pointer in the parser.
99
      create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
100
2098.4.1 by Brian Aker
Make session encapsulated.
101
      res= alter_table(getSession(), 
1395.1.2 by Brian Aker
More logic pulling from ALTER TABLE
102
                       identifier,
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
103
                       identifier,
2029.1.2 by Brian Aker
Merge in refactor of LIKE up to its own calling pointer in the parser.
104
                       &create_info(), 
1910.2.15 by Brian Aker
Update so that we use shared_ptr from the cache throughout more of the
105
                       *original_table_message,
2029.1.2 by Brian Aker
Merge in refactor of LIKE up to its own calling pointer in the parser.
106
                       createTableMessage(), 
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
107
                       first_table,
108
                       &alter_info,
1892.3.3 by tdavies
struct order_st changed and renamed to c++ class named:Order
109
                       0, (Order*) 0, 0);
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
110
    }
111
  }
1502.1.30 by Brian Aker
First pass on cleanup of Stewart's patch, plus re-engineer to make it work a
112
1100.3.62 by Padraig O'Sullivan
Created a CreateIndex class and DropIndex class instead of a
113
  return res;
114
}
1130.3.12 by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/
115
2104.3.12 by Brian Aker
Merge in create index encap from parser.
116
} /* namespace statement */
1130.3.12 by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/
117
} /* namespace drizzled */