bug #37358 Directly use the driverConnection executeUpdate method (TristanPouliquen)
This PR was merged into the 4.4 branch.
Discussion
----------
Directly use the driverConnection executeUpdate method
executeUpdate & executeQuery methods do not throw a TableNotFoundException. No need for the try/catch as it is done for executeQuery
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix https://github.com/symfony/symfony/issues/37355
| License | MIT
As explained in https://github.com/symfony/symfony/issues/37355, when doing a write operation, one should avoid using the `executeQuery` method of a Connection, as Doctrine's MasterSlaveConnection can pick a slave instance (usually read-only) for these operations.
Commits
-------
eec12ecd23
Use the driverConnection executeUpdate method
This commit is contained in:
commit
73596ef4f7
@ -126,7 +126,7 @@ class Connection
|
|||||||
'available_at' => '?',
|
'available_at' => '?',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->executeQuery($queryBuilder->getSQL(), [
|
$this->executeUpdate($queryBuilder->getSQL(), [
|
||||||
$body,
|
$body,
|
||||||
json_encode($headers),
|
json_encode($headers),
|
||||||
$this->configuration['queue_name'],
|
$this->configuration['queue_name'],
|
||||||
@ -179,7 +179,7 @@ class Connection
|
|||||||
->set('delivered_at', '?')
|
->set('delivered_at', '?')
|
||||||
->where('id = ?');
|
->where('id = ?');
|
||||||
$now = new \DateTime();
|
$now = new \DateTime();
|
||||||
$this->executeQuery($queryBuilder->getSQL(), [
|
$this->executeUpdate($queryBuilder->getSQL(), [
|
||||||
$now,
|
$now,
|
||||||
$doctrineEnvelope['id'],
|
$doctrineEnvelope['id'],
|
||||||
], [
|
], [
|
||||||
@ -329,6 +329,25 @@ class Connection
|
|||||||
return $stmt;
|
return $stmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function executeUpdate(string $sql, array $parameters = [], array $types = [])
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$stmt = $this->driverConnection->executeUpdate($sql, $parameters, $types);
|
||||||
|
} catch (TableNotFoundException $e) {
|
||||||
|
if ($this->driverConnection->isTransactionActive()) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create table
|
||||||
|
if ($this->autoSetup) {
|
||||||
|
$this->setup();
|
||||||
|
}
|
||||||
|
$stmt = $this->driverConnection->executeUpdate($sql, $parameters, $types);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $stmt;
|
||||||
|
}
|
||||||
|
|
||||||
private function getSchema(): Schema
|
private function getSchema(): Schema
|
||||||
{
|
{
|
||||||
$schema = new Schema([], [], $this->driverConnection->getSchemaManager()->createSchemaConfig());
|
$schema = new Schema([], [], $this->driverConnection->getSchemaManager()->createSchemaConfig());
|
||||||
|
Reference in New Issue
Block a user