]> git.joonet.de Git - adminer.git/commitdiff
Integrate Db::result in get_val
authorJakub Vrana <jakub@vrana.cz>
Fri, 28 Mar 2025 14:11:12 +0000 (15:11 +0100)
committerJakub Vrana <jakub@vrana.cz>
Fri, 28 Mar 2025 14:41:38 +0000 (15:41 +0100)
adminer/drivers/mysql.inc.php
adminer/drivers/pgsql.inc.php
adminer/drivers/sqlite.inc.php
adminer/include/db.inc.php
adminer/include/functions.inc.php

index 4925f7001c1e434f50eaa15f67cfe6d4dbe24983..50fcaa3418384465cd6c8ffc01df3420abc9e13a 100644 (file)
@@ -332,7 +332,7 @@ if (!defined('Adminer\DRIVER')) {
                function hasCStyleEscapes(): bool {
                        static $c_style;
                        if ($c_style === null) {
-                               $sql_mode = $this->conn->result("SHOW VARIABLES LIKE 'sql_mode'", 1);
+                               $sql_mode = get_val("SHOW VARIABLES LIKE 'sql_mode'", 1, $this->conn);
                                $c_style = (strpos($sql_mode, 'NO_BACKSLASH_ESCAPES') === false);
                        }
                        return $c_style;
index 32213ffc4c90d8d7517ca4df28d77998d5e66530..a6010ca1e01e3e89edbe4b3067749e6498b9047b 100644 (file)
@@ -285,7 +285,7 @@ if (isset($_GET["pgsql"])) {
                function hasCStyleEscapes(): bool {
                        static $c_style;
                        if ($c_style === null) {
-                               $c_style = ($this->conn->result("SHOW standard_conforming_strings") == "off");
+                               $c_style = (get_val("SHOW standard_conforming_strings", 0, $this->conn) == "off");
                        }
                        return $c_style;
                }
@@ -308,7 +308,7 @@ if (isset($_GET["pgsql"])) {
                        if (min_version(9, 0, $connection)) {
                                $connection->query("SET application_name = 'Adminer'");
                        }
-                       $version = $connection->result("SELECT version()");
+                       $version = get_val("SELECT version()", 0, $connection);
                        $connection->flavor = (preg_match('~CockroachDB~', $version) ? 'cockroach' : '');
                        $connection->server_info = preg_replace('~^\D*([\d.]+[-\w]*).*~', '\1', $version);
                        if ($connection->flavor == 'cockroach') { // we don't use "PostgreSQL / CockroachDB" by default because it's too long
@@ -463,7 +463,7 @@ ORDER BY a.attnum") as $row
                        $connection2 = $connection;
                }
                $return = array();
-               $table_oid = $connection2->result("SELECT oid FROM pg_class WHERE relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema()) AND relname = " . q($table));
+               $table_oid = get_val("SELECT oid FROM pg_class WHERE relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema()) AND relname = " . q($table), 0, $connection2);
                $columns = get_key_vals("SELECT attnum, attname FROM pg_attribute WHERE attrelid = $table_oid AND attnum > 0", $connection2);
                foreach (
                        get_rows("SELECT relname, indisunique::int, indisprimary::int, indkey, indoption, (indpred IS NOT NULL)::int as indispartial
index ac23dce12f038d8157d0b6e70c7ff76f5c00d5dd..04518a505324e46f4f54b4a24766952e72e40c65 100644 (file)
@@ -151,7 +151,7 @@ if (isset($_GET["sqlite"])) {
                }
 
                function checkConstraints(string $table): array {
-                       preg_match_all('~ CHECK *(\( *(((?>[^()]*[^() ])|(?1))*) *\))~', $this->conn->result("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = " . q($table)), $matches); //! could be inside a comment
+                       preg_match_all('~ CHECK *(\( *(((?>[^()]*[^() ])|(?1))*) *\))~', get_val("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = " . q($table), 0, $this->conn), $matches); //! could be inside a comment
                        return array_combine($matches[2], $matches[2]);
                }
        }
@@ -276,7 +276,7 @@ if (isset($_GET["sqlite"])) {
                        $connection2 = $connection;
                }
                $return = array();
-               $sql = $connection2->result("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = " . q($table));
+               $sql = get_val("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = " . q($table), 0, $connection2);
                if (preg_match('~\bPRIMARY\s+KEY\s*\((([^)"]+|"[^"]*"|`[^`]*`)++)~i', $sql, $match)) {
                        $return[""] = array("type" => "PRIMARY", "columns" => array(), "lengths" => array(), "descs" => array());
                        preg_match_all('~((("[^"]*+")+|(?:`[^`]*+`)+)|(\S+))(\s+(ASC|DESC))?(,\s*|$)~i', $match[1], $matches, PREG_SET_ORDER);
index 1a609b7fac26f365713c43ba7f517bcd200a23f2..bd352e2ab85aa289bbdf623aeb37a7f692bbcfbd 100644 (file)
@@ -47,16 +47,4 @@ abstract class SqlDb {
        function next_result(): bool {
                return false;
        }
-
-       /** Get single field from result
-       * @return string|bool
-       */
-       function result(string $query, int $field = 0) {
-               $result = $this->query($query);
-               if (!is_object($result)) {
-                       return false;
-               }
-               $row = $result->fetch_row();
-               return ($row ? $row[$field] : false);
-       }
 }
index 1ea224f1d30cdc883b67cc7177c7096e2bc436f5..a38f28ba17d9b7b8f49816088a2e985c9e1ceef7 100644 (file)
@@ -164,11 +164,17 @@ function get_password() {
 }
 
 /** Get single value from database
-* @return string or false if error
+* @return string|false false if error
 */
-function get_val(string $query, int $field = 0): string {
+function get_val(string $query, int $field = 0, ?Db $conn = null) {
        global $connection;
-       return $connection->result($query, $field);
+       $conn = $conn ?: $connection;
+       $result = $conn->query($query);
+       if (!is_object($result)) {
+               return false;
+       }
+       $row = $result->fetch_row();
+       return ($row ? $row[$field] : false);
 }
 
 /** Get list of values from database
@@ -855,7 +861,7 @@ function slow_query(string $query): array {
        if (!$slow_query && support("kill")) {
                $connection2 = connect($adminer->credentials());
                if (is_object($connection2) && ($db == "" || $connection2->select_db($db))) {
-                       $kill = $connection2->result(connection_id()); // MySQL and MySQLi can use thread_id but it's not in PDO_MySQL
+                       $kill = get_val(connection_id(), 0, $connection2); // MySQL and MySQLi can use thread_id but it's not in PDO_MySQL
                        echo script("const timeout = setTimeout(() => { ajax('" . js_escape(ME) . "script=kill', function () {}, 'kill=$kill&token=$token'); }, 1000 * $timeout);");
                }
        }