~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_schema.cc

Merge Andrew - Enable boost filesystem requirement and fix linking requirements for it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <drizzled/statement/create_schema.h>
25
25
#include <drizzled/db.h>
26
26
#include <drizzled/plugin/event_observer.h>
27
 
#include <drizzled/message.h>
28
27
 
29
28
#include <string>
30
29
 
44
43
  }
45
44
 
46
45
  SchemaIdentifier schema_identifier(string(session->lex->name.str, session->lex->name.length));
47
 
  if (not check(schema_identifier))
 
46
  if (not check_db_name(session, schema_identifier))
 
47
  {
 
48
    my_error(ER_WRONG_DB_NAME, MYF(0), schema_identifier.getSQLPath().c_str());
48
49
    return false;
 
50
  }
49
51
 
50
 
  drizzled::message::init(schema_message, session->lex->name.str);
 
52
  schema_message.set_name(session->lex->name.str);
 
53
  schema_message.mutable_engine()->set_name(std::string("filesystem")); // For the moment we have only one.
 
54
  if (not schema_message.has_collation())
 
55
  {
 
56
    schema_message.set_collation(default_charset_info->name);
 
57
  }
51
58
 
52
59
  bool res = false;
53
 
  std::string path;
54
 
  schema_identifier.getSQLPath(path);
55
 
 
56
 
  if (unlikely(plugin::EventObserver::beforeCreateDatabase(*session, path)))
 
60
  if (unlikely(plugin::EventObserver::beforeCreateDatabase(*session, schema_identifier.getSQLPath())))
57
61
  {
58
 
    my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), path.c_str());
 
62
    my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), schema_identifier.getSQLPath().c_str());
59
63
  }
60
64
  else
61
65
  {
62
66
    res= mysql_create_db(session, schema_message, is_if_not_exists);
63
 
    if (unlikely(plugin::EventObserver::afterCreateDatabase(*session, path, res)))
 
67
    if (unlikely(plugin::EventObserver::afterCreateDatabase(*session, schema_identifier.getSQLPath(), res)))
64
68
    {
65
 
      my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), path.c_str());
 
69
      my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), schema_identifier.getSQLPath().c_str());
66
70
      res = false;
67
71
    }
68
72
 
71
75
  return not res;
72
76
}
73
77
 
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
78
// We don't actually test anything at this point, we assume it is all bad.
99
79
bool statement::CreateSchema::validateSchemaOptions()
100
80
{