~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_schema.cc

mergeĀ lp:~linuxjedi/drizzle/trunk-remove-drizzleadmin

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
 
21
#include <config.h>
22
22
 
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>
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()->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))
51
53
    return false;
52
54
 
53
 
  drizzled::message::schema::init(schema_message, getSession()->lex->name.str);
 
55
  drizzled::message::schema::init(schema_message, lex().name.str);
 
56
 
 
57
  message::set_definer(schema_message, *session().user());
54
58
 
55
59
  bool res = false;
56
 
  std::string path;
57
 
  schema_identifier.getSQLPath(path);
 
60
  std::string path = schema_identifier.getSQLPath();
58
61
 
59
 
  if (unlikely(plugin::EventObserver::beforeCreateDatabase(*getSession(), path)))
 
62
  if (unlikely(plugin::EventObserver::beforeCreateDatabase(session(), path)))
60
63
  {
61
64
    my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), path.c_str());
62
65
  }
63
66
  else
64
67
  {
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)))
67
70
    {
68
71
      my_error(ER_EVENT_OBSERVER_PLUGIN, schema_identifier);
69
72
      res = false;
79
82
  if (not identifier.isValid())
80
83
    return false;
81
84
 
82
 
  if (not plugin::Authorization::isAuthorized(getSession()->user(), identifier))
 
85
  if (not plugin::Authorization::isAuthorized(*session().user(), identifier))
83
86
    return false;
84
87
 
85
 
  if (not getSession()->getLex()->exists())
 
88
  if (not lex().exists())
86
89
  {
87
90
    if (plugin::StorageEngine::doesSchemaExist(identifier))
88
91
    {