Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 73596ef

Browse filesBrowse files
committed
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 #37355 | License | MIT As explained in #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 ------- eec12ec Use the driverConnection executeUpdate method
2 parents 2f23b01 + eec12ec commit 73596ef
Copy full SHA for 73596ef

File tree

1 file changed

+21
-2
lines changed
Filter options

1 file changed

+21
-2
lines changed

‎src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php
+21-2Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function send(string $body, array $headers, int $delay = 0): string
126126
'available_at' => '?',
127127
]);
128128

129-
$this->executeQuery($queryBuilder->getSQL(), [
129+
$this->executeUpdate($queryBuilder->getSQL(), [
130130
$body,
131131
json_encode($headers),
132132
$this->configuration['queue_name'],
@@ -179,7 +179,7 @@ public function get(): ?array
179179
->set('delivered_at', '?')
180180
->where('id = ?');
181181
$now = new \DateTime();
182-
$this->executeQuery($queryBuilder->getSQL(), [
182+
$this->executeUpdate($queryBuilder->getSQL(), [
183183
$now,
184184
$doctrineEnvelope['id'],
185185
], [
@@ -329,6 +329,25 @@ private function executeQuery(string $sql, array $parameters = [], array $types
329329
return $stmt;
330330
}
331331

332+
private function executeUpdate(string $sql, array $parameters = [], array $types = [])
333+
{
334+
try {
335+
$stmt = $this->driverConnection->executeUpdate($sql, $parameters, $types);
336+
} catch (TableNotFoundException $e) {
337+
if ($this->driverConnection->isTransactionActive()) {
338+
throw $e;
339+
}
340+
341+
// create table
342+
if ($this->autoSetup) {
343+
$this->setup();
344+
}
345+
$stmt = $this->driverConnection->executeUpdate($sql, $parameters, $types);
346+
}
347+
348+
return $stmt;
349+
}
350+
332351
private function getSchema(): Schema
333352
{
334353
$schema = new Schema([], [], $this->driverConnection->getSchemaManager()->createSchemaConfig());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.