~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/alter_schema.cc

  • Committer: Brian Aker
  • Date: 2010-06-05 00:15:57 UTC
  • mfrom: (1589.1.1 drizzle_events)
  • Revision ID: brian@gaz-20100605001557-j1k41ni5k9mis891
Merge in Barry.

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
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <config.h>
 
21
#include "config.h"
22
22
#include <drizzled/show.h>
23
23
#include <drizzled/session.h>
24
24
#include <drizzled/statement/alter_schema.h>
25
25
#include <drizzled/plugin/storage_engine.h>
26
 
#include <drizzled/schema.h>
27
 
#include <drizzled/message.h>
 
26
#include <drizzled/db.h>
28
27
 
29
28
#include <string>
30
29
 
35
34
 
36
35
bool statement::AlterSchema::execute()
37
36
{
38
 
  LEX_STRING *db= &getSession()->getLex()->name;
39
 
  message::schema::shared_ptr old_definition;
 
37
  LEX_STRING *db= &session->lex->name;
 
38
  message::Schema old_definition;
40
39
 
41
40
  if (not validateSchemaOptions())
42
41
    return true;
43
42
 
44
 
  identifier::Schema schema_identifier(string(db->str, db->length));
 
43
  SchemaIdentifier schema_identifier(string(db->str, db->length));
45
44
 
46
 
  if (not schema::check(*getSession(), schema_identifier))
 
45
  if (not check_db_name(session, schema_identifier))
47
46
  {
48
 
    my_error(ER_WRONG_DB_NAME, schema_identifier);
49
 
 
 
47
    my_error(ER_WRONG_DB_NAME, MYF(0), schema_identifier.getSQLPath().c_str());
50
48
    return false;
51
49
  }
52
50
 
53
 
  identifier::Schema identifier(db->str);
54
 
  if (not (old_definition= plugin::StorageEngine::getSchemaDefinition(identifier)))
55
 
  {
56
 
    my_error(ER_SCHEMA_DOES_NOT_EXIST, identifier); 
57
 
    return true;
58
 
  }
59
 
 
60
 
  if (getSession()->inTransaction())
61
 
  {
62
 
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
63
 
    return true;
64
 
  }
65
 
  /*
66
 
    @todo right now the logic for alter schema is just sitting here, at some point this should be packaged up in a class/etc.
67
 
  */
68
 
 
69
 
  // First initialize the schema message
70
 
  drizzled::message::schema::init(schema_message, old_definition->name());
71
 
 
72
 
  // We set the name from the old version to keep case preference
73
 
  schema_message.set_version(old_definition->version());
74
 
  schema_message.set_uuid(old_definition->uuid());
75
 
  schema_message.mutable_engine()->set_name(old_definition->engine().name());
76
 
 
77
 
  // We need to make sure we don't destroy any collation that might have
78
 
  // been changed.
 
51
  schema_message.set_name(db->str);
 
52
  schema_message.mutable_engine()->set_name("filesystem"); // For the moment we have only one.
 
53
  SchemaIdentifier identifier(schema_message.name());
 
54
 
 
55
  if (not plugin::StorageEngine::getSchemaDefinition(identifier, old_definition))
 
56
  {
 
57
    my_error(ER_SCHEMA_DOES_NOT_EXIST, MYF(0), db->str);
 
58
    return true;
 
59
  }
 
60
 
 
61
  if (session->inTransaction())
 
62
  {
 
63
    my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, 
 
64
               ER(ER_LOCK_OR_ACTIVE_TRANSACTION), 
 
65
               MYF(0));
 
66
    return true;
 
67
  }
 
68
 
79
69
  if (not schema_message.has_collation())
80
70
  {
81
 
    schema_message.set_collation(old_definition->collation());
 
71
    schema_message.set_collation(schema_message.collation());
82
72
  }
83
 
  
84
 
  drizzled::message::update(schema_message);
85
73
 
86
 
  bool res= schema::alter(*getSession(), schema_message, *old_definition);
 
74
  bool res= mysql_alter_db(session, schema_message);
87
75
 
88
76
  return not res;
89
77
}