18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
23
#include <drizzled/show.h>
24
24
#include <drizzled/session.h>
25
25
#include <drizzled/statement/create_schema.h>
26
#include <drizzled/db.h>
26
#include <drizzled/schema.h>
27
27
#include <drizzled/plugin/event_observer.h>
28
28
#include <drizzled/message.h>
29
29
#include <drizzled/plugin/storage_engine.h>
30
#include <drizzled/sql_lex.h>
31
#include <drizzled/plugin/authorization.h>
40
42
if (not validateSchemaOptions())
43
if (getSession()->inTransaction())
45
if (session().inTransaction())
45
47
my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
49
identifier::Schema schema_identifier(string(getSession()->lex->name.str, getSession()->lex->name.length));
51
identifier::Schema schema_identifier(string(lex().name.str, lex().name.length));
50
52
if (not check(schema_identifier))
53
drizzled::message::schema::init(schema_message, getSession()->lex->name.str);
55
drizzled::message::schema::init(schema_message, lex().name.str);
57
message::set_definer(schema_message, *session().user());
57
schema_identifier.getSQLPath(path);
60
std::string path = schema_identifier.getSQLPath();
59
if (unlikely(plugin::EventObserver::beforeCreateDatabase(*getSession(), path)))
62
if (unlikely(plugin::EventObserver::beforeCreateDatabase(session(), path)))
61
64
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
res= schema::create(session(), schema_message, lex().exists());
69
if (unlikely(plugin::EventObserver::afterCreateDatabase(session(), path, res)))
68
71
my_error(ER_EVENT_OBSERVER_PLUGIN, schema_identifier);
79
82
if (not identifier.isValid())
82
if (not plugin::Authorization::isAuthorized(getSession()->user(), identifier))
85
if (not plugin::Authorization::isAuthorized(*session().user(), identifier))
85
if (not getSession()->getLex()->exists())
88
if (not lex().exists())
87
90
if (plugin::StorageEngine::doesSchemaExist(identifier))