Skip to content

Loading…

DBAL-278 - Add lastInsertId() support for sequences (OCI8 Driver) #147

Closed
wants to merge 1 commit into from

3 participants

@franek

Add lastInsertId() support for Sequence

@travisbot

This pull request passes (merged 70f3829 into f3effdb).

@beberlei
Doctrine member

Fixed in master df9bec4 - This is not really a bug, so it will only appear in 2.3

@beberlei beberlei closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 17 additions and 1 deletion.
  1. +17 −1 lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php
View
18 lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php 100644 → 100755
@@ -102,9 +102,25 @@ public function exec($statement)
return $stmt->rowCount();
}
+ /**
+ * {@inheritdoc}
+ */
public function lastInsertId($name = null)
{
- //TODO: throw exception or support sequences?
+ // For sequence
+ if (is_string($name)) {
+ // We can check eventually check the presence of the sequence in the table
+ // USER_SEQUENCES
+ $sql = 'SELECT ' . $name . '.CURRVAL FROM DUAL';
+ // will throw an exception if this sequence does not exist
+ $stmt = $this->query($sql);
+ $result = $stmt->fetch(\PDO::FETCH_ASSOC);
+ if ($result !== false && isset($result['CURRVAL'])) {
+ return (int) $result['CURRVAL'];
+ }
+ }
+ // OCI8 driver does not provide support of lastInsertId
+ return null;
}
/**
Something went wrong with that request. Please try again.