~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_schema.cc

  • Committer: Mark Atwood
  • Date: 2011-10-27 05:08:12 UTC
  • mfrom: (2445.1.11 rf)
  • Revision ID: me@mark.atwood.name-20111027050812-1icvs72lb0u4xdc4
mergeĀ lp:~olafvdspek/drizzle/refactor8

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
#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>
 
30
#include <drizzled/sql_lex.h>
 
31
#include <drizzled/plugin/authorization.h>
28
32
 
29
33
#include <string>
30
34
 
31
35
using namespace std;
32
36
 
33
 
namespace drizzled
34
 
{
 
37
namespace drizzled {
35
38
 
36
39
bool statement::CreateSchema::execute()
37
40
{
38
41
  if (not validateSchemaOptions())
39
42
    return true;
40
43
 
41
 
  if (not session->endActiveTransaction())
 
44
  if (session().inTransaction())
42
45
  {
 
46
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
43
47
    return true;
44
48
  }
45
49
 
46
 
  SchemaIdentifier schema_identifier(string(session->lex->name.str, session->lex->name.length));
 
50
  identifier::Schema schema_identifier(to_string(lex().name));
47
51
  if (not check(schema_identifier))
48
52
    return false;
49
53
 
50
 
  drizzled::message::init(schema_message, session->lex->name.str);
 
54
  drizzled::message::schema::init(schema_message, lex().name.data());
 
55
 
 
56
  message::set_definer(schema_message, *session().user());
51
57
 
52
58
  bool res = false;
53
 
  std::string path;
54
 
  schema_identifier.getSQLPath(path);
 
59
  std::string path = schema_identifier.getSQLPath();
55
60
 
56
 
  if (unlikely(plugin::EventObserver::beforeCreateDatabase(*session, path)))
 
61
  if (unlikely(plugin::EventObserver::beforeCreateDatabase(session(), path)))
57
62
  {
58
63
    my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), path.c_str());
59
64
  }
60
65
  else
61
66
  {
62
 
    res= mysql_create_db(session, schema_message, is_if_not_exists);
63
 
    if (unlikely(plugin::EventObserver::afterCreateDatabase(*session, path, res)))
 
67
    res= schema::create(session(), schema_message, lex().exists());
 
68
    if (unlikely(plugin::EventObserver::afterCreateDatabase(session(), path, res)))
64
69
    {
65
 
      my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), path.c_str());
 
70
      my_error(ER_EVENT_OBSERVER_PLUGIN, schema_identifier);
66
71
      res = false;
67
72
    }
68
73
 
71
76
  return not res;
72
77
}
73
78
 
74
 
bool statement::CreateSchema::check(const SchemaIdentifier &identifier)
 
79
bool statement::CreateSchema::check(const identifier::Schema &identifier)
75
80
{
76
81
  if (not identifier.isValid())
77
82
    return false;
78
83
 
79
 
  if (not plugin::Authorization::isAuthorized(getSession()->user(), identifier))
 
84
  if (not plugin::Authorization::isAuthorized(*session().user(), identifier))
80
85
    return false;
81
86
 
82
 
  if (not is_if_not_exists)
 
87
  if (not lex().exists())
83
88
  {
84
89
    if (plugin::StorageEngine::doesSchemaExist(identifier))
85
90
    {
86
 
      std::string name;
87
 
 
88
 
      identifier.getSQLPath(name);
89
 
      my_error(ER_DB_CREATE_EXISTS, MYF(0), name.c_str());
 
91
      my_error(ER_DB_CREATE_EXISTS, identifier);
90
92
 
91
93
      return false;
92
94
    }
114
116
}
115
117
 
116
118
} /* namespace drizzled */
117