CSV Byte-order-mark
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@448 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
9890b6c22d
commit
f48161b43e
47
dump.inc.php
47
dump.inc.php
|
@ -1,50 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
include "./export.inc.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) {
|
function dump_routines($db) {
|
||||||
global $mysql;
|
global $mysql;
|
||||||
if ($mysql->server_info >= 5) {
|
if ($_POST["format"] != "csv" && $mysql->server_info >= 5) {
|
||||||
$out = "";
|
$out = "";
|
||||||
foreach (array("FUNCTION", "PROCEDURE") as $routine) {
|
foreach (array("FUNCTION", "PROCEDURE") as $routine) {
|
||||||
$result = $mysql->query("SHOW $routine STATUS WHERE Db = '" . $mysql->escape_string($db) . "'");
|
$result = $mysql->query("SHOW $routine STATUS WHERE Db = '" . $mysql->escape_string($db) . "'");
|
||||||
|
@ -87,13 +46,12 @@ function dump($db, $style) {
|
||||||
if ($_POST["format"] == "csv") {
|
if ($_POST["format"] == "csv") {
|
||||||
echo tar_file("$db/$row[Name].csv", ob_get_clean());
|
echo tar_file("$db/$row[Name].csv", ob_get_clean());
|
||||||
}
|
}
|
||||||
} else {
|
} elseif ($_POST["format"] != "csv") {
|
||||||
$views[] = $row["Name"];
|
$views[] = $row["Name"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$result->free();
|
$result->free();
|
||||||
}
|
}
|
||||||
if ($_POST["format"] != "csv") {
|
|
||||||
foreach ($views as $view) {
|
foreach ($views as $view) {
|
||||||
dump_table($view, $_POST["tables"][0]);
|
dump_table($view, $_POST["tables"][0]);
|
||||||
}
|
}
|
||||||
|
@ -101,7 +59,6 @@ function dump($db, $style) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function tar_file($filename, $contents) {
|
function tar_file($filename, $contents) {
|
||||||
$return = pack("a100a8a8a8a12a12", $filename, 644, 0, 0, decoct(strlen($contents)), decoct(time()));
|
$return = pack("a100a8a8a8a12a12", $filename, 644, 0, 0, decoct(strlen($contents)), decoct(time()));
|
||||||
|
|
|
@ -8,6 +8,48 @@ function dump_csv($row) {
|
||||||
echo implode(",", $row) . "\n";
|
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 = "") {
|
function dump_data($table, $style, $from = "") {
|
||||||
global $mysql, $max_packet;
|
global $mysql, $max_packet;
|
||||||
if ($style) {
|
if ($style) {
|
||||||
|
@ -52,9 +94,11 @@ function dump_data($table, $style, $from = "") {
|
||||||
}
|
}
|
||||||
$result->free();
|
$result->free();
|
||||||
}
|
}
|
||||||
|
if ($_POST["format"] != "csv") {
|
||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function dump_headers($identifier, $multi_table = false) {
|
function dump_headers($identifier, $multi_table = false) {
|
||||||
$filename = (strlen($identifier) ? preg_replace('~[^a-z0-9_]~i', '-', $identifier) : "dump");
|
$filename = (strlen($identifier) ? preg_replace('~[^a-z0-9_]~i', '-', $identifier) : "dump");
|
||||||
|
|
|
@ -65,6 +65,7 @@ if ($_POST && !$error) {
|
||||||
$deleted = 0;
|
$deleted = 0;
|
||||||
if ($_POST["export"] || $_POST["export_result"]) {
|
if ($_POST["export"] || $_POST["export_result"]) {
|
||||||
dump_headers($_GET["select"]);
|
dump_headers($_GET["select"]);
|
||||||
|
dump_table($_GET["select"], "");
|
||||||
}
|
}
|
||||||
if (isset($_POST["truncate"])) {
|
if (isset($_POST["truncate"])) {
|
||||||
$result = $mysql->query($where ? "DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : "TRUNCATE " . idf_escape($_GET["select"]));
|
$result = $mysql->query($where ? "DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : "TRUNCATE " . idf_escape($_GET["select"]));
|
||||||
|
|
Loading…
Reference in a new issue