~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/alter_schema.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-11-28 22:02:19 UTC
  • mfrom: (1228 push)
  • mto: (1228.4.1 push)
  • mto: This revision was merged to the branch mainline in revision 1234.
  • Revision ID: osullivan.padraig@gmail.com-20091128220219-m3x28m8q2unbirke
MergeĀ fromĀ trunk.

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/alter_schema.h>
25
 
#include <drizzled/plugin/storage_engine.h>
26
 
#include <drizzled/db.h>
27
 
#include <drizzled/message.h>
28
 
 
29
 
#include <string>
30
 
 
31
 
using namespace std;
32
25
 
33
26
namespace drizzled
34
27
{
36
29
bool statement::AlterSchema::execute()
37
30
{
38
31
  LEX_STRING *db= &session->lex->name;
39
 
  message::schema::shared_ptr old_definition;
40
 
 
41
 
  if (not validateSchemaOptions())
42
 
    return true;
43
 
 
44
 
  SchemaIdentifier schema_identifier(string(db->str, db->length));
45
 
 
46
 
  if (not check_db_name(session, schema_identifier))
 
32
  if (check_db_name(db))
47
33
  {
48
 
    std::string path;
49
 
    schema_identifier.getSQLPath(path);
50
 
    my_error(ER_WRONG_DB_NAME, MYF(0), path.c_str());
51
 
 
 
34
    my_error(ER_WRONG_DB_NAME, MYF(0), db->str);
52
35
    return false;
53
36
  }
54
 
 
55
 
  SchemaIdentifier identifier(db->str);
56
 
  if (not plugin::StorageEngine::getSchemaDefinition(identifier, old_definition))
57
 
  {
58
 
    my_error(ER_SCHEMA_DOES_NOT_EXIST, MYF(0), db->str);
59
 
    return true;
60
 
  }
61
 
 
62
37
  if (session->inTransaction())
63
38
  {
64
39
    my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, 
66
41
               MYF(0));
67
42
    return true;
68
43
  }
69
 
  /*
70
 
    @todo right now the logic for alter schema is just sitting here, at some point this should be packaged up in a class/etc.
71
 
  */
72
 
 
73
 
  // We set the name from the old version to keep case preference
74
 
  schema_message.set_name(old_definition->name());
75
 
  schema_message.set_version(old_definition->version());
76
 
  schema_message.set_uuid(old_definition->uuid());
77
 
  schema_message.mutable_engine()->set_name(old_definition->engine().name());
78
 
 
79
 
  // We need to make sure we don't destroy any collation that might have
80
 
  // been changed.
81
 
  if (not schema_message.has_collation())
82
 
  {
83
 
    schema_message.set_collation(old_definition->collation());
84
 
  }
85
 
  
86
 
  drizzled::message::update(schema_message);
87
 
 
88
 
  bool res= mysql_alter_db(session, schema_message);
89
 
 
90
 
  return not res;
 
44
  bool res= mysql_alter_db(session, db->str, &create_info);
 
45
  return res;
91
46
}
92
47
 
93
48
} /* namespace drizzled */