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

Doc Bug #16867 PostgreSQL errors when using Native sequences
Submitted: 2009-12-03 02:28 UTC
From: madsliejensen Assigned: madsliejensen
Status: Closed Package: DB_DataObject (version 1.8.12)
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  


 [2009-12-03 02:28 UTC] madsliejensen (Mads Lie Jensen)
Description: ------------ When a tables primary key is a native sequence, for postgreSQL, DB_DataObject does a 'SELECT currval(<sequence-name>)' to get the key to use when inserting a new row. (In DataObject.php line 1084) However, you cannot call currval() without first having called nextval(<sequence-name>), thus, there will be an error from postgreSQL. The correct thing to do would be 'SELECT nextval(<sequence-name>)' instead.

Comments

 [2009-12-03 02:29 UTC] madsliejensen (Mads Lie Jensen)
 [2009-12-03 05:30 UTC] alan_k (Alan Knowles)
-Type: Bug +Type: Documentation Problem
It's not documented (could probably do with a note in the manual somwhere) , but you need to create your tables like this. CREATE TABLE reservations ( id integer DEFAULT nextval('reservations_seq'::text) NOT NULL sequence name is tablename with _seq at the end.
 [2009-12-03 13:07 UTC] madsliejensen (Mads Lie Jensen)
You're right - i missed that my sequences where named <tablename>_<fieldname>_seq. It seems like I could then make a sequenceKey()-method in the table's DataObject, to return the name of the sequence to use. However, the docblock for DB_DataObject::sequenceKey() say that its a private method, and the manual page doesn't say anything about this method. However, the docblock also say: 'Override this to return ....'
 [2009-12-03 13:56 UTC] alan_k (Alan Knowles)
that's some old code ;) the config allows you to do this: sequence_{tablename} = sequencekey_name
 [2011-02-20 14:17 UTC] madsliejensen (Mads Lie Jensen)
-Status: Open +Status: Closed -Assigned To: +Assigned To: madsliejensen
 [2011-02-21 09:05 UTC] alan_k (Alan Knowles)
doc comments have been fixed in SVN now.