From 984d0907c8c41003d4f636de2c24fe073f2f522f Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Wed, 21 Apr 2010 15:09:52 +0000 Subject: [PATCH] SQLite variables git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1467 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- adminer/drivers/mysql.inc.php | 8 +++++++ adminer/drivers/sqlite.inc.php | 37 +++++++++++++++++++++++---------- adminer/include/editing.inc.php | 2 +- adminer/variables.inc.php | 7 +++---- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index f6006744..459cb93a 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -666,6 +666,14 @@ if (!defined("DRIVER")) { return $connection->result("SHOW CREATE TABLE " . idf_escape($table), 1); } + function show_variables() { + return get_key_vals("SHOW VARIABLES"); + } + + function show_status() { + return get_key_vals("SHOW STATUS"); + } + /** Check whether a feature is supported * @param string * @return bool diff --git a/adminer/drivers/sqlite.inc.php b/adminer/drivers/sqlite.inc.php index 48ee0460..e3be1ff5 100644 --- a/adminer/drivers/sqlite.inc.php +++ b/adminer/drivers/sqlite.inc.php @@ -44,7 +44,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { function result($query, $field = 0) { $result = $this->query($query); - if (!$result) { + if (!is_object($result)) { return false; } $row = $result->_result->fetch(); @@ -89,37 +89,38 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { } else { - class Min_SQLite extends SQLite3 { - var $extension = "SQLite3", $server_info, $affected_rows, $error; + class Min_SQLite { + var $extension = "SQLite3", $server_info, $affected_rows, $error, $_connection; function __construct() { - $version = $this->version(); + $this->_connection = new SQLite3(":memory:"); // required to display variables + $version = $this->_connection->version(); $this->server_info = $version["versionString"]; } function open($filename) { - parent::__construct($filename); + $this->_connection->open($filename); } function query($query) { - $result = @parent::query($query); + $result = @$this->_connection->query($query); if (!$result) { - $this->error = $this->lastErrorMsg(); + $this->error = $this->_connection->lastErrorMsg(); return false; } elseif ($result->numColumns()) { return new Min_Result($result); } - $this->affected_rows = $this->changes(); + $this->affected_rows = $this->_connection->changes(); return true; } function quote($string) { - return "'" . $this->escapeString($string) . "'"; + return "'" . $this->_connection->escapeString($string) . "'"; } function result($query, $field = 0) { $result = $this->query($query); - if (!$result) { + if (!is_object($result)) { return false; } $row = $result->_result->fetchArray(); @@ -254,6 +255,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { $return = array(); $result = $connection->query("SELECT name AS Name, type AS Engine FROM sqlite_master WHERE type IN ('table', 'view')" . ($name != "" ? " AND name = " . $connection->quote($name) : "")); while ($row = $result->fetch_assoc()) { + $row["Auto_increment"] = ""; $return[$row["Name"]] = $row; } $result = $connection->query("SELECT * FROM sqlite_sequence"); @@ -456,8 +458,21 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { return $connection->result("SELECT sql FROM sqlite_master WHERE name = " . $connection->quote($table)); } + function show_variables() { + global $connection; + $return = array(); + foreach (array("auto_vacuum", "cache_size", "count_changes", "default_cache_size", "empty_result_callbacks", "encoding", "foreign_keys", "full_column_names", "fullfsync", "journal_mode", "journal_size_limit", "legacy_file_format", "locking_mode", "page_size", "max_page_count", "read_uncommitted", "recursive_triggers", "reverse_unordered_selects", "secure_delete", "short_column_names", "synchronous", "temp_store", "temp_store_directory", "schema_version", "compile_options", "integrity_check", "quick_check") as $key) { + $return[$key] = $connection->result("PRAGMA $key"); + } + return $return; + } + + function show_status() { + // not supported + } + function support($feature) { - return ereg('^(view|trigger)$', $feature); + return ereg('^(view|trigger|variables)$', $feature); } $driver = "sqlite"; diff --git a/adminer/include/editing.inc.php b/adminer/include/editing.inc.php index 3a2260b7..ee7c86e3 100644 --- a/adminer/include/editing.inc.php +++ b/adminer/include/editing.inc.php @@ -55,7 +55,7 @@ function select($result, $connection2 = null) { } else { if ($blobs[$key] && !is_utf8($val)) { $val = "" . lang('%d byte(s)', strlen($val)) . ""; //! link to download - } elseif ($val == "") { + } elseif (!strlen($val)) { // strlen - SQLite can return int $val = " "; // some content to print a border } else { $val = h($val); diff --git a/adminer/variables.inc.php b/adminer/variables.inc.php index eb33eaf1..cc817c05 100644 --- a/adminer/variables.inc.php +++ b/adminer/variables.inc.php @@ -2,11 +2,10 @@ $status = isset($_GET["status"]); page_header($status ? lang('Status') : lang('Variables')); -$result = $connection->query($status ? "SHOW STATUS" : "SHOW VARIABLES"); echo "\n"; -while ($row = $result->fetch_assoc()) { +foreach (($status ? show_status() : show_variables()) as $key => $val) { echo ""; - echo "
" . h($row["Variable_name"]) . ""; - echo "" . nbsp($row["Value"]); + echo "" . h($key) . ""; + echo "" . nbsp($val); } echo "
\n";