1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-13 18:14:07 +02:00

Optimize table_status()

This commit is contained in:
Jakub Vrana
2013-04-26 20:04:57 -07:00
parent 3cae3e2f7f
commit e24d1fcb02
12 changed files with 31 additions and 24 deletions

View File

@@ -366,11 +366,16 @@ if (!defined("DRIVER")) {
/** Get table status
* @param string
* @param bool return only "Name", "Engine" and "Comment" fields
* @return array array($name => array("Name" => , "Engine" => , "Comment" => , "Oid" => , "Rows" => , "Collation" => , "Auto_increment" => , "Data_length" => , "Index_length" => , "Data_free" => )) or only inner array with $name
*/
function table_status($name = "") {
function table_status($name = "", $fast = false) {
global $connection;
$return = array();
foreach (get_rows("SHOW TABLE STATUS" . ($name != "" ? " LIKE " . q(addcslashes($name, "%_\\")) : "")) as $row) {
foreach (get_rows($fast && $connection->server_info >= 5
? "SELECT table_name AS Name, Engine, TABLE_COMMENT AS Comment FROM information_schema.TABLES WHERE table_schema = " . q(DB) . ($name != "" ? " AND table_name = " . q($name) : "")
: "SHOW TABLE STATUS" . ($name != "" ? " LIKE " . q(addcslashes($name, "%_\\")) : "")
) as $row) {
if ($row["Engine"] == "InnoDB") {
// ignore internal comment, unnecessary since MySQL 5.1.21
$row["Comment"] = preg_replace('~(?:(.+); )?InnoDB free: .*~', '\\1', $row["Comment"]);
@@ -391,7 +396,7 @@ if (!defined("DRIVER")) {
* @return bool
*/
function is_view($table_status) {
return !isset($table_status["Rows"]);
return !isset($table_status["Engine"]);
}
/** Check if table supports foreign keys
@@ -960,6 +965,9 @@ if (!defined("DRIVER")) {
if (ereg("binary", $field["type"])) {
return "HEX(" . idf_escape($field["field"]) . ")";
}
if ($field["type"] == "bit") {
return "BIN(" . idf_escape($field["field"]) . " + 0)"; // + 0 is required outside MySQLnd
}
if (ereg("geometry|point|linestring|polygon", $field["type"])) {
return "AsWKT(" . idf_escape($field["field"]) . ")";
}
@@ -974,6 +982,9 @@ if (!defined("DRIVER")) {
if (ereg("binary", $field["type"])) {
$return = "UNHEX($return)";
}
if ($field["type"] == "bit") {
return "CONV($return, 2, 10) + 0";
}
if (ereg("geometry|point|linestring|polygon", $field["type"])) {
$return = "GeomFromText($return)";
}