18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
23
#include <drizzled/show.h>
23
24
#include <drizzled/session.h>
24
25
#include <drizzled/statement/create_schema.h>
25
#include <drizzled/db.h>
26
#include <drizzled/schema.h>
26
27
#include <drizzled/plugin/event_observer.h>
27
28
#include <drizzled/message.h>
29
#include <drizzled/plugin/storage_engine.h>
38
40
if (not validateSchemaOptions())
41
if (not session->endActiveTransaction())
43
if (getSession()->inTransaction())
45
my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
46
SchemaIdentifier schema_identifier(string(session->lex->name.str, session->lex->name.length));
49
identifier::Schema schema_identifier(string(getSession()->getLex()->name.str, getSession()->getLex()->name.length));
47
50
if (not check(schema_identifier))
50
drizzled::message::schema::init(schema_message, session->lex->name.str);
53
drizzled::message::schema::init(schema_message, getSession()->getLex()->name.str);
54
57
schema_identifier.getSQLPath(path);
56
if (unlikely(plugin::EventObserver::beforeCreateDatabase(*session, path)))
59
if (unlikely(plugin::EventObserver::beforeCreateDatabase(*getSession(), path)))
58
61
my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), path.c_str());
62
res= create_db(session, schema_message, session->getLex()->exists());
63
if (unlikely(plugin::EventObserver::afterCreateDatabase(*session, path, res)))
65
res= schema::create(*getSession(), schema_message, getSession()->getLex()->exists());
66
if (unlikely(plugin::EventObserver::afterCreateDatabase(*getSession(), path, res)))
65
my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), path.c_str());
68
my_error(ER_EVENT_OBSERVER_PLUGIN, schema_identifier);
74
bool statement::CreateSchema::check(const SchemaIdentifier &identifier)
77
bool statement::CreateSchema::check(const identifier::Schema &identifier)
76
79
if (not identifier.isValid())
79
if (not plugin::Authorization::isAuthorized(getSession()->user(), identifier))
82
if (not plugin::Authorization::isAuthorized(*getSession()->user(), identifier))
82
if (not session->getLex()->exists())
85
if (not getSession()->getLex()->exists())
84
87
if (plugin::StorageEngine::doesSchemaExist(identifier))
88
identifier.getSQLPath(name);
89
my_error(ER_DB_CREATE_EXISTS, MYF(0), name.c_str());
89
my_error(ER_DB_CREATE_EXISTS, identifier);