-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
pymysql: fetch result type #5567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What are the situations where you wouldn't want to check |
Here's my actual code where I don't want to check for it: self._cursor.execute("select connection_id() as id")
self._connection_id = self._cursor.fetchone()["id"] # type: ignore As far as I can tell, |
You are right, I actually have similar code, where I know the exact number of rows and columns returned (for example |
Haha, I just opened my IDE and it automatically opened to this piece of code: query = (
"SELECT "
"COUNT(*), "
"SUM(CASE WHEN benutzer.kuerzel LIKE 'B%' THEN 0 ELSE 1 END) "
"FROM patienten LEFT OUTER JOIN benutzer "
"ON patienten.behandlerid = benutzer.solid "
"WHERE passiv = 0 AND behandelt_seit >= ? AND behandelt_seit < ?"
)
rows = store.execute_sql(query, [dt1, dt2])
assert rows is not None
assert len(rows) == 1
return rows[0][0], rows[0][1] or 0 (Although it's using |
Ideally
cursor
would have typepymysql.cursors.DictCursor
, so thatcursor.fetchone()
would returnDict[str, Any]
instead of an annoying union.Because
cursor.fetchone()
can returnNone
but often checking for it is annoying, it could instead returnUnion[Dict[str, Any], Any]
. See #5528 for a similar situation.We could make
connection
generic and overloadconnect()
to figure out what typeconnection.cursor()
returns. Something like this (omitting lots of irrelevant stuff):The downside is that now all other arguments of
connect()
have to be copy/pasted into two places, and there's many of them.The text was updated successfully, but these errors were encountered: