mirror of
https://github.com/vrana/adminer.git
synced 2025-08-07 23:27:17 +02:00
Integrate Db::result in get_val
This commit is contained in:
@@ -332,7 +332,7 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
function hasCStyleEscapes(): bool {
|
function hasCStyleEscapes(): bool {
|
||||||
static $c_style;
|
static $c_style;
|
||||||
if ($c_style === null) {
|
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);
|
$c_style = (strpos($sql_mode, 'NO_BACKSLASH_ESCAPES') === false);
|
||||||
}
|
}
|
||||||
return $c_style;
|
return $c_style;
|
||||||
|
@@ -285,7 +285,7 @@ if (isset($_GET["pgsql"])) {
|
|||||||
function hasCStyleEscapes(): bool {
|
function hasCStyleEscapes(): bool {
|
||||||
static $c_style;
|
static $c_style;
|
||||||
if ($c_style === null) {
|
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;
|
return $c_style;
|
||||||
}
|
}
|
||||||
@@ -308,7 +308,7 @@ if (isset($_GET["pgsql"])) {
|
|||||||
if (min_version(9, 0, $connection)) {
|
if (min_version(9, 0, $connection)) {
|
||||||
$connection->query("SET application_name = 'Adminer'");
|
$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->flavor = (preg_match('~CockroachDB~', $version) ? 'cockroach' : '');
|
||||||
$connection->server_info = preg_replace('~^\D*([\d.]+[-\w]*).*~', '\1', $version);
|
$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
|
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;
|
$connection2 = $connection;
|
||||||
}
|
}
|
||||||
$return = array();
|
$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);
|
$columns = get_key_vals("SELECT attnum, attname FROM pg_attribute WHERE attrelid = $table_oid AND attnum > 0", $connection2);
|
||||||
foreach (
|
foreach (
|
||||||
get_rows("SELECT relname, indisunique::int, indisprimary::int, indkey, indoption, (indpred IS NOT NULL)::int as indispartial
|
get_rows("SELECT relname, indisunique::int, indisprimary::int, indkey, indoption, (indpred IS NOT NULL)::int as indispartial
|
||||||
|
@@ -151,7 +151,7 @@ if (isset($_GET["sqlite"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkConstraints(string $table): array {
|
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]);
|
return array_combine($matches[2], $matches[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -276,7 +276,7 @@ if (isset($_GET["sqlite"])) {
|
|||||||
$connection2 = $connection;
|
$connection2 = $connection;
|
||||||
}
|
}
|
||||||
$return = array();
|
$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)) {
|
if (preg_match('~\bPRIMARY\s+KEY\s*\((([^)"]+|"[^"]*"|`[^`]*`)++)~i', $sql, $match)) {
|
||||||
$return[""] = array("type" => "PRIMARY", "columns" => array(), "lengths" => array(), "descs" => array());
|
$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);
|
preg_match_all('~((("[^"]*+")+|(?:`[^`]*+`)+)|(\S+))(\s+(ASC|DESC))?(,\s*|$)~i', $match[1], $matches, PREG_SET_ORDER);
|
||||||
|
@@ -47,16 +47,4 @@ abstract class SqlDb {
|
|||||||
function next_result(): bool {
|
function next_result(): bool {
|
||||||
return false;
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -164,11 +164,17 @@ function get_password() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get single value from database
|
/** 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;
|
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
|
/** Get list of values from database
|
||||||
@@ -855,7 +861,7 @@ function slow_query(string $query): array {
|
|||||||
if (!$slow_query && support("kill")) {
|
if (!$slow_query && support("kill")) {
|
||||||
$connection2 = connect($adminer->credentials());
|
$connection2 = connect($adminer->credentials());
|
||||||
if (is_object($connection2) && ($db == "" || $connection2->select_db($db))) {
|
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);");
|
echo script("const timeout = setTimeout(() => { ajax('" . js_escape(ME) . "script=kill', function () {}, 'kill=$kill&token=$token'); }, 1000 * $timeout);");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user