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
00037 bool statement::AlterSchema::execute()
00038 {
00039 LEX_STRING *db= &lex().name;
00040 message::schema::shared_ptr old_definition;
00041
00042 if (not validateSchemaOptions())
00043 return true;
00044
00045 identifier::Schema schema_identifier(string(db->str, db->length));
00046
00047 if (not schema::check(session(), schema_identifier))
00048 {
00049 my_error(ER_WRONG_DB_NAME, schema_identifier);
00050
00051 return false;
00052 }
00053
00054 identifier::Schema identifier(db->str);
00055 if (not (old_definition= plugin::StorageEngine::getSchemaDefinition(identifier)))
00056 {
00057 my_error(ER_SCHEMA_DOES_NOT_EXIST, identifier);
00058 return true;
00059 }
00060
00061 if (session().inTransaction())
00062 {
00063 my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
00064 return true;
00065 }
00066
00067
00068
00069
00070
00071 drizzled::message::schema::init(schema_message, old_definition->name());
00072
00073
00074 schema_message.set_version(old_definition->version());
00075 schema_message.set_uuid(old_definition->uuid());
00076 schema_message.mutable_engine()->set_name(old_definition->engine().name());
00077
00078
00079
00080 if (not schema_message.has_collation())
00081 {
00082 schema_message.set_collation(old_definition->collation());
00083 }
00084
00085 drizzled::message::update(schema_message);
00086
00087 bool res= schema::alter(session(), schema_message, *old_definition);
00088
00089 return not res;
00090 }
00091
00092 }
00093