2011-02-09 17:57:10 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/** Link system tables (in mysql and information_schema databases) by foreign keys
|
2015-09-08 09:23:25 -07:00
|
|
|
* @link https://www.adminer.org/plugins/#use
|
2017-02-27 13:43:33 +01:00
|
|
|
* @author Jakub Vrana, https://www.vrana.cz/
|
2018-01-14 11:03:54 +01:00
|
|
|
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
|
|
|
|
|
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
|
2011-02-09 17:57:10 +01:00
|
|
|
*/
|
|
|
|
|
class AdminerForeignSystem {
|
2025-02-21 13:53:18 +01:00
|
|
|
|
2011-02-09 17:57:10 +01:00
|
|
|
function foreignKeys($table) {
|
2025-03-06 17:34:21 +01:00
|
|
|
if (Adminer\DRIVER == "server" && Adminer\DB == "mysql") {
|
2025-03-05 09:14:49 +01:00
|
|
|
$return = array(
|
|
|
|
|
"columns_priv" => array(array("table" => "user", "source" => array("Host", "User"), "target" => array("Host", "User"))),
|
|
|
|
|
"db" => array(array("table" => "user", "source" => array("Host", "User"), "target" => array("Host", "User"))),
|
|
|
|
|
"help_category" => array(array("table" => "help_category", "source" => array("parent_category_id"), "target" => array("help_category_id"))),
|
2025-03-12 11:38:28 +01:00
|
|
|
"help_relation" => array(
|
|
|
|
|
array("table" => "help_topic", "source" => array("help_topic_id"), "target" => array("help_topic_id")),
|
|
|
|
|
array("table" => "help_keyword", "source" => array("help_keyword_id"), "target" => array("help_keyword_id")),
|
|
|
|
|
),
|
2025-03-05 09:14:49 +01:00
|
|
|
"help_topic" => array(array("table" => "help_category", "source" => array("help_category_id"), "target" => array("help_category_id"))),
|
|
|
|
|
"procs_priv" => array(array("table" => "user", "source" => array("Host", "User"), "target" => array("Host", "User")), array("table" => "proc", "source" => array("Db", "Routine_name"), "target" => array("db", "name"))),
|
|
|
|
|
"tables_priv" => array(array("table" => "user", "source" => array("Host", "User"), "target" => array("Host", "User"))),
|
|
|
|
|
"time_zone_name" => array(array("table" => "time_zone", "source" => array("Time_zone_id"), "target" => array("Time_zone_id"))),
|
2025-03-12 11:38:28 +01:00
|
|
|
"time_zone_transition" => array(
|
|
|
|
|
array("table" => "time_zone", "source" => array("Time_zone_id"), "target" => array("Time_zone_id")),
|
|
|
|
|
array("table" => "time_zone_transition_type", "source" => array("Time_zone_id", "Transition_type_id"), "target" => array("Time_zone_id", "Transition_type_id")),
|
|
|
|
|
),
|
2025-03-05 09:14:49 +01:00
|
|
|
"time_zone_transition_type" => array(array("table" => "time_zone", "source" => array("Time_zone_id"), "target" => array("Time_zone_id"))),
|
|
|
|
|
);
|
|
|
|
|
return $return[$table];
|
2025-03-06 17:34:21 +01:00
|
|
|
} elseif (Adminer\DB == "information_schema") {
|
2025-03-31 08:21:50 +02:00
|
|
|
$schemata = $this->schemata("TABLE");
|
|
|
|
|
$tables = $this->tables("TABLE");
|
2011-02-09 17:57:10 +01:00
|
|
|
$columns = array("table" => "COLUMNS", "source" => array("TABLE_CATALOG", "TABLE_SCHEMA", "TABLE_NAME", "COLUMN_NAME"), "target" => array("TABLE_CATALOG", "TABLE_SCHEMA", "TABLE_NAME", "COLUMN_NAME"));
|
2025-03-31 08:21:50 +02:00
|
|
|
$character_sets = $this->character_sets("CHARACTER_SET_NAME");
|
|
|
|
|
$collations = $this->collations("COLLATION_NAME");
|
|
|
|
|
$routine_charsets = array($this->character_sets("CHARACTER_SET_CLIENT"), $this->collations("COLLATION_CONNECTION"), $this->collations("DATABASE_COLLATION"));
|
2025-03-05 09:14:49 +01:00
|
|
|
$return = array(
|
2025-03-31 08:21:50 +02:00
|
|
|
"CHARACTER_SETS" => array($this->collations("DEFAULT_COLLATE_NAME")),
|
|
|
|
|
"CHECK_CONSTRAINTS" => array($this->schemata("CONSTRAINT")),
|
2025-03-05 09:14:49 +01:00
|
|
|
"COLLATIONS" => array($character_sets),
|
|
|
|
|
"COLLATION_CHARACTER_SET_APPLICABILITY" => array($collations, $character_sets),
|
|
|
|
|
"COLUMNS" => array($schemata, $tables, $character_sets, $collations),
|
|
|
|
|
"COLUMN_PRIVILEGES" => array($schemata, $tables, $columns),
|
2025-03-31 08:21:50 +02:00
|
|
|
"COLUMNS_EXTENSIONS" => array($schemata, $tables, $columns),
|
|
|
|
|
"TABLES" => array($schemata, $this->collations("TABLE_COLLATION")),
|
|
|
|
|
"SCHEMATA" => array($this->character_sets("DEFAULT_CHARACTER_SET_NAME"), $this->collations("DEFAULT_COLLATION_NAME")),
|
|
|
|
|
"EVENTS" => array_merge(array($this->schemata("EVENT")), $routine_charsets),
|
2025-03-05 09:14:49 +01:00
|
|
|
"FILES" => array($schemata, $tables),
|
2025-03-07 07:44:26 +01:00
|
|
|
"KEY_COLUMN_USAGE" => array(
|
2025-03-31 08:21:50 +02:00
|
|
|
$this->schemata("CONSTRAINT"),
|
2025-03-07 07:44:26 +01:00
|
|
|
$schemata,
|
|
|
|
|
$tables,
|
|
|
|
|
$columns,
|
2025-03-31 08:21:50 +02:00
|
|
|
$this->schemata("TABLE", "REFERENCED_TABLE"),
|
|
|
|
|
$this->tables("TABLE", "REFERENCED_TABLE"),
|
2025-03-07 07:44:26 +01:00
|
|
|
array("source" => array("TABLE_CATALOG", "REFERENCED_TABLE_SCHEMA", "REFERENCED_TABLE_NAME", "REFERENCED_COLUMN_NAME")) + $columns,
|
|
|
|
|
),
|
2025-03-05 09:14:49 +01:00
|
|
|
"PARTITIONS" => array($schemata, $tables),
|
2025-03-07 07:44:26 +01:00
|
|
|
"REFERENTIAL_CONSTRAINTS" => array(
|
2025-03-31 08:21:50 +02:00
|
|
|
$this->schemata("CONSTRAINT"),
|
|
|
|
|
$this->schemata("UNIQUE_CONSTRAINT"),
|
|
|
|
|
$this->tables("CONSTRAINT", "CONSTRAINT", "TABLE_NAME"),
|
|
|
|
|
$this->tables("CONSTRAINT", "CONSTRAINT", "REFERENCED_TABLE_NAME"),
|
2025-03-07 07:44:26 +01:00
|
|
|
),
|
2025-03-31 08:21:50 +02:00
|
|
|
"ROUTINES" => array_merge(array($this->schemata("ROUTINE")), $routine_charsets),
|
2025-03-05 09:14:49 +01:00
|
|
|
"SCHEMA_PRIVILEGES" => array($schemata),
|
2025-03-31 08:21:50 +02:00
|
|
|
"STATISTICS" => array($schemata, $tables, $columns, $this->schemata("TABLE", "INDEX")),
|
2025-03-07 07:44:26 +01:00
|
|
|
"TABLE_CONSTRAINTS" => array(
|
2025-03-31 08:21:50 +02:00
|
|
|
$this->schemata("CONSTRAINT"),
|
|
|
|
|
$this->schemata("CONSTRAINT", "TABLE"),
|
|
|
|
|
$this->tables("CONSTRAINT", "TABLE"),
|
2025-03-07 07:44:26 +01:00
|
|
|
),
|
2025-03-31 08:21:50 +02:00
|
|
|
"TABLE_CONSTRAINTS_EXTENSIONS" => array($this->schemata("CONSTRAINT"), $this->tables("CONSTRAINT", "CONSTRAINT", "TABLE_NAME")),
|
2025-03-05 09:14:49 +01:00
|
|
|
"TABLE_PRIVILEGES" => array($schemata, $tables),
|
2025-03-07 07:44:26 +01:00
|
|
|
"TRIGGERS" => array_merge(array(
|
2025-03-31 08:21:50 +02:00
|
|
|
$this->schemata("TRIGGER"),
|
|
|
|
|
$this->schemata("EVENT_OBJECT"),
|
|
|
|
|
$this->tables("EVENT_OBJECT", "EVENT_OBJECT", "EVENT_OBJECT_TABLE"),
|
2025-03-07 07:44:26 +01:00
|
|
|
), $routine_charsets),
|
2025-03-31 08:21:50 +02:00
|
|
|
"VIEWS" => array($schemata, $this->character_sets("CHARACTER_SET_CLIENT"), $this->collations("COLLATION_CONNECTION")),
|
2025-03-05 09:14:49 +01:00
|
|
|
);
|
|
|
|
|
return $return[$table];
|
2011-02-09 17:57:10 +01:00
|
|
|
}
|
|
|
|
|
}
|
2025-03-31 08:21:50 +02:00
|
|
|
|
|
|
|
|
private function schemata($catalog, $schema = null) {
|
|
|
|
|
return array("table" => "SCHEMATA", "source" => array($catalog . "_CATALOG", ($schema ?: $catalog) . "_SCHEMA"), "target" => array("CATALOG_NAME", "SCHEMA_NAME"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function tables($catalog, $schema = null, $table_name = null) {
|
|
|
|
|
$schema = ($schema ?: $catalog);
|
|
|
|
|
return array("table" => "TABLES", "source" => array($catalog . "_CATALOG", $schema . "_SCHEMA", ($table_name ?: $schema . "_NAME")), "target" => array("TABLE_CATALOG", "TABLE_SCHEMA", "TABLE_NAME"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function character_sets($source) {
|
|
|
|
|
return array("table" => "CHARACTER_SETS", "source" => array($source), "target" => array("CHARACTER_SET_NAME"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function collations($source) {
|
|
|
|
|
return array("table" => "COLLATIONS", "source" => array($source), "target" => array("COLLATION_NAME"));
|
|
|
|
|
}
|
2011-02-09 17:57:10 +01:00
|
|
|
}
|