From 550289de512ddc51a7f350aed5b08b2df4b236ab Mon Sep 17 00:00:00 2001 From: Joe Koop Date: Fri, 28 Oct 2022 20:05:58 -0500 Subject: [PATCH] MySQL: Support CHECK constraint added list of check constraints to mysql table view added create, alter, drop check constraints (mysql) chore: use the correct function to sql-escape fix: feature detection for check constraints (mysql) fix: get check constraint info (mysql) correct the capitalization of a section title to be consistent with the other section titles added a missing `` --- adminer/check.inc.php | 35 +++++++++++++++++++++++++++++++++ adminer/drivers/mysql.inc.php | 16 +++++++++++++-- adminer/include/version.inc.php | 2 +- adminer/index.php | 2 ++ adminer/lang/cs.inc.php | 8 ++++++++ adminer/lang/xx.inc.php | 8 ++++++++ adminer/table.inc.php | 21 ++++++++++++++++++-- changes.txt | 3 ++- todo.txt | 1 - 9 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 adminer/check.inc.php diff --git a/adminer/check.inc.php b/adminer/check.inc.php new file mode 100644 index 00000000..37c5348d --- /dev/null +++ b/adminer/check.inc.php @@ -0,0 +1,35 @@ + $TABLE)); + +if (!$row) { + $checks = check_constraints($TABLE); + $row = array("name" => $name, "clause" => $checks[$name]); +} +?> + +
+

: " data-maxlength="64" autocapitalize="off"> 'create-table-check-constraints.html', + 'mariadb' => 'constraint/', +)); ?> +

+

+ + +

diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index c600c55a..abddc771 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -864,6 +864,18 @@ if (!defined("DRIVER")) { return true; } + /** Get defined check constraints + * @param string + * @return array array($name => $statement) + */ + function check_constraints($table) { + // MariaDB contains CHECK_CONSTRAINTS.TABLE_NAME, MySQL not + return get_key_vals("SELECT c.CONSTRAINT_NAME, c.CHECK_CLAUSE +FROM information_schema.CHECK_CONSTRAINTS c +JOIN information_schema.TABLE_CONSTRAINTS t ON c.CONSTRAINT_SCHEMA = t.CONSTRAINT_SCHEMA AND c.CONSTRAINT_NAME = t.CONSTRAINT_NAME +WHERE c.CONSTRAINT_SCHEMA = " . q(DB) . " AND t.TABLE_NAME = " . q($table)); + } + /** Get information about trigger * @param string trigger name * @return array array("Trigger" => , "Timing" => , "Event" => , "Of" => , "Type" => , "Statement" => ) @@ -1128,11 +1140,11 @@ if (!defined("DRIVER")) { } /** Check whether a feature is supported - * @param string "comment", "copy", "database", "descidx", "drop_col", "dump", "event", "indexes", "kill", "materializedview", "partitioning", "privileges", "procedure", "processlist", "routine", "scheme", "sequence", "status", "table", "trigger", "type", "variables", "view", "view_trigger" + * @param string "check", "comment", "copy", "database", "descidx", "drop_col", "dump", "event", "indexes", "kill", "materializedview", "partitioning", "privileges", "procedure", "processlist", "routine", "scheme", "sequence", "status", "table", "trigger", "type", "variables", "view", "view_trigger" * @return bool */ function support($feature) { - return !preg_match("~scheme|sequence|type|view_trigger|materializedview" . (min_version(8) ? "" : "|descidx" . (min_version(5.1) ? "" : "|event|partitioning" . (min_version(5) ? "" : "|routine|trigger|view"))) . "~", $feature); + return !preg_match("~scheme|sequence|type|view_trigger|materializedview" . (min_version(8) ? "" : "|descidx" . (min_version(5.1) ? "" : "|event|partitioning" . (min_version(5) ? "" : "|routine|trigger|view"))) . (min_version('8.0.16', '10.2.1') ? "" : "|check") . "~", $feature); } /** Kill a process diff --git a/adminer/include/version.inc.php b/adminer/include/version.inc.php index 9127d04d..abeb157e 100644 --- a/adminer/include/version.inc.php +++ b/adminer/include/version.inc.php @@ -1,2 +1,2 @@ 'Typ byl odstraněn.', 'Type has been created.' => 'Typ byl vytvořen.', 'Alter type' => 'Pozměnit typ', + + // MySQL check constraints + 'Checks' => 'Kontroly', + 'Create check' => 'Vytvořit kontrolu', + 'Alter check' => 'Změnit kontrolu', + 'Check has been created.' => 'Kontrola byla vytvořena.', + 'Check has been altered.' => 'Kontrola byla změněna.', + 'Check has been dropped.' => 'Kontrola byla odstraněna.', ); diff --git a/adminer/lang/xx.inc.php b/adminer/lang/xx.inc.php index 9b66a21d..0922ed4f 100644 --- a/adminer/lang/xx.inc.php +++ b/adminer/lang/xx.inc.php @@ -345,4 +345,12 @@ $translations = array( 'Type has been dropped.' => 'Xx.', 'Type has been created.' => 'Xx.', 'Alter type' => 'Xx', + + // MySQL check constraints + 'Checks' => 'Xx', + 'Create check' => 'Xx', + 'Alter check' => 'Xx', + 'Check has been created.' => 'Xx.', + 'Check has been altered.' => 'Xx.', + 'Check has been dropped.' => 'Xx.', ); diff --git a/adminer/table.inc.php b/adminer/table.inc.php index 7817287c..114f8de1 100644 --- a/adminer/table.inc.php +++ b/adminer/table.inc.php @@ -48,14 +48,31 @@ if (!is_view($table_status)) { . "" ; echo "(" . implode(", ", array_map('h', $foreign_key["target"])) . ")"; - echo "" . h($foreign_key["on_delete"]) . "\n"; - echo "" . h($foreign_key["on_update"]) . "\n"; + echo "" . h($foreign_key["on_delete"]); + echo "" . h($foreign_key["on_update"]); echo '' . lang('Alter') . ''; + echo "\n"; } echo "\n"; } echo '

" . lang('Checks') . "

\n"; + $check_constraints = check_constraints($TABLE); + if ($check_constraints) { + echo "\n"; + foreach ($check_constraints as $key => $val) { + echo ""; + echo "
" . h($val); + echo "" . lang('Alter') . ""; + echo "\n"; + } + echo "
\n"; + } + echo '