Sorry to revive this topic.

Amir Elaguizy, what was your modifications in the implementation of the 
first message?
I need something similar to this for Oracle


Em segunda-feira, 16 de dezembro de 2013 23h05min09s UTC-3, Amir Elaguizy 
escreveu:
>
> Thanks!
>
> On Saturday, December 14, 2013 8:08:55 AM UTC-6, Michael Bayer wrote:
>>
>> you’d probably want to tack that onto _flush() instead as that’s called 
>> by autoflush also.
>>
>> if you want to just raise an exception on flush, do a  before_flush event 
>> and just raise.
>>
>>
>> On Dec 14, 2013, at 8:42 AM, Amir Elaguizy <[email protected]> wrote:
>>
>> What is the best way to achieve a session that is read-only?
>>
>> I found this code online:
>>
>> 1
>> 2
>> 3
>> 4
>> 5
>> 6
>> 7
>> 8
>> 9
>> 10
>> 11
>> 12
>> 13
>> 14
>> 15
>> 16
>> 17
>> 18
>> 19
>> 20
>> from sqlalchemy import create_engine
>> from sqlalchemy.orm import sessionmaker
>>  
>> ## Based on code by Yannick Gingras
>>  
>> def abort_ro(*args,**kwargs):
>>     ''' the terrible consequences for trying 
>>         to flush to the db '''
>>     print "No writing allowed, tsk!  We're telling mom!"
>>     return 
>>  
>> def db_setup(connstring='sqlite:///:memory:', 
>>                echo=False, readonly=True):
>>     engine = create_engine(connstring, echo=echo)
>>     Session = sessionmaker(bind=engine, autoflush=False, autocommit=False
>> )
>>     session = Session()
>>     if readonly:
>>         session.flush = abort_ro   # now it won't flush!
>>  
>> <code class="python spaces" style="outline: 0px !important; font-size: 
>> 1em !important; border-top-left-radius: 0px !important; 
>> border-top-right-radius: 0px !important; border-bottom-right-radius: 0px 
>> !important; border-bottom-left-radius: 0px !important; background-image: 
>> none !important; bottom: auto !important; float: none !important; height: 
>> auto !important; left: auto !important; line-height: 1.1em !important; 
>> overflow: visible !important; position: static !important; right: auto 
>> !important; top: auto !important; width: auto !important; box-sizing: 
>> content-box !important; font-family: Consolas, 'Bitstr
>>
>> ...
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to