Merge pull request #8388 from sminnee/showqueries-backtrace

NEW: Add ?showqueries=backtrace
This commit is contained in:
Robbie Averill 2018-09-19 11:21:36 +02:00 committed by GitHub
commit 3b7802bb51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -41,6 +41,7 @@ session variables, used templates and much more.
| URL Variable | | Values | | Description |
| ------------ | | --------- | | ----------- |
| showqueries | | 1|inline | | List all SQL queries executed, the `inline` option will do a fudge replacement of parameterised queries |
| showqueries | | 1|backtrace | | List all SQL queries executed, the `backtrace` option will do a fudge replacement of parameterised queries *and* show a backtrace of every query |
| previewwrite | | 1 | | List all insert / update SQL queries, and **don't** execute them. Useful for previewing writes to the database. |
## Security Redirects

View File

@ -11,6 +11,7 @@ use SilverStripe\ORM\Queries\SQLUpdate;
use SilverStripe\ORM\Queries\SQLInsert;
use BadMethodCallException;
use Exception;
use SilverStripe\Dev\Backtrace;
/**
* Abstract database connectivity class.
@ -212,11 +213,16 @@ abstract class Database
$result = $callback($sql);
$endtime = round(microtime(true) - $starttime, 4);
// replace parameters as closely as possible to what we'd expect the DB to put in
if (strtolower($_REQUEST['showqueries']) == 'inline') {
if (in_array(strtolower($_REQUEST['showqueries']), ['inline', 'backtrace'])) {
$sql = DB::inline_parameters($sql, $parameters);
}
$queryCount = sprintf("%04d", $this->queryCount);
Debug::message("\n$queryCount: $sql\n{$endtime}s\n", false);
// Show a backtrace if ?showqueries=backtrace
if ($_REQUEST['showqueries'] === 'backtrace') {
Backtrace::backtrace();
}
return $result;
} else {
return $callback($sql);