]> git.joonet.de Git - adminer.git/commitdiff
MS SQL: Support export
authorJakub Vrana <jakub@vrana.cz>
Wed, 26 Feb 2025 12:37:58 +0000 (13:37 +0100)
committerJakub Vrana <jakub@vrana.cz>
Wed, 26 Feb 2025 15:47:18 +0000 (16:47 +0100)
adminer/drivers/mssql.inc.php
adminer/dump.inc.php
adminer/include/editing.inc.php
changes.txt

index 035efdbfa46b68eaea09cac84bcdcd7ab8dd79b8..562b33ad5149c533bbc7d93943c0272f5aba4677 100644 (file)
@@ -654,10 +654,56 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)
                return true; // ALTER USER is permanent
        }
 
+       function create_sql($table, $auto_increment, $style) {
+               global $driver;
+               if (is_view(table_status($table))) {
+                       $view = view($table);
+                       return "CREATE VIEW " . table($table) . " AS $view[select]";
+               }
+               $fields = array();
+               $primary = false;
+               foreach (fields($table) as $name => $field) {
+                       $val = process_field($field, $field);
+                       if ($val[6]) {
+                               $primary = true;
+                       }
+                       $fields[] = implode("", $val);
+               }
+               foreach (indexes($table) as $name => $index) {
+                       if (!$primary || $index["type"] != "PRIMARY") {
+                               $columns = array();
+                               foreach ($index["columns"] as $key => $val) {
+                                       $columns[] = idf_escape($val) . ($index["descs"][$key] ? " DESC" : "");
+                               }
+                               $name = idf_escape($name);
+                               $fields[] = ($index["type"] == "INDEX" ? "INDEX $name" : "CONSTRAINT $name " . ($index["type"] == "UNIQUE" ? "UNIQUE" : "PRIMARY KEY")) . " (" . implode(", ", $columns) . ")";
+                       }
+               }
+               foreach (foreign_keys($table) as $foreign) {
+                       $fields[] = ltrim(format_foreign_key($foreign));
+               }
+               foreach ($driver->checkConstraints($table) as $name => $check) {
+                       $fields[] = "CONSTRAINT " . idf_escape($name) . " CHECK ($check)";
+               }
+               return "CREATE TABLE " . table($table) . " (\n\t" . implode(",\n\t", $fields) . "\n)";
+       }
+
+       function truncate_sql($table) {
+               return "TRUNCATE TABLE " . table($table);
+       }
+
        function use_sql($database) {
                return "USE " . idf_escape($database);
        }
 
+       function trigger_sql($table) {
+               $return = "";
+               foreach (triggers($table) as $name => $trigger) {
+                       $return .= create_trigger(" ON " . table($table), trigger($name)) . ";";
+               }
+               return $return;
+       }
+
        function show_variables() {
                return array();
        }
@@ -674,7 +720,7 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)
        }
 
        function support($feature) {
-               return preg_match('~^(check|comment|columns|database|drop_col|indexes|descidx|scheme|sql|table|trigger|view|view_trigger)$~', $feature); //! routine|
+               return preg_match('~^(check|comment|columns|database|drop_col|dump|indexes|descidx|scheme|sql|table|trigger|view|view_trigger)$~', $feature); //! routine|
        }
 
        function driver_config() {
index d79793b5cc54251d4e9f0faef0b7e17ab1cd10e6..951e2f32405032d325f0d0ebc1227022b1038d01 100644 (file)
@@ -126,7 +126,7 @@ SET foreign_key_checks = 0;
        }
 
        if ($is_sql) {
-               echo "-- " . $connection->result("SELECT NOW()") . "\n";
+               echo "-- " . gmdate("Y-m-d H:i:s e") . "\n";
        }
        exit;
 }
index 337669888b04de61a0be30438ceb163c8a158af1..2f53b83d41a0b14d661ded2bda789593dc45cb86 100644 (file)
@@ -266,11 +266,11 @@ function process_length($length) {
 * @return string
 */
 function process_type($field, $collate = "COLLATE") {
-       global $unsigned;
+       global $unsigned, $jush;
        return " $field[type]"
                . process_length($field["length"])
                . (preg_match(number_type(), $field["type"]) && in_array($field["unsigned"], $unsigned) ? " $field[unsigned]" : "")
-               . (preg_match('~char|text|enum|set~', $field["type"]) && $field["collation"] ? " $collate " . q($field["collation"]) : "")
+               . (preg_match('~char|text|enum|set~', $field["type"]) && $field["collation"] ? " $collate " . ($jush == "mssql" ? $field["collation"] : q($field["collation"])) : "")
        ;
 }
 
index fac9152550ff2c8c258144a7ae0bd08c93ab6b19..5e61d6d7422e9d2e244feb4640f45420fcf0878f 100644 (file)
@@ -3,6 +3,7 @@ SQLite: Support CHECK constraint
 SQLite: Add command Check tables
 SQLite: Display all rows of variable values
 SQLite: Remove support for SQLite version 2
+MS SQL: Support export (bug #480)
 MongoDB: Remove support for deprecated extension mongo
 
 Adminer-4.17.1 (released 2025-02-25):