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

Support dictionary option in cursor class

Details

    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}
      

      Attachments

        Activity

          georg Georg Richter added a comment -

          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}
          

          georg Georg Richter added a comment - 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}
          georg Georg Richter added a comment -

          rev. e873f87fabe99410dab5e736eb6f50104fbd1999

          georg Georg Richter added a comment - rev. e873f87fabe99410dab5e736eb6f50104fbd1999

          People

            georg Georg Richter
            georg Georg Richter
            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.