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>
32 #include <drizzled/catalog/instance.h>
40 bool statement::CreateSchema::execute()
42 if (not validateSchemaOptions())
45 if (session().inTransaction())
47 my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
52 to_string(lex().name));
53 if (not check(schema_identifier))
56 drizzled::message::schema::init(schema_message, schema_identifier);
58 message::set_definer(schema_message, *session().user());
61 std::string path = schema_identifier.getSQLPath();
63 if (unlikely(plugin::EventObserver::beforeCreateDatabase(session(), path)))
65 my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), path.c_str());
69 res= schema::create(session(), schema_message, lex().exists());
70 if (unlikely(plugin::EventObserver::afterCreateDatabase(session(), path, res)))
72 my_error(ER_EVENT_OBSERVER_PLUGIN, schema_identifier);
83 if (not identifier.isValid())
86 if (not plugin::Authorization::isAuthorized(*session().user(), identifier))
89 if (not lex().exists())
91 if (plugin::StorageEngine::doesSchemaExist(identifier))
93 my_error(ER_DB_CREATE_EXISTS, identifier);
103 bool statement::CreateSchema::validateSchemaOptions()
105 size_t num_engine_options= schema_message.engine().options_size();
106 bool rc= num_engine_options ?
false :
true;
108 for (
size_t y= 0; y < num_engine_options; ++y)
110 my_error(ER_UNKNOWN_SCHEMA_OPTION, MYF(0),
111 schema_message.engine().options(y).name().c_str(),
112 schema_message.engine().options(y).state().c_str());