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