~drizzle-trunk/drizzle/development

1100.3.47 by Padraig O'Sullivan
Extracted the ALTER DATABASE command into its own class and implementation
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2009 Sun Microsystems, Inc.
1100.3.47 by Padraig O'Sullivan
Extracted the ALTER DATABASE command into its own class and implementation
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
21
#include <config.h>
1100.3.47 by Padraig O'Sullivan
Extracted the ALTER DATABASE command into its own class and implementation
22
#include <drizzled/show.h>
23
#include <drizzled/session.h>
24
#include <drizzled/statement/alter_schema.h>
1273.19.28 by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it...
25
#include <drizzled/plugin/storage_engine.h>
2159.2.5 by Brian Aker
Merge in move of schema.
26
#include <drizzled/schema.h>
1802.12.2 by Brian Aker
Correcting alter schema to fix bug around schema not altering collate
27
#include <drizzled/message.h>
2234.1.4 by Olaf van der Spek
Refactor includes
28
#include <drizzled/sql_lex.h>
1100.3.47 by Padraig O'Sullivan
Extracted the ALTER DATABASE command into its own class and implementation
29
1235.4.6 by Stewart Smith
ALTER DATABASE using NormalisedDatabaseName
30
#include <string>
31
1235.4.26 by Stewart Smith
s/using std::string/using namespace std/ for create-alter-database-using-proto
32
using namespace std;
1235.4.6 by Stewart Smith
ALTER DATABASE using NormalisedDatabaseName
33
1130.3.12 by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/
34
namespace drizzled
35
{
1100.3.47 by Padraig O'Sullivan
Extracted the ALTER DATABASE command into its own class and implementation
36
37
bool statement::AlterSchema::execute()
38
{
2224.2.8 by Olaf van der Spek
Statement::lex()
39
  LEX_STRING *db= &lex().name;
1966.2.1 by Brian Aker
Clean up style for shared_ptr for messages around table/schema.
40
  message::schema::shared_ptr old_definition;
1235.4.6 by Stewart Smith
ALTER DATABASE using NormalisedDatabaseName
41
1502.1.30 by Brian Aker
First pass on cleanup of Stewart's patch, plus re-engineer to make it work a
42
  if (not validateSchemaOptions())
43
    return true;
44
2087.4.1 by Brian Aker
Merge in schema identifier.
45
  identifier::Schema schema_identifier(string(db->str, db->length));
1415 by Brian Aker
Mass overhaul to use schema_identifier.
46
2227.4.2 by Olaf van der Spek
Statement::session()
47
  if (not schema::check(session(), schema_identifier))
1100.3.47 by Padraig O'Sullivan
Extracted the ALTER DATABASE command into its own class and implementation
48
  {
2041.3.15 by Brian Aker
Cleanup error usage around identifier usage.
49
    my_error(ER_WRONG_DB_NAME, schema_identifier);
1954.2.1 by Brian Aker
getSQLPath() modified to take a string so that we can const the table
50
1100.3.47 by Padraig O'Sullivan
Extracted the ALTER DATABASE command into its own class and implementation
51
    return false;
52
  }
1273 by Brian Aker
Revert db patch.
53
2087.4.1 by Brian Aker
Merge in schema identifier.
54
  identifier::Schema identifier(db->str);
2159.2.1 by Brian Aker
Remove the pass by reference, it really wasn't a good choice.
55
  if (not (old_definition= plugin::StorageEngine::getSchemaDefinition(identifier)))
1273.19.28 by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it...
56
  {
2041.3.15 by Brian Aker
Cleanup error usage around identifier usage.
57
    my_error(ER_SCHEMA_DOES_NOT_EXIST, identifier); 
1273.19.28 by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it...
58
    return true;
59
  }
60
2227.4.1 by Olaf van der Spek
Statement::session()
61
  if (session().inTransaction())
1100.3.47 by Padraig O'Sullivan
Extracted the ALTER DATABASE command into its own class and implementation
62
  {
1890.2.44 by Stewart Smith
error out on ALTER SCHEMA inside a transaction with ER_TRANSACTIONAL_DDL_NOT_SUPPORTED. Previously this would be ER_LOCK_OR_ACTIVE_TRANSACTION which isn't exactly correct or consistent with others.
63
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
1100.3.47 by Padraig O'Sullivan
Extracted the ALTER DATABASE command into its own class and implementation
64
    return true;
65
  }
1802.12.2 by Brian Aker
Correcting alter schema to fix bug around schema not altering collate
66
  /*
67
    @todo right now the logic for alter schema is just sitting here, at some point this should be packaged up in a class/etc.
68
  */
69
2017.3.1 by Brian Aker
Merge catalog with current trunk.
70
  // First initialize the schema message
71
  drizzled::message::schema::init(schema_message, old_definition->name());
72
1802.12.2 by Brian Aker
Correcting alter schema to fix bug around schema not altering collate
73
  // We set the name from the old version to keep case preference
1812.3.8 by Brian Aker
This switches our schema system over to using a shared ptr. Lets see how
74
  schema_message.set_version(old_definition->version());
75
  schema_message.set_uuid(old_definition->uuid());
76
  schema_message.mutable_engine()->set_name(old_definition->engine().name());
1802.12.2 by Brian Aker
Correcting alter schema to fix bug around schema not altering collate
77
78
  // We need to make sure we don't destroy any collation that might have
79
  // been changed.
1273.19.28 by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it...
80
  if (not schema_message.has_collation())
81
  {
1812.3.8 by Brian Aker
This switches our schema system over to using a shared ptr. Lets see how
82
    schema_message.set_collation(old_definition->collation());
1273.19.28 by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it...
83
  }
1802.12.1 by Brian Aker
This solves bug lp:654905
84
  
1802.12.2 by Brian Aker
Correcting alter schema to fix bug around schema not altering collate
85
  drizzled::message::update(schema_message);
1273.19.26 by Brian Aker
Move Alter schema to SE interface.
86
2227.4.2 by Olaf van der Spek
Statement::session()
87
  bool res= schema::alter(session(), schema_message, *old_definition);
1273.19.26 by Brian Aker
Move Alter schema to SE interface.
88
89
  return not res;
1100.3.47 by Padraig O'Sullivan
Extracted the ALTER DATABASE command into its own class and implementation
90
}
1130.3.12 by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/
91
92
} /* namespace drizzled */
93