Uploaded image for project: 'MariaDB Connector/Python'
  1. MariaDB Connector/Python
  2. CONPY-68

jsonfield (longtext) returning as bytes

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.9.59
    • Fix Version/s: 1.0.1
    • Component/s: Generic
    • Labels:
      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')

        Attachments

          Activity

            People

            Assignee:
            georg Georg Richter
            Reporter:
            lucianobarcaro Luciano Barcaro
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Git Integration