24 #include <drizzled/session.h>
25 #include <drizzled/statement/create_schema.h>
26 #include <drizzled/schema.h>
27 #include <drizzled/plugin/event_observer.h>
28 #include <drizzled/message.h>
29 #include <drizzled/plugin/storage_engine.h>
30 #include <drizzled/sql_lex.h>
31 #include <drizzled/plugin/authorization.h>
39 bool statement::CreateSchema::execute()
41 if (not validateSchemaOptions())
44 if (session().inTransaction())
46 my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
51 if (not check(schema_identifier))
54 drizzled::message::schema::init(schema_message, lex().name.data());
56 message::set_definer(schema_message, *session().user());
59 std::string path = schema_identifier.getSQLPath();
61 if (unlikely(plugin::EventObserver::beforeCreateDatabase(session(), path)))
63 my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), path.c_str());
67 res= schema::create(session(), schema_message, lex().exists());
68 if (unlikely(plugin::EventObserver::afterCreateDatabase(session(), path, res)))
70 my_error(ER_EVENT_OBSERVER_PLUGIN, schema_identifier);
81 if (not identifier.isValid())
84 if (not plugin::Authorization::isAuthorized(*session().user(), identifier))
87 if (not lex().exists())
89 if (plugin::StorageEngine::doesSchemaExist(identifier))
91 my_error(ER_DB_CREATE_EXISTS, identifier);
101 bool statement::CreateSchema::validateSchemaOptions()
103 size_t num_engine_options= schema_message.engine().options_size();
104 bool rc= num_engine_options ?
false :
true;
106 for (
size_t y= 0; y < num_engine_options; ++y)
108 my_error(ER_UNKNOWN_SCHEMA_OPTION, MYF(0),
109 schema_message.engine().options(y).name().c_str(),
110 schema_message.engine().options(y).state().c_str());