From 21ea4aeaf172f9118637e79bbe1433a2d774a07b Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Mon, 3 Sep 2007 11:12:38 +0000 Subject: [PATCH] Check errors git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@355 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- select.inc.php | 124 +++++++++++++++++++++++++------------------------ 1 file changed, 64 insertions(+), 60 deletions(-) diff --git a/select.inc.php b/select.inc.php index c38194af..a9df916e 100644 --- a/select.inc.php +++ b/select.inc.php @@ -122,76 +122,80 @@ function add_row(field) { echo "
 
\n"; $result = $mysql->query("SELECT SQL_CALC_FOUND_ROWS * FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "") . (strlen($limit) ? " LIMIT " . intval($limit) . " OFFSET " . ($limit * $_GET["page"]) : "")); - if (!$result->num_rows) { - echo "

" . lang('No rows.') . "

\n"; + if (!$result) { + echo "

" . lang('Error in query') . ": " . htmlspecialchars($mysql->error) . "

\n"; } else { - $found_rows = $mysql->result($mysql->query(" SELECT FOUND_ROWS()")); // space for mysql.trace_mode - $foreign_keys = array(); - foreach (foreign_keys($_GET["select"]) as $foreign_key) { - foreach ($foreign_key["source"] as $val) { - $foreign_keys[$val][] = $foreign_key; - } - } - - echo "\n"; - for ($j=0; $row = $result->fetch_assoc(); $j++) { - if (!$j) { - echo "\n"; + if (!$result->num_rows) { + echo "

" . lang('No rows.') . "

\n"; + } else { + $found_rows = $mysql->result($mysql->query(" SELECT FOUND_ROWS()")); // space for mysql.trace_mode + $foreign_keys = array(); + foreach (foreign_keys($_GET["select"]) as $foreign_key) { + foreach ($foreign_key["source"] as $val) { + $foreign_keys[$val][] = $foreign_key; + } } - $unique_idf = '&' . implode('&', unique_idf($row, $indexes)); - echo '"; - //! multiple delete by checkboxes - foreach ($row as $key => $val) { - if (!isset($val)) { - $val = "NULL"; - } elseif (preg_match('~blob|binary~', $fields[$key]["type"]) && preg_match('~[\\x80-\\xFF]~', $val)) { - $val = '' . lang('%d byte(s)', strlen($val)) . ''; - } else { - if (!strlen(trim($val))) { - $val = " "; - } elseif (intval($text_length) > 0 && preg_match('~blob|text~', $fields[$key]["type"]) && strlen($val) > intval($text_length)) { - $val = (preg_match('~blob~', $fields[$key]["type"]) ? nl2br(htmlspecialchars(substr($val, 0, intval($text_length)))) . "..." : shorten_utf8($val, intval($text_length))); + + echo "
 " . implode("", array_map('htmlspecialchars', array_keys($row))) . "
' . lang('edit') . "
\n"; + for ($j=0; $row = $result->fetch_assoc(); $j++) { + if (!$j) { + echo "\n"; + } + $unique_idf = '&' . implode('&', unique_idf($row, $indexes)); + echo '"; + //! multiple delete by checkboxes + foreach ($row as $key => $val) { + if (!isset($val)) { + $val = "NULL"; + } elseif (preg_match('~blob|binary~', $fields[$key]["type"]) && preg_match('~[\\x80-\\xFF]~', $val)) { + $val = '' . lang('%d byte(s)', strlen($val)) . ''; } else { - $val = nl2br(htmlspecialchars($val)); - if ($fields[$key]["type"] == "char") { - $val = "$val"; + if (!strlen(trim($val))) { + $val = " "; + } elseif (intval($text_length) > 0 && preg_match('~blob|text~', $fields[$key]["type"]) && strlen($val) > intval($text_length)) { + $val = (preg_match('~blob~', $fields[$key]["type"]) ? nl2br(htmlspecialchars(substr($val, 0, intval($text_length)))) . "..." : shorten_utf8($val, intval($text_length))); + } else { + $val = nl2br(htmlspecialchars($val)); + if ($fields[$key]["type"] == "char") { + $val = "$val"; + } } - } - foreach ((array) $foreign_keys[$key] as $foreign_key) { - if (count($foreign_keys[$key]) == 1 || count($foreign_key["source"]) == 1) { - $val = "\">$val"; - foreach ($foreign_key["source"] as $i => $source) { - $val = "&where%5B$i%5D%5Bcol%5D=" . urlencode($foreign_key["target"][$i]) . "&where%5B$i%5D%5Bop%5D=%3D&where%5B$i%5D%5Bval%5D=" . urlencode($row[$source]) . $val; + foreach ((array) $foreign_keys[$key] as $foreign_key) { + if (count($foreign_keys[$key]) == 1 || count($foreign_key["source"]) == 1) { + $val = "\">$val"; + foreach ($foreign_key["source"] as $i => $source) { + $val = "&where%5B$i%5D%5Bcol%5D=" . urlencode($foreign_key["target"][$i]) . "&where%5B$i%5D%5Bop%5D=%3D&where%5B$i%5D%5Bval%5D=" . urlencode($row[$source]) . $val; + } + $val = '' . ($page + 1) . ""); - } - echo "

" . lang('Page') . ":"; - print_page(0); - if ($_GET["page"] > 3) { - echo " ..."; + echo "

\n"; } - for ($i = max(1, $_GET["page"] - 2); $i < min($max_page, $_GET["page"] + 3); $i++) { - print_page($i); - } - if ($_GET["page"] + 3 < $max_page) { - echo " ..."; + echo "
 " . implode("", array_map('htmlspecialchars', array_keys($row))) . "
' . lang('edit') . "
\n"; + if (intval($limit) && $found_rows > $limit) { + $max_page = floor(($found_rows - 1) / $limit); + function print_page($page) { + echo " " . ($page == $_GET["page"] ? $page + 1 : '' . ($page + 1) . ""); + } + echo "

" . lang('Page') . ":"; + print_page(0); + if ($_GET["page"] > 3) { + echo " ..."; + } + for ($i = max(1, $_GET["page"] - 2); $i < min($max_page, $_GET["page"] + 3); $i++) { + print_page($i); + } + if ($_GET["page"] + 3 < $max_page) { + echo " ..."; + } + print_page($max_page); + echo "

\n"; } - print_page($max_page); - echo "

\n"; } + $result->free(); } - $result->free(); } -- 2.39.5