~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_schema.cc

  • Committer: Brian Aker
  • Date: 2010-12-19 06:20:54 UTC
  • mfrom: (2005.1.1 bug673105)
  • Revision ID: brian@tangent.org-20101219062054-1kt0l3dxs4z2z8md
Merge Dave.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
#include "config.h"
22
 
 
23
22
#include <drizzled/show.h>
24
23
#include <drizzled/session.h>
25
24
#include <drizzled/statement/create_schema.h>
26
25
#include <drizzled/db.h>
27
26
#include <drizzled/plugin/event_observer.h>
28
27
#include <drizzled/message.h>
29
 
#include <drizzled/plugin/storage_engine.h>
30
28
 
31
29
#include <string>
32
30
 
40
38
  if (not validateSchemaOptions())
41
39
    return true;
42
40
 
43
 
  if (getSession()->inTransaction())
 
41
  if (not session->endActiveTransaction())
44
42
  {
45
 
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
46
43
    return true;
47
44
  }
48
45
 
49
 
  identifier::Schema schema_identifier(string(getSession()->lex->name.str, getSession()->lex->name.length));
 
46
  SchemaIdentifier schema_identifier(string(session->lex->name.str, session->lex->name.length));
50
47
  if (not check(schema_identifier))
51
48
    return false;
52
49
 
53
 
  drizzled::message::schema::init(schema_message, getSession()->lex->name.str);
 
50
  drizzled::message::init(schema_message, session->lex->name.str);
54
51
 
55
52
  bool res = false;
56
53
  std::string path;
57
54
  schema_identifier.getSQLPath(path);
58
55
 
59
 
  if (unlikely(plugin::EventObserver::beforeCreateDatabase(*getSession(), path)))
 
56
  if (unlikely(plugin::EventObserver::beforeCreateDatabase(*session, path)))
60
57
  {
61
58
    my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), path.c_str());
62
59
  }
63
60
  else
64
61
  {
65
 
    res= create_db(getSession(), schema_message, getSession()->getLex()->exists());
66
 
    if (unlikely(plugin::EventObserver::afterCreateDatabase(*getSession(), path, res)))
 
62
    res= mysql_create_db(session, schema_message, is_if_not_exists);
 
63
    if (unlikely(plugin::EventObserver::afterCreateDatabase(*session, path, res)))
67
64
    {
68
 
      my_error(ER_EVENT_OBSERVER_PLUGIN, schema_identifier);
 
65
      my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), path.c_str());
69
66
      res = false;
70
67
    }
71
68
 
74
71
  return not res;
75
72
}
76
73
 
77
 
bool statement::CreateSchema::check(const identifier::Schema &identifier)
 
74
bool statement::CreateSchema::check(const SchemaIdentifier &identifier)
78
75
{
79
76
  if (not identifier.isValid())
80
77
    return false;
82
79
  if (not plugin::Authorization::isAuthorized(getSession()->user(), identifier))
83
80
    return false;
84
81
 
85
 
  if (not getSession()->getLex()->exists())
 
82
  if (not is_if_not_exists)
86
83
  {
87
84
    if (plugin::StorageEngine::doesSchemaExist(identifier))
88
85
    {
89
 
      my_error(ER_DB_CREATE_EXISTS, identifier);
 
86
      std::string name;
 
87
 
 
88
      identifier.getSQLPath(name);
 
89
      my_error(ER_DB_CREATE_EXISTS, MYF(0), name.c_str());
90
90
 
91
91
      return false;
92
92
    }