]> git.joonet.de Git - adminer.git/commitdiff
Separate get_key_vals function
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 18 Nov 2009 12:32:39 +0000 (12:32 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 18 Nov 2009 12:32:39 +0000 (12:32 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1244 7c3ca157-0c34-0410-bff1-cbf682f78f5c

editor/include/adminer.inc.php
editor/include/editing.inc.php

index b7b95060454b5a967922e62ac168447cb0977aa1..1d311772425335300acfa926e8c701243d8210ed 100644 (file)
@@ -127,10 +127,7 @@ ORDER BY ORDINAL_POSITION");
                                                // uses constant number of queries to get the descriptions, join would be complex, multiple queries would be slow
                                                $descriptions = $this->values[$foreignKey["table"]];
                                                if (!$descriptions) {
-                                                       $result = $connection->query("SELECT $id, $name FROM " . idf_escape($foreignKey["table"]) . " WHERE $id IN (" . implode(", ", $ids) . ")");
-                                                       while ($row = $result->fetch_row()) {
-                                                               $descriptions[$row[0]] = $row[1];
-                                                       }
+                                                       $descriptions = get_key_vals("SELECT $id, $name FROM " . idf_escape($foreignKey["table"]) . " WHERE $id IN (" . implode(", ", $ids) . ")");
                                                }
                                                // use the descriptions
                                                foreach ($rows as $n => $row) {
@@ -482,13 +479,9 @@ ORDER BY ORDINAL_POSITION");
                                if (strlen($name)) {
                                        $return = &$this->values[$foreignKey["table"]];
                                        if (!isset($return)) {
-                                               $result = $connection->query("SELECT $id, $name FROM " . idf_escape($foreignKey["table"]) . " ORDER BY 2 LIMIT 1001");
-                                               $return = array();
-                                               if ($result->num_rows < 1001) { // optionlist with more than 1000 options would be too big
-                                                       $return[""] = "";
-                                                       while ($row = $result->fetch_row()) {
-                                                               $return[$row[0]] = $row[1];
-                                                       }
+                                               $return = array("" => "") + get_key_vals("SELECT $id, $name FROM " . idf_escape($foreignKey["table"]) . " ORDER BY 2 LIMIT 1001");
+                                               if (count($return) > 1001) {
+                                                       $return = array();
                                                }
                                        }
                                        return $return;
index 22f08826f394916f73cccc90ce5d0165cfd4233c..31cf291b96735bacd8f171391f7408db4ecdca20 100644 (file)
@@ -3,3 +3,13 @@ function email_header($header) {
        // iconv_mime_encode requires PHP 5, imap_8bit requires IMAP extension
        return "=?UTF-8?B?" . base64_encode($header) . "?="; //! split long lines
 }
+
+function get_key_vals($query) {
+       global $connection;
+       $return = array();
+       $result = $connection->query($query);
+       while ($row = $result->fetch_row()) {
+               $return[$row[0]] = $row[1];
+       }
+       return $return;
+}