On Jun 18, 2008, at 12:41 PM, Hans wrote:
>
> Ok, this makes sense. I guess I don't need to worry about the
> threadlocal stuff if I'm always creating and disposing of connections.
>
> For example, if I have a DAO method (classmethod) that peforms some
> custom SQL query, it sounds like the clean & simple way to do this
> would be to just create and dispose of the connection within that
> method. Then I don't need to worry about thread safety issues
> (right?).
>
> def get_some_data(cls, params):
> conn = engine.connect()
> rs = conn.execute('stored proc or complex SQL here')
> return rs
you could just as easily use engine.execute() for a case like the
above, which does basically the same thing. theres no thread safety
issues inherent.
>
> On a follow-up note, If I am creating a new connection (calling
> engine.connect()) for every method, will that actually be creating a
> new connection (assuming I'm not using strategy="threadlocal")? If
> so, is there a better convention? -- I assume that something like a
> singleton pattern would be right out, since that would imply sharing
> between threads.
when you say engine.connect() it draws the connection from the
connection pool. So whether or not a new connection is "created" at
that point depends on the configuration and current state of the pool.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---