Home » Database » MDB2 » Bug #9107
currID using wrong method to get last value of sequence
Details
| Submitted | 2006-10-20 13:35 UTC |
|---|---|
| From | mcraig at leadehealth dot com |
| Assigned | lsmith |
| Status | Closed |
| Package | MDB2 |
| PHP Version | 4.4.3 |
| OS | linux 2.6 |
| Roadmaps | (Not assigned) |
Comments
[2006-10-20 13:35 UTC] mcraig at leadehealth dot com
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:
http://www.codecomments.com/message1086631.html
[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]