Optimize export speed
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1033 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
25f01d352a
commit
8fe1aa0161
|
@ -146,7 +146,6 @@ DROP PROCEDURE adminer_drop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dump();
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
//! memory consumption, speed
|
//! memory consumption
|
||||||
|
|
||||||
function dump_table($table, $style, $is_view = false) {
|
function dump_table($table, $style, $is_view = false) {
|
||||||
global $dbh;
|
global $dbh;
|
||||||
|
@ -103,12 +103,15 @@ function dump_data($table, $style, $select = "") {
|
||||||
$result = $dbh->query(($select ? $select : "SELECT * FROM " . idf_escape($table))); //! enum and set as numbers, microtime
|
$result = $dbh->query(($select ? $select : "SELECT * FROM " . idf_escape($table))); //! enum and set as numbers, microtime
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$fields = fields($table);
|
$fields = fields($table);
|
||||||
$length = 0;
|
$insert = "";
|
||||||
|
$buffer = "";
|
||||||
while ($row = $result->fetch_assoc()) {
|
while ($row = $result->fetch_assoc()) {
|
||||||
if ($_POST["format"] == "csv") {
|
if ($_POST["format"] == "csv") {
|
||||||
dump_csv($row);
|
dump_csv($row);
|
||||||
} else {
|
} else {
|
||||||
$insert = "INSERT INTO " . idf_escape($table) . " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ") VALUES";
|
if (!$insert) {
|
||||||
|
$insert = "INSERT INTO " . idf_escape($table) . " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ") VALUES";
|
||||||
|
}
|
||||||
$row2 = array();
|
$row2 = array();
|
||||||
foreach ($row as $key => $val) {
|
foreach ($row as $key => $val) {
|
||||||
$row2[$key] = (isset($val) ? (ereg('int|float|double|decimal', $fields[$key]["type"]) ? $val : $dbh->quote($val)) : "NULL"); //! columns looking like functions
|
$row2[$key] = (isset($val) ? (ereg('int|float|double|decimal', $fields[$key]["type"]) ? $val : $dbh->quote($val)) : "NULL"); //! columns looking like functions
|
||||||
|
@ -122,23 +125,21 @@ function dump_data($table, $style, $select = "") {
|
||||||
dump("$insert ($s) ON DUPLICATE KEY UPDATE " . implode(", ", $set) . ";\n");
|
dump("$insert ($s) ON DUPLICATE KEY UPDATE " . implode(", ", $set) . ";\n");
|
||||||
} else {
|
} else {
|
||||||
$s = "\n($s)";
|
$s = "\n($s)";
|
||||||
if (!$length) {
|
if (!$buffer) {
|
||||||
dump($insert . $s);
|
$buffer = $insert . $s;
|
||||||
$length = strlen($insert) + strlen($s);
|
|
||||||
} else {
|
} else {
|
||||||
$length += 1 + strlen($s); // 1 - separator length
|
if (strlen($buffer) + 1 + strlen($s) < $max_packet) { // 1 - separator length
|
||||||
if ($length < $max_packet) {
|
$buffer .= ",$s";
|
||||||
dump(",$s");
|
|
||||||
} else {
|
} else {
|
||||||
dump(";\n$insert$s");
|
dump("$buffer;\n");
|
||||||
$length = strlen($insert) + strlen($s);
|
$buffer = $insert . $s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($_POST["format"] != "csv" && $style != "INSERT+UPDATE" && $result->num_rows) {
|
if ($_POST["format"] != "csv" && $style != "INSERT+UPDATE" && $buffer) {
|
||||||
dump(";\n");
|
dump("$buffer;\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,8 +152,6 @@ function dump_headers($identifier, $multi_table = false) {
|
||||||
if ($_POST["output"] == "file" || $_POST["compress"]) {
|
if ($_POST["output"] == "file" || $_POST["compress"]) {
|
||||||
header("Content-Disposition: attachment; filename=$filename.$ext" . ($_POST["compress"] == "gz" ? ".gz" : ""));
|
header("Content-Disposition: attachment; filename=$filename.$ext" . ($_POST["compress"] == "gz" ? ".gz" : ""));
|
||||||
}
|
}
|
||||||
ob_flush();
|
|
||||||
flush();
|
|
||||||
return $ext;
|
return $ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -360,14 +360,9 @@ function process_input($field) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function dump($string = null) { // null $string forces sending of buffer
|
function dump($string) {
|
||||||
static $buffer = "";
|
|
||||||
if ($_POST["compress"] == "gz") {
|
if ($_POST["compress"] == "gz") {
|
||||||
$buffer .= $string;
|
echo gzencode($string);
|
||||||
if (!isset($string) || strlen($buffer) > 1e6) {
|
|
||||||
echo gzencode($buffer);
|
|
||||||
$buffer = "";
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
echo $string;
|
echo $string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,6 @@ if ($_POST && !$error) {
|
||||||
}
|
}
|
||||||
dump_data($_GET["select"], "INSERT", implode(" UNION ALL ", $union));
|
dump_data($_GET["select"], "INSERT", implode(" UNION ALL ", $union));
|
||||||
}
|
}
|
||||||
dump();
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
if (!$adminer->selectEmailProcess($where)) {
|
if (!$adminer->selectEmailProcess($where)) {
|
||||||
|
|
Loading…
Reference in a new issue