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.

This commit is contained in:
Garvin Hicking
2003-02-24 16:59:36 +00:00
parent 820ad9c0cd
commit 30b1873e61
15 changed files with 191 additions and 54 deletions

View File

@@ -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) . '\')"';
}

View File

@@ -157,7 +157,7 @@ else if (PMA_MYSQL_INT_VERSION >= 32303) {
<?php echo $strProperties; ?></a>
</td>
<td bgcolor="<?php echo $bgcolor; ?>">
<a href="sql.php3?<?php echo $tbl_url_query; ?>&amp;reload=1&amp;sql_query=<?php echo urlencode('DROP TABLE ' . PMA_backquote($table)); ?>&amp;zero_rows=<?php echo urlencode(sprintf($strTableHasBeenDropped, htmlspecialchars($table))); ?>"
<a href="sql.php3?<?php echo $tbl_url_query; ?>&amp;reload=1&amp;purge=1&amp;sql_query=<?php echo urlencode('DROP TABLE ' . PMA_backquote($table)); ?>&amp;zero_rows=<?php echo urlencode(sprintf($strTableHasBeenDropped, htmlspecialchars($table))); ?>"
onclick="return confirmLink(this, 'DROP TABLE <?php echo PMA_jsFormat($table); ?>')">
<?php echo $strDrop; ?></a>
</td>
@@ -416,7 +416,7 @@ else {
<a href="tbl_properties.php3?<?php echo $tbl_url_query; ?>"><?php echo $strProperties; ?></a>
</td>
<td bgcolor="<?php echo $bgcolor; ?>">
<a href="sql.php3?<?php echo $tbl_url_query; ?>&amp;reload=1&amp;sql_query=<?php echo urlencode('DROP TABLE ' . PMA_backquote($table)); ?>&amp;zero_rows=<?php echo urlencode(sprintf($strTableHasBeenDropped, $table_name)); ?>"><?php echo $strDrop; ?></a>
<a href="sql.php3?<?php echo $tbl_url_query; ?>&amp;reload=1&amp;purge=1&amp;sql_query=<?php echo urlencode('DROP TABLE ' . PMA_backquote($table)); ?>&amp;zero_rows=<?php echo urlencode(sprintf($strTableHasBeenDropped, $table_name)); ?>"><?php echo $strDrop; ?></a>
</td>
<td bgcolor="<?php echo $bgcolor; ?>">
<a href="sql.php3?<?php echo $tbl_url_query; ?>&amp;sql_query=<?php echo urlencode('DELETE FROM ' . PMA_backquote($table)); ?>&amp;zero_rows=<?php echo urlencode(sprintf($strTableHasBeenEmptied, $table_name)); ?>"><?php echo $strEmpty; ?></a>

View File

@@ -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 = '<table border="0" cellpadding="0" cellspacing="0"><tr><th>';
$comments_table_wrap_post = '</th></tr><tr><th style="font-size: 8pt; font-weight: normal">' . htmlspecialchars($comments_map[$fields_meta[$i]->name]) . '</td></tr></table>';
} 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";
?>
<th <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?>>
<?php echo $comments_table_wrap_pre; ?>
<a href="sql.php3?<?php echo $url_query; ?>" <?php echo (($disp_direction == 'horizontalflipped' AND $GLOBALS['cfg']['HeaderFlipType'] == 'css') ? 'style = "direction: ltr; writing-mode: tb-rl;"' : ''); ?>>
<?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name)); ?></a><?php echo $order_img . "\n"; ?>
<?php echo $comments_table_wrap_post; ?>
</th>
<?php
}
$vertical_display['desc'][] = ' <th>' . "\n"
. $comments_table_wrap_pre
. ' <a href="sql.php3?' . $url_query . '">' . "\n"
. ' ' . htmlspecialchars($fields_meta[$i]->name) . '</a>' . $order_img . "\n"
. $comments_table_wrap_post
. ' </th>' . "\n";
} // end if (2.1)
@@ -639,12 +662,16 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
echo "\n";
?>
<th <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?> <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css' ? 'style = "direction: ltr; writing-mode: tb-rl;"' : ''); ?>>
<?php echo $comments_table_wrap_pre; ?>
<?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake'? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name)) . "\n"; ?>
<?php echo $comments_table_wrap_post; ?>
</th>
<?php
}
$vertical_display['desc'][] = ' <th>' . "\n"
. $comments_table_wrap_pre
. ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
. $comments_table_wrap_post
. ' </th>';
} // end else (2.2)
} // end for

View File

@@ -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) . '\''

View File

@@ -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';

View File

@@ -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"

View File

@@ -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);

View File

@@ -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();
}

View File

@@ -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

View File

@@ -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);

View File

@@ -39,6 +39,17 @@ $is_backup = ($action != 'tbl_create.php3' && $action != 'tbl_addfield.php3');
<th><?php echo $strDefault; ?>**</th>
<th><?php echo $strExtra; ?></th>
<?php
require('./libraries/relation.lib.php3');
require('./libraries/transformations.lib.php3');
$cfgRelation = PMA_getRelationsParam();
$comments_map = array();
if ($cfgRelation['commwork']) {
$comments_map = PMA_getComments($db, $table);
echo '<th>' . $strComments . '</th>';
}
// 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++) {
</select>
</td>
<?php
// garvin: comments
if ($cfgRelation['commwork']) {
?>
<td bgcolor="<?php echo $bgcolor; ?>">
<input id="field_<?php echo $i; ?>_7" type="text" name="field_comments[]" size="8" value="<?php echo (isset($row) && isset($row['Field']) && is_array($comments_map) && isset($comments_map[$row['Field']]) ? htmlspecialchars($comments_map[$row['Field']]) : ''); ?>" class="textfield" />
</td>
<?php
}
// lem9: See my other comment about removing this 'if'.
if (!$is_backup) {
if (isset($row) && isset($row['Key']) && $row['Key'] == 'PRI') {

View File

@@ -47,7 +47,7 @@ if ($table_info_num_rows > 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) . '&amp;reload=1&amp;sql_query=' . urlencode('DROP TABLE ' . PMA_backquote($table) ) . '&amp;zero_rows=' . urlencode(sprintf($strTableHasBeenDropped, htmlspecialchars($table)));
$arg7 = ereg_replace('tbl_properties[^.]*.php3$', 'db_details.php3', $url_query) . '&amp;reload=1&amp;purge=1&amp;sql_query=' . urlencode('DROP TABLE ' . PMA_backquote($table) ) . '&amp;zero_rows=' . urlencode(sprintf($strTableHasBeenDropped, htmlspecialchars($table)));
$att7 = 'class="drop" onclick="return confirmLink(this, \'DROP TABLE ' . PMA_jsFormat($table) . '\')"';

View File

@@ -72,6 +72,20 @@ $fields_cnt = mysql_num_rows($fields_rs);
</tr>
<?php
$comments_map = array();
if ($GLOBALS['cfg']['ShowPropertyComments']) {
require('./libraries/relation.lib.php3');
require('./libraries/transformations.lib.php3');
$cfgRelation = PMA_getRelationsParam();
if ($cfgRelation['commwork']) {
$comments_map = PMA_getComments($db, $table);
}
}
$i = 0;
$aryFields = array();
$checked = (!empty($checkall) ? ' checked="checked"' : '');
@@ -125,6 +139,14 @@ while ($row = PMA_mysql_fetch_array($fields_rs)) {
$field_encoded = urlencode($row['Field']);
$field_name = htmlspecialchars($row['Field']);
// garvin: underline commented fields and display a hover-title (CSS only)
$comment_style = '';
if (isset($comments_map[$row['Field']])) {
$field_name = '<span style="border-bottom: 1px dashed black;" title="' . htmlspecialchars($comments_map[$row['Field']]) . '">' . $field_name . '</span>';
}
if (isset($pk_array[$row['Field']])) {
$field_name = '<u>' . $field_name . '</u>';
}

View File

@@ -19,20 +19,6 @@ require('./libraries/relation.lib.php3');
$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)

View File

@@ -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);
}
}