On Jan 21, 2011, at 9:16 AM, bool wrote:

> 
> I am not an expert in these concepts, so just trying to make sure I
> understand what you said.
> 
> 1. If I use connection.execute(), then then every sql statements is
> not put in its own transactions.
> 2. But If I use connection-less execution like table.execute or
> engine.execute() then every statement is put in its own transaction.

so the relevant info we're talking about is here:  
http://www.sqlalchemy.org/docs/core/connections.html

connectionless execution - execute statement in a new transaction, if its an 
INSERT/UPDATE/DELETE, autocommit:

        engine.execute("select * from table")

implicit, connectionless execution - same behavior, executes in a new 
transaction, autocommits:

        table.insert().execute(a=5, b=4)

explicit execution - uses a Connection, but will autocommit ....

        conn = engine.connect()
        conn.execute("insert into table (a, b, c) values (1, 2, 3)")

...unless you start a transaction:

        trans = conn.begin()
        conn.execute("insert into table (a, b, c) values (1, 2, 3)")
        conn.execute("insert into table (a, b, c) values (4, 5, 6)")
        trans.commit()


ORM: using the Session, you're in a transaction for all operations, bounded by 
rollback()/commit():

        sess = Session()
        sess.execute("insert into table (a, b, c) values (1, 2, 3)")
        sess.execute("insert into table (a, b, c) values (4, 5, 6)")
        sess.commit()

... unless you're using autocommit :

        sess = Session(autocommit=True)


> 
> Can you confirm if the above understanding is correct.
> 
> Also what is the DBAPI that you generally refer to ?

DBAPI is what you're talking to your database with:  

http://www.python.org/dev/peps/pep-0249/


-- 
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