18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include <drizzled/server_includes.h>
23
22
#include <drizzled/show.h>
24
23
#include <drizzled/session.h>
25
24
#include <drizzled/statement/create_schema.h>
26
#include <drizzled/db.h>
27
#include <drizzled/plugin/event_observer.h>
28
#include <drizzled/message.h>
29
#include <drizzled/plugin/storage_engine.h>
38
29
bool statement::CreateSchema::execute()
40
if (not validateSchemaOptions())
43
if (getSession()->inTransaction())
45
my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
49
identifier::Schema schema_identifier(string(getSession()->lex->name.str, getSession()->lex->name.length));
50
if (not check(schema_identifier))
53
drizzled::message::schema::init(schema_message, getSession()->lex->name.str);
57
schema_identifier.getSQLPath(path);
59
if (unlikely(plugin::EventObserver::beforeCreateDatabase(*getSession(), path)))
61
my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), path.c_str());
65
res= create_db(getSession(), schema_message, getSession()->getLex()->exists());
66
if (unlikely(plugin::EventObserver::afterCreateDatabase(*getSession(), path, res)))
68
my_error(ER_EVENT_OBSERVER_PLUGIN, schema_identifier);
77
bool statement::CreateSchema::check(const identifier::Schema &identifier)
79
if (not identifier.isValid())
82
if (not plugin::Authorization::isAuthorized(getSession()->user(), identifier))
85
if (not getSession()->getLex()->exists())
87
if (plugin::StorageEngine::doesSchemaExist(identifier))
89
my_error(ER_DB_CREATE_EXISTS, identifier);
98
// We don't actually test anything at this point, we assume it is all bad.
99
bool statement::CreateSchema::validateSchemaOptions()
101
size_t num_engine_options= schema_message.engine().options_size();
102
bool rc= num_engine_options ? false : true;
104
for (size_t y= 0; y < num_engine_options; ++y)
106
my_error(ER_UNKNOWN_SCHEMA_OPTION, MYF(0),
107
schema_message.engine().options(y).name().c_str(),
108
schema_message.engine().options(y).state().c_str());
31
if (! session->endActiveTransaction())
35
char *alias= session->strmake(session->lex->name.str,
36
session->lex->name.length);
38
check_db_name(&session->lex->name))
40
my_error(ER_WRONG_DB_NAME, MYF(0), session->lex->name.str);
43
bool res= mysql_create_db(session, session->lex->name.str, &create_info);
116
47
} /* namespace drizzled */