Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
0.9.59
-
None
Description
Internally, mariadb converts json columns to longtext, but all queries involving json columns are returning as bytes. Should return as string.
import mariadb |
import json |
|
db = mariadb.connect(host='xxx', user='yyy', password='zzz', database='temp') |
qr = db.cursor(buffered=True) |
|
qr.execute('''create table tmp_json(
|
id int unsigned not null primary key, |
myJson json)''')
|
|
qr.execute('show columns from tmp_json') |
for col in qr: |
print(col) |
# Returns:
|
# ('id', 'int(10) unsigned', 'NO', 'PRI', None, '')
|
# ('myJson', 'longtext', 'YES', '', None, '')
|
|
content = {'a': 'aaa', 'b': 'bbb', 'c': 123} |
|
qr.execute('insert into tmp_json (id, myJson) values (?, ?)', (1, json.dumps(content))) |
qr.execute('select myJson from tmp_json where id=1') |
|
myJson, = qr.fetchone() |
print(myJson, type(myJson)) |
# Returns:
|
# b'{"a": "aaa", "b": "bbb", "c": 123}' <class 'bytes'>
|
|
qr.execute('drop table tmp_json') |