]> git.joonet.de Git - adminer.git/commitdiff
PostgreSQL: Limit rows in data manipulation without unique key
authorJakub Vrana <jakub@vrana.cz>
Thu, 1 Feb 2018 15:56:50 +0000 (16:56 +0100)
committerJakub Vrana <jakub@vrana.cz>
Thu, 1 Feb 2018 15:58:01 +0000 (16:58 +0100)
adminer/drivers/firebird.inc.php
adminer/drivers/mssql.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/oracle.inc.php
adminer/drivers/pgsql.inc.php
adminer/drivers/sqlite.inc.php
adminer/include/driver.inc.php
adminer/select.inc.php
changes.txt

index 68f983207a4155080413ceea6d12c7876c37eac5..822b33b9a10d04de8951790871d3cb3ebfd47600 100644 (file)
@@ -147,7 +147,7 @@ if (isset($_GET["firebird"])) {
                return $return;
        }
 
-       function limit1($query, $where) {
+       function limit1($table, $query, $where) {
                return limit($query, $where, 1);
        }
 
index 0f119ad2f07c4e07815232c58b32d83a403c352f..becfaeae0dd006d21c0f844341d59cf4f0e3e2cc 100644 (file)
@@ -308,7 +308,7 @@ if (isset($_GET["mssql"])) {
                return ($limit !== null ? " TOP (" . ($limit + $offset) . ")" : "") . " $query$where"; // seek later
        }
 
-       function limit1($query, $where) {
+       function limit1($table, $query, $where) {
                return limit($query, $where, 1);
        }
 
index b06405d941572d9e3e0b22846acdc991925516f0..34a3b1d17de851bf99e9f4a1635489231bab4cd2 100644 (file)
@@ -362,11 +362,12 @@ if (!defined("DRIVER")) {
        }
 
        /** Formulate SQL modification query with limit 1
+       * @param string
        * @param string everything after UPDATE or DELETE
        * @param string
        * @return string
        */
-       function limit1($query, $where) {
+       function limit1($table, $query, $where) {
                return limit($query, $where, 1);
        }
 
index 363481f6dac45259a179c850a3060beea07bef15..3e7b997419a39e54121311fee2128499960ca617 100644 (file)
@@ -175,8 +175,8 @@ if (isset($_GET["oracle"])) {
                ));
        }
 
-       function limit1($query, $where) {
-               return " $query$where";
+       function limit1($table, $query, $where) {
+               return " $query$where"; //! limit
        }
 
        function db_collation($db, $collations) {
index ed69ecd6d04350e43f5bbdf95ec51ee341fa3b34..733b4c5b916c938625c31d99a941f7a1607e577e 100644 (file)
@@ -226,8 +226,8 @@ if (isset($_GET["pgsql"])) {
                return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : "");
        }
 
-       function limit1($query, $where) {
-               return " $query$where";
+       function limit1($table, $query, $where) {
+               return (preg_match('~^INTO~', $query) ? limit($query, $where, 1) : "$query WHERE ctid = (SELECT ctid FROM " . table($table) . "$where LIMIT 1)");
        }
 
        function db_collation($db, $collations) {
index 58e0f1031377bceb3ff83810db91982be0a39d26..9d8efbb3235bfccf9c8bcad8b9bac3c37fbec54c 100644 (file)
@@ -242,9 +242,9 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : "");
        }
 
-       function limit1($query, $where) {
+       function limit1($table, $query, $where) {
                global $connection;
-               return ($connection->result("SELECT sqlite_compileoption_used('ENABLE_UPDATE_DELETE_LIMIT')") ? limit($query, $where, 1) : " $query$where");
+               return ($connection->result("SELECT sqlite_compileoption_used('ENABLE_UPDATE_DELETE_LIMIT')") ? limit($query, $where, 1) : " $query$where"); //! limit
        }
 
        function db_collation($db, $collations) {
index 543894bbf7c27cdeef9f5edab10f2966b7de34e9..5db00dcb0ee13b15e8deb678eb9652e3b1442850 100644 (file)
@@ -50,7 +50,7 @@
        */
        function delete($table, $queryWhere, $limit = 0) {
                $query = "FROM " . table($table);
-               return queries("DELETE" . ($limit ? limit1($query, $queryWhere) : " $query$queryWhere"));
+               return queries("DELETE" . ($limit ? limit1($table, $query, $queryWhere) : " $query$queryWhere"));
        }
        
        /** Update data in table
@@ -67,7 +67,7 @@
                        $values[] = "$key = $val";
                }
                $query = table($table) . " SET$separator" . implode(",$separator", $values);
-               return queries("UPDATE" . ($limit ? limit1($query, $queryWhere) : " $query$queryWhere"));
+               return queries("UPDATE" . ($limit ? limit1($table, $query, $queryWhere) : " $query$queryWhere"));
        }
        
        /** Insert data into table
index 2bb27d84c7ac73ab624e05f670c24b395482b5ab..8c6ba242583d04beca2225ed778154a6e33e36f4 100644 (file)
@@ -123,7 +123,7 @@ if ($_POST && !$error) {
                                                $result = ($_POST["delete"]
                                                        ? $driver->delete($TABLE, $where2, 1)
                                                        : ($_POST["clone"]
-                                                               ? queries("INSERT" . limit1($query, $where2))
+                                                               ? queries("INSERT" . limit1($TABLE, $query, $where2))
                                                                : $driver->update($TABLE, $set, $where2, 1)
                                                        )
                                                );
index 74867992711737f2b96fd2335315fc756de9a251..8e8a2dce0e663da8571a38391b7a1d2e8695c6a7 100644 (file)
@@ -9,7 +9,8 @@ MySQL, PostgreSQL: Display warnings
 MySQL: Add floor and ceil select functions
 MySQL: Add FIND_IN_SET search operator
 MariaDB: Support JSON since MariaDB 10.2
-PostgreSQL: Support functions
+PostgreSQL: Support routines
+PostgreSQL: Limit rows in data manipulation without unique key
 PostgreSQL: Allow editing views with uppercase letters (bug #467)
 PostgreSQL: Allow now() as default value (bug #525)
 SimpleDB: Document that allow_url_fopen is required