diff --git a/public_html/media/css/core.css b/public_html/media/css/core.css
index 217df23f..0e062fbd 100644
--- a/public_html/media/css/core.css
+++ b/public_html/media/css/core.css
@@ -391,14 +391,6 @@ ul.tagit input {
margin: -1px 0 0 0;
}
-pre.debug {
- margin-left: 1em;
- text-align: left;
- color: black;
- white-space: normal;
- text-indent: -1em;
-}
-
.spoiler:before,
.spoiler:after {
color: gray;
diff --git a/public_html/media/css/debug.css b/public_html/media/css/debug.css
new file mode 100644
index 00000000..a93f0a94
--- /dev/null
+++ b/public_html/media/css/debug.css
@@ -0,0 +1,30 @@
+div.debug {
+ background: #f5f5f5;
+ font-size: 90%;
+ margin: 1em 0;
+ padding: 1em;
+ color: black;
+ text-align: left;
+}
+div.debug pre {
+ margin-left: 1em;
+ white-space: normal;
+ text-indent: -1em;
+}
+div.debug pre.query {
+ color: maroon;
+}
+div.debug pre.bindings {
+ color: gray;
+}
+div.debug pre.bindings .value {
+ color: green;
+ font-weight: bold;
+ margin-right: 1em;
+}
+div.debug pre.query span {
+ background: rgba(255, 0, 0, 0.05);
+}
+div.debug pre.query span:hover {
+ background: white;
+}
diff --git a/src/Database.php b/src/Database.php
index 974d5dc3..0a4a9cf4 100644
--- a/src/Database.php
+++ b/src/Database.php
@@ -2,7 +2,7 @@
class Database
{
protected static $pdo = null;
- protected static $queries = [];
+ protected static $queryLogs = [];
public static function connect($driver, $location, $user, $pass)
{
@@ -51,38 +51,52 @@ class Database
return self::$pdo !== null;
}
- public static function exec(SqlStatement $stmt)
+ private static function execInternal(SqlStatement $stmt, $callback)
{
if (!self::connected())
throw new Exception('Database is not connected');
+
$stmtPdo = self::convertStatement($stmt);
try
{
+ $timeStart = microtime(true);
$stmtPdo->execute();
+ $timeExec = microtime(true) - $timeStart;
+
+ $timeStart = microtime(true);
+ $ret = $callback($stmtPdo);
+ $timeFetch = microtime(true) - $timeStart;
}
catch (Exception $e)
{
throw new Exception('Problem with ' . $stmt->getAsString() . ' execution (' . $e->getMessage() . ')');
}
- self::$queries []= $stmt;
- return $stmtPdo;
+ $queryLog = new StdClass();
+ $queryLog->statement = $stmt;
+ $queryLog->timeExec = $timeExec;
+ $queryLog->timeFetch = $timeFetch;
+ self::$queryLogs []= $queryLog;
+ return $ret;
+ }
+
+ public static function exec(SqlStatement $stmt)
+ {
+ return self::execInternal($stmt, function($stmtPdo) { });
}
public static function fetchOne(SqlStatement $stmt)
{
- $stmtPdo = self::exec($stmt);
- return $stmtPdo->fetch();
+ return self::execInternal($stmt, function($stmtPdo) { return $stmtPdo->fetch(); });
}
public static function fetchAll(SqlStatement $stmt)
{
- $stmtPdo = self::exec($stmt);
- return $stmtPdo->fetchAll();
+ return self::execInternal($stmt, function($stmtPdo) { return $stmtPdo->fetchAll(); });
}
public static function getLogs()
{
- return self::$queries;
+ return self::$queryLogs;
}
public static function inTransaction()
diff --git a/src/Views/debug.phtml b/src/Views/debug.phtml
new file mode 100644
index 00000000..d49d2973
--- /dev/null
+++ b/src/Views/debug.phtml
@@ -0,0 +1,24 @@
+
+
+
+
+ statement->getAsString();
+ $query = str_replace('(', '
(', $query);
+ $query = str_replace(')', ')', $query);
+ ?>
+
+
+
' . $log->statement->getBindings()[$key] . '';
+ },
+ array_keys($log->statement->getBindings()))) ?>
+
+
+ Execution: | timeExec) ?> |
+ Retrieval: | timeFetch) ?> |
+
+
+
+
diff --git a/src/Views/layout-normal.phtml b/src/Views/layout-normal.phtml
index 15e5d219..a7f440bd 100644
--- a/src/Views/layout-normal.phtml
+++ b/src/Views/layout-normal.phtml
@@ -43,18 +43,13 @@ LayoutHelper::addScript('core.js');