mirror of
https://github.com/maximebf/php-debugbar.git
synced 2025-01-16 21:08:34 +01:00
Bug fix repead params sql (#387)
* Bug fix repead params sql * Fix array * Fix array
This commit is contained in:
parent
7702b864a3
commit
4048ff47ed
@ -123,8 +123,9 @@ class TracedStatement
|
||||
}
|
||||
|
||||
$matchRule = "/({$marker}(?!\w))(?=(?:[^$quotationChar]|[$quotationChar][^$quotationChar]*[$quotationChar])*$)/";
|
||||
|
||||
$sql = preg_replace($matchRule, $v, $sql, 1);
|
||||
for ($i = 0; $i <= mb_substr_count($sql, $k); $i++) {
|
||||
$sql = preg_replace($matchRule, $v, $sql, 1);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = strtr($sql, array_flip($cleanBackRefCharMap));
|
||||
|
@ -59,7 +59,7 @@ class TracedStatementTest extends DebugBarTestCase
|
||||
public function testReplacementParamsContainingPotentialAdditionalQuestionMarkPlaceholderGeneratesCorrectString()
|
||||
{
|
||||
$hasQuestionMark = "Asking a question?";
|
||||
$string = "Asking for a friend";
|
||||
$string = "Asking for a friend";
|
||||
|
||||
$sql = "INSERT INTO questions SET question = ?, detail = ?";
|
||||
|
||||
@ -89,7 +89,7 @@ class TracedStatementTest extends DebugBarTestCase
|
||||
public function testReplacementParamsContainingPotentialAdditionalNamedPlaceholderGeneratesCorrectString()
|
||||
{
|
||||
$hasQuestionMark = "Asking a question with a :string inside";
|
||||
$string = "Asking for a friend";
|
||||
$string = "Asking for a friend";
|
||||
|
||||
$sql = "INSERT INTO questions SET question = :question, detail = :string";
|
||||
|
||||
@ -118,4 +118,36 @@ class TracedStatementTest extends DebugBarTestCase
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if query parameters are being replaced in the correct way
|
||||
* @bugFix Before fix it : select *
|
||||
* from geral.person p
|
||||
* left join geral.contract c
|
||||
* on c.id_person = p.id_person
|
||||
* where c.status = <1> and
|
||||
* p.status <> :status;
|
||||
* @return void
|
||||
*/
|
||||
public function testRepeadParamsQuery()
|
||||
{
|
||||
$sql = 'select *
|
||||
from geral.person p
|
||||
left join geral.contract c
|
||||
on c.id_person = p.id_person
|
||||
where c.status = :status and
|
||||
p.status <> :status';
|
||||
$params = array(
|
||||
':status' => 1
|
||||
);
|
||||
$traced = new TracedStatement($sql, $params);
|
||||
$expected = 'select *
|
||||
from geral.person p
|
||||
left join geral.contract c
|
||||
on c.id_person = p.id_person
|
||||
where c.status = <1> and
|
||||
p.status <> <1>';
|
||||
$result = $traced->getSqlWithParams();
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user