From 3e31d888ba03e9bf863c09871ca3b2330a2954d1 Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Mon, 24 Feb 2003 17:04:34 +0000 Subject: [PATCH] Display column comments in table/database dumps, as inline SQL-Comments --- libraries/build_dump.lib.php3 | 26 +++++++++++++++++++++++++- tbl_dump.php3 | 10 +++++++++- tbl_properties_export.php3 | 14 ++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/libraries/build_dump.lib.php3 b/libraries/build_dump.lib.php3 index 8bfebc0f8..1c5c1b604 100644 --- a/libraries/build_dump.lib.php3 +++ b/libraries/build_dump.lib.php3 @@ -35,6 +35,7 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ * @param string the table name * @param string the end of line sequence * @param string the url to go back in case of error + * @param boolean whether to include column comments * * @return string the CREATE statement on success * @@ -46,7 +47,7 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ * * @access public */ - function PMA_getTableDef($db, $table, $crlf, $error_url) + function PMA_getTableDef($db, $table, $crlf, $error_url, $comments = false) { global $drop; global $use_backquotes; @@ -56,6 +57,12 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ $schema_create .= 'DROP TABLE IF EXISTS ' . PMA_backquote(PMA_htmlFormat($table), $use_backquotes) . ';' . $crlf; } + if ($comments) { + $comments_map = PMA_getComments($db, $table); + } else { + $comments_map = array(); + } + // Steve Alberty's patch for complete table dump, // modified by Lem9 to allow older MySQL versions to continue to work if (PMA_MYSQL_INT_VERSION >= 32321) { @@ -91,6 +98,17 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ . (($use_backquotes) ? PMA_backquote($tmpres[0]) : $tmpres[0]) . substr($tmpres[1], $pos); $schema_create .= str_replace("\n", $crlf, PMA_htmlFormat($tmpres[1])); + + // garvin: Because replacing within a direct mysql result is a bit dangerous, just insert comments after that. + if ($comments && is_array($comments_map) && count($comments_map) > 0) { + $schema_create .= $crlf . $crlf . '/* COMMENTS FOR TABLE ' . PMA_backquote($table, $use_backquotes) . ':' . $crlf; + @reset($comments_map); + while(list($comment_field, $comment) = each($comments_map)) { + $schema_create .= ' ' . PMA_backquote($comment_field, $use_backquotes) . $crlf . ' ' . PMA_backquote($comment, $use_backquotes) . $crlf; + // omitting html_format is intentional. No use for htmlchars in the dump. + } + $schema_create .= '*/'; + } } mysql_free_result($result); return $schema_create; @@ -112,6 +130,12 @@ if (!defined('PMA_BUILD_DUMP_LIB_INCLUDED')){ if ($row['Extra'] != '') { $schema_create .= ' ' . $row['Extra']; } + + if ($comments && is_array($comments_map) && isset($comments_map[$row['Field']])) { + $schema_create .= $crlf . ' /* ' . PMA_backquote($comments_map[$row['Field']], $use_backquotes) . ' */'; + // omitting html_format is intentional. No use for htmlchars in the dump. + } + $schema_create .= ',' . $crlf; } // end while mysql_free_result($result); diff --git a/tbl_dump.php3 b/tbl_dump.php3 index fea4069ee..7b586f6f9 100755 --- a/tbl_dump.php3 +++ b/tbl_dump.php3 @@ -171,6 +171,14 @@ if ($num_tables == 0) { else { // No csv or xml or latex format -> add some comments at the top + if ($use_comments) { + require('./libraries/relation.lib.php3'); + $cfgRelation = PMA_getRelationsParam(); + $use_comments_work = true; + } else { + $use_comments_work = false; + } + if ($what != 'csv' && $what != 'excel' && $what != 'xml' && $what != 'latex') { $dump_buffer .= '# phpMyAdmin MySQL-Dump' . $crlf . '# version ' . PMA_VERSION . $crlf @@ -210,7 +218,7 @@ else { . $crlf . '#' . $crlf . '# ' . $strTableStructure . ' ' . $formatted_table_name . $crlf . '#' . $crlf . $crlf - . PMA_getTableDef($db, $table, $crlf, $err_url) . ';' . $crlf; + . PMA_getTableDef($db, $table, $crlf, $err_url, $use_comments_work) . ';' . $crlf; } if (function_exists('PMA_kanji_str_conv')) { // Y.Kawada $dump_buffer = PMA_kanji_str_conv($dump_buffer, $knjenc, isset($xkana) ? $xkana : ''); diff --git a/tbl_properties_export.php3 b/tbl_properties_export.php3 index 525bb10d2..78d589b44 100755 --- a/tbl_properties_export.php3 +++ b/tbl_properties_export.php3 @@ -95,6 +95,20 @@ if (PMA_MYSQL_INT_VERSION >= 32306) { +    + +
+