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

Request #9989 lastInsertID with no table / field specified
Submitted: 2007-01-31 15:25 UTC
From: mario dot adam at schaeffler dot com Assigned: quipo
Status: Closed Package: MDB2_Driver_pgsql (version 1.3.0)
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  


 [2007-01-31 15:25 UTC] mario dot adam at schaeffler dot com (Mario Adam)
Description: ------------ The function lastInsertID() returns the result vom CURRVAL for a specified sequence. The function expects two optional parameters $table and $field which both are set to null per default. Calling this function with no parameters (and therefor use null for both $table and $field) would result in CURRVAL('_seq'), if '_seq' was the suffix for sequences. As long you do not have a sequence called like that, an error will be returned. I think, it has to be dicussed, if it wasn't better to return the last used ID at all. LASTVAL could be used for that. A possible solution is pasted in "Test script" below... Test script: --------------- function lastInsertID($table = null, $field = null) { if (empty($table) && empty($field)) { return $this->queryOne("SELECT lastval()", 'integer'); } else { $seq = $table.(empty($field) ? '' : '_'.$field); $sequence_name = $this->getSequenceName($seq); return $this->queryOne("SELECT currval('$sequence_name')", 'integer'); } }

Comments

 [2007-03-12 12:38 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2013-04-29 18:59 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!