]> git.joonet.de Git - adminer.git/commitdiff
PostgreSQL: Export DROP SEQUENCE if dropping table
authorJakub Vrana <jakub@vrana.cz>
Mon, 22 Jan 2018 13:33:21 +0000 (14:33 +0100)
committerJakub Vrana <jakub@vrana.cz>
Mon, 22 Jan 2018 13:33:21 +0000 (14:33 +0100)
adminer/drivers/mysql.inc.php
adminer/drivers/pgsql.inc.php
adminer/drivers/sqlite.inc.php
adminer/include/adminer.inc.php
changes.txt

index 635fe971a38e35220b251da1a1df2d7ed27d5870..e43d3c7e6294e0f5b0769e31656a7b5faf57d94a 100644 (file)
@@ -915,9 +915,10 @@ if (!defined("DRIVER")) {
        /** Get SQL command to create table
        * @param string
        * @param bool
+       * @param string
        * @return string
        */
-       function create_sql($table, $auto_increment) {
+       function create_sql($table, $auto_increment, $style) {
                global $connection;
                $return = $connection->result("SHOW CREATE TABLE " . table($table), 1);
                if (!$auto_increment) {
index 787c6ae9b3c1b778eef69e0dc1fe3582cc2ae4c0..36f1788b0d128ec18ef5b7906442a1337614963a 100644 (file)
@@ -617,7 +617,7 @@ AND typelem = 0"
                return $return;
        }
 
-       function create_sql($table, $auto_increment) {
+       function create_sql($table, $auto_increment, $style) {
                global $connection;
                $return = '';
                $return_parts = array();
@@ -647,7 +647,8 @@ AND typelem = 0"
                        if (preg_match('~nextval\(\'([^\']+)\'\)~', $field['default'], $matches)) {
                                $sequence_name = $matches[1];
                                $sq = reset(get_rows("SELECT * FROM $sequence_name"));
-                               $sequences[] = "CREATE SEQUENCE $sequence_name INCREMENT $sq[increment_by] MINVALUE $sq[min_value] MAXVALUE $sq[max_value] START " . ($auto_increment ? $sq['last_value'] : 1) . " CACHE $sq[cache_value];";
+                               $sequences[] = ($style == "DROP+CREATE" ? "DROP SEQUENCE $sequence_name;\n" : "")
+                                       . "CREATE SEQUENCE $sequence_name INCREMENT $sq[increment_by] MINVALUE $sq[min_value] MAXVALUE $sq[max_value] START " . ($auto_increment ? $sq['last_value'] : 1) . " CACHE $sq[cache_value];";
                        }
                }
 
index 27af882cc30946a5786116b6fa6d5c405940a490..e09c89d3d40ba37e1b46d562d15a09d7c7adad4e 100644 (file)
@@ -715,7 +715,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                return true;
        }
 
-       function create_sql($table, $auto_increment) {
+       function create_sql($table, $auto_increment, $style) {
                global $connection;
                $return = $connection->result("SELECT sql FROM sqlite_master WHERE type IN ('table', 'view') AND name = " . q($table));
                foreach (indexes($table) as $name => $index) {
index fa24f9cf301912e8887b9c01bfdf57e07d09679d..98c3dd61ab43524a272da61c7b9a5eb35faf14e3 100644 (file)
@@ -737,7 +737,7 @@ class Adminer {
                                }
                                $create = "CREATE TABLE " . table($table) . " (" . implode(", ", $fields) . ")";
                        } else {
-                               $create = create_sql($table, $_POST["auto_increment"]);
+                               $create = create_sql($table, $_POST["auto_increment"], $style);
                        }
                        set_utf8mb4($create);
                        if ($style && $create) {
index 51bc4714894235999101d1ebff93414b58d62e68..c3e2565f835cdf515ee3c455d243ca6c21ba2bd8 100644 (file)
@@ -4,6 +4,7 @@ CSP: Allow any styles, images, media and fonts, disallow base-uri
 SQLite: Enable foreign key checks
 PostgreSQL: Respect NULL default value
 PostgreSQL: Do not export triggers if not requested
+PostgreSQL: Export DROP SEQUENCE if dropping table
 Elasticsearch: Insert, update, delete
 
 Adminer 4.4.0 (released 2018-01-17):