commit() or rollback() on the connection object as necessary, eg.

con = g.pool.connection()
cur = con.cursor()

try:
    # do some stuff
    cur.execute("update .... ")
    cur.execute("update .... ")
    cur.execute("insert into .... ")
    con.commit()
except:
    con.rollback()



On Thu, 23 Jul 2009, ????? ?????? wrote:

>

On 22 ÿÿÿÿÿÿ, 21:15, [email protected] wrote:
> In your lib/app_globals.py set up a database pool (using DBUtils).
>
> eg.
>
>          self.pool = PooledDB(MySQLdb,
>                               int(app_conf['db.pool_size']),
>                               user=app_conf['db.user'],
>                               passwd=app_conf['db.password'],
>                               host=app_conf['db.host'],
>                               db=app_conf['db.name'],
>                               cursorclass=MySQLdb.cursors.DictCursor)
>
> Then you can access a db connection from the pool in your controllers
> using the 'g' variable:
>
> con = g.pool.connection()
> cur = con.cursor()
> cur.execute("select * from foo")
> results = cur.fetchall()
>
> You can ofcourse encapsulate this in your Sql class.
>
> Hope that helps,
>
How to use transaction with DBUtils?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to