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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
//! memory consumption, speed
|
||||
//! memory consumption
|
||||
|
||||
function dump_table($table, $style, $is_view = false) {
|
||||
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
|
||||
if ($result) {
|
||||
$fields = fields($table);
|
||||
$length = 0;
|
||||
$insert = "";
|
||||
$buffer = "";
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
if ($_POST["format"] == "csv") {
|
||||
dump_csv($row);
|
||||
} else {
|
||||
if (!$insert) {
|
||||
$insert = "INSERT INTO " . idf_escape($table) . " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ") VALUES";
|
||||
}
|
||||
$row2 = array();
|
||||
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
|
||||
|
@ -122,23 +125,21 @@ function dump_data($table, $style, $select = "") {
|
|||
dump("$insert ($s) ON DUPLICATE KEY UPDATE " . implode(", ", $set) . ";\n");
|
||||
} else {
|
||||
$s = "\n($s)";
|
||||
if (!$length) {
|
||||
dump($insert . $s);
|
||||
$length = strlen($insert) + strlen($s);
|
||||
if (!$buffer) {
|
||||
$buffer = $insert . $s;
|
||||
} else {
|
||||
$length += 1 + strlen($s); // 1 - separator length
|
||||
if ($length < $max_packet) {
|
||||
dump(",$s");
|
||||
if (strlen($buffer) + 1 + strlen($s) < $max_packet) { // 1 - separator length
|
||||
$buffer .= ",$s";
|
||||
} else {
|
||||
dump(";\n$insert$s");
|
||||
$length = strlen($insert) + strlen($s);
|
||||
dump("$buffer;\n");
|
||||
$buffer = $insert . $s;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($_POST["format"] != "csv" && $style != "INSERT+UPDATE" && $result->num_rows) {
|
||||
dump(";\n");
|
||||
if ($_POST["format"] != "csv" && $style != "INSERT+UPDATE" && $buffer) {
|
||||
dump("$buffer;\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -151,8 +152,6 @@ function dump_headers($identifier, $multi_table = false) {
|
|||
if ($_POST["output"] == "file" || $_POST["compress"]) {
|
||||
header("Content-Disposition: attachment; filename=$filename.$ext" . ($_POST["compress"] == "gz" ? ".gz" : ""));
|
||||
}
|
||||
ob_flush();
|
||||
flush();
|
||||
return $ext;
|
||||
}
|
||||
|
||||
|
|
|
@ -360,14 +360,9 @@ function process_input($field) {
|
|||
}
|
||||
}
|
||||
|
||||
function dump($string = null) { // null $string forces sending of buffer
|
||||
static $buffer = "";
|
||||
function dump($string) {
|
||||
if ($_POST["compress"] == "gz") {
|
||||
$buffer .= $string;
|
||||
if (!isset($string) || strlen($buffer) > 1e6) {
|
||||
echo gzencode($buffer);
|
||||
$buffer = "";
|
||||
}
|
||||
echo gzencode($string);
|
||||
} else {
|
||||
echo $string;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,6 @@ if ($_POST && !$error) {
|
|||
}
|
||||
dump_data($_GET["select"], "INSERT", implode(" UNION ALL ", $union));
|
||||
}
|
||||
dump();
|
||||
exit;
|
||||
}
|
||||
if (!$adminer->selectEmailProcess($where)) {
|
||||
|
|
Loading…
Reference in a new issue