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

jsonfield (longtext) returning as bytes

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 0.9.59
    • 1.0.1
    • Generic
    • 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

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

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.