Werner F. Bruhin wrote:
> Michael,
>
> Michael Bayer wrote:
>   
>> On Nov 6, 2007, at 12:20 PM, Werner F. Bruhin wrote:
>>
>>   
>>     
>>> I insert a raw into a table and then retrieve again but columns which
>>> are filled by a db trigger don't return the updated values.
>>>
>>> The following is a code snippet and I wonder what I am missing.
>>>
>>> engine = sa.create_engine(url, encoding='utf8', echo=False)
>>> Session = sao.sessionmaker(autoflush=True, transactional=True)
>>> Session.configure(bind=engine)
>>> session = Session()
>>> botlot = db.Bottaglot()
>>> session.save(botlot)
>>> session.commit()
>>>
>>> print 'org'
>>> print botlot.bottaglotid
>>> print botlot.updated
>>>
>>> botlot2 = session.query(db.Bottaglot).get(botlot.bottaglotid)
>>> print 'reloaded'
>>> print botlot2.bottaglotid
>>> print botlot2.updated
>>>
>>> Both columns "updated" will show None instead of at least for  
>>> botlot2 it
>>> should show the current date which was inserted into that column by  
>>> a db
>>> trigger.
>>>
>>>     
>>>       
>> set a PassiveDefault on the triggered column.  that will indicate to  
>> the mapper that it should post-fetch the value after an insert. note  
>> that if the trigger is on a primary key column, it wont work since we  
>> need primary key values in order to post-fetch.
>>   
>>     
> PassiveDefault is great to know.
>
> However I still have a problem with the following.
>
> In a program I do something like this:
> botlot3 = session.query(db.Bottaglot).get(39)
>
> Then some other user and/or application changes data (I faked this by 
> setting a debugger break point and used the db admin tool to change some 
> data and committed it) in the database and commits, then when I do this:
> botlot4 = session.query(db.Bottaglot).get(39)
>   
Instead of using ".get(" I ended up using "refresh", i.e. something like 
this:

session.refresh(botlot3)

Which re-queried the database and gave the values of the columns which 
were completed by the db trigger.

Werner

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to