~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/drop_index.cc

  • Committer: Brian Aker
  • Date: 2009-02-21 00:18:15 UTC
  • Revision ID: brian@tangent.org-20090221001815-x20e8h71e984lvs1
Completion (?) of uint conversion.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems, Inc.
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
 
 
21
 
#include "config.h"
22
 
 
23
 
#include "drizzled/show.h"
24
 
#include "drizzled/session.h"
25
 
#include "drizzled/statement/drop_index.h"
26
 
#include "drizzled/statement/alter_table.h"
27
 
#include "drizzled/db.h"
28
 
#include "drizzled/plugin/storage_engine.h"
29
 
 
30
 
namespace drizzled
31
 
{
32
 
 
33
 
bool statement::DropIndex::execute()
34
 
{
35
 
  TableList *first_table= (TableList *) getSession()->lex->select_lex.table_list.first;
36
 
  TableList *all_tables= getSession()->lex->query_tables;
37
 
 
38
 
  /* Chicken/Egg... we need to search for the table, to know if the table exists, so we can build a full identifier from it */
39
 
  message::table::shared_ptr original_table_message;
40
 
  {
41
 
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
42
 
    if (plugin::StorageEngine::getTableDefinition(*getSession(), identifier, original_table_message) != EEXIST)
43
 
    {
44
 
      my_error(ER_BAD_TABLE_ERROR, identifier);
45
 
      return true;
46
 
    }
47
 
  }
48
 
 
49
 
  /*
50
 
     CREATE INDEX and DROP INDEX are implemented by calling ALTER
51
 
     TABLE with proper arguments.
52
 
 
53
 
     In the future ALTER TABLE will notice that the request is to
54
 
     only add indexes and create these one by one for the existing
55
 
     table without having to do a full rebuild.
56
 
   */
57
 
  /* Prepare stack copies to be re-execution safe */
58
 
  HA_CREATE_INFO create_info;
59
 
 
60
 
  assert(first_table == all_tables && first_table != 0);
61
 
  if (getSession()->inTransaction())
62
 
  {
63
 
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
64
 
    return true;
65
 
  }
66
 
 
67
 
  create_info.db_type= 0;
68
 
 
69
 
  bool res;
70
 
  if (original_table_message->type() == message::Table::STANDARD )
71
 
  {
72
 
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
73
 
 
74
 
    create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
75
 
 
76
 
    res= alter_table(getSession(), 
77
 
                     identifier,
78
 
                     identifier,
79
 
                     &create_info, 
80
 
                     *original_table_message,
81
 
                     create_table_proto, 
82
 
                     first_table,
83
 
                     &alter_info,
84
 
                     0, (Order*) 0, 0);
85
 
  }
86
 
  else
87
 
  {
88
 
    identifier::Table catch22(first_table->getSchemaName(), first_table->getTableName());
89
 
    Table *table= getSession()->find_temporary_table(catch22);
90
 
    assert(table);
91
 
    {
92
 
      identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName(), table->getShare()->getPath());
93
 
      create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
94
 
 
95
 
      res= alter_table(getSession(), 
96
 
                       identifier,
97
 
                       identifier,
98
 
                       &create_info, 
99
 
                       *original_table_message,
100
 
                       create_table_proto, 
101
 
                       first_table,
102
 
                       &alter_info,
103
 
                       0, (Order*) 0, 0);
104
 
    }
105
 
  }
106
 
  return res;
107
 
}
108
 
 
109
 
} /* namespace drizzled */