From 71be65fdcdce2a7228170c25606a1cdd5710e7c2 Mon Sep 17 00:00:00 2001 From: maximebf Date: Mon, 4 Nov 2013 14:14:57 -0300 Subject: [PATCH] added parameter to specify the quotationChar in PDOCollector (fixed #38) --- src/DebugBar/DataCollector/PDO/PDOCollector.php | 12 ++++++++++-- src/DebugBar/DataCollector/PDO/TracedStatement.php | 14 +++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/DebugBar/DataCollector/PDO/PDOCollector.php b/src/DebugBar/DataCollector/PDO/PDOCollector.php index ba4e4dc..0e64ca9 100644 --- a/src/DebugBar/DataCollector/PDO/PDOCollector.php +++ b/src/DebugBar/DataCollector/PDO/PDOCollector.php @@ -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(), diff --git a/src/DebugBar/DataCollector/PDO/TracedStatement.php b/src/DebugBar/DataCollector/PDO/TracedStatement.php index de77e9b..3e2800a 100644 --- a/src/DebugBar/DataCollector/PDO/TracedStatement.php +++ b/src/DebugBar/DataCollector/PDO/TracedStatement.php @@ -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 {