~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_schema.cc

  • Committer: Patrick Galbraith
  • Date: 2009-10-08 22:42:05 UTC
  • mto: (1166.5.3 memcached_functions)
  • mto: This revision was merged to the branch mainline in revision 1189.
  • Revision ID: patg@patrick-galbraiths-macbook-pro.local-20091008224205-gq1pehjsivvx0qo9
Starting over with a fresh tree, moved in memcached functions.

Memcached Functions for Drizzle. 

All tests pass.

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 <drizzled/server_includes.h>
22
22
#include <drizzled/show.h>
23
23
#include <drizzled/session.h>
24
24
#include <drizzled/statement/create_schema.h>
25
 
#include <drizzled/db.h>
26
 
#include <drizzled/plugin/event_observer.h>
27
 
#include <drizzled/message.h>
28
 
 
29
 
#include <string>
30
 
 
31
 
using namespace std;
32
 
 
33
 
namespace drizzled
34
 
{
 
25
 
 
26
using namespace drizzled;
35
27
 
36
28
bool statement::CreateSchema::execute()
37
29
{
38
 
  if (not validateSchemaOptions())
39
 
    return true;
40
 
 
41
 
  if (not session->endActiveTransaction())
42
 
  {
43
 
    return true;
44
 
  }
45
 
 
46
 
  SchemaIdentifier schema_identifier(string(session->lex->name.str, session->lex->name.length));
47
 
  if (not check(schema_identifier))
48
 
    return false;
49
 
 
50
 
  drizzled::message::init(schema_message, session->lex->name.str);
51
 
 
52
 
  bool res = false;
53
 
  std::string path;
54
 
  schema_identifier.getSQLPath(path);
55
 
 
56
 
  if (unlikely(plugin::EventObserver::beforeCreateDatabase(*session, path)))
57
 
  {
58
 
    my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), path.c_str());
59
 
  }
60
 
  else
61
 
  {
62
 
    res= mysql_create_db(session, schema_message, is_if_not_exists);
63
 
    if (unlikely(plugin::EventObserver::afterCreateDatabase(*session, path, res)))
64
 
    {
65
 
      my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), path.c_str());
66
 
      res = false;
67
 
    }
68
 
 
69
 
  }
70
 
 
71
 
  return not res;
72
 
}
73
 
 
74
 
bool statement::CreateSchema::check(const SchemaIdentifier &identifier)
75
 
{
76
 
  if (not identifier.isValid())
77
 
    return false;
78
 
 
79
 
  if (not plugin::Authorization::isAuthorized(getSession()->getSecurityContext(), identifier))
80
 
    return false;
81
 
 
82
 
  if (not is_if_not_exists)
83
 
  {
84
 
    if (plugin::StorageEngine::doesSchemaExist(identifier))
85
 
    {
86
 
      std::string name;
87
 
 
88
 
      identifier.getSQLPath(name);
89
 
      my_error(ER_DB_CREATE_EXISTS, MYF(0), name.c_str());
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;
114
 
}
115
 
 
116
 
} /* namespace drizzled */
117
 
 
 
30
  if (! session->endActiveTransaction())
 
31
  {
 
32
    return true;
 
33
  }
 
34
  char *alias= session->strmake(session->lex->name.str,
 
35
                                session->lex->name.length);
 
36
  if (! alias ||
 
37
      check_db_name(&session->lex->name))
 
38
  {
 
39
    my_error(ER_WRONG_DB_NAME, MYF(0), session->lex->name.str);
 
40
    return false;
 
41
  }
 
42
  bool res= mysql_create_db(session, session->lex->name.str, &create_info);
 
43
  return res;
 
44
}