~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_table.cc

  • Committer: Monty Taylor
  • Date: 2010-05-15 18:23:34 UTC
  • mto: (1530.6.1)
  • mto: This revision was merged to the branch mainline in revision 1556.
  • Revision ID: mordred@inaugust.com-20100515182334-bgbmwij0mioklajx
Renamed classes that were in drizzled::plugin but which were not meant
for consumption by plugin authors to drizzled::module - since they
really have to do with plugin module loading. This way when we
look in drizzled/plugin, we see nothing but plugin interfaces. Win.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <drizzled/lock.h>
24
24
#include <drizzled/session.h>
25
25
#include <drizzled/statement/create_table.h>
26
 
#include <drizzled/message.h>
27
 
#include <drizzled/identifier.h>
 
26
#include <drizzled/table_identifier.h>
28
27
 
29
28
#include <iostream>
30
29
 
52
51
    if (create_info.db_type == NULL)
53
52
    {
54
53
      my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), 
55
 
               create_table_message.engine().name().c_str());
 
54
               create_table_message.name().c_str());
56
55
 
57
56
      return true;
58
57
    }
62
61
    create_info.db_type= session->getDefaultStorageEngine();
63
62
  }
64
63
 
65
 
  if (not validateCreateTableOption())
 
64
  /* 
 
65
    Now we set the name in our Table proto so that it will match 
 
66
    create_info.db_type.
 
67
  */
66
68
  {
67
 
    return true;
 
69
    message::Table::StorageEngine *protoengine;
 
70
 
 
71
    protoengine= create_table_message.mutable_engine();
 
72
    protoengine->set_name(create_info.db_type->getName());
68
73
  }
69
74
 
70
75
 
80
85
  TableList *create_table= session->lex->unlink_first_table(&link_to_local);
81
86
  TableList *select_tables= session->lex->query_tables;
82
87
 
83
 
  drizzled::message::init(create_table_message, create_table_message.name(), create_table->getSchemaName(), create_info.db_type->getName());
84
 
 
85
 
  TableIdentifier new_table_identifier(create_table->getSchemaName(),
86
 
                                       create_table->getTableName(),
 
88
 
 
89
  /*
 
90
    Now that we have the engine, we can figure out the table identifier. We need the engine in order
 
91
    to determine if the table is transactional or not if it is temp.
 
92
  */
 
93
 
 
94
  create_table_message.set_schema(create_table->db);
 
95
 
 
96
  TableIdentifier new_table_identifier(create_table->db,
 
97
                                       create_table->table_name,
87
98
                                       create_table_message.type());
88
99
 
89
 
  if (not check(new_table_identifier))
 
100
  if (create_table_precheck(new_table_identifier))
90
101
  {
91
102
    /* put tables back for PS rexecuting */
92
103
    session->lex->link_first_table_back(create_table, link_to_local);
109
120
     TABLE in the same way. That way we avoid that a new table is
110
121
     created during a gobal read lock.
111
122
   */
112
 
  if (! (need_start_waiting= not session->wait_if_global_read_lock(0, 1)))
 
123
  if (! (need_start_waiting= ! wait_if_global_read_lock(session, 0, 1)))
113
124
  {
114
125
    /* put tables back for PS rexecuting */
115
126
    session->lex->link_first_table_back(create_table, link_to_local);
126
137
    if (not lex_identified_temp_table)
127
138
    {
128
139
      session->lex->link_first_table_back(create_table, link_to_local);
129
 
      create_table->setCreate(true);
 
140
      create_table->create= true;
130
141
    }
131
142
 
132
143
    if (not (res= session->openTablesLock(session->lex->query_tables)))
146
157
             Release the protection against the global read lock and wake
147
158
             everyone, who might want to set a global read lock.
148
159
           */
149
 
          session->startWaitingGlobalReadLock();
 
160
          start_waiting_global_read_lock(session);
150
161
          /* put tables back for PS rexecuting */
151
162
          session->lex->link_first_table_back(create_table, link_to_local);
152
 
 
153
163
          return true;
154
164
        }
155
165
      }
225
235
     Release the protection against the global read lock and wake
226
236
     everyone, who might want to set a global read lock.
227
237
   */
228
 
  session->startWaitingGlobalReadLock();
 
238
  start_waiting_global_read_lock(session);
229
239
 
230
240
  return res;
231
241
}
232
242
 
233
 
bool statement::CreateTable::check(const TableIdentifier &identifier)
234
 
{
235
 
  // Check table name for validity
236
 
  if (not identifier.isValid())
237
 
    return false;
238
 
 
239
 
  // See if any storage engine objects to the name of the file
240
 
  if (not plugin::StorageEngine::canCreateTable(identifier))
241
 
  {
242
 
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", identifier.getSchemaName().c_str());
243
 
 
244
 
    return false;
245
 
  }
246
 
 
247
 
  // Make sure the schema exists, we will do this again during the actual
248
 
  // create for the table.
249
 
  if (not plugin::StorageEngine::doesSchemaExist(identifier))
250
 
  {
251
 
    my_error(ER_BAD_DB_ERROR, MYF(0), identifier.getSchemaName().c_str());
252
 
 
253
 
    return false;
254
 
  }
255
 
 
256
 
  return true;
257
 
}
258
 
 
259
 
bool statement::CreateTable::validateCreateTableOption()
260
 
{
261
 
  bool rc= true;
262
 
  size_t num_engine_options= create_table_message.engine().options_size();
263
 
 
264
 
  assert(create_info.db_type);
265
 
 
266
 
  for (size_t y= 0; y < num_engine_options; ++y)
267
 
  {
268
 
    bool valid= create_info.db_type->validateCreateTableOption(create_table_message.engine().options(y).name(),
269
 
                                                               create_table_message.engine().options(y).state());
270
 
 
271
 
    if (not valid)
272
 
    {
273
 
      my_error(ER_UNKNOWN_ENGINE_OPTION, MYF(0),
274
 
               create_table_message.engine().options(y).name().c_str(),
275
 
               create_table_message.engine().options(y).state().c_str());
276
 
 
277
 
      rc= false;
278
 
    }
279
 
  }
280
 
 
281
 
  return rc;
282
 
}
283
 
 
284
243
} /* namespace drizzled */
285
244