John Fabiani wrote:
> dabo Commit
> Revision 3177
> Date: 2007-06-14 10:37:17 -0700 (Thu, 14 Jun 2007)
> Author: Johnf
> Trac: http://svn.dabodev.com/trac/dabo/changeset/3177
> 
> Changed:
> U   trunk/dabo/db/dbPostgreSQL.py
> 
> Log:
> Added routine ( getLastInsertID) to support getting the current value for the 
> PK.  Thanks to Larry Long for pointing out that saveAll() was not working and 
> Ed Leafe for pointing to the right method.
> 
> Diff:
> Modified: trunk/dabo/db/dbPostgreSQL.py
> ===================================================================
> --- trunk/dabo/db/dbPostgreSQL.py     2007-06-13 16:30:34 UTC (rev 3176)
> +++ trunk/dabo/db/dbPostgreSQL.py     2007-06-14 17:37:17 UTC (rev 3177)
> @@ -222,3 +222,49 @@
>               to the database written to disk.
>               """
>               self.commitTransaction(cursor)
> +             
> +     def getLastInsertID(self, cursor):
> +             """ Return the ID of the last inserted row, or None.
> +             
> +             When inserting a new record in a table that auto-generates a PK 
> (such 
> +             as a serial data type) value, different databases have their 
> own way of retrieving that value.
> +             With Postgres a sequence is created.  The SQL statement 
> determines the sequence name 
> +             ('table_pkid_seq') and needs three parameters the schema name, 
> table name, and the primary
> +             key field for the table.
> +             cursor.KeyField = primary field
> +             cursor.Table = returns 'schema.table' for the cursor
> +             
> +             Postgres uses 'currval(sequence_name)' to determine the last 
> value of the session.
> +             If two different sessions are open (two users accessing the 
> same table for example)
> +             currval() will return the correct value for each session.
> +             
> +             """

What happens when there is more than 1 record inserted?
Did you test this case or are you sure about that this would work?

Uwe


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/dabo-dev/[EMAIL PROTECTED]

Reply via email to