Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-299

PreparedStatement.setObject(Type.BIT, "1") should register as true.

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 1.4.5
    • 1.5.2
    • Other
    • None
    • Java8

    Description

      I called PreparedStatement.setObject(Type.BIT, "1"). I expected this value registered true.
      But it was actually false .

      I find the code at github. I found the next code in AbstractMariaDbPrepareStatement.java:781

      public void setObject(final int parameterIndex, final Object obj, final int targetSqlType) throws SQLException {
      ...
              } else if (obj instanceof String) {
      ...
                          case Types.BIT:
                              setBoolean(parameterIndex, Boolean.valueOf(str));
                              break;
      

      Types.BIT must be handled as a numeric type than a boolean type but the compatibility is important. So I think the next code is more appropriate.

                          case Types.BOOLEAN:
                          case Types.BIT:
                                  setBoolean(parameterIndex, Boolean.valueOf("true".equals(str) || !"0".equals(str)));
                              break;
      

      And I tested on MySQL Connector/J. It handled Types.BIT as a numeric type.

      Attachments

        Activity

          hidekatsu-izuno Hidekatsu Izuno created issue -
          diego dupin Diego Dupin added a comment - fixed with commit : https://github.com/MariaDB/mariadb-connector-j/commit/18fac0608b6b100b0811729b146194743b1b7a53
          diego dupin Diego Dupin made changes -
          Field Original Value New Value
          Component/s Other [ 12201 ]
          Fix Version/s 1.5.2-GA [ 22122 ]
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 75760 ] MariaDB v4 [ 134873 ]

          People

            diego dupin Diego Dupin
            hidekatsu-izuno Hidekatsu Izuno
            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.