~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_schema.cc

  • Committer: Brian Aker
  • Date: 2009-11-18 06:24:48 UTC
  • mfrom: (1220.1.15 staging)
  • Revision ID: brian@gaz-20091118062448-o36lo3yv81sc6u9z
Merge Brian + Stewart

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, Inc.
 
4
 *  Copyright (C) 2009 Sun Microsystems
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"
22
 
 
 
21
#include <drizzled/server_includes.h>
23
22
#include <drizzled/show.h>
24
23
#include <drizzled/session.h>
25
24
#include <drizzled/statement/create_schema.h>
26
 
#include <drizzled/db.h>
27
 
#include <drizzled/plugin/event_observer.h>
28
 
#include <drizzled/message.h>
29
 
#include <drizzled/plugin/storage_engine.h>
30
 
 
31
 
#include <string>
32
 
 
33
 
using namespace std;
34
25
 
35
26
namespace drizzled
36
27
{
37
28
 
38
29
bool statement::CreateSchema::execute()
39
30
{
40
 
  if (not validateSchemaOptions())
41
 
    return true;
42
 
 
43
 
  if (getSession()->inTransaction())
44
 
  {
45
 
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
46
 
    return true;
47
 
  }
48
 
 
49
 
  identifier::Schema schema_identifier(string(getSession()->lex->name.str, getSession()->lex->name.length));
50
 
  if (not check(schema_identifier))
51
 
    return false;
52
 
 
53
 
  drizzled::message::schema::init(schema_message, getSession()->lex->name.str);
54
 
 
55
 
  bool res = false;
56
 
  std::string path;
57
 
  schema_identifier.getSQLPath(path);
58
 
 
59
 
  if (unlikely(plugin::EventObserver::beforeCreateDatabase(*getSession(), path)))
60
 
  {
61
 
    my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), path.c_str());
62
 
  }
63
 
  else
64
 
  {
65
 
    res= create_db(getSession(), schema_message, getSession()->getLex()->exists());
66
 
    if (unlikely(plugin::EventObserver::afterCreateDatabase(*getSession(), path, res)))
67
 
    {
68
 
      my_error(ER_EVENT_OBSERVER_PLUGIN, schema_identifier);
69
 
      res = false;
70
 
    }
71
 
 
72
 
  }
73
 
 
74
 
  return not res;
75
 
}
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
 
 
98
 
// We don't actually test anything at this point, we assume it is all bad.
99
 
bool statement::CreateSchema::validateSchemaOptions()
100
 
{
101
 
  size_t num_engine_options= schema_message.engine().options_size();
102
 
  bool rc= num_engine_options ? false : true;
103
 
 
104
 
  for (size_t y= 0; y < num_engine_options; ++y)
105
 
  {
106
 
    my_error(ER_UNKNOWN_SCHEMA_OPTION, MYF(0),
107
 
             schema_message.engine().options(y).name().c_str(),
108
 
             schema_message.engine().options(y).state().c_str());
109
 
 
110
 
    rc= false;
111
 
  }
112
 
 
113
 
  return rc;
 
31
  if (! session->endActiveTransaction())
 
32
  {
 
33
    return true;
 
34
  }
 
35
  char *alias= session->strmake(session->lex->name.str,
 
36
                                session->lex->name.length);
 
37
  if (! alias ||
 
38
      check_db_name(&session->lex->name))
 
39
  {
 
40
    my_error(ER_WRONG_DB_NAME, MYF(0), session->lex->name.str);
 
41
    return false;
 
42
  }
 
43
  bool res= mysql_create_db(session, session->lex->name.str, &create_info);
 
44
  return res;
114
45
}
115
46
 
116
47
} /* namespace drizzled */