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 <google/protobuf/text_format.h>
00027 #include <drizzled/plugin/authorization.h>
00028 #include <string>
00029
00030 using namespace std;
00031 using namespace drizzled;
00032
00033 ShowCreateTable::ShowCreateTable() :
00034 show_dictionary::Show("TABLE_SQL_DEFINITION")
00035 {
00036 add_field("TABLE_NAME", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
00037 add_field("TABLE_SQL_DEFINITION", plugin::TableFunction::STRING, TABLE_FUNCTION_BLOB_SIZE, false);
00038 }
00039
00040 ShowCreateTable::Generator::Generator(Field **arg) :
00041 show_dictionary::Show::Generator(arg),
00042 is_primed(false)
00043 {
00044 if (not isShowQuery())
00045 return;
00046
00047 statement::Show& select= static_cast<statement::Show&>(statement());
00048
00049 if (not select.getShowTable().empty() && not select.getShowSchema().empty())
00050 {
00051 identifier::Table identifier(select.getShowSchema(), select.getShowTable());
00052
00053 if (not plugin::Authorization::isAuthorized(*getSession().user(),
00054 identifier, false))
00055 {
00056 drizzled::error::access(*getSession().user(), identifier);
00057 return;
00058 }
00059
00060 table_message= plugin::StorageEngine::getTableMessage(getSession(),
00061 identifier);
00062
00063 if (table_message)
00064 is_primed= true;
00065 }
00066 }
00067
00068 bool ShowCreateTable::Generator::populate()
00069 {
00070 enum drizzled::message::TransformSqlError transform_err;
00071
00072 if (not is_primed)
00073 return false;
00074
00075 std::string create_sql;
00076 transform_err= message::transformTableDefinitionToSql(*table_message,
00077 create_sql,
00078 message::DRIZZLE,
00079 false);
00080 if (transform_err != drizzled::message::NONE)
00081 {
00082 return false;
00083 }
00084
00085 push(table_message->name());
00086 push(create_sql);
00087 is_primed= false;
00088
00089 return true;
00090 }