]> git.joonet.de Git - adminer.git/commitdiff
PostgreSQL: Support CHECK constraint
authorJakub Vrana <jakub@vrana.cz>
Sat, 22 Feb 2025 20:08:23 +0000 (21:08 +0100)
committerJakub Vrana <jakub@vrana.cz>
Sat, 22 Feb 2025 20:08:23 +0000 (21:08 +0100)
adminer/check.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/pgsql.inc.php
adminer/include/editing.inc.php
changes.txt

index 37c5348d7f87721d01fe8524394fd03dba483947..0d8b06dbbef3212a4386f9e96b49fb970fad2b81 100644 (file)
@@ -4,7 +4,7 @@ $name = $_GET["name"];
 $row = $_POST;
 
 if ($row && !$error) {
-       $result = ($name == "" || queries("ALTER TABLE " . table($TABLE) . " DROP CHECK " . idf_escape($name)));
+       $result = ($name == "" || queries("ALTER TABLE " . table($TABLE) . " DROP CONSTRAINT " . idf_escape($name)));
        if (!$row["drop"] && $result) {
                $result = queries("ALTER TABLE " . table($TABLE) . " ADD" . ($row["name"] != "" ? " CONSTRAINT " . idf_escape($row["name"]) . "" : "") . " CHECK ($row[clause])"); //! SQL injection
        }
index abddc771dbec451fce96cb4ffb87a9947292e151..d3d527260e270eae4e95f9a272ce45ecc0b3175f 100644 (file)
@@ -864,18 +864,6 @@ 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" => )
index 2cc438c84a0520bb2cff56f911acf85c34128384..77cfc418a666e5c07f85715e18c19c2e08d14437 100644 (file)
@@ -911,7 +911,7 @@ AND typelem = 0"
        }
 
        function support($feature) {
-               return preg_match('~^(database|table|columns|sql|indexes|descidx|comment|view|' . (min_version(9.3) ? 'materializedview|' : '') . 'scheme|routine|processlist|sequence|trigger|type|variables|drop_col|kill|dump)$~', $feature);
+               return preg_match('~^(check|database|table|columns|sql|indexes|descidx|comment|view|' . (min_version(9.3) ? 'materializedview|' : '') . 'scheme|routine|processlist|sequence|trigger|type|variables|drop_col|kill|dump)$~', $feature);
        }
 
        function kill_process($val) {
index 5d358218d0262716db37cd386c5dfb44e9978a70..27c182b95b3f7817c50bd704a5457a9f38c1d916 100644 (file)
@@ -532,6 +532,20 @@ function create_routine($routine, $row) {
        ;
 }
 
+/** Get defined check constraints
+* @param string
+* @return array array($name => $clause)
+*/
+function check_constraints($table) {
+       // MariaDB contains CHECK_CONSTRAINTS.TABLE_NAME, MySQL and PostrgreSQL not
+       return get_key_vals("SELECT c.CONSTRAINT_NAME, 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($_GET["ns"] != "" ? $_GET["ns"] : DB) . "
+AND t.TABLE_NAME = " . q($table) . "
+AND CHECK_CLAUSE NOT LIKE '% IS NOT NULL'"); // ignore default IS NOT NULL checks in PostrgreSQL
+}
+
 /** Remove current user definer from SQL command
 * @param string
 * @return string
index 2df0b59ec98a6be3ea6ed04f4e5ad723b9d802c7..ded6505f1e398b77fd57cbc3f0ad7fe18489f5d0 100644 (file)
@@ -1,6 +1,6 @@
 Adminer 4.17.0-dev:
 Hide index column options by default
-MySQL: Support CHECK constraint
+MySQL, PostgreSQL: Support CHECK constraint
 PostgreSQL: Link user defined types
 PostgreSQL: Constraint enum values in editing (bug #270)
 SQLite: Show all supported pragmas in Variables