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

Commit

Permalink
Merge branch 'hotfix/3912'
Browse files Browse the repository at this point in the history
Close #4240
Fixes #3912
  • Loading branch information
weierophinney committed Apr 16, 2013
2 parents 27f6cba + d11db3b commit 1913f89
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions library/Zend/Db/TableGateway/Feature/SequenceFeature.php
Expand Up @@ -42,7 +42,7 @@ public function __construct($primaryKeyField, $sequenceName)
} }


/** /**
* @param Insert $insert * @param Insert $insert
*/ */
public function preInsert(Insert $insert) public function preInsert(Insert $insert)
{ {
Expand All @@ -55,17 +55,19 @@ public function preInsert(Insert $insert)
} }


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


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


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


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


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


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

0 comments on commit 1913f89

Please sign in to comment.