1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-14 10:34:01 +02:00

Use driver() instead of $driver

This commit is contained in:
Jakub Vrana
2025-03-29 21:00:44 +01:00
parent 845445baad
commit 168ea5ae6d
22 changed files with 83 additions and 109 deletions

View File

@@ -640,7 +640,6 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)) as $row
}
function create_sql($table, $auto_increment, $style) {
global $driver;
if (is_view(table_status1($table))) {
$view = view($table);
return "CREATE VIEW " . table($table) . " AS $view[select]";
@@ -664,7 +663,7 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)) as $row
$fields[] = ($index["type"] == "INDEX" ? "INDEX $name" : "CONSTRAINT $name " . ($index["type"] == "UNIQUE" ? "UNIQUE" : "PRIMARY KEY")) . " (" . implode(", ", $columns) . ")";
}
}
foreach ($driver->checkConstraints($table) as $name => $check) {
foreach (driver()->checkConstraints($table) as $name => $check) {
$fields[] = "CONSTRAINT " . idf_escape($name) . " CHECK ($check)";
}
return "CREATE TABLE " . table($table) . " (\n\t" . implode(",\n\t", $fields) . "\n)";

View File

@@ -556,13 +556,12 @@ if (!defined('Adminer\DRIVER')) {
* @return ForeignKey[]
*/
function foreign_keys(string $table): array {
global $driver;
static $pattern = '(?:`(?:[^`]|``)+`|"(?:[^"]|"")+")';
$return = array();
$create_table = get_val("SHOW CREATE TABLE " . table($table), 1);
if ($create_table) {
preg_match_all(
"~CONSTRAINT ($pattern) FOREIGN KEY ?\\(((?:$pattern,? ?)+)\\) REFERENCES ($pattern)(?:\\.($pattern))? \\(((?:$pattern,? ?)+)\\)(?: ON DELETE ($driver->onActions))?(?: ON UPDATE ($driver->onActions))?~",
"~CONSTRAINT ($pattern) FOREIGN KEY ?\\(((?:$pattern,? ?)+)\\) REFERENCES ($pattern)(?:\\.($pattern))? \\(((?:$pattern,? ?)+)\\)(?: ON DELETE (driver()->onActions))?(?: ON UPDATE (driver()->onActions))?~",
$create_table,
$matches,
PREG_SET_ORDER
@@ -860,13 +859,12 @@ if (!defined('Adminer\DRIVER')) {
* @return Routine
*/
function routine(string $name, string $type): array {
global $driver;
$aliases = array("bool", "boolean", "integer", "double precision", "real", "dec", "numeric", "fixed", "national char", "national varchar");
$space = "(?:\\s|/\\*[\s\S]*?\\*/|(?:#|-- )[^\n]*\n?|--\r?\n)";
$enum = $driver->enumLength;
$type_pattern = "((" . implode("|", array_merge(array_keys($driver->types()), $aliases)) . ")\\b(?:\\s*\\(((?:[^'\")]|$enum)++)\\))?"
$enum = driver()->enumLength;
$type_pattern = "((" . implode("|", array_merge(array_keys(driver()->types()), $aliases)) . ")\\b(?:\\s*\\(((?:[^'\")]|$enum)++)\\))?"
. "\\s*(zerofill\\s*)?(unsigned(?:\\s+zerofill)?)?)(?:\\s*(?:CHARSET|CHARACTER\\s+SET)\\s*['\"]?([^'\"\\s,]+)['\"]?)?";
$pattern = "$space*(" . ($type == "FUNCTION" ? "" : $driver->inout) . ")?\\s*(?:`((?:[^`]|``)*)`\\s*|\\b(\\S+)\\s+)$type_pattern";
$pattern = "$space*(" . ($type == "FUNCTION" ? "" : driver()->inout) . ")?\\s*(?:`((?:[^`]|``)*)`\\s*|\\b(\\S+)\\s+)$type_pattern";
$create = get_val("SHOW CREATE $type " . idf_escape($name), 2);
preg_match("~\\(((?:$pattern\\s*,?)*)\\)\\s*" . ($type == "FUNCTION" ? "RETURNS\\s+$type_pattern\\s+" : "") . "(.*)~is", $create, $match);
$fields = array();

View File

@@ -484,7 +484,6 @@ ORDER BY indisprimary DESC, indisunique DESC", $connection2) as $row
}
function foreign_keys($table) {
global $driver;
$return = array();
foreach (
get_rows("SELECT conname, condeferrable::int AS deferrable, pg_get_constraintdef(oid) AS definition
@@ -500,8 +499,8 @@ ORDER BY conkey, conname") as $row
$row['table'] = idf_unescape($match2[4]);
}
$row['target'] = array_map('Adminer\idf_unescape', array_map('trim', explode(',', $match[3])));
$row['on_delete'] = (preg_match("~ON DELETE ($driver->onActions)~", $match[4], $match2) ? $match2[1] : 'NO ACTION');
$row['on_update'] = (preg_match("~ON UPDATE ($driver->onActions)~", $match[4], $match2) ? $match2[1] : 'NO ACTION');
$row['on_delete'] = (preg_match("~ON DELETE (driver()->onActions)~", $match[4], $match2) ? $match2[1] : 'NO ACTION');
$row['on_update'] = (preg_match("~ON UPDATE (driver()->onActions)~", $match[4], $match2) ? $match2[1] : 'NO ACTION');
$return[$row['conname']] = $row;
}
}
@@ -793,12 +792,12 @@ AND typelem = 0"
}
function set_schema($schema, $connection2 = null) {
global $connection, $driver;
global $connection;
if (!$connection2) {
$connection2 = $connection;
}
$return = $connection2->query("SET search_path TO " . idf_escape($schema));
$driver->setUserTypes(types()); //! get types from current_schemas('t')
driver()->setUserTypes(types()); //! get types from current_schemas('t')
return $return;
}
@@ -820,7 +819,6 @@ AND typelem = 0"
}
function create_sql($table, $auto_increment, $style) {
global $driver;
$return_parts = array();
$sequences = array();
@@ -872,7 +870,7 @@ AND typelem = 0"
}
}
foreach ($driver->checkConstraints($table) as $conname => $consrc) {
foreach (driver()->checkConstraints($table) as $conname => $consrc) {
$return_parts[] = "CONSTRAINT " . idf_escape($conname) . " CHECK $consrc";
}

View File

@@ -459,7 +459,6 @@ if (isset($_GET["sqlite"])) {
* @param string $add_check CHECK constraint to add
*/
function recreate_table(string $table, string $name, array $fields, array $originals, array $foreign, int $auto_increment = 0, $indexes = array(), string $drop_check = "", string $add_check = ""): bool {
global $driver;
if ($table != "") {
if (!$fields) {
foreach (fields($table) as $key => $field) {
@@ -524,7 +523,7 @@ if (isset($_GET["sqlite"])) {
$changes[] = " " . implode($field);
}
$changes = array_merge($changes, array_filter($foreign));
foreach ($driver->checkConstraints($table) as $check) {
foreach (driver()->checkConstraints($table) as $check) {
if ($check != $drop_check) {
$changes[] = " CHECK ($check)";
}