~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_schema.cc

  • Committer: Stewart Smith
  • Date: 2010-03-02 06:41:59 UTC
  • mto: (1309.2.13 build)
  • mto: This revision was merged to the branch mainline in revision 1318.
  • Revision ID: stewart@flamingspork.com-20100302064159-gktw6hcbs3u0fflm
move Item_result out to its own header file and out of common.h

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <drizzled/session.h>
24
24
#include <drizzled/statement/create_schema.h>
25
25
#include <drizzled/db.h>
26
 
#include <drizzled/plugin/event_observer.h>
27
 
#include <drizzled/message.h>
28
26
 
29
27
#include <string>
30
28
 
35
33
 
36
34
bool statement::CreateSchema::execute()
37
35
{
38
 
  if (not validateSchemaOptions())
39
 
    return true;
40
 
 
41
36
  if (not session->endActiveTransaction())
42
37
  {
43
38
    return true;
44
39
  }
45
40
 
46
 
  SchemaIdentifier schema_identifier(string(session->lex->name.str, session->lex->name.length));
47
 
  if (not check(schema_identifier))
 
41
  if (check_db_name(&session->lex->name))
 
42
  {
 
43
    my_error(ER_WRONG_DB_NAME, MYF(0), session->lex->name.str);
48
44
    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
 
 
 
45
  }
 
46
 
 
47
  schema_message.set_name(session->lex->name.str);
 
48
  if (not schema_message.has_collation())
 
49
  {
 
50
    schema_message.set_collation(default_charset_info->name);
 
51
  }
 
52
 
 
53
  bool res= mysql_create_db(session, schema_message, is_if_not_exists);
71
54
  return not res;
72
55
}
73
56
 
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
57
} /* namespace drizzled */
117
58