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 <plugin/show_dictionary/dictionary.h>
00023 #include <drizzled/identifier.h>
00024 #include <drizzled/message.h>
00025 #include <drizzled/message/statement_transform.h>
00026 #include <string>
00027
00028 using namespace std;
00029 using namespace drizzled;
00030
00031 ShowCreateSchema::ShowCreateSchema() :
00032 show_dictionary::Show("SCHEMA_SQL_DEFINITION")
00033 {
00034 add_field("SCHEMA_NAME", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
00035 add_field("SCHEMA_SQL_DEFINITION", plugin::TableFunction::STRING, TABLE_FUNCTION_BLOB_SIZE, false);
00036 }
00037
00038 ShowCreateSchema::Generator::Generator(Field **arg) :
00039 show_dictionary::Show::Generator(arg),
00040 if_not_exists(false)
00041 {
00042 if (not isShowQuery())
00043 return;
00044
00045 statement::Show& select= static_cast<statement::Show&>(statement());
00046
00047 if (not select.getShowSchema().empty())
00048 {
00049 schema_name.append(select.getShowTable());
00050 identifier::Schema identifier(select.getShowSchema());
00051
00052 if (not plugin::Authorization::isAuthorized(*getSession().user(),
00053 identifier, false))
00054 {
00055 drizzled::error::access(*getSession().user(), identifier);
00056 return;
00057 }
00058
00059 schema_message= plugin::StorageEngine::getSchemaDefinition(identifier);
00060
00061 if_not_exists= select.getShowExists();
00062 }
00063 }
00064
00065 bool ShowCreateSchema::Generator::populate()
00066 {
00067 if (not schema_message)
00068 return false;
00069
00070 std::string buffer;
00071
00072
00073 {
00074 buffer.append("CREATE DATABASE ");
00075
00076 if (if_not_exists)
00077 buffer.append("IF NOT EXISTS ");
00078
00079 buffer.append("`");
00080 buffer.append(schema_message->name());
00081 buffer.append("`");
00082
00083 if (schema_message->has_collation())
00084 {
00085 buffer.append(" COLLATE = ");
00086 buffer.append(schema_message->collation());
00087 }
00088
00089 if (not message::is_replicated(*schema_message))
00090 {
00091 buffer.append(" REPLICATE = FALSE");
00092 }
00093 }
00094
00095 push(schema_message->name());
00096 push(buffer);
00097
00098 schema_message.reset();
00099
00100 return true;
00101 }