From 30b1873e617690e88c8f7b5a6195483ae6ce77d8 Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Mon, 24 Feb 2003 16:59:36 +0000 Subject: [PATCH] Update and display column comments in Add/Edit Fieldmode and CREATE table mode. Display comments in table structure (optional) with underlined CSS-mouseovers. Display comments in browser mode (optional), both in vertical and horizontal display mode. Keep column comments in synch, when DROPping/ALTERing and moving/copying tables. --- db_details_links.php3 | 2 +- db_details_structure.php3 | 4 ++-- libraries/display_tbl.lib.php3 | 27 ++++++++++++++++++++++++ libraries/relation.lib.php3 | 8 +++---- scripts/create_tables.sql | 2 +- sql.php3 | 21 +++++++++++++++++++ tbl_addfield.php3 | 13 ++++++++++++ tbl_alter.php3 | 14 +++++++++++++ tbl_create.php3 | 14 +++++++++++++ tbl_move_copy.php3 | 38 ++++++++++++++++++++++++++++++++++ tbl_properties.inc.php3 | 19 +++++++++++++++++ tbl_properties_links.php3 | 2 +- tbl_properties_structure.php3 | 22 ++++++++++++++++++++ tbl_relation.php3 | 47 ++---------------------------------------- tbl_rename.php3 | 12 +++++++++++ 15 files changed, 191 insertions(+), 54 deletions(-) diff --git a/db_details_links.php3 b/db_details_links.php3 index 1a098b20b0..802cfaa9fe 100644 --- a/db_details_links.php3 +++ b/db_details_links.php3 @@ -46,7 +46,7 @@ if ($cfg['AllowUserDropDatabase']) { . urlencode('DROP DATABASE ' . PMA_backquote($db)) . '&zero_rows=' . urlencode(sprintf($strDatabaseHasBeenDropped, htmlspecialchars(PMA_backquote($db)))) - . '&goto=main.php3&back=db_details' . $sub_part . '.php3&reload=1'; + . '&goto=main.php3&back=db_details' . $sub_part . '.php3&reload=1&purge=1'; $att5 = 'class="drop" ' . 'onclick="return confirmLink(this, \'DROP DATABASE ' . PMA_jsFormat($db) . '\')"'; } diff --git a/db_details_structure.php3 b/db_details_structure.php3 index 76a9af658b..567cd1f2f8 100644 --- a/db_details_structure.php3 +++ b/db_details_structure.php3 @@ -157,7 +157,7 @@ else if (PMA_MYSQL_INT_VERSION >= 32303) { - @@ -416,7 +416,7 @@ else { - + diff --git a/libraries/display_tbl.lib.php3 b/libraries/display_tbl.lib.php3 index 9f809db6f8..c3f231fea1 100644 --- a/libraries/display_tbl.lib.php3 +++ b/libraries/display_tbl.lib.php3 @@ -518,6 +518,15 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { // 2. Displays the fields' name // 2.0 If sorting links should be used, checks if the query is a "JOIN" // statement (see 2.1.3) + + // 2.0.1 Prepare Display column comments if enabled ($cfg['ShowBrowseComments']). + // Do not show comments, if using horizontalflipped mode, because of space usage + if ($GLOBALS['cfg']['ShowBrowseComments'] && $GLOBALS['cfgRelation']['commwork'] && $disp_direction != 'horizontalflipped') { + $comments_map = PMA_getComments($db, $table); + } else { + $comments_map = array(); + } + if ($is_display['sort_lnk'] == '1') { $is_join = eregi('(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN', $sql_query, $select_stt); } else { @@ -525,6 +534,15 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { } for ($i = 0; $i < $fields_cnt; $i++) { + // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled. + if (isset($comments_map[$fields_meta[$i]->name])) { + $comments_table_wrap_pre = '
'; + $comments_table_wrap_post = '
' . htmlspecialchars($comments_map[$fields_meta[$i]->name]) . '
'; + } else { + $comments_table_wrap_pre = ''; + $comments_table_wrap_post = ''; + } + // 2.1 Results can be sorted if ($is_display['sort_lnk'] == '1') { // Defines the url used to append/modify a sorting order @@ -550,6 +568,7 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { } else { $unsorted_sql_query = $sql_query; } + // 2.1.2 Checks if the current column is used to sort the // results if (empty($sql_order)) { @@ -622,14 +641,18 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { echo "\n"; ?> > + > name), "
\n") : htmlspecialchars($fields_meta[$i]->name)); ?>
+ ' . "\n" + . $comments_table_wrap_pre . ' ' . "\n" . ' ' . htmlspecialchars($fields_meta[$i]->name) . '' . $order_img . "\n" + . $comments_table_wrap_post . ' ' . "\n"; } // end if (2.1) @@ -639,12 +662,16 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { echo "\n"; ?> > + name), "
\n") : htmlspecialchars($fields_meta[$i]->name)) . "\n"; ?> + ' . "\n" + . $comments_table_wrap_pre . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n" + . $comments_table_wrap_post . ' '; } // end else (2.2) } // end for diff --git a/libraries/relation.lib.php3 b/libraries/relation.lib.php3 index 5441d84cf9..b6570f8dab 100644 --- a/libraries/relation.lib.php3 +++ b/libraries/relation.lib.php3 @@ -298,10 +298,10 @@ if (!defined('PMA_RELATION_LIB_INCLUDED')){ global $cfgRelation; if ($table != '') { - $com_qry = 'SELECT column_name, ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['column_comments']) - . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' - . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; - $com_rs = PMA_query_as_cu($com_qry); + $com_qry = 'SELECT column_name, ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['column_comments']) + . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' + . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; + $com_rs = PMA_query_as_cu($com_qry); } else { $com_qry = 'SELECT comment FROM ' . PMA_backquote($cfgRelation['column_comments']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' diff --git a/scripts/create_tables.sql b/scripts/create_tables.sql index b997fabc3d..93705f2850 100644 --- a/scripts/create_tables.sql +++ b/scripts/create_tables.sql @@ -69,7 +69,7 @@ CREATE TABLE `PMA_column_comments` ( db_name varchar(64) NOT NULL default '', table_name varchar(64) NOT NULL default '', column_name varchar(64) NOT NULL default '', - comment varchar(255) NOT NULL default '', + `comment` varchar(255) NOT NULL default '', PRIMARY KEY (id), UNIQUE KEY db_name (db_name, table_name, column_name) ) TYPE=MyISAM COMMENT='Comments for Columns'; diff --git a/sql.php3 b/sql.php3 index c8c3cde495..b46f3ff38e 100755 --- a/sql.php3 +++ b/sql.php3 @@ -437,6 +437,27 @@ else { } else { // not $is_select $unlim_num_rows = 0; } // end rows total count + + // garvin: if a table or database gets dropped, check column comments. + if (isset($purge)) { + include('./libraries/relation.lib.php3'); + $cfgRelation = PMA_getRelationsParam(); + + if ($cfgRelation['commwork']) { + if (isset($table) && isset($db) && !empty($table) && !empty($db)) { + $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_comments']) + . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' + . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; + $rmv_rs = PMA_query_as_cu($remove_query); + unset($rmv_query); + } elseif (isset($db) && !empty($db)) { + $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_comments']) + . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''; + $rmv_rs = PMA_query_as_cu($remove_query); + unset($rmv_query); + } + } // end if relation-stuff + } // end if ($purge) } // end else "didn't ask to see php code" diff --git a/tbl_addfield.php3 b/tbl_addfield.php3 index 5182937bab..e52ccb650a 100755 --- a/tbl_addfield.php3 +++ b/tbl_addfield.php3 @@ -192,6 +192,19 @@ if (isset($submit)) { } } // end if + // garvin: If comments were sent, enable relation stuff + require('./libraries/relation.lib.php3'); + + $cfgRelation = PMA_getRelationsParam(); + + // garvin: Update comment table, if a comment was set. + if (is_array($field_comments) && $cfgRelation['commwork']) { + @reset($field_comments); + while(list($fieldindex, $fieldcomment) = each($field_comments)) { + PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment); + } + } + // Go back to the structure sub-page $sql_query = $sql_query_cpy; unset($sql_query_cpy); diff --git a/tbl_alter.php3 b/tbl_alter.php3 index 6d04b9005a..8ba31fadea 100755 --- a/tbl_alter.php3 +++ b/tbl_alter.php3 @@ -87,6 +87,20 @@ if (isset($submit)) { $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url); $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered; $btnDrop = 'Fake'; + + // garvin: If comments were sent, enable relation stuff + require('./libraries/relation.lib.php3'); + + $cfgRelation = PMA_getRelationsParam(); + + // garvin: Update comment table, if a comment was set. + if (is_array($field_comments) && $cfgRelation['commwork']) { + @reset($field_comments); + while(list($fieldindex, $fieldcomment) = each($field_comments)) { + PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment, $field_orig[$fieldindex]); + } + } + include('./tbl_properties_structure.php3'); exit(); } diff --git a/tbl_create.php3 b/tbl_create.php3 index 90c5ca6392..9d15bc5062 100755 --- a/tbl_create.php3 +++ b/tbl_create.php3 @@ -192,6 +192,20 @@ if (isset($submit)) { $sql_query = $query_cpy . ';'; unset($query_cpy); $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenCreated; + + // garvin: If comments were sent, enable relation stuff + require('./libraries/relation.lib.php3'); + + $cfgRelation = PMA_getRelationsParam(); + + // garvin: Update comment table, if a comment was set. + if (is_array($field_comments) && $cfgRelation['commwork']) { + @reset($field_comments); + while(list($fieldindex, $fieldcomment) = each($field_comments)) { + PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment); + } + } + include('./' . $cfg['DefaultTabTable']); exit(); } // end do create table diff --git a/tbl_move_copy.php3 b/tbl_move_copy.php3 index b9f1ee0921..7a3bb27565 100644 --- a/tbl_move_copy.php3 +++ b/tbl_move_copy.php3 @@ -113,6 +113,9 @@ if (isset($new_name) && trim($new_name) != '') { $sql_query .= "\n\n" . $sql_insert_data; } + include('./libraries/relation.lib.php3'); + $cfgRelation = PMA_getRelationsParam(); + // Drops old table if the user has requested to move it if (isset($submit_move)) { $sql_drop_table = 'DROP TABLE ' . $source; @@ -121,9 +124,44 @@ if (isset($new_name) && trim($new_name) != '') { include('./header.inc.php3'); PMA_mysqlDie('', $sql_drop_table, '', $err_url); } + + // garvin: Move old entries from comments to new table + if ($cfgRelation['commwork']) { + $remove_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_comments']) + . ' SET table_name = \'' . PMA_sqlAddslashes($new_name) . '\', ' + . ' db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' + . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' + . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; + $rmv_rs = PMA_query_as_cu($remove_query); + unset($rmv_query); + } + $sql_query .= "\n\n" . $sql_drop_table . ';'; $db = $target_db; $table = $new_name; + } else { + // garvin: Create new entries as duplicates from old comments + if ($cfgRelation['commwork']) { + // Get all comments and MIME-Types for current table + $comments_copy_query = 'SELECT + column_name, ' . PMA_backquote('comment') . ' + FROM ' . PMA_backquote($cfgRelation['column_comments']) . ' + WHERE + db_name = \'' . PMA_sqlAddslashes($db) . '\' AND + table_name = \'' . PMA_sqlAddslashes($table) . '\''; + $comments_copy_rs = PMA_query_as_cu($comments_copy_query); + + // Write every comment as new copied entry. [MIME] + while ($comments_copy_row = @PMA_mysql_fetch_array($comments_copy_rs)) { + $new_comment_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_comments']) + . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ') ' + . ' VALUES(' + . '\'' . PMA_sqlAddslashes($target_db) . '\',' + . '\'' . PMA_sqlAddslashes($new_name) . '\',' + . '\'' . PMA_handleSlashes($comments_copy_row['comment']) . '\')'; + $new_comment_rs = PMA_query_as_cu($new_comment_query); + } // end while + } } $message = (isset($submit_move) ? $strMoveTableOK : $strCopyTableOK); diff --git a/tbl_properties.inc.php3 b/tbl_properties.inc.php3 index 5a89fe0d4d..2d7b59bc39 100755 --- a/tbl_properties.inc.php3 +++ b/tbl_properties.inc.php3 @@ -39,6 +39,17 @@ $is_backup = ($action != 'tbl_create.php3' && $action != 'tbl_addfield.php3'); ** ' . $strComments . ''; +} + // lem9: We could remove this 'if' and let the key information be shown and // editable. However, for this to work, tbl_alter must be modified to use the // key fields, as tbl_addfield does. @@ -222,6 +233,14 @@ for ($i = 0 ; $i < $num_fields; $i++) { + + + + 0) { // The 'back' is supposed to be set to the current sub-page. This is necessary // when you have js deactivated, you click on Drop, then click cancel, and want // to get back to the same sub-page. -$arg7 = ereg_replace('tbl_properties[^.]*.php3$', 'db_details.php3', $url_query) . '&reload=1&sql_query=' . urlencode('DROP TABLE ' . PMA_backquote($table) ) . '&zero_rows=' . urlencode(sprintf($strTableHasBeenDropped, htmlspecialchars($table))); +$arg7 = ereg_replace('tbl_properties[^.]*.php3$', 'db_details.php3', $url_query) . '&reload=1&purge=1&sql_query=' . urlencode('DROP TABLE ' . PMA_backquote($table) ) . '&zero_rows=' . urlencode(sprintf($strTableHasBeenDropped, htmlspecialchars($table))); $att7 = 'class="drop" onclick="return confirmLink(this, \'DROP TABLE ' . PMA_jsFormat($table) . '\')"'; diff --git a/tbl_properties_structure.php3 b/tbl_properties_structure.php3 index f62f569531..b5a914c7e8 100755 --- a/tbl_properties_structure.php3 +++ b/tbl_properties_structure.php3 @@ -72,6 +72,20 @@ $fields_cnt = mysql_num_rows($fields_rs); ' . $field_name . ''; + } + if (isset($pk_array[$row['Field']])) { $field_name = '' . $field_name . ''; } diff --git a/tbl_relation.php3 b/tbl_relation.php3 index 9a56c219d9..f8bd53aab2 100644 --- a/tbl_relation.php3 +++ b/tbl_relation.php3 @@ -20,20 +20,6 @@ $cfgRelation = PMA_getRelationsParam(); /** - * Adds/removes slashes if required - * - * @param string the string to slash - * - * @return string the slashed string - * - * @access public - */ -function PMA_handleSlashes($val) { - return (get_magic_quotes_gpc() ? str_replace('\\"', '"', $val) : PMA_sqlAddslashes($val)); -} // end of the "PMA_handleSlashes()" function - - -/** * Updates */ @@ -105,37 +91,8 @@ if ($cfgRelation['displaywork'] if ($cfgRelation['commwork'] && isset($submit_comm) && $submit_comm == 'true') { while (list($key, $value) = each($comment)) { - $test_qry = 'SELECT ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['column_comments']) - . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' - . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' - . ' AND column_name = \'' . PMA_handleSlashes($key) . '\''; - $test_rs = PMA_query_as_cu($test_qry); - if ($test_rs && mysql_num_rows($test_rs) > 0) { - if (strlen($value) > 0) { - $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_comments']) - . ' SET ' . PMA_backquote('comment') . ' = \'' . PMA_handleSlashes($value) . '\'' - . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' - . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' - . ' AND column_name = \'' . PMA_handleSlashes($key) . '\''; - } else { - $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_comments']) - . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' - . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' - . ' AND column_name = \'' . PMA_handleSlashes($key) . '\''; - } - } else if (strlen($value) > 0) { - $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_comments']) - . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ') ' - . ' VALUES(' - . '\'' . PMA_sqlAddslashes($db) . '\',' - . '\'' . PMA_sqlAddslashes($table) . '\',' - . '\'' . PMA_handleSlashes($key) . '\',' - . '\'' . PMA_handleSlashes($value) . '\')'; - } - if (isset($upd_query)){ - $upd_rs = PMA_query_as_cu($upd_query); - unset($upd_query); - } + // garvin: I exported the snippet here to a function (relation.lib.php3) , so it can be used multiple times throughout other pages where you can set comments. + PMA_setComment($db, $table, $key, $value); } // end while (transferred data) } // end if (commwork) diff --git a/tbl_rename.php3 b/tbl_rename.php3 index 07325999b2..ec23c2c9d4 100755 --- a/tbl_rename.php3 +++ b/tbl_rename.php3 @@ -41,6 +41,18 @@ if (isset($new_name) && trim($new_name) != '') { $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url); $message = sprintf($strRenameTableOK, $old_name, $table); $reload = 1; + + // garvin: Move old entries from comments to new table + include('./libraries/relation.lib.php3'); + $cfgRelation = PMA_getRelationsParam(); + if ($cfgRelation['commwork']) { + $remove_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_comments']) + . ' SET table_name = \'' . PMA_sqlAddslashes($table) . '\'' + . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' + . ' AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\''; + $rmv_rs = PMA_query_as_cu($remove_query); + unset($rmv_query); + } } -- 2.11.4.GIT