Skip to content

Commit c898802

Browse files
committed
bug #54566 [Doctrine][Messenger] Use common sequence name to get id from Oracle (rjd22)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [Doctrine][Messenger] Use common sequence name to get id from Oracle | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #54193 | License | MIT This is a fix for #54193 by using a common sequence name for getting the ID's for Oracle databases. This will require the user to name their sequences seq_<table_name> or SEQ_<TABLE_NAME> but at least allows you to use messenger with Oracle after properly setting up the table. Commits ------- 52c3a32 [Doctrine][Messenger] Use common sequence name to get id from Oracle
2 parents f5a5104 + 52c3a32 commit c898802

File tree

1 file changed

+20
-1
lines changed
  • src/Symfony/Component/Messenger/Bridge/Doctrine/Transport

1 file changed

+20
-1
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,18 @@ private function executeInsert(string $sql, array $parameters = [], array $types
470470
if (!$id) {
471471
throw new TransportException('no id was returned by PostgreSQL from RETURNING clause.');
472472
}
473+
} elseif ($this->driverConnection->getDatabasePlatform() instanceof OraclePlatform) {
474+
$sequenceName = 'seq_'.$this->configuration['table_name'];
475+
476+
$this->driverConnection->executeStatement($sql, $parameters, $types);
477+
478+
$result = $this->driverConnection->fetchOne('SELECT '.$sequenceName.'.CURRVAL FROM DUAL');
479+
480+
$id = (int) $result;
481+
482+
if (!$id) {
483+
throw new TransportException('no id was returned by Oracle from sequence: '.$sequenceName);
484+
}
473485
} else {
474486
$this->driverConnection->executeStatement($sql, $parameters, $types);
475487

@@ -507,7 +519,7 @@ private function addTableToSchema(Schema $schema): void
507519
$table = $schema->createTable($this->configuration['table_name']);
508520
// add an internal option to mark that we created this & the non-namespaced table name
509521
$table->addOption(self::TABLE_OPTION_NAME, $this->configuration['table_name']);
510-
$table->addColumn('id', Types::BIGINT)
522+
$idColumn = $table->addColumn('id', Types::BIGINT)
511523
->setAutoincrement(true)
512524
->setNotnull(true);
513525
$table->addColumn('body', Types::TEXT)
@@ -527,6 +539,13 @@ private function addTableToSchema(Schema $schema): void
527539
$table->addIndex(['queue_name']);
528540
$table->addIndex(['available_at']);
529541
$table->addIndex(['delivered_at']);
542+
543+
// We need to create a sequence for Oracle and set the id column to get the correct nextval
544+
if ($this->driverConnection->getDatabasePlatform() instanceof OraclePlatform) {
545+
$idColumn->setDefault('seq_'.$this->configuration['table_name'].'.nextval');
546+
547+
$schema->createSequence('seq_'.$this->configuration['table_name']);
548+
}
530549
}
531550

532551
private function decodeEnvelopeHeaders(array $doctrineEnvelope): array

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy