1
0
mirror of https://github.com/maximebf/php-debugbar.git synced 2025-01-17 13:28:35 +01:00

added parameter to specify the quotationChar in PDOCollector (fixed #38)

This commit is contained in:
maximebf 2013-11-04 14:14:57 -03:00
parent a7e1479ed4
commit 71be65fdcd
2 changed files with 21 additions and 5 deletions

View File

@ -17,6 +17,8 @@ class PDOCollector extends DataCollector implements Renderable
protected $renderSqlWithParams = false; protected $renderSqlWithParams = false;
protected $sqlQuotationChar = '<>';
/** /**
* @param TraceablePDO $pdo * @param TraceablePDO $pdo
* @param TimeDataCollector $timeCollector * @param TimeDataCollector $timeCollector
@ -34,9 +36,10 @@ class PDOCollector extends DataCollector implements Renderable
* *
* @param boolean $enabled * @param boolean $enabled
*/ */
public function setRenderSqlWithParams($enabled = true) public function setRenderSqlWithParams($enabled = true, $quotationChar = '<>')
{ {
$this->renderSqlWithParams = $enabled; $this->renderSqlWithParams = $enabled;
$this->sqlQuotationChar = $quotationChar;
} }
public function isSqlRenderedWithParams() public function isSqlRenderedWithParams()
@ -44,6 +47,11 @@ class PDOCollector extends DataCollector implements Renderable
return $this->renderSqlWithParams; return $this->renderSqlWithParams;
} }
public function getSqlQuotationChar()
{
return $this->sqlQuotationChar;
}
/** /**
* Adds a new PDO instance to be collector * Adds a new PDO instance to be collector
* *
@ -109,7 +117,7 @@ class PDOCollector extends DataCollector implements Renderable
$stmts = array(); $stmts = array();
foreach ($pdo->getExecutedStatements() as $stmt) { foreach ($pdo->getExecutedStatements() as $stmt) {
$stmts[] = array( $stmts[] = array(
'sql' => $this->renderSqlWithParams ? $stmt->getSqlWithParams() : $stmt->getSql(), 'sql' => $this->renderSqlWithParams ? $stmt->getSqlWithParams($this->sqlQuotationChar) : $stmt->getSql(),
'row_count' => $stmt->getRowCount(), 'row_count' => $stmt->getRowCount(),
'stmt_id' => $stmt->getPreparedId(), 'stmt_id' => $stmt->getPreparedId(),
'prepared_stmt' => $stmt->getSql(), 'prepared_stmt' => $stmt->getSql(),

View File

@ -73,13 +73,21 @@ class TracedStatement
/** /**
* Returns the SQL string with any parameters used embedded * Returns the SQL string with any parameters used embedded
* *
* @param string $quotationChar
* @return string * @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; $sql = $this->sql;
foreach ($this->parameters as $k => $v) { foreach ($this->parameters as $k => $v) {
$v = sprintf('<%s>', $v); $v = "$quoteLeft$v$quoteRight";
if (!is_numeric($k)) { if (!is_numeric($k)) {
$sql = str_replace($k, $v, $sql); $sql = str_replace($k, $v, $sql);
} else { } else {