~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_schema.cc

Refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
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>
30
32
 
31
33
#include <string>
32
34
 
40
42
  if (not validateSchemaOptions())
41
43
    return true;
42
44
 
43
 
  if (getSession()->inTransaction())
 
45
  if (session().inTransaction())
44
46
  {
45
47
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
46
48
    return true;
47
49
  }
48
50
 
49
 
  identifier::Schema schema_identifier(string(getSession()->getLex()->name.str, getSession()->getLex()->name.length));
 
51
  identifier::Schema schema_identifier(string(lex().name.str, lex().name.length));
50
52
  if (not check(schema_identifier))
51
53
    return false;
52
54
 
53
 
  drizzled::message::schema::init(schema_message, getSession()->getLex()->name.str);
 
55
  drizzled::message::schema::init(schema_message, lex().name.str);
54
56
 
55
57
  bool res = false;
56
58
  std::string path;
57
59
  schema_identifier.getSQLPath(path);
58
60
 
59
 
  if (unlikely(plugin::EventObserver::beforeCreateDatabase(*getSession(), path)))
 
61
  if (unlikely(plugin::EventObserver::beforeCreateDatabase(session(), path)))
60
62
  {
61
63
    my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), path.c_str());
62
64
  }
63
65
  else
64
66
  {
65
 
    res= schema::create(*getSession(), schema_message, getSession()->getLex()->exists());
66
 
    if (unlikely(plugin::EventObserver::afterCreateDatabase(*getSession(), path, res)))
 
67
    res= schema::create(session(), schema_message, lex().exists());
 
68
    if (unlikely(plugin::EventObserver::afterCreateDatabase(session(), path, res)))
67
69
    {
68
70
      my_error(ER_EVENT_OBSERVER_PLUGIN, schema_identifier);
69
71
      res = false;
79
81
  if (not identifier.isValid())
80
82
    return false;
81
83
 
82
 
  if (not plugin::Authorization::isAuthorized(*getSession()->user(), identifier))
 
84
  if (not plugin::Authorization::isAuthorized(*session().user(), identifier))
83
85
    return false;
84
86
 
85
 
  if (not getSession()->getLex()->exists())
 
87
  if (not lex().exists())
86
88
  {
87
89
    if (plugin::StorageEngine::doesSchemaExist(identifier))
88
90
    {