On Jul 5, 1:17 pm, SamDonaldson <[EMAIL PROTECTED]> wrote:
>
> engine = create_engine(db_uri)
> connection = engine.contextual_connect()
>
> # I now have the connection object, so I can start my txn on writes to
> the db
>
> trans = connection.begin()
>
> # now execute the sql
> connection.execute("INSERT .....")
> trans.commit()
> connection.close()
>
> Even though this is trivial, I wanted to make sure that calling
> create_engine repeatedly is not a problem for every time I want to do
> a dml on mysql?  And, based on the docs, contextual_connect() should
> function the same for the default plain strategy and threadlocal, and
> it will always try to get a connection from the pool.

heres from that "dbengines.html" page you read (emphasis added):

The Engine will ask the connection pool for a connection when a SQL
statement is executed. The default connection pool, QueuePool as well
as the default SQLite connection pool SingletonThreadPool, will open
connections to the database on an as-needed basis. As concurrent
statements are executed, QueuePool will grow its pool of connections
to a default size of five, and will allow a default "overflow" of ten.
***Since the Engine is essentially "home base" for the connection
pool, it follows that you should keep a single Engine per database
established within an application, rather than creating a new one for
each connection.***


>
> Thanks for your help on this and if you can, could you send me chapter
> 6 of your book?

i sent you an invite to a google group where you can get a view of
it.  chapters will also be publically downloadable as we write them in
a few months.


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to