Details
-
New Feature
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
0.9.56
Description
Support returning Dict class instead of default list when fetching rows:
import mariadb |
|
connection=mariadb.connect(user="user") |
cursor=connection.cursor(dictionary=True) |
cursor.execute("SELECT 1 as foo") |
row= cursor.fetchone |
print(row) |
should return
{'foo': 1} |
It should be documented, that this option only exists for compatibility reasons. If possible dictionary=True should be avoided, since it may lead to inconsistency: While in a dictionary keys are unique, they are not unique in a result set:
>>> cursor=conn.cursor(dictionary=True)
>>> cursor.execute("select 1 as foo, 'bar' as foo")
>>> cursor.fetchone()
{'foo': 'bar'}
>>> cursor.execute("select 1,2,1")
>>> cursor.fetchone()
{'1': 1, '2': 2}