From 64dc144785a53ff87f65416055d234aaa1794454 Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Thu, 13 Mar 2003 17:47:42 +0000 Subject: [PATCH] RFE #638800 - Highlight SQL fields as discussed in the tracker. --- ChangeLog | 4 ++ config.inc.php3 | 1 + libraries/display_tbl.lib.php3 | 92 +++++++++++++++++++++++----------- 3 files changed, 69 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index 44fc9340e..658187faa 100755 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,10 @@ $Id$ $Source$ 2003-03-13 Garvin Hicking + * config.inc.php3: Put a note for flipped headers: CSS only works for IE. ('writing-mode') + * libraries/display_tbl.lib.php3: Display fields used for WHERE query highlighted in + results page (1px border in the color of BrowserMarkerColor around the cells). + RFE #638800 * libraries/build_dump.lib.php3, db_details_structure.php3, db_printview.php3, pdf_schema.php3, tbl_dump.php3, tbl_printview.php3, tbl_properties_structure.php3, lang/*: RFE #7000385: Export AUTO_INCREMENT field. diff --git a/config.inc.php3 b/config.inc.php3 index 1ad26700e..d7ad68d2f 100755 --- a/config.inc.php3 +++ b/config.inc.php3 @@ -393,6 +393,7 @@ $cfg['DefaultPropDisplay'] = 'horizontal'; // default display direction for alt // (horizontal|vertical) $cfg['HeaderFlipType'] = 'css'; // table-header rotation via faking or css? (css|fake) + // NOTE: CSS only works in IE browsers! $cfg['ShowBrowseComments'] = TRUE; // shows stored relation-comments in 'browse' mode. $cfg['ShowPropertyComments']= TRUE; // shows stored relation-comments in 'table property' mode. $cfg['RepeatCells'] = 100; // repeat header names every X cells? (0 = deactivate) diff --git a/libraries/display_tbl.lib.php3 b/libraries/display_tbl.lib.php3 index 475f55a0c..6731eced1 100644 --- a/libraries/display_tbl.lib.php3 +++ b/libraries/display_tbl.lib.php3 @@ -385,6 +385,7 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { * @param array which elements to display * @param array the list of fields properties * @param integer the total number of fields returned by the sql query + * @param array the analyzed query * * @return boolean always true * @@ -409,12 +410,12 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { * * @see PMA_displayTable() */ - function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0) + function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = array()) { global $lang, $convcharset, $server, $db, $table; global $goto; global $sql_query, $num_rows, $pos, $session_max_rows; - global $vertical_display, $disp_direction, $repeat_cells; + global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns; global $dontlimitchars; if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { @@ -538,17 +539,44 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { } else { $is_join = FALSE; } - 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 = ''; + // garvin: See if we have to highlight any header fields of a WHERE query. + // Uses SQL-Parser results. + $highlight_columns = array(); + if (isset($analyzed_sql) && isset($analyzed_sql[0]) && + isset($analyzed_sql[0]['where_clause_identifiers'])) { + + $wi = 0; + @reset($analyzed_sql[0]['where_clause_identifiers']); + while(list($wci_nr, $wci) = each($analyzed_sql[0]['where_clause_identifiers'])) { + $wi++; + // garvin: We only count the even words, because uneven words are the + // contents of the identifies. I guess. ;) + if ($wi % 2 != 0) { + $highlightkey = $analyzed_sql[0]['where_clause_identifiers'][$wi-1]; + $highlight_columns[$highlightkey] = 'true'; + } + } } + for ($i = 0; $i < $fields_cnt; $i++) { + // garvin: See if this column should get highlight because it's used in the + // where-query. + if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) { + $column_style = 'style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '"'; + } else { + $column_style = ''; + } + + // 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 @@ -646,15 +674,15 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { echo "\n"; ?> - > + > - > + > name), "
\n") : htmlspecialchars($fields_meta[$i]->name)); ?>
' . "\n" + $vertical_display['desc'][] = ' ' . "\n" . $comments_table_wrap_pre . ' ' . "\n" . ' ' . htmlspecialchars($fields_meta[$i]->name) . '' . $order_img . "\n" @@ -667,14 +695,14 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { echo "\n"; ?> - > + > name), "
\n") : htmlspecialchars($fields_meta[$i]->name)) . "\n"; ?> ' . "\n" + $vertical_display['desc'][] = ' ' . "\n" . $comments_table_wrap_pre . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n" . $comments_table_wrap_post @@ -773,7 +801,7 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { global $lang, $convcharset, $server, $db, $table; global $goto; global $sql_query, $pos, $session_max_rows, $fields_meta, $fields_cnt; - global $vertical_display, $disp_direction, $repeat_cells; + global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns; global $dontlimitchars; if (!is_array($map)) { @@ -1008,6 +1036,14 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { // depend on whether the "is_null" php4 function is // available or not $pointer = (function_exists('is_null') ? $i : $meta->name); + + // garvin: See if this column should get highlight because it's used in the + // where-query. + if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) { + $column_style = 'style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '"'; + } else { + $column_style = ''; + } // garvin: Wrap MIME-transformations. [MIME] $default_function = 'htmlspecialchars'; // default_function @@ -1059,9 +1095,9 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { //if (!isset($row[$meta->name]) if (!isset($row[$pointer]) || (function_exists('is_null') && is_null($row[$pointer]))) { - $vertical_display['data'][$row_no][$i] = ' NULL' . "\n"; + $vertical_display['data'][$row_no][$i] = ' NULL' . "\n"; } else if ($row[$pointer] != '') { - $vertical_display['data'][$row_no][$i] = ' '; + $vertical_display['data'][$row_no][$i] = ' '; reset($analyzed_sql[0]['select_expr']); while (list ($select_expr_position, $select_expr) = each ($analyzed_sql[0]['select_expr'])) { @@ -1104,7 +1140,7 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { } $vertical_display['data'][$row_no][$i] .= '' . "\n"; } else { - $vertical_display['data'][$row_no][$i] = '  ' . "\n"; + $vertical_display['data'][$row_no][$i] = '  ' . "\n"; } // b l o b @@ -1127,12 +1163,12 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { $blobtext .= ']'; $blobtext = ($default_function != $transform_function ? $transform_function($blobtext, $transform_options) : $default_function($blobtext)); - $vertical_display['data'][$row_no][$i] = ' ' . $blobtext . ''; + $vertical_display['data'][$row_no][$i] = ' ' . $blobtext . ''; } else { //if (!isset($row[$meta->name]) if (!isset($row[$pointer]) || (function_exists('is_null') && is_null($row[$pointer]))) { - $vertical_display['data'][$row_no][$i] = ' NULL' . "\n"; + $vertical_display['data'][$row_no][$i] = ' NULL' . "\n"; } else if ($row[$pointer] != '') { // garvin: if a transform function for blob is set, none of these replacements will be made if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) { @@ -1145,16 +1181,16 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { $row[$pointer] = str_replace("\011", '    ', str_replace(' ', '  ', $row[$pointer])); $row[$pointer] = ereg_replace("((\015\012)|(\015)|(\012))", '
', $row[$pointer]); - $vertical_display['data'][$row_no][$i] = ' ' . $row[$pointer] . '' . "\n"; + $vertical_display['data'][$row_no][$i] = ' ' . $row[$pointer] . '' . "\n"; } else { - $vertical_display['data'][$row_no][$i] = '  ' . "\n"; + $vertical_display['data'][$row_no][$i] = '  ' . "\n"; } } } else { //if (!isset($row[$meta->name]) if (!isset($row[$pointer]) || (function_exists('is_null') && is_null($row[$pointer]))) { - $vertical_display['data'][$row_no][$i] = ' NULL' . "\n"; + $vertical_display['data'][$row_no][$i] = ' NULL' . "\n"; } else if ($row[$pointer] != '') { // loic1: support blanks in the key $relation_id = $row[$pointer]; @@ -1185,7 +1221,7 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { // loic1: do not wrap if date field type $nowrap = (eregi('DATE|TIME', $meta->type) ? ' nowrap="nowrap"' : ''); - $vertical_display['data'][$row_no][$i] = ' '; + $vertical_display['data'][$row_no][$i] = ' '; reset($analyzed_sql[0]['select_expr']); while (list ($select_expr_position, $select_expr) = each ($analyzed_sql[0]['select_expr'])) { @@ -1228,7 +1264,7 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { } $vertical_display['data'][$row_no][$i] .= '' . "\n"; } else { - $vertical_display['data'][$row_no][$i] = '  ' . "\n"; + $vertical_display['data'][$row_no][$i] = '  ' . "\n"; } } @@ -1471,7 +1507,7 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { global $lang, $server, $cfg, $db, $table; global $goto; global $sql_query, $num_rows, $unlim_num_rows, $pos, $fields_meta, $fields_cnt; - global $vertical_display, $disp_direction, $repeat_cells; + global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns; global $dontlimitchars; global $cfgRelation; @@ -1578,7 +1614,7 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { echo 'border="' . $GLOBALS['cfg']['Border'] . '" cellpadding="5"'; } echo '>' . "\n"; - PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt); + PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql); PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql); // lem9: vertical output case if ($disp_direction == 'vertical') {