Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

A Better fix for #3912 #4240

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions library/Zend/Db/TableGateway/Feature/SequenceFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,19 @@ public function preInsert(Insert $insert)
}

$this->sequenceValue = $this->nextSequenceId();
if ($this->sequenceValue === null)
if ($this->sequenceValue === null) {
return $insert;
}

$insert->values(array($this->primaryKeyField => $this->sequenceValue), Insert::VALUES_MERGE);
return $insert;
}

public function postInsert(StatementInterface $statement, ResultInterface $result)
{
if ($this->sequenceValue !== null)
if ($this->sequenceValue !== null) {
$this->tableGateway->lastInsertValue = $this->sequenceValue;
}
}

/**
Expand All @@ -77,7 +79,6 @@ public function nextSequenceId()
$platform = $this->tableGateway->adapter->getPlatform();
$platformName = $platform->getName();

$sql = '';
switch ($platformName) {
case 'Oracle':
$sql = 'SELECT ' . $platform->quoteIdentifier($this->sequenceName) . '.NEXTVAL FROM dual';
Expand All @@ -92,7 +93,7 @@ public function nextSequenceId()
$statement = $this->tableGateway->adapter->createStatement();
$statement->prepare($sql);
$result = $statement->execute();
$sequence = $result->getResource()->fetch(\PDO::FETCH_ASSOC);
$sequence = $result->current();
unset($statement, $result);
return $sequence['nextval'];
}
Expand All @@ -106,7 +107,6 @@ public function lastSequenceId()
$platform = $this->tableGateway->adapter->getPlatform();
$platformName = $platform->getName();

$sql = '';
switch ($platformName) {
case 'Oracle':
$sql = 'SELECT ' . $platform->quoteIdentifier($this->sequenceName) . '.CURRVAL FROM dual';
Expand All @@ -121,7 +121,7 @@ public function lastSequenceId()
$statement = $this->tableGateway->adapter->createStatement();
$statement->prepare($sql);
$result = $statement->execute();
$sequence = $result->getResource()->fetch(\PDO::FETCH_ASSOC);
$sequence = $result->current();
unset($statement, $result);
return $sequence['currval'];
}
Expand Down