]> git.joonet.de Git - adminer.git/commitdiff
Improve drivers
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 21 Apr 2010 22:22:23 +0000 (22:22 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 21 Apr 2010 22:22:23 +0000 (22:22 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1470 7c3ca157-0c34-0410-bff1-cbf682f78f5c

adminer/drivers/pgsql.inc.php
adminer/drivers/sqlite.inc.php
adminer/include/editing.inc.php
adminer/include/functions.inc.php

index a42a21e66c821e684b45424c3f75fe349d492bf1..ff3399607646b79db57c74ebba0c2f217a85d926 100644 (file)
@@ -105,11 +105,13 @@ if (isset($_GET["pgsql"])) {
                        function fetch_field() {
                                $column = $this->_offset++;
                                $row = new stdClass;
-                               $row->orgtable = pg_field_table($this->_result, $column);
+                               if (function_exists('pg_field_table')) {
+                                       $row->orgtable = pg_field_table($this->_result, $column);
+                               }
                                $row->name = pg_field_name($this->_result, $column);
                                $row->orgname = $row->name;
                                $row->type = pg_field_type($this->_result, $column);
-                               $row->charsetnr = ($row->type == "bytea" ? 63 : 0);
+                               $row->charsetnr = ($row->type == "bytea" ? 63 : 0); // 63 - binary
                                return $row;
                        }
                        
@@ -178,7 +180,7 @@ if (isset($_GET["pgsql"])) {
        
        function tables_list() {
                global $connection;
-               return get_key_vals("SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name");
+               return get_key_vals("SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = current_schema() ORDER BY table_name");
        }
        
        function count_tables($databases) {
@@ -188,7 +190,12 @@ if (isset($_GET["pgsql"])) {
        function table_status($name = "") {
                global $connection;
                $return = array();
-               $result = $connection->query("SELECT relname AS \"Name\", CASE relkind WHEN 'r' THEN '' ELSE 'view' END AS \"Engine\", pg_relation_size(oid) AS \"Data_length\", pg_catalog.obj_description(oid, 'pg_class') AS \"Comment\" FROM pg_catalog.pg_class WHERE relkind IN ('r','v') AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'public')" . ($name != "" ? " AND relname = " . $connection->quote($name) : "")); //! Index_length, Auto_increment
+               $result = $connection->query("SELECT relname AS \"Name\", CASE relkind WHEN 'r' THEN '' ELSE 'view' END AS \"Engine\", pg_relation_size(oid) AS \"Data_length\", pg_catalog.obj_description(oid, 'pg_class') AS \"Comment\"
+FROM pg_catalog.pg_class
+WHERE relkind IN ('r','v')
+AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema())"
+                       . ($name != "" ? " AND relname = " . $connection->quote($name) : "")
+               ); //! Index_length, Auto_increment
                while ($row = $result->fetch_assoc()) {
                        $return[$row["Name"]] = $row;
                }
index 5124db4a4293dd14700527cf89b2a4ec222e12ee..8abd2dfa5832b916c435c199ca310bf62f4040aa 100644 (file)
@@ -19,6 +19,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                                
                                function __construct() {
                                        $this->server_info = sqlite_libversion();
+                                       $this->_connection = new SQLiteDatabase(":memory:");
                                }
                                
                                function open($filename) {
@@ -79,9 +80,16 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                                }
                                
                                function fetch_field() {
+                                       $name = $this->_result->fieldName($this->_offset++);
+                                       $pattern = '(\\[.*]|"(?:[^"]|"")*"|(.+))';
+                                       if (preg_match("~^($pattern\\.)?$pattern\$~", $name, $match)) {
+                                               $table = ($match[3] != "" ? $match[3] : idf_unescape($match[2]));
+                                               $name = ($match[5] != "" ? $match[5] : idf_unescape($match[4]));
+                                       }
                                        return (object) array(
-                                               "name" => $this->_result->fieldName($this->_offset++),
-                                               //! type, orgtable, charsetnr
+                                               "name" => $name,
+                                               "orgname" => $name,
+                                               "orgtable" => $table,
                                        );
                                }
                                
@@ -99,7 +107,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                                }
                                
                                function open($filename) {
-                                       $this->_connection->open($filename);
+                                       $this->_connection = new SQLite3($filename);
                                }
                                
                                function query($query) {
@@ -146,10 +154,11 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                                
                                function fetch_field() {
                                        $column = $this->_offset++;
+                                       $type = $this->_result->columnType($column);
                                        return (object) array(
                                                "name" => $this->_result->columnName($column),
-                                               "type" => $this->_result->columnType($column),
-                                               //! orgtable, charsetnr
+                                               "type" => $type,
+                                               "charsetnr" => ($type == SQLITE3_BLOB ? 63 : 0), // 63 - binary
                                        );
                                }
                                
@@ -163,13 +172,8 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                class Min_DB extends Min_SQLite {
                        
                        function select_db($filename) {
-                               static $connected = false;
-                               if ($connected) {
-                                       return true;
-                               }
                                set_exception_handler('connect_error'); // try/catch is not compatible with PHP 4
                                $this->open($filename);
-                               $connected = true;
                                restore_exception_handler();
                                return true;
                        }
index ee7c86e3bf903024af14fdaf75c79c977fb26945..2c5c5334443a93fa3ff926fd8e0df5821ff66bba 100644 (file)
@@ -40,7 +40,7 @@ function select($result, $connection2 = null) {
                                                        $links[$j] = $orgtable;
                                                }
                                        }
-                                       if ($field->charsetnr == 63) {
+                                       if ($field->charsetnr == 63) { // 63 - binary
                                                $blobs[$j] = true;
                                        }
                                        $types[$j] = $field->type;
@@ -59,7 +59,7 @@ function select($result, $connection2 = null) {
                                                $val = "&nbsp;"; // some content to print a border
                                        } else {
                                                $val = h($val);
-                                               if ($types[$key] == 254) {
+                                               if ($types[$key] == 254) { // 254 - char
                                                        $val = "<code>$val</code>";
                                                }
                                        }
index 3dd0fc9a6099b6be1cb316efedb7e83e52963dc0..75d24cd671edfc91d471f0f00caedc847fe6346a 100644 (file)
@@ -13,7 +13,8 @@ function connection() {
 * @return string
 */
 function idf_unescape($idf) {
-       return str_replace($idf[0] . $idf[0], $idf[0], substr($idf, 1, -1));
+       $last = substr($idf, -1);
+       return str_replace($last . $last, $last, substr($idf, 1, -1));
 }
 
 /** Escape string to use inside ''