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>
29
28
#include <iostream>
52
51
if (create_info.db_type == NULL)
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());
62
61
create_info.db_type= session->getDefaultStorageEngine();
65
if (not validateCreateTableOption())
65
Now we set the name in our Table proto so that it will match
69
message::Table::StorageEngine *protoengine;
71
protoengine= create_table_message.mutable_engine();
72
protoengine->set_name(create_info.db_type->getName());
80
85
TableList *create_table= session->lex->unlink_first_table(&link_to_local);
81
86
TableList *select_tables= session->lex->query_tables;
83
drizzled::message::init(create_table_message, create_table_message.name(), create_table->getSchemaName(), create_info.db_type->getName());
85
TableIdentifier new_table_identifier(create_table->getSchemaName(),
86
create_table->getTableName(),
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.
94
create_table_message.set_schema(create_table->db);
96
TableIdentifier new_table_identifier(create_table->db,
97
create_table->table_name,
87
98
create_table_message.type());
89
if (not check(new_table_identifier))
100
if (create_table_precheck(new_table_identifier))
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.
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)))
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)
128
139
session->lex->link_first_table_back(create_table, link_to_local);
129
create_table->setCreate(true);
140
create_table->create= true;
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.
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);
225
235
Release the protection against the global read lock and wake
226
236
everyone, who might want to set a global read lock.
228
session->startWaitingGlobalReadLock();
238
start_waiting_global_read_lock(session);
233
bool statement::CreateTable::check(const TableIdentifier &identifier)
235
// Check table name for validity
236
if (not identifier.isValid())
239
// See if any storage engine objects to the name of the file
240
if (not plugin::StorageEngine::canCreateTable(identifier))
242
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", identifier.getSchemaName().c_str());
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))
251
my_error(ER_BAD_DB_ERROR, MYF(0), identifier.getSchemaName().c_str());
259
bool statement::CreateTable::validateCreateTableOption()
262
size_t num_engine_options= create_table_message.engine().options_size();
264
assert(create_info.db_type);
266
for (size_t y= 0; y < num_engine_options; ++y)
268
bool valid= create_info.db_type->validateCreateTableOption(create_table_message.engine().options(y).name(),
269
create_table_message.engine().options(y).state());
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());
284
243
} /* namespace drizzled */