Derby
  1. Derby
  2. DERBY-4889

Different byte to boolean conversion on embedded and client

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 10.7.1.1
    • Fix Version/s: 10.7.1.1
    • Component/s: JDBC
    • Labels:
      None
    • Issue & fix info:
      Repro attached
    • Bug behavior facts:
      Embedded/Client difference

      Description

      The following code prints "true" with the embedded driver and "false" with the client driver:

      PreparedStatement ps = c.prepareStatement("values cast(? as boolean)");
      ps.setByte(1, (byte) 32);
      ResultSet rs = ps.executeQuery();
      rs.next();
      System.out.println(rs.getBoolean(1));

      If setByte() is replaced with setInt(), they both print "true".

        Issue Links

          Activity

          Hide
          Knut Anders Hatlen added a comment - - edited

          Same issue exists for setShort().

          Show
          Knut Anders Hatlen added a comment - - edited Same issue exists for setShort().
          Hide
          Knut Anders Hatlen added a comment -

          Also an issue for setObject() with a java.lang.Byte or java.lang.Short object.

          Show
          Knut Anders Hatlen added a comment - Also an issue for setObject() with a java.lang.Byte or java.lang.Short object.
          Hide
          Knut Anders Hatlen added a comment -

          ParameterMappingTest contains a workaround for this issue. Search for a comment with this issue number in the source file.

          Show
          Knut Anders Hatlen added a comment - ParameterMappingTest contains a workaround for this issue. Search for a comment with this issue number in the source file.
          Hide
          Rick Hillegas added a comment -

          Thanks for finding this bug, Knut. I can confirm this behavior also with the following INSERT statement where column A has type BOOLEAN:

          insert into t( a ) values ( ? )

          For the client, the following calls insert TRUE:

          ps.setInt( 1, 32 );
          ps.setLong( 1, 32 );
          ps.setObject( 1, new Integer( 32 ) );
          ps.setObject( 1, new Long( 32L ) );

          but the following calls insert FALSE:

          ps.setByte( 1, (byte) 32 );
          ps.setByte( 1, (short) 32 );
          ps.setObject( 1, new Byte( (byte) 32 ) );
          ps.setObject( 1, new Short( (short) 32 ) );

          All calls insert TRUE in the embedded case.

          Show
          Rick Hillegas added a comment - Thanks for finding this bug, Knut. I can confirm this behavior also with the following INSERT statement where column A has type BOOLEAN: insert into t( a ) values ( ? ) For the client, the following calls insert TRUE: ps.setInt( 1, 32 ); ps.setLong( 1, 32 ); ps.setObject( 1, new Integer( 32 ) ); ps.setObject( 1, new Long( 32L ) ); but the following calls insert FALSE: ps.setByte( 1, (byte) 32 ); ps.setByte( 1, (short) 32 ); ps.setObject( 1, new Byte( (byte) 32 ) ); ps.setObject( 1, new Short( (short) 32 ) ); All calls insert TRUE in the embedded case.
          Hide
          Rick Hillegas added a comment -

          Attaching derby-4889-01-aa-removeSpecialCase.diff. This patch removes a piece of defensive coding which caused this error. The regression tests passed for me on this patch. In addition, I ran the compabitility tests using two versions of Derby: 10.6.1.0 and the trunk. Those tests ran cleanly too. Committed at subversion revision 1032667.

          There was a piece of defensive coding in the server-side network code which really didn't do anything except cause this bug. I removed that code. Now the test cases run correctly.

          Touches the following files:

          -------------

          M java/drda/org/apache/derby/impl/drda/DRDAConnThread.java

          Removed the defensive code which caused the bug.

          -------------

          Removed a special case which Knut added in order to enable some boolean tests. The special case canonized wrong results for the network run.

          M java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java

          Show
          Rick Hillegas added a comment - Attaching derby-4889-01-aa-removeSpecialCase.diff. This patch removes a piece of defensive coding which caused this error. The regression tests passed for me on this patch. In addition, I ran the compabitility tests using two versions of Derby: 10.6.1.0 and the trunk. Those tests ran cleanly too. Committed at subversion revision 1032667. There was a piece of defensive coding in the server-side network code which really didn't do anything except cause this bug. I removed that code. Now the test cases run correctly. Touches the following files: ------------- M java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Removed the defensive code which caused the bug. ------------- Removed a special case which Knut added in order to enable some boolean tests. The special case canonized wrong results for the network run. M java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java
          Hide
          Knut Anders Hatlen added a comment -

          I've verified that the code in the bug description produces the expected result for all valid short and byte values now. Thanks for fixing it, Rick.

          Show
          Knut Anders Hatlen added a comment - I've verified that the code in the bug description produces the expected result for all valid short and byte values now. Thanks for fixing it, Rick.

            People

            • Assignee:
              Rick Hillegas
              Reporter:
              Knut Anders Hatlen
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development