> each query, or just returning it to the connection pool via close()
> (which also calls rollback()) and then re-acquiring it from the pool
> as needed.

I have a wrapper function called execute() whcih traps any errors and
then recreates the mysql engine object and tries to resubmit the qry:

def initialize_connection():
    mysql.db = create_engine('mysql://%s:[EMAIL PROTECTED]/%s' % 
(config.DB_USER,
config.DB_PASS, config.DB_HOST, config.DB_NAME))
    mysql.conn = mysql.db.connect()

initialize_connection()

def execute(qry):
    try:
        _rows = mysql.conn.execute(qry)
    except:
        initialize_connection()
        _rows = mysql.conn.execute(qry)
    rows = []
    for i, row in enumerate(_rows):
        row_dict = attrdict()
        if i == 0:
            column_headers = row.keys()
        for key in column_headers:
            row_dict[key] = getattr(row, key)
        rows.append(row_dict)
    return rows

Should I add:

mysql.conn = mysql.db.connect()
mysq.close()

at the beginning and end of the function?

I convert the result set to a list of dicts since I get not compress
and pickle the objects being returned by sqlalchemy.

Thanks,

Vineet



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

Reply via email to