On 25 Feb 2014, at 04:52, Bao Niu <niuba...@gmail.com> wrote:

>       * All transactions are rolled back and all connections returned to the 
> connection pool, unless the Session was bound directly to a Connection, in 
> which case the connection is still maintained (but still rolled back).
> I'm using SQLite. In the above paragraph, how is 'all connections returned to 
> the connection pool' implemented? SQLite seems Not to support connection 
> pooling.
> In addition, what does 'the Session was bound directly to a Connection' refer 
> to?
> 
> 
> By the way, is there a sub-group for beginner users? I appreciate all the 
> responses from pro users here, it's really super newbie-friendly, but I feel 
> my questions tend to be basic and taking up the fast lane is really not my 
> intention.
> 

SQLAlchemy supports various strategies for connection pooling. For SQLite, SA 
defaults to no pooling at all against file-based databases. See the docs at:

  
http://docs.sqlalchemy.org/en/rel_0_9/dialects/sqlite.html#threading-pooling-behavior

and

  http://docs.sqlalchemy.org/en/rel_0_9/core/pooling.html

An SQLAlchemy session can be bound to a "connectable", which is either an 
engine (as returned by create_engine) or a connection. If it is bound to an 
engine, it will create connections as necessary, and return them to the pool 
when it is finished with them. If it is bound to a connection, it will keep 
hold of that connection indefinitely.

In the example at:

  http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#getting-a-session

the object called "Session" is a factory for producing actual sessions. It is 
bound to an engine, and so the sessions it produces will also be bound to that 
engine.

In the example at:

  
http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#creating-ad-hoc-session-objects-with-alternate-arguments

the "Session" factory is still bound to an engine, but by calling 
Session(bind=engine.connect()), it creates a session instance bound to a single 
connection.

(It's also possible for a session not to be bound to anything at all, in which 
case SA will look at the MetaData object that holds the table that is being 
queried. If it is bound to an engine or connection, the session will use that. 
This approach tends to be downplayed these days though)

I hope that makes sense. Don't worry about asking questions - it's the whole 
point of the group, and I'm always glad when I see a question I can actually 
answer ;-)

Simon

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to