Skip to content

Commit 52c3a32

Browse files
rjd22fabpot
authored andcommitted
[Doctrine][Messenger] Use common sequence name to get id from Oracle
1 parent f2e8474 commit 52c3a32

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)