Permalink
Browse files

Move select function

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1106 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent 0355c92 commit 471ae2b2d66da773850069a7d430e019da403049 jakubvrana committed Sep 13, 2009
Showing with 77 additions and 77 deletions.
  1. +77 −0 adminer/include/editing.inc.php
  2. +0 −77 adminer/include/functions.inc.php
@@ -1,4 +1,81 @@
<?php
+/** Print select result
+* @param Min_Result
+* @param Min_DB connection to examine indexes
+* @return null
+*/
+function select($result, $dbh2 = null) {
+ if (!$result->num_rows) {
+ echo "<p class='message'>" . lang('No rows.') . "\n";
+ } else {
+ echo "<table cellspacing='0' class='nowrap'>\n";
+ $links = array(); // colno => orgtable - create links from these columns
+ $indexes = array(); // orgtable => array(column => colno) - primary keys
+ $columns = array(); // orgtable => array(column => ) - not selected columns in primary key
+ $blobs = array(); // colno => bool - display bytes for blobs
+ $types = array(); // colno => type - display char in <code>
+ odd(''); // reset odd for each result
+ for ($i=0; $row = $result->fetch_row(); $i++) {
+ if (!$i) {
+ echo "<thead><tr>";
+ for ($j=0; $j < count($row); $j++) {
+ $field = $result->fetch_field();
+ if (strlen($field->orgtable)) {
+ if (!isset($indexes[$field->orgtable])) {
+ // find primary key in each table
+ $indexes[$field->orgtable] = array();
+ foreach (indexes($field->orgtable, $dbh2) as $index) {
+ if ($index["type"] == "PRIMARY") {
+ $indexes[$field->orgtable] = array_flip($index["columns"]);
+ break;
+ }
+ }
+ $columns[$field->orgtable] = $indexes[$field->orgtable];
+ }
+ if (isset($columns[$field->orgtable][$field->orgname])) {
+ unset($columns[$field->orgtable][$field->orgname]);
+ $indexes[$field->orgtable][$field->orgname] = $j;
+ $links[$j] = $field->orgtable;
+ }
+ }
+ if ($field->charsetnr == 63) {
+ $blobs[$j] = true;
+ }
+ $types[$j] = $field->type;
+ echo "<th>" . h($field->name);
+ }
+ echo "</thead>\n";
+ }
+ echo "<tr" . odd() . ">";
+ foreach ($row as $key => $val) {
+ if (!isset($val)) {
+ $val = "<i>NULL</i>";
+ } else {
+ if ($blobs[$key] && !is_utf8($val)) {
+ $val = "<i>" . lang('%d byte(s)', strlen($val)) . "</i>"; //! link to download
+ } elseif (!strlen(trim($val, " \t"))) {
+ $val = "&nbsp;"; // some content to print a border
+ } else {
+ $val = nl2br(h($val));
+ if ($types[$key] == 254) {
+ $val = "<code>$val</code>";
+ }
+ }
+ if (isset($links[$key]) && !$columns[$links[$key]]) {
+ $link = "edit=" . urlencode($links[$key]);
+ foreach ($indexes[$links[$key]] as $col => $j) {
+ $link .= "&where" . urlencode("[" . bracket_escape($col) . "]") . "=" . urlencode($row[$j]);
+ }
+ $val = "<a href='" . h(ME . $link) . "'>$val</a>";
+ }
+ }
+ echo "<td>$val";
+ }
+ }
+ echo "</table>\n";
+ }
+}
+
function referencable_primary($self) {
$return = array(); // table_name => field
foreach (table_status_referencable() as $table_name => $table) {
@@ -283,83 +283,6 @@ function odd($return = ' class="odd"') {
return ($i++ % 2 ? $return : '');
}
-/** Print select result
-* @param Min_Result
-* @param Min_DB connection to examine indexes
-* @return null
-*/
-function select($result, $dbh2 = null) {
- if (!$result->num_rows) {
- echo "<p class='message'>" . lang('No rows.') . "\n";
- } else {
- echo "<table cellspacing='0' class='nowrap'>\n";
- $links = array(); // colno => orgtable - create links from these columns
- $indexes = array(); // orgtable => array(column => colno) - primary keys
- $columns = array(); // orgtable => array(column => ) - not selected columns in primary key
- $blobs = array(); // colno => bool - display bytes for blobs
- $types = array(); // colno => type - display char in <code>
- odd(''); // reset odd for each result
- for ($i=0; $row = $result->fetch_row(); $i++) {
- if (!$i) {
- echo "<thead><tr>";
- for ($j=0; $j < count($row); $j++) {
- $field = $result->fetch_field();
- if (strlen($field->orgtable)) {
- if (!isset($indexes[$field->orgtable])) {
- // find primary key in each table
- $indexes[$field->orgtable] = array();
- foreach (indexes($field->orgtable, $dbh2) as $index) {
- if ($index["type"] == "PRIMARY") {
- $indexes[$field->orgtable] = array_flip($index["columns"]);
- break;
- }
- }
- $columns[$field->orgtable] = $indexes[$field->orgtable];
- }
- if (isset($columns[$field->orgtable][$field->orgname])) {
- unset($columns[$field->orgtable][$field->orgname]);
- $indexes[$field->orgtable][$field->orgname] = $j;
- $links[$j] = $field->orgtable;
- }
- }
- if ($field->charsetnr == 63) {
- $blobs[$j] = true;
- }
- $types[$j] = $field->type;
- echo "<th>" . h($field->name);
- }
- echo "</thead>\n";
- }
- echo "<tr" . odd() . ">";
- foreach ($row as $key => $val) {
- if (!isset($val)) {
- $val = "<i>NULL</i>";
- } else {
- if ($blobs[$key] && !is_utf8($val)) {
- $val = "<i>" . lang('%d byte(s)', strlen($val)) . "</i>"; //! link to download
- } elseif (!strlen(trim($val, " \t"))) {
- $val = "&nbsp;"; // some content to print a border
- } else {
- $val = nl2br(h($val));
- if ($types[$key] == 254) {
- $val = "<code>$val</code>";
- }
- }
- if (isset($links[$key]) && !$columns[$links[$key]]) {
- $link = "edit=" . urlencode($links[$key]);
- foreach ($indexes[$links[$key]] as $col => $j) {
- $link .= "&where" . urlencode("[" . bracket_escape($col) . "]") . "=" . urlencode($row[$j]);
- }
- $val = "<a href='" . h(ME . $link) . "'>$val</a>";
- }
- }
- echo "<td>$val";
- }
- }
- echo "</table>\n";
- }
-}
-
/** Check whether the string is in UTF-8
* @param string
* @return bool

0 comments on commit 471ae2b

Please sign in to comment.