Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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

Closed
wants to merge 1 commit into from

3 participants

François D. Don't Add Me To Your Organization a.k.a The Travis Bot Benjamin Eberlei
François D.
franek commented May 16, 2012

Add lastInsertId() support for Sequence

Don't Add Me To Your Organization a.k.a The Travis Bot

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

Benjamin Eberlei
Owner

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

Benjamin Eberlei beberlei closed this May 22, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
18  lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php 100644 → 100755
@@ -102,9 +102,25 @@ public function exec($statement)
102 102
         return $stmt->rowCount();
103 103
     }
104 104
 
  105
+    /**
  106
+     * {@inheritdoc}
  107
+     */
105 108
     public function lastInsertId($name = null)
106 109
     {
107  
-        //TODO: throw exception or support sequences?
  110
+        // For sequence
  111
+        if (is_string($name)) {
  112
+            // We can check eventually check the presence of the sequence in the table
  113
+            // USER_SEQUENCES
  114
+            $sql = 'SELECT ' . $name . '.CURRVAL FROM DUAL';
  115
+            // will throw an exception if this sequence does not exist
  116
+            $stmt = $this->query($sql);
  117
+            $result = $stmt->fetch(\PDO::FETCH_ASSOC);
  118
+            if ($result !== false && isset($result['CURRVAL'])) {
  119
+                return (int) $result['CURRVAL'];
  120
+            }
  121
+        }
  122
+        // OCI8 driver does not provide support of lastInsertId
  123
+        return null;
108 124
     }
109 125
 
110 126
     /**
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.