~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_index.cc

  • Committer: Stewart Smith
  • Date: 2011-03-29 01:30:47 UTC
  • mto: (2257.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2258.
  • Revision ID: stewart@flamingspork.com-20110329013047-5ujzfx6pahmwuko2
have CachedDirectory print out a warning if we can't stat() something in a directory. We should always have access to at least stat() things in directories Drizzle is running in (otherwise there is likely a problem)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
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"
 
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>
27
28
 
28
29
namespace drizzled
29
30
{
30
31
 
 
32
namespace statement
 
33
{
 
34
 
 
35
CreateIndex::CreateIndex(Session *in_session) :
 
36
  CreateTable(in_session)
 
37
  {
 
38
    set_command(SQLCOM_CREATE_INDEX);
 
39
    alter_info.flags.set(ALTER_ADD_INDEX);
 
40
    lex().col_list.clear();
 
41
  }
 
42
 
31
43
bool statement::CreateIndex::execute()
32
44
{
33
 
  TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
34
 
  TableList *all_tables= session->lex->query_tables;
 
45
  TableList *first_table= (TableList *) lex().select_lex.table_list.first;
 
46
  TableList *all_tables= lex().query_tables;
35
47
 
36
48
  /* Chicken/Egg... we need to search for the table, to know if the table exists, so we can build a full identifier from it */
37
49
  message::table::shared_ptr original_table_message;
38
50
  {
39
 
    TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName());
40
 
    if (plugin::StorageEngine::getTableDefinition(*session, identifier, original_table_message) != EEXIST)
 
51
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
 
52
    if (not (original_table_message= plugin::StorageEngine::getTableMessage(session(), identifier)))
41
53
    {
42
 
      std::string path;
43
 
      identifier.getSQLPath(path);
44
 
      my_error(ER_BAD_TABLE_ERROR, MYF(0), path.c_str());
 
54
      my_error(ER_BAD_TABLE_ERROR, identifier);
45
55
      return true;
46
56
    }
47
57
  }
56
66
  */
57
67
 
58
68
  assert(first_table == all_tables && first_table != 0);
59
 
  if (! session->endActiveTransaction())
 
69
  if (session().inTransaction())
60
70
  {
 
71
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
61
72
    return true;
62
73
  }
63
74
 
64
75
  bool res;
65
76
  if (original_table_message->type() == message::Table::STANDARD )
66
77
  {
67
 
    TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName());
68
 
    create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
 
78
    identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
 
79
    create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
69
80
 
70
 
    res= alter_table(session, 
71
 
                     identifier,
72
 
                     identifier,
73
 
                     &create_info, 
 
81
    res= alter_table(&session(), 
 
82
                     identifier,
 
83
                     identifier,
 
84
                     &create_info(), 
74
85
                     *original_table_message,
75
 
                     create_table_message, 
 
86
                     createTableMessage(), 
76
87
                     first_table,
77
88
                     &alter_info,
78
89
                     0, (Order*) 0, 0);
79
90
  }
80
91
  else
81
92
  {
82
 
    TableIdentifier catch22(first_table->getSchemaName(), first_table->getTableName());
83
 
    Table *table= session->find_temporary_table(catch22);
 
93
    identifier::Table catch22(first_table->getSchemaName(), first_table->getTableName());
 
94
    Table *table= session().find_temporary_table(catch22);
84
95
    assert(table);
85
96
    {
86
 
      TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
87
 
      create_info.default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
 
97
      identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
 
98
      create_info().default_table_charset= plugin::StorageEngine::getSchemaCollation(identifier);
88
99
 
89
 
      res= alter_table(session, 
90
 
                       identifier,
91
 
                       identifier,
92
 
                       &create_info, 
 
100
      res= alter_table(&session(), 
 
101
                       identifier,
 
102
                       identifier,
 
103
                       &create_info(), 
93
104
                       *original_table_message,
94
 
                       create_table_message, 
 
105
                       createTableMessage(), 
95
106
                       first_table,
96
107
                       &alter_info,
97
108
                       0, (Order*) 0, 0);
101
112
  return res;
102
113
}
103
114
 
 
115
} /* namespace statement */
104
116
} /* namespace drizzled */