~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/alter_schema.cc

  • Committer: Olaf van der Spek
  • Date: 2011-03-29 12:04:36 UTC
  • mto: (2257.1.1 build) (2276.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2258.
  • Revision ID: olafvdspek@gmail.com-20110329120436-vozkuer8vqgh027p
Always call assert()

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 <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/db.h>
 
26
#include <drizzled/schema.h>
27
27
#include <drizzled/message.h>
 
28
#include <drizzled/sql_lex.h>
28
29
 
29
30
#include <string>
30
31
 
35
36
 
36
37
bool statement::AlterSchema::execute()
37
38
{
38
 
  LEX_STRING *db= &session->lex->name;
 
39
  LEX_STRING *db= &lex().name;
39
40
  message::schema::shared_ptr old_definition;
40
41
 
41
42
  if (not validateSchemaOptions())
42
43
    return true;
43
44
 
44
 
  SchemaIdentifier schema_identifier(string(db->str, db->length));
 
45
  identifier::Schema schema_identifier(string(db->str, db->length));
45
46
 
46
 
  if (not check_db_name(session, schema_identifier))
 
47
  if (not schema::check(session(), schema_identifier))
47
48
  {
48
 
    std::string path;
49
 
    schema_identifier.getSQLPath(path);
50
 
    my_error(ER_WRONG_DB_NAME, MYF(0), path.c_str());
 
49
    my_error(ER_WRONG_DB_NAME, schema_identifier);
51
50
 
52
51
    return false;
53
52
  }
54
53
 
55
 
  SchemaIdentifier identifier(db->str);
56
 
  if (not plugin::StorageEngine::getSchemaDefinition(identifier, old_definition))
 
54
  identifier::Schema identifier(db->str);
 
55
  if (not (old_definition= plugin::StorageEngine::getSchemaDefinition(identifier)))
57
56
  {
58
 
    my_error(ER_SCHEMA_DOES_NOT_EXIST, MYF(0), db->str);
 
57
    my_error(ER_SCHEMA_DOES_NOT_EXIST, identifier); 
59
58
    return true;
60
59
  }
61
60
 
62
 
  if (session->inTransaction())
 
61
  if (session().inTransaction())
63
62
  {
64
 
    my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, 
65
 
               ER(ER_LOCK_OR_ACTIVE_TRANSACTION), 
66
 
               MYF(0));
 
63
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
67
64
    return true;
68
65
  }
69
66
  /*
70
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.
71
68
  */
72
69
 
 
70
  // First initialize the schema message
 
71
  drizzled::message::schema::init(schema_message, old_definition->name());
 
72
 
73
73
  // We set the name from the old version to keep case preference
74
 
  schema_message.set_name(old_definition->name());
75
74
  schema_message.set_version(old_definition->version());
76
75
  schema_message.set_uuid(old_definition->uuid());
77
76
  schema_message.mutable_engine()->set_name(old_definition->engine().name());
85
84
  
86
85
  drizzled::message::update(schema_message);
87
86
 
88
 
  bool res= mysql_alter_db(session, schema_message);
 
87
  bool res= schema::alter(session(), schema_message, *old_definition);
89
88
 
90
89
  return not res;
91
90
}