~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_schema.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

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