]> git.joonet.de Git - adminer.git/commitdiff
MS SQL: Set identity_insert in export
authorJakub Vrana <jakub@vrana.cz>
Wed, 26 Feb 2025 12:59:47 +0000 (13:59 +0100)
committerJakub Vrana <jakub@vrana.cz>
Wed, 26 Feb 2025 15:47:24 +0000 (16:47 +0100)
adminer/include/adminer.inc.php

index 645e71c821cdf9ad98b7865af40f57c641ccfb80..a7d8f8d13de8922fc56e8ad222981061582f0e7d 100644 (file)
@@ -825,11 +825,21 @@ class Adminer {
                if ($style) {
                        $max_packet = ($jush == "sqlite" ? 0 : 1048576); // default, minimum is 1024
                        $fields = array();
+                       $identity_insert = false;
                        if ($_POST["format"] == "sql") {
                                if ($style == "TRUNCATE+INSERT") {
                                        echo truncate_sql($table) . ";\n";
                                }
                                $fields = fields($table);
+                               if ($jush == "mssql") {
+                                       foreach ($fields as $field) {
+                                               if ($field["auto_increment"]) {
+                                                       echo "SET IDENTITY_INSERT " . table($table) . " ON;\n";
+                                                       $identity_insert = true;
+                                                       break;
+                                               }
+                                       }
+                               }
                        }
                        $result = $connection->query($query, 1); // 1 - MYSQLI_USE_RESULT //! enum and set as numbers
                        if ($result) {
@@ -892,6 +902,9 @@ class Adminer {
                        } elseif ($_POST["format"] == "sql") {
                                echo "-- " . str_replace("\n", " ", $connection->error) . "\n";
                        }
+                       if ($identity_insert) {
+                               echo "SET IDENTITY_INSERT " . table($table) . " OFF;\n";
+                       }
                }
        }