Permalink
Browse files

Save SQL query to history

Display history

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@691 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent ec76fad commit cd0758422e946230628165aa894d44e186169506 jakubvrana committed Jun 15, 2009
Showing with 21 additions and 8 deletions.
  1. +3 −3 adminer/include/functions.inc.php
  2. +1 −2 adminer/lang/cs.inc.php
  3. +16 −1 adminer/sql.inc.php
  4. +1 −1 changes.txt
  5. +0 −1 todo.txt
@@ -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) {
@@ -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) {
View
@@ -57,7 +57,6 @@
'Select' => 'Vypsat',
'New item' => 'Nová položka',
'Search' => 'Vyhledat',
- 'Sort' => 'Setřídit',
'ASC' => 'vzestupně',
'DESC' => 'sestupně',
'Limit' => 'Limit',
@@ -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',
@@ -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',
);
View
@@ -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;
@@ -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
@@ -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 } ?>
View
@@ -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
View
@@ -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

0 comments on commit cd07584

Please sign in to comment.