Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.5.0b5

Bug #9107 currID using wrong method to get last value of sequence
Submitted: 2006-10-20 13:35 UTC
From: mcraig at leadehealth dot com Assigned: lsmith
Status: Closed Package: MDB2 (version 1.2.2)
PHP Version: 4.4.3 OS: linux 2.6
Roadmaps: (Not assigned)    

 [2006-10-20 13:35 UTC] mcraig at leadehealth dot com (Matt Craig)
Description: ------------ This code from "function currID()" in MDB2_Driver_pgsql is using last_value of a sequence which is not connection specific within PostgreSQL: return $this->queryOne("SELECT last_value FROM $sequence_name",'integer'); "last_value" will return the globally unique last value as the whole database sees it. return $this->queryOne("SELECT currval(<seqname>)", 'integer'); is the correct way to get the connection specific Postgres sequence value. This bug was also appearing in DataObject and fixed in this manner as seen in this pear-dev thread:


 [2006-10-20 13:54 UTC] lsmith (Lukas Smith)
the problem is that the cross database behaviour is to get the global last value generated for the given sequence. so the solution is to implement lastInsertID() in the sequence using drivers using currval() or similar methods.
 [2006-10-20 14:12 UTC] mcraig at leadehealth dot com
do you already have a lastInsertID() in mind? Could this use the fix proposed for currID? function lastInsertID($table = null, $field = null) { $sequence_name = $this->quoteIdentifier($this->getSequenceName($table), true); return $this->queryOne("SELECT currval('$sequence_name')", 'integer'); } [darn 60 col textarea]
 [2006-10-20 14:23 UTC] lsmith (Lukas Smith)
I have applied a fix for PostgreSQL, now we need a fix for Interbase and Oracle.
 [2006-10-20 15:06 UTC] quipo (Lorenzo Alberton)
Added to Firebird/Interbase driver too. We probably need a testcase...
 [2006-10-20 15:57 UTC] quipo (Lorenzo Alberton)
sorry, I misread the bug report. AFAIK, there's no equivalent to postgresql's currval() in firebird.
 [2006-10-20 17:43 UTC] lsmith (Lukas Smith)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on by the end of next Sunday (CET). If this was a problem with the website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.