~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
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
21
#include "config.h"
2148.7.12 by Brian Aker
Merge in header fixes.
22
1130.3.13 by Monty Taylor
Finished cleaning namespaces in drizzled/statement
23
#include "drizzled/show.h"
24
#include "drizzled/session.h"
25
#include "drizzled/statement/create_index.h"
26
#include "drizzled/statement/alter_table.h"
1235.4.23 by Stewart Smith
fix includes for drizzled/db.h. Now only in .cc files, no header files. should make modifying db.h much less painful.
27
#include "drizzled/db.h"
2148.7.12 by Brian Aker
Merge in header fixes.
28
#include "drizzled/plugin/storage_engine.h"
1100.3.62 by Padraig O'Sullivan
Created a CreateIndex class and DropIndex class instead of a
29
1130.3.12 by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/
30
namespace drizzled
31
{
1100.3.62 by Padraig O'Sullivan
Created a CreateIndex class and DropIndex class instead of a
32
2096.1.4 by Brian Aker
Clean up errors and pass information in creation of statement.
33
namespace statement
34
{
35
2104.3.12 by Brian Aker
Merge in create index encap from parser.
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
  }
2096.1.4 by Brian Aker
Clean up errors and pass information in creation of statement.
44
1100.3.62 by Padraig O'Sullivan
Created a CreateIndex class and DropIndex class instead of a
45
bool statement::CreateIndex::execute()
46
{
2098.4.1 by Brian Aker
Make session encapsulated.
47
  TableList *first_table= (TableList *) getSession()->lex->select_lex.table_list.first;
48
  TableList *all_tables= getSession()->lex->query_tables;
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
49
50
  /* 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,...)
51
  message::table::shared_ptr original_table_message;
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
52
  {
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
53
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
2098.4.1 by Brian Aker
Make session encapsulated.
54
    if (plugin::StorageEngine::getTableDefinition(*getSession(), identifier, original_table_message) != EEXIST)
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
55
    {
2096.1.6 by Brian Aker
Merge in fixes for error messages.
56
      my_error(ER_BAD_TABLE_ERROR, identifier);
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
57
      return true;
58
    }
59
  }
60
1100.3.62 by Padraig O'Sullivan
Created a CreateIndex class and DropIndex class instead of a
61
  /*
62
    CREATE INDEX and DROP INDEX are implemented by calling ALTER
63
    TABLE with proper arguments.
64
65
    In the future ALTER TABLE will notice that the request is to
66
    only add indexes and create these one by one for the existing
67
    table without having to do a full rebuild.
68
  */
69
70
  assert(first_table == all_tables && first_table != 0);
2104 by Brian Aker
Session encapsulation.
71
  if (getSession()->inTransaction())
1100.3.62 by Padraig O'Sullivan
Created a CreateIndex class and DropIndex class instead of a
72
  {
1890.2.48 by Stewart Smith
error out on CREATE INDEX inside a transaction with ER_TRANSACTIONAL_DDL_NOT_SUPPORTED.
73
    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
74
    return true;
75
  }
76
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
77
  bool res;
1910.2.15 by Brian Aker
Update so that we use shared_ptr from the cache throughout more of the
78
  if (original_table_message->type() == message::Table::STANDARD )
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
79
  {
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
80
    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.
81
    create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
82
2098.4.1 by Brian Aker
Make session encapsulated.
83
    res= alter_table(getSession(), 
1395.1.2 by Brian Aker
More logic pulling from ALTER TABLE
84
                     identifier,
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
85
                     identifier,
2029.1.2 by Brian Aker
Merge in refactor of LIKE up to its own calling pointer in the parser.
86
                     &create_info(), 
1910.2.15 by Brian Aker
Update so that we use shared_ptr from the cache throughout more of the
87
                     *original_table_message,
2029.1.2 by Brian Aker
Merge in refactor of LIKE up to its own calling pointer in the parser.
88
                     createTableMessage(), 
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
89
                     first_table,
90
                     &alter_info,
1892.3.3 by tdavies
struct order_st changed and renamed to c++ class named:Order
91
                     0, (Order*) 0, 0);
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
92
  }
93
  else
94
  {
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
95
    identifier::Table catch22(first_table->getSchemaName(), first_table->getTableName());
2098.4.1 by Brian Aker
Make session encapsulated.
96
    Table *table= getSession()->find_temporary_table(catch22);
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
97
    assert(table);
98
    {
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
99
      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.
100
      create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
101
2098.4.1 by Brian Aker
Make session encapsulated.
102
      res= alter_table(getSession(), 
1395.1.2 by Brian Aker
More logic pulling from ALTER TABLE
103
                       identifier,
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
104
                       identifier,
2029.1.2 by Brian Aker
Merge in refactor of LIKE up to its own calling pointer in the parser.
105
                       &create_info(), 
1910.2.15 by Brian Aker
Update so that we use shared_ptr from the cache throughout more of the
106
                       *original_table_message,
2029.1.2 by Brian Aker
Merge in refactor of LIKE up to its own calling pointer in the parser.
107
                       createTableMessage(), 
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
108
                       first_table,
109
                       &alter_info,
1892.3.3 by tdavies
struct order_st changed and renamed to c++ class named:Order
110
                       0, (Order*) 0, 0);
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
111
    }
112
  }
1502.1.30 by Brian Aker
First pass on cleanup of Stewart's patch, plus re-engineer to make it work a
113
1100.3.62 by Padraig O'Sullivan
Created a CreateIndex class and DropIndex class instead of a
114
  return res;
115
}
1130.3.12 by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/
116
2104.3.12 by Brian Aker
Merge in create index encap from parser.
117
} /* namespace statement */
1130.3.12 by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/
118
} /* namespace drizzled */