From 4cfe6263d9daa7c3924e8edb9b2c48dc7db35ad9 Mon Sep 17 00:00:00 2001 From: Mathieu Rochette Date: Wed, 11 Mar 2015 17:52:11 +0100 Subject: [PATCH] fix logger for SQL commands --- adminer/include/adminer.inc.php | 9 +++++++++ adminer/sql.inc.php | 2 +- plugins/plugin.php | 5 +++++ plugins/sql-log.php | 8 ++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 3028e7d5..c6ceedd7 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -197,6 +197,15 @@ focus(document.getElementById('username')); ; } + /** Query printed in SQL command before execution + * @param string query to be executed + * @return string escaped query to be printed + */ + function sqlCommandQuery($query) + { + return shorten_utf8(trim($query), 1000); + } + /** Description of a row in a table * @param string * @return string SQL expression, empty string for no description diff --git a/adminer/sql.inc.php b/adminer/sql.inc.php index fbecbfb2..296cfc56 100644 --- a/adminer/sql.inc.php +++ b/adminer/sql.inc.php @@ -93,7 +93,7 @@ if (!$error && $_POST) { $empty = false; $q = substr($query, 0, $pos); $commands++; - $print = "
" . shorten_utf8(trim($q), 1000) . "
\n"; + $print = "
" . $adminer->sqlCommandQuery($q) . "
\n"; if ($jush == "sqlite" && preg_match("~^$space*+ATTACH\\b~i", $q, $match)) { // PHP doesn't support setting SQLITE_LIMIT_ATTACHED echo $print; diff --git a/plugins/plugin.php b/plugins/plugin.php index aae72c35..de26f4dc 100644 --- a/plugins/plugin.php +++ b/plugins/plugin.php @@ -177,6 +177,11 @@ class AdminerPlugin extends Adminer { return $this->_applyPlugin(__FUNCTION__, $args); } + function sqlCommandQuery($query) { + $args = func_get_args(); + return $this->_applyPlugin(__FUNCTION__, $args); + } + function rowDescription($table) { $args = func_get_args(); return $this->_applyPlugin(__FUNCTION__, $args); diff --git a/plugins/sql-log.php b/plugins/sql-log.php index 2c5f2d5f..757adc0d 100644 --- a/plugins/sql-log.php +++ b/plugins/sql-log.php @@ -18,6 +18,14 @@ class AdminerSqlLog { } function messageQuery($query, $time) { + $this->_log($query); + } + + function sqlCommandQuery($query) { + $this->_log($query); + } + + function _log($query) { if ($this->filename == "") { $adminer = adminer(); $this->filename = $adminer->database() . ".sql"; // no database goes to ".sql" to avoid collisions