On Apr 16, 2007, at 12:06 PM, <[EMAIL PROTECTED]>
<[EMAIL PROTECTED]> wrote:
> Actually, I did use the onSaveNew and I do have AutoPopulatePK=True.
>
> I set the AutoPopulatePK in the afterInit. Should I place is
> somewhere else?
No, as long as it's set before you call new().
I'm reviewing the code that gets the new PK from the backend, and it
depends on the python database adapter properly populating a property
after an insert. I know that the MySQLdb adapter does this, and I
don't see any override code in dbPostgreSQL, so one thing that could
be going wrong is that psycopg isn't populating the appropriate
property.
Can you modify dabo.db.dBackend.py as follows:
141 def getLastInsertID(self, cursor):
142 """ Return the ID of the last inserted row, or None.
143
144 When inserting a new record in a table that auto-generates a PK
145 value, different databases have their own way of retrieving
that value.
146 This method should be coded in backend-specific subclasses to
address
147 that database's approach.
148 """
149 # Here is some code to fall back on if the specific subclass
doesn't
150 # override.
151 try:
152 # According to PEP-0249, it is common practice for a
readonly
153 # lastrowid attribute to be added by module authors,
which will
154 # keep the last-insert id. This is by no means
guaranteed,
though.
155 # I've confirmed that it does work for MySQLdb.
print "LASTROWID=", cursor.lastrowid
156 return cursor.lastrowid
157 except AttributeError:
print "LASTROWID NOT FOUND"
158 return None
The lines to add are right after line 155 and 157. Run your app
again and insert the new record. When you save it, you should either
get a PK printing out on the console, or the 'not found' message.
-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/dabo-users/[EMAIL PROTECTED]