Skip to content

Commit

Permalink
Save SQL query to history
Browse files Browse the repository at this point in the history
Display history

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@691 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information
jakubvrana committed Jun 15, 2009
1 parent ec76fad commit cd07584
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
6 changes: 3 additions & 3 deletions adminer/include/functions.inc.php
Expand Up @@ -101,7 +101,7 @@ function query_redirect($query, $location, $message, $redirect = true, $execute
$id = "sql-" . count($_SESSION["messages"]);
$sql = "";
if ($query) {
$sql = " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><span id='$id' class='hidden'><br /><code class='jush-sql'>" . htmlspecialchars($query) . '</code><br /><a href="' . htmlspecialchars($SELF) . 'sql=&amp;history=' . count($_SESSION["history"][$_GET["server"]][$_GET["db"]]) . '">' . lang('Edit') . '</a></span>';
$sql = " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><span id='$id' class='hidden'><br /><code class='jush-sql'>" . htmlspecialchars($query) . '</code><br /><a href="' . htmlspecialchars($SELF . 'sql=&history=' . count($_SESSION["history"][$_GET["server"]][$_GET["db"]])) . '">' . lang('Edit') . '</a></span>';
$_SESSION["history"][$_GET["server"]][$_GET["db"]][] = $query;
}
if ($execute) {
Expand Down Expand Up @@ -230,9 +230,9 @@ function is_utf8($val) {
return (preg_match('~~u', $val) && !preg_match('~[\\0-\\x8\\xB\\xC\\xE-\\x1F]~', $val));
}

function shorten_utf8($string, $length) {
function shorten_utf8($string, $length = 80, $suffix = "") {
preg_match("~^(.{0,$length})(.?)~su", $string, $match);
return htmlspecialchars($match[1]) . ($match[2] ? "<em>...</em>" : "");
return htmlspecialchars($match[1]) . $suffix . ($match[2] ? "<em>...</em>" : "");
}

function friendly_url($val) {
Expand Down
3 changes: 1 addition & 2 deletions adminer/lang/cs.inc.php
Expand Up @@ -57,7 +57,6 @@
'Select' => 'Vypsat',
'New item' => 'Nová položka',
'Search' => 'Vyhledat',
'Sort' => 'Setřídit',
'ASC' => 'vzestupně',
'DESC' => 'sestupně',
'Limit' => 'Limit',
Expand Down Expand Up @@ -196,7 +195,6 @@
'Move' => 'Přesunout',
'Engine' => 'Úložiště',
'Save and continue edit' => 'Uložit a pokračovat v editaci',
'clone' => 'klonovat',
'original' => 'původní',
'%d item(s) have been affected.' => array('Byl ovlivněn %d záznam.', 'Byly ovlivněny %d záznamy.', 'Bylo ovlivněno %d záznamů.'),
'whole result' => 'celý výsledek',
Expand All @@ -215,4 +213,5 @@
'Maximum number of allowed fields exceeded. Please increase %s and %s.' => 'Byl překročen maximální povolený počet polí. Zvyšte prosím %s a %s.',
'(anywhere)' => '(kdekoliv)',
'%.3f s' => '%.3f s',
'History' => 'Historie',
);
17 changes: 16 additions & 1 deletion adminer/sql.inc.php
@@ -1,10 +1,14 @@
<?php
page_header(lang('SQL command'), $error);
$history = &$_SESSION["history"][$_GET["server"]][$_GET["db"]];

if (!$error && $_POST) {
if (is_string($query = (isset($_POST["file"]) ? get_file("sql_file") : $_POST["query"]))) {
@set_time_limit(0);
$query = str_replace("\r", "", $query);
if (strlen($query) && end($history) != $query) {
$history[] = $query;
}
$delimiter = ";";
$offset = 0;
$empty = true;
Expand All @@ -24,7 +28,7 @@
$offset = $match[0][1] + strlen($match[0][0]);
} else {
$empty = false;
echo "<pre class='jush-sql'>" . shorten_utf8(trim(substr($query, 0, $match[0][1])), 100) . "</pre>\n";
echo "<pre class='jush-sql'>" . shorten_utf8(trim(substr($query, 0, $match[0][1]))) . "</pre>\n";
flush();
$start = explode(" ", microtime());
//! don't allow changing of character_set_results, convert encoding of displayed query
Expand Down Expand Up @@ -79,5 +83,16 @@
<input type="hidden" name="token" value="<?php echo $token; ?>" />
<input type="submit" name="file" value="<?php echo lang('Execute'); ?>" />
</p>

<?php
if ($history) {
echo "<fieldset><legend>" . lang('History') . "</legend>\n";
foreach ($history as $key => $val) {
echo '<a href="' . htmlspecialchars($SELF . "sql=&history=$key") . '">' . lang('Edit') . '</a> <code class="jush-sql">' . shorten_utf8(str_replace("\n", " ", $val), 80, "</code>") . "<br />\n";
}
echo "</fieldset>\n";
}
?>

</form>
<?php } ?>
2 changes: 1 addition & 1 deletion changes.txt
Expand Up @@ -4,7 +4,7 @@ Simplify export
Display execution time in SQL query
Relative date and time functions
Version checker
Save queries to history
Save queries to history and display it on SQL page
Ability to select all rows on current page of select
Separate JavaScript functions
Always use the default style before the external one
Expand Down
1 change: 0 additions & 1 deletion todo.txt
Expand Up @@ -5,7 +5,6 @@ MySQL 5 BIT data type
Transactions in export
Compress export and import
Create view and routine options
Visualize SQL queries history
Function to fix database encoding - http://php.vrana.cz/prevod-kodovani-mysql.php
Utilize information_schema.USER_PRIVILEGES in Privileges
Highlight SQL textarea - may use external CodePress
Expand Down

0 comments on commit cd07584

Please sign in to comment.