From 181e1aca824015d4bb76aba0758c720dadb20a0e Mon Sep 17 00:00:00 2001 From: Marcel Tschopp Date: Sat, 10 Apr 2004 19:04:01 +0000 Subject: [PATCH] Use PMA_DBI_fetch_row instead of PMA_DBI_fetch_array in display_tbl.lib.php --- ChangeLog | 2 + libraries/dbi/mysqli.dbi.lib.php | 1 + libraries/display_tbl.lib.php | 96 ++++++++++++++++---------------- libraries/relation.lib.php | 2 +- sql.php | 2 + 5 files changed, 53 insertions(+), 50 deletions(-) diff --git a/ChangeLog b/ChangeLog index 565785c51..80a36095d 100755 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,8 @@ $Source$ libraries/relation.lib.php, libraries/dbi/mysqli.dbi.lib.php: Changed some queries to use MYSQLI_STORE_RESULT. phpMyAdmin now works with MYSQLI_USE_RESULT as default. + * libraries/display_tbl.lib.php: Use PMA_DBI_fetch_row instead of + PMA_DBI_fetch_array. 2004-04-07 Marc Delisle * tbl_select.php, lang/*: feature 788608: new features for Search: diff --git a/libraries/dbi/mysqli.dbi.lib.php b/libraries/dbi/mysqli.dbi.lib.php index 47ea3dfa1..66eab1cca 100644 --- a/libraries/dbi/mysqli.dbi.lib.php +++ b/libraries/dbi/mysqli.dbi.lib.php @@ -92,6 +92,7 @@ function PMA_DBI_select_db($dbname, $link = NULL) { } function PMA_DBI_try_query($query, $link = NULL, $options = 0) { + //print_r(debug_backtrace()); if ($options == ($options | PMA_DBI_QUERY_STORE)) { $method = MYSQLI_STORE_RESULT; } elseif ($options == ($options | PMA_DBI_QUERY_UNBUFFERED)) { diff --git a/libraries/display_tbl.lib.php b/libraries/display_tbl.lib.php index c447dea23..a91a08418 100644 --- a/libraries/display_tbl.lib.php +++ b/libraries/display_tbl.lib.php @@ -980,8 +980,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) // ne0x: Use function PMA_DBI_fetch_array() due to mysqli // compatibility. Now this function is wrapped. - while ($row = PMA_DBI_fetch_array($dt_result)) { - + while ($row = PMA_DBI_fetch_row($dt_result)) { // lem9: "vertical display" mode stuff if (($row_no != 0) && ($repeat_cells != 0) && !($row_no % $repeat_cells) && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) { echo '' . "\n"; @@ -1072,18 +1071,21 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) // loic1: To fix bug #474943 under php4, the row // pointer will depend on whether the "is_null" // php4 function is available or not - $pointer = (function_exists('is_null') ? $i : $meta->name); - if (!isset($row[$meta->name]) - || (function_exists('is_null') && is_null($row[$pointer]))) { + // ne0x: Not used anymore because PMA needs PHP > 4.1.0 where + // the "is_null" function is available. + // + // $pointer = (function_exists('is_null') ? $i : $meta->name); + + if (!isset($row[$i]) || is_null($row[$i])) { $condition .= 'IS NULL AND'; } else { if ($meta->type == 'blob' // hexify only if this is a true not empty BLOB && stristr($field_flags, 'BINARY') - && !empty($row[$pointer])) { - $condition .= 'LIKE 0x' . bin2hex($row[$pointer]). ' AND'; + && !empty($row[$i])) { + $condition .= 'LIKE 0x' . bin2hex($row[$i]). ' AND'; } else { - $condition .= '= \'' . PMA_sqlAddslashes($row[$pointer], FALSE, TRUE) . '\' AND'; + $condition .= '= \'' . PMA_sqlAddslashes($row[$i], FALSE, TRUE) . '\' AND'; } } if ($meta->primary_key > 0) { @@ -1151,8 +1153,8 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) if ($table == $GLOBALS['cfg']['Bookmark']['table'] && $db == $GLOBALS['cfg']['Bookmark']['db']) { $bookmark_go = '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)]))) { @@ -1288,10 +1289,9 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) // associative and numeric indices? //if (!isset($row[$meta->name]) - if (!isset($row[$pointer]) - || (function_exists('is_null') && is_null($row[$pointer]))) { + if (!isset($row[$i]) || is_null($row[$i])) { $vertical_display['data'][$row_no][$i] = ' NULL' . "\n"; - } else if ($row[$pointer] != '') { + } else if ($row[$i] != '') { $vertical_display['data'][$row_no][$i] = ' '; if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) { @@ -1312,7 +1312,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2]) . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) - . ' = ' . $row[$pointer]; + . ' = ' . $row[$i]; $dispresult = PMA_DBI_try_query($dispsql); if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) { list($dispval) = PMA_DBI_fetch_row($dispresult, 0); @@ -1320,24 +1320,25 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) else { $dispval = $GLOBALS['strLinkNotFound']; } + @PMA_DBI_free_result($dispresult); } else { $dispval = ''; } // end if... else... if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') { - $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options, $meta) : $transform_function($row[$pointer], array(), $meta)) . ' [->' . $dispval . ']'; + $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta)) . ' [->' . $dispval . ']'; } else { $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : ''; $vertical_display['data'][$row_no][$i] .= '' - . ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options, $meta) : $transform_function($row[$pointer], array(), $meta)) . ''; + . '&sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$i]) . '"' . $title . '>' + . ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta)) . ''; } } else { - $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options, $meta) : $transform_function($row[$pointer], array(), $meta)); + $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta)); } $vertical_display['data'][$row_no][$i] .= '' . "\n"; } else { @@ -1354,8 +1355,8 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) $field_flags = PMA_DBI_field_flags($dt_result, $i); if (stristr($field_flags, 'BINARY')) { $blobtext = '[BLOB'; - if (isset($row[$pointer])) { - $blob_size = PMA_formatByteDown(strlen($row[$pointer]), 3, 1); + if (isset($row[$i])) { + $blob_size = PMA_formatByteDown(strlen($row[$i]), 3, 1); $blobtext .= ' - '. $blob_size [0] . ' ' . $blob_size[1]; unset($blob_size); } @@ -1365,52 +1366,48 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) $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]))) { + if (!isset($row[$i]) || is_null($row[$i])) { $vertical_display['data'][$row_no][$i] = ' NULL' . "\n"; - } else if ($row[$pointer] != '') { + } else if ($row[$i] != '') { // garvin: if a transform function for blob is set, none of these replacements will be made - if (PMA_strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) { - $row[$pointer] = PMA_substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...'; + if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) { + $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...'; } // loic1: displays all space characters, 4 space // characters for tabulations and / - $row[$pointer] = ($default_function != $transform_function ? $transform_function($row[$pointer], $transform_options, $meta) : $default_function($row[$pointer], array(), $meta)); + $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta)); - $vertical_display['data'][$row_no][$i] = ' ' . $row[$pointer] . '' . "\n"; + $vertical_display['data'][$row_no][$i] = ' ' . $row[$i] . '' . "\n"; } else { $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]))) { + if (!isset($row[$i]) || is_null($row[$i])) { $vertical_display['data'][$row_no][$i] = ' NULL' . "\n"; - } else if ($row[$pointer] != '') { + } else if ($row[$i] != '') { // loic1: support blanks in the key - $relation_id = $row[$pointer]; + $relation_id = $row[$i]; // nijel: Cut all fields to $cfg['LimitChars'] - if (PMA_strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) { - $row[$pointer] = PMA_substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...'; + if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) { + $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...'; } // loic1: displays special characters from binaries $field_flags = PMA_DBI_field_flags($dt_result, $i); if (stristr($field_flags, 'BINARY')) { - $row[$pointer] = str_replace("\x00", '\0', $row[$pointer]); - $row[$pointer] = str_replace("\x08", '\b', $row[$pointer]); - $row[$pointer] = str_replace("\x0a", '\n', $row[$pointer]); - $row[$pointer] = str_replace("\x0d", '\r', $row[$pointer]); - $row[$pointer] = str_replace("\x1a", '\Z', $row[$pointer]); - $row[$pointer] = ($default_function != $transform_function ? $transform_function($row[$pointer], $transform_options, $meta) : $default_function($row[$pointer], array(), $meta)); + $row[$i] = str_replace("\x00", '\0', $row[$i]); + $row[$i] = str_replace("\x08", '\b', $row[$i]); + $row[$i] = str_replace("\x0a", '\n', $row[$i]); + $row[$i] = str_replace("\x0d", '\r', $row[$i]); + $row[$i] = str_replace("\x1a", '\Z', $row[$i]); + $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta)); } // loic1: displays all space characters, 4 space // characters for tabulations and / else { - $row[$pointer] = ($default_function != $transform_function ? $transform_function($row[$pointer], $transform_options, $meta) : $default_function($row[$pointer], array(), $meta)); + $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta)); } // garvin: transform functions may enable nowrapping: @@ -1439,7 +1436,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2]) . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) - . ' = \'' . PMA_sqlAddslashes($row[$pointer]) . '\''; + . ' = \'' . PMA_sqlAddslashes($row[$i]) . '\''; $dispresult = PMA_DBI_try_query($dispsql); if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) { list($dispval) = PMA_DBI_fetch_row($dispresult); @@ -1447,6 +1444,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) else { $dispval = $GLOBALS['strLinkNotFound']; } + @PMA_DBI_free_result($dispresult); } else { $dispval = ''; @@ -1457,9 +1455,9 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) . PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0]) . '&pos=0&session_max_rows=' . $session_max_rows . '&dontlimitchars=' . $dontlimitchars . '&sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'') . '"' . $title . '>' - . $row[$pointer] . ''; + . $row[$i] . ''; } else { - $vertical_display['data'][$row_no][$i] .= $row[$pointer]; + $vertical_display['data'][$row_no][$i] .= $row[$i]; } $vertical_display['data'][$row_no][$i] .= '' . "\n"; } else { diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php index c7aa18928..0ee469179 100644 --- a/libraries/relation.lib.php +++ b/libraries/relation.lib.php @@ -24,7 +24,7 @@ * * @author Mike Beck */ - function PMA_query_as_cu($sql, $show_error = TRUE, $options) { + function PMA_query_as_cu($sql, $show_error = TRUE, $options = 0) { global $err_url_0, $db, $dbh, $cfgRelation; PMA_DBI_select_db($cfgRelation['db'], $dbh); diff --git a/sql.php b/sql.php index 9ffaf4f44..bd115559b 100644 --- a/sql.php +++ b/sql.php @@ -494,6 +494,7 @@ else { // } $cnt_all_result = PMA_DBI_query('SELECT FOUND_ROWS() as count;'); list($unlim_num_rows) = PMA_DBI_fetch_row($cnt_all_result); + @PMA_DBI_free_result($cnt_all_result); } } // end else "just browsing" @@ -568,6 +569,7 @@ else { $goto = 'db_details.php'; unset($table); } + @PMA_DBI_free_result($is_table); } // end if... else... } if (strpos(' ' . $goto, 'db_details') == 1) {