Skip to content

Commit

Permalink
bug #50268 Allow resources in Query::setParam (l-vo)
Browse files Browse the repository at this point in the history
This PR was merged into the 6.2 branch.

Discussion
----------

Allow resources in Query::setParam

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

See #46744 (comment)

(failures in tests seem not related)

Commits
-------

318e0e4 Allow resources in Query::setParam
  • Loading branch information
fabpot committed May 10, 2023
2 parents 3835573 + 318e0e4 commit 3cefdcb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/Middleware/Debug/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function stop(): void
}
}

public function setParam(string|int $param, null|string|int|float|bool &$variable, int $type): void
public function setParam(string|int $param, mixed &$variable, int $type): void
{
// Numeric indexes start at 0 in profiler
$idx = \is_int($param) ? $param - 1 : $param;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,31 @@ public function testWithParamBound(callable $executeMethod)
{
$this->init();

$product = 'product1';
$price = 12.5;
$stock = 5;
$sql = <<<EOT
INSERT INTO products(name, price, stock, picture, tags)
VALUES (?, ?, ?, ?, ?)
EOT;

$expectedRes = $res = $this->getResourceFromString('mydata');

$stmt = $this->conn->prepare('INSERT INTO products(name, price, stock) VALUES (?, ?, ?)');
$stmt = $this->conn->prepare($sql);
$stmt->bindParam(1, $product);
$stmt->bindParam(2, $price);
$stmt->bindParam(3, $stock, ParameterType::INTEGER);
$stmt->bindParam(4, $res, ParameterType::BINARY);

$product = 'product1';
$price = 12.5;
$stock = 5;

$executeMethod($stmt);

// Debug data should not be affected by these changes
$debug = $this->debugDataHolder->getData()['default'] ?? [];
$this->assertCount(2, $debug);
$this->assertSame('INSERT INTO products(name, price, stock) VALUES (?, ?, ?)', $debug[1]['sql']);
$this->assertSame(['product1', '12.5', 5], $debug[1]['params']);
$this->assertSame([ParameterType::STRING, ParameterType::STRING, ParameterType::INTEGER], $debug[1]['types']);
$this->assertSame($sql, $debug[1]['sql']);
$this->assertSame(['product1', 12.5, 5, $expectedRes], $debug[1]['params']);
$this->assertSame([ParameterType::STRING, ParameterType::STRING, ParameterType::INTEGER, ParameterType::BINARY], $debug[1]['types']);
$this->assertGreaterThan(0, $debug[1]['executionMS']);
}

Expand Down

0 comments on commit 3cefdcb

Please sign in to comment.