]> git.joonet.de Git - adminer.git/commitdiff
CSV Byte-order-mark
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Mon, 18 Aug 2008 22:40:45 +0000 (22:40 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Mon, 18 Aug 2008 22:40:45 +0000 (22:40 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@448 7c3ca157-0c34-0410-bff1-cbf682f78f5c

dump.inc.php
export.inc.php
select.inc.php

index c90d18044a09d4a4b626ec120b51df5fdcce546a..ac9e5b7d2a0358c7d9260538ce164ec97092f2a9 100644 (file)
@@ -1,50 +1,9 @@
 <?php
 include "./export.inc.php";
 
-function dump_table($table, $style) {
-       global $mysql, $max_packet, $types;
-       if ($style) {
-               if ($_POST["format"] == "csv") {
-                       dump_csv(array_keys(fields($table)));
-               } else {
-                       $result = $mysql->query("SHOW CREATE TABLE " . idf_escape($table));
-                       if ($result) {
-                               if ($style == "DROP, CREATE") {
-                                       echo "DROP TABLE " . idf_escape($table) . ";\n";
-                               }
-                               $create = $mysql->result($result, 1);
-                               echo ($style == "CREATE, ALTER" ? preg_replace('~^CREATE TABLE ~', '\\0IF NOT EXISTS ', $create) : $create) . ";\n\n";
-                               if ($max_packet < 1073741824) { // protocol limit
-                                       $row_size = 21 + strlen(idf_escape($table));
-                                       foreach (fields($table) as $field) {
-                                               $type = $types[$field["type"]];
-                                               $row_size += 5 + ($field["length"] ? $field["length"] : $type) * (preg_match('~char|text|enum~', $field["type"]) ? 3 : 1); // UTF-8 in MySQL uses up to 3 bytes
-                                       }
-                                       if ($row_size > $max_packet) {
-                                               $max_packet = 1024 * ceil($row_size / 1024);
-                                               echo "SET max_allowed_packet = $max_packet, GLOBAL max_allowed_packet = $max_packet;\n";
-                                       }
-                               }
-                               $result->free();
-                       }
-                       if ($mysql->server_info >= 5) {
-                               $result = $mysql->query("SHOW TRIGGERS LIKE '" . $mysql->escape_string(addcslashes($table, "%_")) . "'");
-                               if ($result->num_rows) {
-                                       echo "DELIMITER ;;\n\n";
-                                       while ($row = $result->fetch_assoc()) {
-                                               echo "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . idf_escape($row["Table"]) . " FOR EACH ROW $row[Statement];;\n\n";
-                                       }
-                                       echo "DELIMITER ;\n\n";
-                               }
-                               $result->free();
-                       }
-               }
-       }
-}
-
 function dump_routines($db) {
        global $mysql;
-       if ($mysql->server_info >= 5) {
+       if ($_POST["format"] != "csv" && $mysql->server_info >= 5) {
                $out = "";
                foreach (array("FUNCTION", "PROCEDURE") as $routine) {
                        $result = $mysql->query("SHOW $routine STATUS WHERE Db = '" . $mysql->escape_string($db) . "'");
@@ -87,18 +46,16 @@ function dump($db, $style) {
                                                if ($_POST["format"] == "csv") {
                                                        echo tar_file("$db/$row[Name].csv", ob_get_clean());
                                                }
-                                       } else {
+                                       } elseif ($_POST["format"] != "csv") {
                                                $views[] = $row["Name"];
                                        }
                                }
                                $result->free();
                        }
-                       if ($_POST["format"] != "csv") {
-                               foreach ($views as $view) {
-                                       dump_table($view, $_POST["tables"][0]);
-                               }
-                               dump_routines($db);
+                       foreach ($views as $view) {
+                               dump_table($view, $_POST["tables"][0]);
                        }
+                       dump_routines($db);
                }
        }
 }
index 1f6c3bd6e8b1ce5e8165dfb083366dea04c8963c..f73fd5598abcdff5be7a2099fb5f4d340804feea 100644 (file)
@@ -8,6 +8,48 @@ function dump_csv($row) {
        echo implode(",", $row) . "\n";
 }
 
+function dump_table($table, $style) {
+       global $mysql, $max_packet, $types;
+       if ($_POST["format"] == "csv") {
+               echo "\xef\xbb\xbf";
+               if ($style) {
+                       dump_csv(array_keys(fields($table)));
+               }
+       } elseif ($style) {
+               $result = $mysql->query("SHOW CREATE TABLE " . idf_escape($table));
+               if ($result) {
+                       if ($style == "DROP, CREATE") {
+                               echo "DROP TABLE " . idf_escape($table) . ";\n";
+                       }
+                       $create = $mysql->result($result, 1);
+                       echo ($style == "CREATE, ALTER" ? preg_replace('~^CREATE TABLE ~', '\\0IF NOT EXISTS ', $create) : $create) . ";\n\n";
+                       if ($max_packet < 1073741824) { // protocol limit
+                               $row_size = 21 + strlen(idf_escape($table));
+                               foreach (fields($table) as $field) {
+                                       $type = $types[$field["type"]];
+                                       $row_size += 5 + ($field["length"] ? $field["length"] : $type) * (preg_match('~char|text|enum~', $field["type"]) ? 3 : 1); // UTF-8 in MySQL uses up to 3 bytes
+                               }
+                               if ($row_size > $max_packet) {
+                                       $max_packet = 1024 * ceil($row_size / 1024);
+                                       echo "SET max_allowed_packet = $max_packet, GLOBAL max_allowed_packet = $max_packet;\n";
+                               }
+                       }
+                       $result->free();
+               }
+               if ($mysql->server_info >= 5) {
+                       $result = $mysql->query("SHOW TRIGGERS LIKE '" . $mysql->escape_string(addcslashes($table, "%_")) . "'");
+                       if ($result->num_rows) {
+                               echo "DELIMITER ;;\n\n";
+                               while ($row = $result->fetch_assoc()) {
+                                       echo "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . idf_escape($row["Table"]) . " FOR EACH ROW $row[Statement];;\n\n";
+                               }
+                               echo "DELIMITER ;\n\n";
+                       }
+                       $result->free();
+               }
+       }
+}
+
 function dump_data($table, $style, $from = "") {
        global $mysql, $max_packet;
        if ($style) {
@@ -52,7 +94,9 @@ function dump_data($table, $style, $from = "") {
                        }
                        $result->free();
                }
-               echo "\n";
+               if ($_POST["format"] != "csv") {
+                       echo "\n";
+               }
        }
 }
 
index 5fe586b48224f43a62e283ebdd9ca3da938528ae..d5681495529632aeb58c181f3f2e7521d7ff563f 100644 (file)
@@ -65,6 +65,7 @@ if ($_POST && !$error) {
        $deleted = 0;
        if ($_POST["export"] || $_POST["export_result"]) {
                dump_headers($_GET["select"]);
+               dump_table($_GET["select"], "");
        }
        if (isset($_POST["truncate"])) {
                $result = $mysql->query($where ? "DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : "TRUNCATE " . idf_escape($_GET["select"]));