]> git.joonet.de Git - adminer.git/commitdiff
Use separate connection for exploring indexes
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 3 Jun 2009 18:34:57 +0000 (18:34 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 3 Jun 2009 18:34:57 +0000 (18:34 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@649 7c3ca157-0c34-0410-bff1-cbf682f78f5c

_compile.php
include/functions.inc.php
include/mysql.inc.php
include/sqlite.inc.php
sql.inc.php

index bb4f7bef74575776861ac2f7a15146bb282d3d35..cc2bdf96e21a22aa612d9feaad9cab233def9941 100644 (file)
@@ -76,7 +76,7 @@ function php_shrink($input) {
        $special_variables = array_flip(array('$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER'));
        static $short_variables = array();
        $shortening = true;
-       $special_functions = array_flip(array('Min_MySQLi', 'Min_MySQLResult', '__construct'));
+       $special_functions = array_flip(array('Min_DB', 'Min_Result', '__construct'));
        $defined_functions = array();
        static $short_functions = array();
        $tokens = token_get_all($input);
index 43de2819a88c456154f99691f327b586ba5d3e41..ada6b22cf3a5d96812827da24c2911b1b7624356 100644 (file)
@@ -143,7 +143,7 @@ function odd($s = ' class="odd"') {
        return ($i++ % 2 ? $s : '');
 }
 
-function select($result) {
+function select($result, $dbh2 = null) {
        global $SELF;
        if (!$result->num_rows) {
                echo "<p class='message'>" . lang('No rows.') . "</p>\n";
@@ -163,7 +163,7 @@ function select($result) {
                                        if (strlen($field->orgtable)) {
                                                if (!isset($indexes[$field->orgtable])) {
                                                        $indexes[$field->orgtable] = array();
-                                                       foreach (indexes($field->orgtable) as $index) {
+                                                       foreach (indexes($field->orgtable, $dbh2) as $index) {
                                                                if ($index["type"] == "PRIMARY") {
                                                                        $indexes[$field->orgtable] = array_flip($index["columns"]);
                                                                        break;
@@ -193,7 +193,7 @@ function select($result) {
                                        if ($blobs[$key] && preg_match('~[\\x80-\\xFF]~', $val)) {
                                                $val = "<i>" . lang('%d byte(s)', strlen($val)) . "</i>";
                                        } else {
-                                               $val = (strlen(trim($val)) ? nl2br(htmlspecialchars($val)) : "&nbsp;");
+                                               $val = nl2br(htmlspecialchars($val));
                                                if ($types[$key] == 254) {
                                                        $val = "<code>$val</code>";
                                                }
index 5d1a0083b3fe6ebf894be2f997c51e11404f0bd5..6876725036e185c1e6820d8a412c84544b968bec 100644 (file)
@@ -1,10 +1,10 @@
 <?php
 if (extension_loaded("mysqli")) {
-       class Min_MySQLi extends MySQLi {
+       class Min_DB extends MySQLi {
                var $extension = "MySQLi";
                
-               function Min_MySQLi() {
-                       $this->init();
+               function Min_DB() {
+                       parent::init();
                }
                
                function connect($server, $username, $password) {
@@ -34,7 +34,7 @@ if (extension_loaded("mysqli")) {
                
                function query($query) {
                        $result = parent::query($query);
-                       return (is_object($result) ? new Min_MySQLiResult($result) : $result);
+                       return (is_object($result) ? new Min_Result($result) : $result);
                }
                
                function multi_query($query) {
@@ -43,7 +43,7 @@ if (extension_loaded("mysqli")) {
                
                function store_result() {
                        $result = parent::store_result();
-                       return (is_object($result) ? new Min_MySQLiResult($result) : $result);
+                       return (is_object($result) ? new Min_Result($result) : $result);
                }
                
                function next_result() {
@@ -55,7 +55,7 @@ if (extension_loaded("mysqli")) {
                }
        }
        
-       class Min_MySQLiResult {
+       class Min_Result {
                var $_result, $num_rows;
                
                function __construct($result) {
@@ -81,10 +81,8 @@ if (extension_loaded("mysqli")) {
                // minification compatibility end
        }
        
-       $dbh = new Min_MySQLi;
-
 } elseif (extension_loaded("mysql")) {
-       class Min_MySQL {
+       class Min_DB {
                var $extension = "MySQL", $_link, $_result, $server_info, $affected_rows, $error;
                
                function connect($server, $username, $password) {
@@ -92,10 +90,13 @@ if (extension_loaded("mysqli")) {
                                (strlen($server) ? $server : ini_get("mysql.default_host")),
                                (strlen("$server$username") ? $username : ini_get("mysql.default_user")),
                                (strlen("$server$username$password") ? $password : ini_get("mysql.default_password")),
+                               true,
                                131072 // CLIENT_MULTI_RESULTS for CALL
                        );
                        if ($this->_link) {
                                $this->server_info = mysql_get_server_info($this->_link);
+                       } else {
+                               $this->error = mysql_error();
                        }
                        return (bool) $this->_link;
                }
@@ -113,7 +114,7 @@ if (extension_loaded("mysqli")) {
                                $this->affected_rows = mysql_affected_rows($this->_link);
                                return true;
                        }
-                       return new Min_MySQLResult($result);
+                       return new Min_Result($result);
                }
                
                function multi_query($query) {
@@ -140,10 +141,10 @@ if (extension_loaded("mysqli")) {
                }
        }
        
-       class Min_MySQLResult {
+       class Min_Result {
                var $_result, $_offset = 0, $num_rows;
                
-               function Min_MySQLResult($result) {
+               function Min_Result($result) {
                        $this->_result = $result;
                        $this->num_rows = mysql_num_rows($result);
                }
@@ -169,10 +170,8 @@ if (extension_loaded("mysqli")) {
                }
        }
        
-       $dbh = new Min_MySQL;
-
 } elseif (extension_loaded("pdo_mysql")) {
-       class Min_PDO_MySQL extends Min_PDO {
+       class Min_DB extends Min_PDO {
                var $extension = "PDO_MySQL";
                
                function connect($server, $username, $password) {
@@ -182,8 +181,6 @@ if (extension_loaded("mysqli")) {
                }
        }
        
-       $dbh = new Min_PDO_MySQL;
-
 } else {
        page_header(lang('No MySQL extension'), lang('None of supported PHP extensions (%s) are available.', 'MySQLi, MySQL, PDO_MySQL'), null);
        page_footer("auth");
@@ -202,6 +199,11 @@ $types = array(
 );
 $unsigned = array("", "unsigned", "zerofill", "unsigned zerofill");
 
+function connect() {
+       $dbh = new Min_DB;
+       return ($dbh->connect($_GET["server"], $_SESSION["usernames"][$_GET["server"]], $_SESSION["passwords"][$_GET["server"]]) ? $dbh : $dbh->error);
+}
+
 function get_databases() {
        $return = &$_SESSION["databases"][$_GET["server"]];
        if (!isset($return)) {
@@ -245,10 +247,13 @@ function fields($table) {
        return $return;
 }
 
-function indexes($table) {
+function indexes($table, $dbh2 = null) {
        global $dbh;
+       if (!is_object($dbh2)) {
+               $dbh2 = $dbh;
+       }
        $return = array();
-       $result = $dbh->query("SHOW INDEX FROM " . idf_escape($table));
+       $result = $dbh2->query("SHOW INDEX FROM " . idf_escape($table));
        if ($result) {
                while ($row = $result->fetch_assoc()) {
                        $return[$row["Key_name"]]["type"] = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE")));
index 2a31ad9505b946875d8f6117e34dcdf506092ef4..156d3198d52df48502251e8f3edbbc53c1d9ecc1 100644 (file)
@@ -2,7 +2,7 @@
 if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
        if ($_GET["sqlite_version"] == 2) {
                
-               class SQLite extends SQLiteDatabase {
+               class Min_SQLite extends SQLiteDatabase {
                        var $extension = "SQLite";
                        
                        function open($filename) {
@@ -18,7 +18,7 @@ if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
                                        $this->affected_rows = parent::changes();
                                        return true;
                                }
-                               return new Min_SQLiteResult($result);
+                               return new Min_Result($result);
                        }
                        
                        function escape_string($string) {
@@ -34,7 +34,7 @@ if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
                        }
                }
                
-               class Min_SQLiteResult {
+               class Min_Result {
                        var $_result, $num_rows;
                        
                        function __construct($result) {
@@ -65,7 +65,7 @@ if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
                
        } else {
                
-               class SQLite extends SQLite3 {
+               class Min_SQLite extends SQLite3 {
                        var $extension = "SQLite3";
                        
                        function open($filename) {
@@ -81,7 +81,7 @@ if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
                                        $this->affected_rows = parent::changes();
                                        return true;
                                }
-                               return new Min_SQLiteResult($result);
+                               return new Min_Result($result);
                        }
                        
                        function escape_string($string) {
@@ -97,7 +97,7 @@ if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
                        }
                }
                
-               class Min_SQLiteResult {
+               class Min_Result {
                        var $_result, $num_rows;
                        
                        function __construct($result) {
@@ -130,14 +130,11 @@ if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
                
        }
        
-       class Min_SQLite extends SQLite {
+       class Min_DB extends Min_SQLite {
                
                function __construct() {
                }
                
-               function connect() {
-               }
-               
                function select_db($filename) {
                        set_exception_handler('connect_error'); // try/catch is not compatible with PHP 4
                        $this->open($filename);
@@ -160,11 +157,8 @@ if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
        }
        
 } elseif (extension_loaded("pdo_sqlite")) {
-       class Min_PDO_MySQL extends Min_PDO {
-               var $extension = "PDO_MySQL";
-               
-               function connect() {
-               }
+       class Min_DB extends Min_PDO {
+               var $extension = "PDO_SQLite";
                
                function select_db($filename) {
                        set_exception_handler('connect_error'); // try/catch is not compatible with PHP 4
@@ -176,12 +170,15 @@ if (extension_loaded($_GET["sqlite_version"] == 2 ? "sqlite" : "sqlite3")) {
                }
        }
        
-       $dbh = new Min_PDO_SQLite;
 }
 
 $types = array("text" => 0, "numeric" => 0, "integer" => 0, "real" => 0, "blob" => 0);
 $unsigned = array();
 
+function connect() {
+       return new Min_DB;
+}
+
 function get_databases() {
        return array();
 }
@@ -212,7 +209,7 @@ function fields($table) {
        return $return;
 }
 
-function indexes($table) {
+function indexes($table, $dbh2 = null) {
        global $dbh;
        $return = array();
        $result = $dbh->query("PRAGMA index_list(" . idf_escape($table) . ")");
index 920eeefd81198ae7c417c1b89adac0ec7d5bcf4b..452108bf4661bb95fbf14e4fc8f50e624fab317d 100644 (file)
@@ -13,6 +13,10 @@ if (!$error && $_POST) {
                $offset = 0;
                $empty = true;
                $space = "(\\s+|/\\*.*\\*/|(#|-- )[^\n]*\n|--\n)";
+               $dbh2 = (strlen($_GET["db"]) ? connect() : null); // connection for exploring indexes (to not replace FOUND_ROWS()) //! PDO - silent error
+               if (is_object($dbh2)) {
+                       $dbh2->select_db($_GET["db"]);
+               }
                while (rtrim($query)) {
                        if (!$offset && preg_match('~^\\s*DELIMITER\\s+(.+)~i', $query, $match)) {
                                $delimiter = $match[1];
@@ -39,7 +43,7 @@ if (!$error && $_POST) {
                                                do {
                                                        $result = $dbh->store_result();
                                                        if (is_object($result)) {
-                                                               select($result);
+                                                               select($result, $dbh2);
                                                        } else {
                                                                if (preg_match("~^$space*(CREATE|DROP)$space+(DATABASE|SCHEMA)\\b~isU", $query)) {
                                                                        unset($_SESSION["databases"][$_GET["server"]]);