~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
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
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>
1235.4.23 by Stewart Smith
fix includes for drizzled/db.h. Now only in .cc files, no header files. should make modifying db.h much less painful.
26
#include <drizzled/db.h>
1802.12.2 by Brian Aker
Correcting alter schema to fix bug around schema not altering collate
27
#include <drizzled/message.h>
1100.3.47 by Padraig O'Sullivan
Extracted the ALTER DATABASE command into its own class and implementation
28
1235.4.6 by Stewart Smith
ALTER DATABASE using NormalisedDatabaseName
29
#include <string>
30
1235.4.26 by Stewart Smith
s/using std::string/using namespace std/ for create-alter-database-using-proto
31
using namespace std;
1235.4.6 by Stewart Smith
ALTER DATABASE using NormalisedDatabaseName
32
1130.3.12 by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/
33
namespace drizzled
34
{
1100.3.47 by Padraig O'Sullivan
Extracted the ALTER DATABASE command into its own class and implementation
35
36
bool statement::AlterSchema::execute()
37
{
1273 by Brian Aker
Revert db patch.
38
  LEX_STRING *db= &session->lex->name;
1966.2.1 by Brian Aker
Clean up style for shared_ptr for messages around table/schema.
39
  message::schema::shared_ptr old_definition;
1235.4.6 by Stewart Smith
ALTER DATABASE using NormalisedDatabaseName
40
1502.1.30 by Brian Aker
First pass on cleanup of Stewart's patch, plus re-engineer to make it work a
41
  if (not validateSchemaOptions())
42
    return true;
43
1415 by Brian Aker
Mass overhaul to use schema_identifier.
44
  SchemaIdentifier schema_identifier(string(db->str, db->length));
45
1578.4.11 by Brian Aker
PAss through the code removing current_session
46
  if (not check_db_name(session, schema_identifier))
1100.3.47 by Padraig O'Sullivan
Extracted the ALTER DATABASE command into its own class and implementation
47
  {
1954.2.1 by Brian Aker
getSQLPath() modified to take a string so that we can const the table
48
    std::string path;
49
    schema_identifier.getSQLPath(path);
50
    my_error(ER_WRONG_DB_NAME, MYF(0), path.c_str());
51
1100.3.47 by Padraig O'Sullivan
Extracted the ALTER DATABASE command into its own class and implementation
52
    return false;
53
  }
1273 by Brian Aker
Revert db patch.
54
1802.12.2 by Brian Aker
Correcting alter schema to fix bug around schema not altering collate
55
  SchemaIdentifier identifier(db->str);
1415 by Brian Aker
Mass overhaul to use schema_identifier.
56
  if (not plugin::StorageEngine::getSchemaDefinition(identifier, old_definition))
1273.19.28 by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it...
57
  {
58
    my_error(ER_SCHEMA_DOES_NOT_EXIST, MYF(0), db->str);
59
    return true;
60
  }
61
1100.3.47 by Padraig O'Sullivan
Extracted the ALTER DATABASE command into its own class and implementation
62
  if (session->inTransaction())
63
  {
64
    my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, 
65
               ER(ER_LOCK_OR_ACTIVE_TRANSACTION), 
66
               MYF(0));
67
    return true;
68
  }
1802.12.2 by Brian Aker
Correcting alter schema to fix bug around schema not altering collate
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
1812.3.8 by Brian Aker
This switches our schema system over to using a shared ptr. Lets see how
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());
1802.12.2 by Brian Aker
Correcting alter schema to fix bug around schema not altering collate
78
79
  // We need to make sure we don't destroy any collation that might have
80
  // been changed.
1273.19.28 by Brian Aker
More cleanup on ALTER SCHEMA. Hey! MySQL never had errors on half of it...
81
  if (not schema_message.has_collation())
82
  {
1812.3.8 by Brian Aker
This switches our schema system over to using a shared ptr. Lets see how
83
    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...
84
  }
1802.12.1 by Brian Aker
This solves bug lp:654905
85
  
1802.12.2 by Brian Aker
Correcting alter schema to fix bug around schema not altering collate
86
  drizzled::message::update(schema_message);
1273.19.26 by Brian Aker
Move Alter schema to SE interface.
87
1273.19.27 by Brian Aker
Move schema writing code to schema engine plugin.
88
  bool res= mysql_alter_db(session, schema_message);
1273.19.26 by Brian Aker
Move Alter schema to SE interface.
89
90
  return not res;
1100.3.47 by Padraig O'Sullivan
Extracted the ALTER DATABASE command into its own class and implementation
91
}
1130.3.12 by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/
92
93
} /* namespace drizzled */
94