~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/drop_index.cc

  • Committer: Brian Aker
  • Date: 2010-10-20 20:26:18 UTC
  • mfrom: (1859.2.13 refactor)
  • Revision ID: brian@tangent.org-20101020202618-9222n39lm329urv5
Merge for Brian 

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/drop_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
31
bool statement::DropIndex::execute()
34
32
{
35
 
  TableList *first_table= (TableList *) getSession()->lex->select_lex.table_list.first;
36
 
  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;
37
35
 
38
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 */
39
 
  message::table::shared_ptr original_table_message;
 
37
  message::Table original_table_message;
40
38
  {
41
 
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
42
 
    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)
43
41
    {
44
 
      my_error(ER_BAD_TABLE_ERROR, identifier);
 
42
      my_error(ER_BAD_TABLE_ERROR, MYF(0), identifier.getSQLPath().c_str());
45
43
      return true;
46
44
    }
47
45
  }
58
56
  HA_CREATE_INFO create_info;
59
57
 
60
58
  assert(first_table == all_tables && first_table != 0);
61
 
  if (getSession()->inTransaction())
 
59
  if (! session->endActiveTransaction())
62
60
  {
63
 
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
64
61
    return true;
65
62
  }
66
63
 
 
64
  memset(&create_info, 0, sizeof(create_info));
67
65
  create_info.db_type= 0;
68
66
 
69
67
  bool res;
70
 
  if (original_table_message->type() == message::Table::STANDARD )
 
68
  if (original_table_message.type() == message::Table::STANDARD )
71
69
  {
72
 
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
 
70
    TableIdentifier identifier(first_table->db, first_table->table_name);
73
71
 
74
72
    create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
75
73
 
76
 
    res= alter_table(getSession(), 
 
74
    res= alter_table(session, 
77
75
                     identifier,
78
76
                     identifier,
79
77
                     &create_info, 
80
 
                     *original_table_message,
 
78
                     original_table_message,
81
79
                     create_table_proto, 
82
80
                     first_table,
83
81
                     &alter_info,
84
 
                     0, (Order*) 0, 0);
 
82
                     0, (order_st*) 0, 0);
85
83
  }
86
84
  else
87
85
  {
88
 
    identifier::Table catch22(first_table->getSchemaName(), first_table->getTableName());
89
 
    Table *table= getSession()->find_temporary_table(catch22);
 
86
    Table *table= session->find_temporary_table(first_table);
90
87
    assert(table);
91
88
    {
92
 
      identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName(), table->getShare()->getPath());
 
89
      TableIdentifier identifier(first_table->db, first_table->table_name, table->getShare()->getPath());
93
90
      create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
94
91
 
95
 
      res= alter_table(getSession(), 
 
92
      res= alter_table(session, 
96
93
                       identifier,
97
94
                       identifier,
98
95
                       &create_info, 
99
 
                       *original_table_message,
 
96
                       original_table_message,
100
97
                       create_table_proto, 
101
98
                       first_table,
102
99
                       &alter_info,
103
 
                       0, (Order*) 0, 0);
 
100
                       0, (order_st*) 0, 0);
104
101
    }
105
102
  }
106
103
  return res;