johnf wrote:
> On Thursday 23 August 2007 15:02, Uwe Grauer wrote:
>> johnf wrote:
>>> On Thursday 23 August 2007 14:39, Ed Leafe wrote:
>>>> On Aug 23, 2007, at 5:02 PM, johnf wrote:
>>>>> I have a parent and several child waiting to be saved.
>>>>> isTransactionManager = True
>>>>>
>>>>> parent is inserted into the DB
>>>>>
>>>>> then getLastInsertID() is called because the children need the PKID
>>>>> of the
>>>>> parent
>>>>>
>>>>> But no commit has occurred.
>>>>>
>>>>> getLastInsertID() fails because of no commit.
>>>>>
>>>>> I don't think this can work?  Anybody have a suggestion on how I
>>>>> might fix
>>>>> this?
>>>>    Is there any other way to query the value without committing?
>>> Yes nextval() will return the next value of the sequence.
>>>
>>>>    If
>>>> not, you should probably use sequence instead, and pre-fetch it using
>>>> the dbPostgreSQL.pregenPK() method (which doesn't exist yet).
>>> Writing the code for pregenPK() would not be that big of a deal.  Assume
>>> that the code is available.  How does Dabo use the method?
>>>
>>>> -- Ed Leafe
>>>> -- http://leafe.com
>>>> -- http://dabodev.com
>>> However, it would be a very big deal to change the code for our current
>>> forms. Any form that uses children (and I have one that uses
>>> grandchildren) depends on the self.FillLinkFromParent = True.  Please
>>> explain how the current Dabo is suppose to deal with the Saveall().
>> Dabos dbFirebird module does use pregenPK in a way that works as expected.
>> I did a quick search on what the default way in postgresql is and found
>> out that there is a currval() method which gets the last inserted
>> sequence id for the given connection.
>>
>> >From the postgresql faq:
>>
>> 4.11.3) Doesn't currval()  lead to a race condition with other users?
>>
>> No. currval() returns the current value assigned by your session, not by
>> all sessions.
> 
> I am using currval() in dbPostgres.py.  Maybe I doing something wrong - take 
> a 
> look:
> 
> tableNameBreak=cursor.Table.split('.',1)
> localSchemaName = tableNameBreak[0]
> localTableName = tableNameBreak[1]
>               
> tempCursor = self._cursor.AuxCursor
> sqltablestr = """SELECT seq.relname::text
>               FROM pg_class src, pg_class seq, pg_namespace, pg_attribute,
>               pg_depend
>               WHERE
>               pg_depend.refobjsubid = pg_attribute.attnum AND
>               pg_depend.refobjid = src.oid AND
>               seq.oid = pg_depend.objid AND
>               src.relnamespace = pg_namespace.oid AND
>               pg_attribute.attrelid = src.oid AND
>               pg_namespace.nspname = '%s' AND
>               src.relname = '%s' AND
>               pg_attribute.attname = '%s'""" % 
>            (localSchemaName,localTableName,cursor.KeyField)
>               
>               
> tempCursor.execute(sqltablestr)
> rs = tempCursor.fetchall()
> 
> sqlWithseq_name="""select currval('%s') as curval""" % (rs[0][0],)
> tempCursor.execute(sqlWithseq_name) 
> rs = tempCursor.fetchall()
> 
> 
> 

Sorry, i missed the call to currval()!
Are you sure that the retrieve of the sequence name works for you?
Please check:
                tempCursor.execute(sqltablestr)
                rs = tempCursor.fetchall()
                sqlWithseq_name="""select currval('%s') as curval""" %
(rs[0][0],)



_______________________________________________
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