00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022 #include <drizzled/show.h>
00023 #include <drizzled/session.h>
00024 #include <drizzled/statement/alter_schema.h>
00025 #include <drizzled/plugin/storage_engine.h>
00026 #include <drizzled/schema.h>
00027 #include <drizzled/message.h>
00028 #include <drizzled/sql_lex.h>
00029
00030 #include <string>
00031
00032 using namespace std;
00033
00034 namespace drizzled {
00035
00036 bool statement::AlterSchema::execute()
00037 {
00038 if (not validateSchemaOptions())
00039 return true;
00040
00041 identifier::Schema schema_identifier(lex().name);
00042
00043 if (not schema::check(session(), schema_identifier))
00044 {
00045 my_error(ER_WRONG_DB_NAME, schema_identifier);
00046 return false;
00047 }
00048
00049 identifier::Schema identifier(lex().name);
00050 message::schema::shared_ptr old_definition= plugin::StorageEngine::getSchemaDefinition(identifier);
00051 if (not old_definition)
00052 {
00053 my_error(ER_SCHEMA_DOES_NOT_EXIST, identifier);
00054 return true;
00055 }
00056
00057 if (session().inTransaction())
00058 {
00059 my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
00060 return true;
00061 }
00062
00063
00064
00065
00066
00067 drizzled::message::schema::init(schema_message, old_definition->name());
00068
00069
00070 schema_message.set_version(old_definition->version());
00071 schema_message.set_uuid(old_definition->uuid());
00072 schema_message.mutable_engine()->set_name(old_definition->engine().name());
00073
00074
00075
00076 if (not schema_message.has_collation())
00077 {
00078 schema_message.set_collation(old_definition->collation());
00079 }
00080
00081 drizzled::message::update(schema_message);
00082
00083 return not schema::alter(session(), schema_message, *old_definition);
00084 }
00085
00086 }