MySQL: Fix displaying multi-columns foreign keys (bug #675)
This commit is contained in:
parent
6a5b0abbb4
commit
36ade4e197
|
@ -582,25 +582,19 @@ if (!defined("DRIVER")) {
|
||||||
* @return array array($name => array("db" => , "ns" => , "table" => , "source" => array(), "target" => array(), "on_delete" => , "on_update" => ))
|
* @return array array($name => array("db" => , "ns" => , "table" => , "source" => array(), "target" => array(), "on_delete" => , "on_update" => ))
|
||||||
*/
|
*/
|
||||||
function foreign_keys($table) {
|
function foreign_keys($table) {
|
||||||
global $connection, $on_actions;
|
|
||||||
static $pattern = '(?:`(?:[^`]|``)+`)|(?:"(?:[^"]|"")+")';
|
|
||||||
$return = array();
|
$return = array();
|
||||||
$create_table = $connection->result("SHOW CREATE TABLE " . table($table), 1);
|
foreach (get_rows("SELECT * FROM information_schema.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_SCHEMA = " . q(DB) . " AND TABLE_NAME = " . q($table)) as $row) {
|
||||||
if ($create_table) {
|
$columns = get_key_vals("SELECT COLUMN_NAME, REFERENCED_COLUMN_NAME FROM information_schema.KEY_COLUMN_USAGE WHERE CONSTRAINT_SCHEMA = " . q(DB) . " AND CONSTRAINT_NAME = " . q($row["CONSTRAINT_NAME"]) . " ORDER BY ORDINAL_POSITION");
|
||||||
preg_match_all("~CONSTRAINT ($pattern) FOREIGN KEY ?\\(((?:$pattern,? ?)+)\\) REFERENCES ($pattern)(?:\\.($pattern))? \\(((?:$pattern,? ?)+)\\)(?: ON DELETE ($on_actions))?(?: ON UPDATE ($on_actions))?~", $create_table, $matches, PREG_SET_ORDER);
|
$db = $row["UNIQUE_CONSTRAINT_SCHEMA"];
|
||||||
foreach ($matches as $match) {
|
$return[$row["CONSTRAINT_NAME"]] = array(
|
||||||
preg_match_all("~$pattern~", $match[2], $source);
|
"db" => ($db == DB ? "" : $db),
|
||||||
preg_match_all("~$pattern~", $match[5], $target);
|
"table" => $row["REFERENCED_TABLE_NAME"],
|
||||||
$return[idf_unescape($match[1])] = array(
|
"source" => array_keys($columns),
|
||||||
"db" => idf_unescape($match[4] != "" ? $match[3] : $match[4]),
|
"target" => array_values($columns),
|
||||||
"table" => idf_unescape($match[4] != "" ? $match[4] : $match[3]),
|
"on_delete" => $row["DELETE_RULE"],
|
||||||
"source" => array_map('idf_unescape', $source[0]),
|
"on_update" => $row["UPDATE_RULE"],
|
||||||
"target" => array_map('idf_unescape', $target[0]),
|
|
||||||
"on_delete" => ($match[6] ? $match[6] : "RESTRICT"),
|
|
||||||
"on_update" => ($match[7] ? $match[7] : "RESTRICT"),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ Do not attempt logging in without password (bug #676)
|
||||||
Stretch footer over the whole table width (bug #624)
|
Stretch footer over the whole table width (bug #624)
|
||||||
Allow overwriting tables when copying them
|
Allow overwriting tables when copying them
|
||||||
Cache busting for adminer.css
|
Cache busting for adminer.css
|
||||||
|
MySQL: Fix displaying multi-columns foreign keys (bug #675)
|
||||||
MySQL: Fix creating users and changing password in MySQL 8 (bug #663)
|
MySQL: Fix creating users and changing password in MySQL 8 (bug #663)
|
||||||
MySQL: Pass SRID to GeomFromText
|
MySQL: Pass SRID to GeomFromText
|
||||||
Elasticsearch: Fix setting number of rows
|
Elasticsearch: Fix setting number of rows
|
||||||
|
|
Loading…
Reference in a new issue