]> git.joonet.de Git - adminer.git/commitdiff
Driver specific trigger export
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 5 May 2010 16:28:37 +0000 (16:28 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 5 May 2010 16:28:37 +0000 (16:28 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1519 7c3ca157-0c34-0410-bff1-cbf682f78f5c

adminer/drivers/mysql.inc.php
adminer/drivers/sqlite.inc.php
adminer/dump.inc.php
adminer/include/export.inc.php
todo.txt

index c0dc2e41120956c63eb9678d6c52aff99b34541f..96e146721495336b4171d9397f5c996722376104 100644 (file)
@@ -770,6 +770,24 @@ if (!defined("DRIVER")) {
                return "USE " . idf_escape($database);
        }
        
+       /** Get SQL commands to create triggers
+       * @param string
+       * @param string
+       * @return string
+       */
+       function trigger_sql($table, $style) {
+               global $connection;
+               $result = $connection->query("SHOW TRIGGERS LIKE " . $connection->quote(addcslashes($table, "%_")));
+               $return = "";
+               if ($result->num_rows) {
+                       while ($row = $result->fetch_assoc()) {
+                               $return .= "\n" . ($style == 'CREATE+ALTER' ? "DROP TRIGGER IF EXISTS " . idf_escape($row["Trigger"]) . ";;\n" : "")
+                               . "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . idf_escape($row["Table"]) . " FOR EACH ROW\n$row[Statement];;\n";
+                       }
+               }
+               return $return;
+       }
+       
        /** Get server variables
        * @return array ($name => $value)
        */
index 028b0e5d4034244a47f38b49e90cd266f65014c8..785401e1a7836ed803849b80fd7c4cce98002b3e 100644 (file)
@@ -498,7 +498,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
        
        function create_sql($table) {
                global $connection;
-               return $connection->result("SELECT sql FROM sqlite_master WHERE name = " . $connection->quote($table));
+               return $connection->result("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = " . $connection->quote($table));
        }
        
        function use_sql($database) {
@@ -506,6 +506,11 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                return "ATTACH " . $connection->quote($database) . " AS " . idf_escape($database);
        }
        
+       function trigger_sql($table, $style) {
+               global $connection;
+               return implode("", get_vals("SELECT sql || ';;\n' FROM sqlite_master WHERE type = 'trigger' AND name = " . $connection->quote($table)));
+       }
+       
        function show_variables() {
                global $connection;
                $return = array();
index 28a2d8a78f96eb312db4fd94205b5262d7ec90c1..22d6680716f1d97f9923c01ac9d2aa3808ae9871 100644 (file)
@@ -80,8 +80,11 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
                                                        if ($data) {
                                                                dump_data($row["Name"], $_POST["data_style"]);
                                                        }
-                                                       if ($_POST["triggers"]) {
-                                                               dump_triggers($row["Name"], $_POST["table_style"]);
+                                                       if ($_POST["format"] == "sql" && $_POST["triggers"]) {
+                                                               $triggers = trigger_sql($row["Name"], $_POST["table_style"]);
+                                                               if ($triggers) {
+                                                                       echo "\nDELIMITER ;;\n$triggers\nDELIMITER ;\n";
+                                                               }
                                                        }
                                                        if ($ext == "tar") {
                                                                echo tar_file((DB != "" ? "" : "$db/") . "$row[Name].csv", ob_get_clean());
index e0b4797dd35d15c381007562a7f252fcf71f7cfb..6cfa41a8368c61237a5442c7c3409cd9f235f5d1 100644 (file)
@@ -9,21 +9,6 @@ function tar_file($filename, $contents) {
        return $return . str_repeat("\0", 512 - strlen($return)) . $contents . str_repeat("\0", 511 - (strlen($contents) + 511) % 512);
 }
 
-function dump_triggers($table, $style) {
-       global $connection;
-       if ($_POST["format"] == "sql" && $style && support("trigger")) {
-               $result = $connection->query("SHOW TRIGGERS LIKE " . $connection->quote(addcslashes($table, "%_")));
-               if ($result->num_rows) {
-                       $s = "\nDELIMITER ;;\n";
-                       while ($row = $result->fetch_assoc()) {
-                               $s .= "\n" . ($style == 'CREATE+ALTER' ? "DROP TRIGGER IF EXISTS " . idf_escape($row["Trigger"]) . ";;\n" : "")
-                               . "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . idf_escape($row["Table"]) . " FOR EACH ROW\n$row[Statement];;\n";
-                       }
-                       echo "$s\nDELIMITER ;\n";
-               }
-       }
-}
-
 function dump_table($table, $style, $is_view = false) {
        global $connection;
        if ($_POST["format"] != "sql") {
index 4beb904cea23ba564de88a4a4228eb52061809cf..c145be74a786c5ec3f5603d11491e9166fa046e9 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -28,7 +28,7 @@ Saving of MySQL 5 BIT data type - don't use quote()
 
 SQLite:
 CSV import - ON DUPLICATE KEY UPDATE
-Export - triggers, CREATE DATABASE
+Export - CREATE DATABASE
 Delimiter in export and SQL command
 Backward keys in Editor