mirror of
https://github.com/maximebf/php-debugbar.git
synced 2025-01-16 21:08:34 +01:00
added parameter to specify the quotationChar in PDOCollector (fixed #38)
This commit is contained in:
parent
a7e1479ed4
commit
71be65fdcd
@ -17,6 +17,8 @@ class PDOCollector extends DataCollector implements Renderable
|
||||
|
||||
protected $renderSqlWithParams = false;
|
||||
|
||||
protected $sqlQuotationChar = '<>';
|
||||
|
||||
/**
|
||||
* @param TraceablePDO $pdo
|
||||
* @param TimeDataCollector $timeCollector
|
||||
@ -34,9 +36,10 @@ class PDOCollector extends DataCollector implements Renderable
|
||||
*
|
||||
* @param boolean $enabled
|
||||
*/
|
||||
public function setRenderSqlWithParams($enabled = true)
|
||||
public function setRenderSqlWithParams($enabled = true, $quotationChar = '<>')
|
||||
{
|
||||
$this->renderSqlWithParams = $enabled;
|
||||
$this->sqlQuotationChar = $quotationChar;
|
||||
}
|
||||
|
||||
public function isSqlRenderedWithParams()
|
||||
@ -44,6 +47,11 @@ class PDOCollector extends DataCollector implements Renderable
|
||||
return $this->renderSqlWithParams;
|
||||
}
|
||||
|
||||
public function getSqlQuotationChar()
|
||||
{
|
||||
return $this->sqlQuotationChar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new PDO instance to be collector
|
||||
*
|
||||
@ -109,7 +117,7 @@ class PDOCollector extends DataCollector implements Renderable
|
||||
$stmts = array();
|
||||
foreach ($pdo->getExecutedStatements() as $stmt) {
|
||||
$stmts[] = array(
|
||||
'sql' => $this->renderSqlWithParams ? $stmt->getSqlWithParams() : $stmt->getSql(),
|
||||
'sql' => $this->renderSqlWithParams ? $stmt->getSqlWithParams($this->sqlQuotationChar) : $stmt->getSql(),
|
||||
'row_count' => $stmt->getRowCount(),
|
||||
'stmt_id' => $stmt->getPreparedId(),
|
||||
'prepared_stmt' => $stmt->getSql(),
|
||||
|
@ -72,14 +72,22 @@ class TracedStatement
|
||||
|
||||
/**
|
||||
* Returns the SQL string with any parameters used embedded
|
||||
*
|
||||
*
|
||||
* @param string $quotationChar
|
||||
* @return string
|
||||
*/
|
||||
public function getSqlWithParams()
|
||||
public function getSqlWithParams($quotationChar = '<>')
|
||||
{
|
||||
if (($l = strlen($quotationChar)) > 1) {
|
||||
$quoteLeft = substr($quotationChar, 0, $l / 2);
|
||||
$quoteRight = substr($quotationChar, $l / 2);
|
||||
} else {
|
||||
$quoteLeft = $quoteRight = $quotationChar;
|
||||
}
|
||||
|
||||
$sql = $this->sql;
|
||||
foreach ($this->parameters as $k => $v) {
|
||||
$v = sprintf('<%s>', $v);
|
||||
$v = "$quoteLeft$v$quoteRight";
|
||||
if (!is_numeric($k)) {
|
||||
$sql = str_replace($k, $v, $sql);
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user