~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_index.cc

Fixed for null values in transaction log.

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