- changed status to closed
Problem of 'fetchone'
Hi SQLAlchemy Team,
Thanks for creating this awesome library.
Not sure of if it is bug. Maybe I'm using it in wrong way. Please help to see this issue.
I have been using MySQL-Python for a long time. Recently I tried to integrated a connection pool which is based on SQLAlchemy, In terms of the legacy code, I'm using the raw_connection from the engine.
Here is the sample code of two implementations:
No Pool Version:
connection = MySQLdb.connect(...)
connection.autocommit(True)
try:
cursor = db.cursor()
if not cursor.execute(sql, values) > 0:
return None
row = cursor.fetchone()
finally:
connection.close()
return row[0]
Pool Version:
pool = create_engine("mysql+mysqldb://...")
connection = pool.raw_connection()
connection.autocommit(True)
try:
cursor = db.cursor()
if not cursor.execute(sql, values) > 0:
return None
row = cursor.fetchone()
finally:
connection.close()
return row[0]
The codes look similar except the way to obtain the connection. After using the pool version, sometimes(not every time, actually in my situation, it occurs with 0.01% of all db queries), the return value of execute
method is great than 0 and the fetchone
method will return None. I guess it may related to the connection reuse, but I have no idea of which part is going wrong. Does anyone can help me?
Comments (2)
-
repo owner -
reporter Thanks for the suggestion. I will move it the mailing list.
- Log in to comment
If you can, let's please continue this on the mailing list at: https://groups.google.com/forum/#!forum/sqlalchemy. We would need to see what "sql" is here, also need to see: 1. your MySQL options, any pool options in use 2. using threads? 3. using eventlet / gevent / tornado / etc? what kind of concurrency? "