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

different behaviour on column with "COLLATE utf8mb4_bin" on select with and without parameter

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • None
    • 1.0.6
    • DBAPI 2.0
    • None

    Description

      Querying a column of type string (254) with "COLLATE utf8mb4_bin" leads to different results when caliing with or without parameter. With parameter the result type is "bytes", without it is "str" (as expected). The reason seems to be in the file mariadb_codecs.c as the function field_fetch_fromtext has a different implementation than field_fetch_callback to convert the result to a python object.

      If you look for the case MYSQL_TYPE_STRING in each method, you will see the difference:

      field_fetch_fromtext:

      if ( self->fields[column].charsetnr == CHARSET_BINARY)

      while in field_fetch_callback:

      if ((self->fields[column].flags & BINARY_FLAG ||
          self->fields[column].charsetnr == CHARSET_BINARY))

      Removing the self->fields[column].flags & BINARY_FLAG results in a consistent result.

      But I'm not sure, if this has some side effects, as (at least I assume) this different implementation has some reasons. If not, I would suggest to consolidate these two functions to use the same code for converting the result.

      Attachments

        Activity

          udessauer Ulrich Dessauer created issue -
          udessauer Ulrich Dessauer made changes -
          Field Original Value New Value
          Description Querying a column of type string (254) with "COLLATE utf8mb4_bin" leads to different results when caliing with or without parameter. With parameter the result type is "bytes", without it is "str" (as expected). The reason seems to be in the file *mariadb_codecs.c* as the function *field_fetch_fromtext* has a different implementation than *field_fetch_callback* to convert the result to a python object.

          If you look for the *case MYSQL_TYPE_STRING* in each method, you will see the difference:

          field_fetch_fromtext:
          {code}if ( self->fields[column].charsetnr == CHARSET_BINARY){code}

          while in field_fetch_callback:
          {code}if ((self->fields[column].flags & BINARY_FLAG ||
              self->fields[column].charsetnr == CHARSET_BINARY)){code}

          Removing the *self->fields[column].flags & BINARY_FLAG* results in a consistent result.

          But I'm not sure, if this has some side effects, as (at least I assume) this different implementation has some reasons. If not, I would suggest to consolidate these two functions to use the same code for converting the result (while glancing through the code, there are more different behaviours, e.g. the numeric values where in one case the signed flag is checked, while not in the other).

          Querying a column of type string (254) with "COLLATE utf8mb4_bin" leads to different results when caliing with or without parameter. With parameter the result type is "bytes", without it is "str" (as expected). The reason seems to be in the file *mariadb_codecs.c* as the function *field_fetch_fromtext* has a different implementation than *field_fetch_callback* to convert the result to a python object.

          If you look for the *case MYSQL_TYPE_STRING* in each method, you will see the difference:

          field_fetch_fromtext:
          {code}if ( self->fields[column].charsetnr == CHARSET_BINARY){code}

          while in field_fetch_callback:
          {code}if ((self->fields[column].flags & BINARY_FLAG ||
              self->fields[column].charsetnr == CHARSET_BINARY)){code}

          Removing the *self->fields[column].flags & BINARY_FLAG* results in a consistent result.

          But I'm not sure, if this has some side effects, as (at least I assume) this different implementation has some reasons. If not, I would suggest to consolidate these two functions to use the same code for converting the result.

          georg Georg Richter made changes -
          Fix Version/s 1.0.6 [ 25218 ]
          georg Georg Richter made changes -
          Component/s DBAPI 2.0 [ 14516 ]
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 118538 ] MariaDB v4 [ 135697 ]

          People

            georg Georg Richter
            udessauer Ulrich Dessauer
            Votes:
            0 Vote for this issue
            Watchers:
            1 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.