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 else
00066 my_error(ER_BAD_TABLE_ERROR, identifier);
00067 }
00068 }
00069
00070 bool ShowCreateTable::Generator::populate()
00071 {
00072 enum drizzled::message::TransformSqlError transform_err;
00073
00074 if (not is_primed)
00075 return false;
00076
00077 std::string create_sql;
00078 transform_err= message::transformTableDefinitionToSql(*table_message,
00079 create_sql,
00080 message::DRIZZLE,
00081 false);
00082 if (transform_err != drizzled::message::NONE)
00083 {
00084 return false;
00085 }
00086
00087 push(table_message->name());
00088 push(create_sql);
00089 is_primed= false;
00090
00091 return true;
00092 }