~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:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems
 
4
 *  Copyright (C) 2009 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
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));
47
 
  if (not check_db_name(session, schema_identifier))
48
 
  {
49
 
    my_error(ER_WRONG_DB_NAME, MYF(0), schema_identifier.getSQLPath().c_str());
 
49
  identifier::Schema schema_identifier(string(getSession()->getLex()->name.str, getSession()->getLex()->name.length));
 
50
  if (not check(schema_identifier))
50
51
    return false;
51
 
  }
52
52
 
53
 
  drizzled::message::init(schema_message, session->lex->name.str);
 
53
  drizzled::message::schema::init(schema_message, getSession()->getLex()->name.str);
54
54
 
55
55
  bool res = false;
56
 
  if (unlikely(plugin::EventObserver::beforeCreateDatabase(*session, schema_identifier.getSQLPath())))
 
56
  std::string path;
 
57
  schema_identifier.getSQLPath(path);
 
58
 
 
59
  if (unlikely(plugin::EventObserver::beforeCreateDatabase(*getSession(), path)))
57
60
  {
58
 
    my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), schema_identifier.getSQLPath().c_str());
 
61
    my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), path.c_str());
59
62
  }
60
63
  else
61
64
  {
62
 
    res= mysql_create_db(session, schema_message, is_if_not_exists);
63
 
    if (unlikely(plugin::EventObserver::afterCreateDatabase(*session, schema_identifier.getSQLPath(), 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), schema_identifier.getSQLPath().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
 
 
77
bool statement::CreateSchema::check(const identifier::Schema &identifier)
 
78
{
 
79
  if (not identifier.isValid())
 
80
    return false;
 
81
 
 
82
  if (not plugin::Authorization::isAuthorized(*getSession()->user(), identifier))
 
83
    return false;
 
84
 
 
85
  if (not getSession()->getLex()->exists())
 
86
  {
 
87
    if (plugin::StorageEngine::doesSchemaExist(identifier))
 
88
    {
 
89
      my_error(ER_DB_CREATE_EXISTS, identifier);
 
90
 
 
91
      return false;
 
92
    }
 
93
  }
 
94
 
 
95
  return true;
 
96
}
 
97
 
74
98
// We don't actually test anything at this point, we assume it is all bad.
75
99
bool statement::CreateSchema::validateSchemaOptions()
76
100
{