On 05/19/2017 12:08 AM, Van Klaveren, Brian N. wrote:
Hi,
I need access to MySQLdb.connection.error() and
MySQLdb.connection.errno(), as we have a database which is throwing
custom error codes that are higher than CR_MAX_ERROR (for reference:
https://github.com/PyMySQL/mysqlclient-python/blob/master/_mysql.c#L124)
My actual code looks like something along these lines:
from sqlalchemy import create_engine, text
engine = create_engine(url)
sql = "SELECT... "
try:
conn = engine.connect()
rows = conn.execute(text(sql))
except Exception as e:
if hasattr(conn.connection, "error"):
print(conn.connection.errno())
print(conn.connection.error())
I've also tried:
err_conn = conn._branch()
try:
err_conn = engine.connect()
rows = err_conn.execute(text(sql))
except Exception as e:
if hasattr(err_conn.connection, "error"):
print(err_conn.connection.errno())
print(err_conn.connection.error())
with no luck.
I'm not sure how to write a minimal test that just uses vanilla MySQL,
because I'm not sure how to trigger an error with a errno > CR_MAX_ERROR
other than in our system.
I'm losing the information somehow, via a connection being
closed/reopened or something? I'm not really sure. What might be the a
way to handle this without just using raw_connection or writing a new
dialect?
what's the actual error that's causing this to occur? if the error is
one that SQLAlchemy considers to be a "disconnect", it will recycle the
connection.
To guaranteed get at the error the moment it happens with the original
connection, the cursor, and everything else, use the handle_error event:
http://docs.sqlalchemy.org/en/latest/core/events.html?highlight=handle_error#sqlalchemy.events.ConnectionEvents.handle_error
Thanks,
Brian
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and
Verifiable Example. See http://stackoverflow.com/help/mcve for a full
description.
---
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.