~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_schema.cc

  • Committer: lbieber
  • Date: 2010-10-01 13:06:31 UTC
  • mfrom: (1802.2.2 drizzle-bug-651948)
  • mto: This revision was merged to the branch mainline in revision 1805.
  • Revision ID: lbieber@orisndriz08-20101001130631-xubscnhmj7r5dn6g
Merge Andrew - Fix bug 651948 - Index lengths not retrieved using drizzledump

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
19
19
 */
20
20
 
21
21
#include "config.h"
22
 
 
23
22
#include <drizzled/show.h>
24
23
#include <drizzled/session.h>
25
24
#include <drizzled/statement/create_schema.h>
26
25
#include <drizzled/db.h>
27
26
#include <drizzled/plugin/event_observer.h>
28
 
#include <drizzled/message.h>
29
 
#include <drizzled/plugin/storage_engine.h>
30
27
 
31
28
#include <string>
32
29
 
40
37
  if (not validateSchemaOptions())
41
38
    return true;
42
39
 
43
 
  if (getSession()->inTransaction())
 
40
  if (not session->endActiveTransaction())
44
41
  {
45
 
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
46
42
    return true;
47
43
  }
48
44
 
49
 
  identifier::Schema schema_identifier(string(getSession()->lex->name.str, getSession()->lex->name.length));
50
 
  if (not check(schema_identifier))
 
45
  SchemaIdentifier schema_identifier(string(session->lex->name.str, session->lex->name.length));
 
46
  if (not check_db_name(session, schema_identifier))
 
47
  {
 
48
    my_error(ER_WRONG_DB_NAME, MYF(0), schema_identifier.getSQLPath().c_str());
51
49
    return false;
 
50
  }
52
51
 
53
 
  drizzled::message::schema::init(schema_message, getSession()->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
  }
54
58
 
55
59
  bool res = false;
56
 
  std::string path;
57
 
  schema_identifier.getSQLPath(path);
58
 
 
59
 
  if (unlikely(plugin::EventObserver::beforeCreateDatabase(*getSession(), path)))
 
60
  if (unlikely(plugin::EventObserver::beforeCreateDatabase(*session, schema_identifier.getSQLPath())))
60
61
  {
61
 
    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());
62
63
  }
63
64
  else
64
65
  {
65
 
    res= create_db(getSession(), schema_message, getSession()->getLex()->exists());
66
 
    if (unlikely(plugin::EventObserver::afterCreateDatabase(*getSession(), path, res)))
 
66
    res= mysql_create_db(session, schema_message, is_if_not_exists);
 
67
    if (unlikely(plugin::EventObserver::afterCreateDatabase(*session, schema_identifier.getSQLPath(), res)))
67
68
    {
68
 
      my_error(ER_EVENT_OBSERVER_PLUGIN, schema_identifier);
 
69
      my_error(ER_EVENT_OBSERVER_PLUGIN, MYF(0), schema_identifier.getSQLPath().c_str());
69
70
      res = false;
70
71
    }
71
72
 
74
75
  return not res;
75
76
}
76
77
 
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
78
// We don't actually test anything at this point, we assume it is all bad.
99
79
bool statement::CreateSchema::validateSchemaOptions()
100
80
{