Save memory
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1018 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
e75ef01c2c
commit
1f09dd31d6
|
@ -8,9 +8,13 @@ if (!$error && $_POST["clear"]) {
|
||||||
page_header(lang('SQL command'), $error);
|
page_header(lang('SQL command'), $error);
|
||||||
|
|
||||||
if (!$error && $_POST) {
|
if (!$error && $_POST) {
|
||||||
$query = ($_POST["webfile"] ? @file_get_contents("adminer.sql") : ($_POST["file"] ? get_file("sql_file") : $_POST["query"]));
|
$query = $_POST["query"];
|
||||||
|
if ($_POST["webfile"]) {
|
||||||
|
$query = @file_get_contents("adminer.sql");
|
||||||
|
} elseif ($_POST["file"]) {
|
||||||
|
$query = get_file("sql_file");
|
||||||
|
}
|
||||||
if (is_string($query)) { // get_file() returns error as number, file_get_contents as false
|
if (is_string($query)) { // get_file() returns error as number, file_get_contents as false
|
||||||
$query = rtrim($query);
|
|
||||||
if (strlen($query) && (!$history || end($history) != $query)) { // don't add repeated
|
if (strlen($query) && (!$history || end($history) != $query)) { // don't add repeated
|
||||||
$history[] = $query;
|
$history[] = $query;
|
||||||
}
|
}
|
||||||
|
@ -30,24 +34,10 @@ if (!$error && $_POST) {
|
||||||
preg_match('(' . preg_quote($delimiter) . '|[\'`"]|/\\*|-- |#|$)', $query, $match, PREG_OFFSET_CAPTURE, $offset); // should always match
|
preg_match('(' . preg_quote($delimiter) . '|[\'`"]|/\\*|-- |#|$)', $query, $match, PREG_OFFSET_CAPTURE, $offset); // should always match
|
||||||
$found = $match[0][0];
|
$found = $match[0][0];
|
||||||
$offset = $match[0][1] + strlen($found);
|
$offset = $match[0][1] + strlen($found);
|
||||||
if ($found && $found != $delimiter) {
|
if (!$found && !strlen(rtrim($query))) {
|
||||||
// is not end of a query - find closing part
|
break;
|
||||||
if (ereg('/\\*|-- |#', $found)) {
|
}
|
||||||
$offset = strpos($query, ($found == "/*" ? "*/" : "\n"), $offset);
|
if (!$found || $found == $delimiter) { // end of a query
|
||||||
if (!$offset) {
|
|
||||||
$offset = strlen($query);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// find matching quote
|
|
||||||
while (preg_match("~$found|\\\\.|\$~s", $query, $match, PREG_OFFSET_CAPTURE, $offset)) {
|
|
||||||
$s = $match[0][0];
|
|
||||||
$offset = $match[0][1] + strlen($s);
|
|
||||||
if (!$s || $s == $found) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$empty = false;
|
$empty = false;
|
||||||
echo "<pre class='jush-sql'>" . shorten_utf8(trim(substr($query, 0, $match[0][1]))) . "</pre>\n";
|
echo "<pre class='jush-sql'>" . shorten_utf8(trim(substr($query, 0, $match[0][1]))) . "</pre>\n";
|
||||||
ob_flush();
|
ob_flush();
|
||||||
|
@ -80,6 +70,19 @@ if (!$error && $_POST) {
|
||||||
}
|
}
|
||||||
$query = substr($query, $offset);
|
$query = substr($query, $offset);
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
|
} elseif (ereg('/\\*|-- |#', $found)) { // find closing part
|
||||||
|
$offset = strpos($query, ($found == "/*" ? "*/" : "\n"), $offset);
|
||||||
|
if (!$offset) {
|
||||||
|
$offset = strlen($query);
|
||||||
|
}
|
||||||
|
} else { // find matching quote
|
||||||
|
while (preg_match("~$found|\\\\.|\$~s", $query, $match, PREG_OFFSET_CAPTURE, $offset)) {
|
||||||
|
$s = $match[0][0];
|
||||||
|
$offset = $match[0][1] + strlen($s);
|
||||||
|
if (!$s || $s == $found) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +118,7 @@ if ($history) {
|
||||||
echo "<fieldset><legend>" . lang('History') . "</legend>\n";
|
echo "<fieldset><legend>" . lang('History') . "</legend>\n";
|
||||||
foreach ($history as $key => $val) {
|
foreach ($history as $key => $val) {
|
||||||
//! save and display timestamp
|
//! save and display timestamp
|
||||||
echo '<a href="' . h(ME . "sql=&history=$key") . '">' . lang('Edit') . '</a> <code class="jush-sql">' . shorten_utf8(ltrim(str_replace("\n", " ", preg_replace('~^(#|-- ).*~m', '', $val))), 80, "</code>") . "<br>\n";
|
echo '<a href="' . h(ME . "sql=&history=$key") . '">' . lang('Edit') . '</a> <code class="jush-sql">' . shorten_utf8(ltrim(str_replace("\n", " ", str_replace("\r", "", preg_replace('~^(#|-- ).*~m', '', $val)))), 80, "</code>") . "<br>\n";
|
||||||
}
|
}
|
||||||
echo "<input type='submit' name='clear' value='" . lang('Clear') . "'>\n";
|
echo "<input type='submit' name='clear' value='" . lang('Clear') . "'>\n";
|
||||||
echo "</fieldset>\n";
|
echo "</fieldset>\n";
|
||||||
|
|
1
todo.txt
1
todo.txt
|
@ -5,6 +5,7 @@ Highlight found fields
|
||||||
MySQL 5 BIT data type
|
MySQL 5 BIT data type
|
||||||
Transactions in export
|
Transactions in export
|
||||||
Compress export and import
|
Compress export and import
|
||||||
|
SQL query and CSV import - read file progressively to save memory
|
||||||
Create view and routine options
|
Create view and routine options
|
||||||
Function to fix database encoding - http://php.vrana.cz/prevod-kodovani-mysql.php
|
Function to fix database encoding - http://php.vrana.cz/prevod-kodovani-mysql.php
|
||||||
Highlight SQL textarea - may use external CodePress
|
Highlight SQL textarea - may use external CodePress
|
||||||
|
|
Loading…
Reference in a new issue