On Wed, May 16, 2012 at 11:27 PM, Michael Bayer
<mike...@zzzcomputing.com> wrote:
>
> On May 16, 2012, at 11:11 AM, limodou wrote:
>
>> Thank you for the detail explains. And I tried like this again:
>>
>> 1. if there are only select statements it will ok,  and the select
>> statements will fetch the new changed records.
>> 2. select after update, if there is no record at some point, it'll not
>> fetch the new changed records in the later loop, just like what you
>> said the "state" is hold.
>>
>> So in my application, I need to do like:
>>
>> while True:
>>    for row in select(xxx):
>>        update(xxxx)
>>
>> And I want to keep each update has seperate transaction, maybe like this:
>>
>> while True:
>>    conn = engine.connect()
>>    for row in conn.execute(select(xxx)):
>>        trans = conn.begin()
>>        conn.execute(update(xxxx))
>>        trans.commit()
>>
>> But above code is not right, I should put the transaction out of the
>> loop just like what you written. So I want to know what is the suit
>> appoach of keeping each update has seperate transaction? Should I use
>> nested transaction?
>
> OK you need to use two different connections here, for the "read from one 
> connection, persist on another in a short transaction" pattern.  Again the 
> "with engine.begin()" thing, which is new as of 0.7...6?  makes this pretty 
> succinct:
>
>
> while True:
>    with engine.begin() as conn:
>        for row in conn.execute(select...):
>            with engine.begin() as c2:
>                c2.execute(update...)
>   sleep(...)
>
>

Ok, I see. And the last word, is there a way to disable the
accumulation of transactional state?

Thank you very much.

-- 
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
UliWeb <<simple web framework>>: http://code.google.com/p/uliweb/
My Blog: http://hi.baidu.com/limodou

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to