Derby
  1. Derby
  2. DERBY-4684

Correct the implicit casting of other types to BOOLEAN

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 10.6.1.0
    • Fix Version/s: 10.7.1.1
    • Component/s: SQL
    • Labels:
      None
    • Bug behavior facts:
      Deviation from standard

      Description

      Via a UNION query, it is possible to implicitly cast non-BOOLEAN types to BOOLEAN today. These implicit casts do not obey the SQL Standard rules defined in part 2, section 6.12 (<cast specification>). Derby should support the Standard rules.

      The following query shows how you can implicitly cast a non-BOOLEAN data type to BOOLEAN today:

      select isindex from sys.sysconglomerates where conglomeratename = 'foo'
      union
      values ( 1 )

        Issue Links

          Activity

          Hide
          Rick Hillegas added a comment -

          Attaching derby-4684-01-ab-implicitCastsToBoolean.diff. This causes Derby to raise an exception if you try to implicitly cast to or from BOOLEAN in a way which violates the SQL Standard. Regression tests passed for me with this patch applied.

          This patch removes the ability to cast numerics to boolean. It also prevents String values from being cast to BOOLEAN unless they are the handful of legal values allowed by the Standard. I believe that most users won't even notice these changes, for the following reasons:

          1) Getting Derby to implicitly cast to BOOLEAN involves writing a very contrived query whose point is to trick Derby into returning an unsupported data type.

          2) No existing tests failed with this patch.

          Touches the following files:

          ----------

          M java/engine/org/apache/derby/impl/sql/compile/BooleanTypeCompiler.java

          Don't allow numerics to be stored in BOOLEANs.

          ----------

          M java/engine/org/apache/derby/iapi/types/SQLBoolean.java

          Raise an error if, at run time, you try to cast a bad String to BOOLEAN.

          ----------

          M java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java

          Regression test to verify the Standard behavior.

          Show
          Rick Hillegas added a comment - Attaching derby-4684-01-ab-implicitCastsToBoolean.diff. This causes Derby to raise an exception if you try to implicitly cast to or from BOOLEAN in a way which violates the SQL Standard. Regression tests passed for me with this patch applied. This patch removes the ability to cast numerics to boolean. It also prevents String values from being cast to BOOLEAN unless they are the handful of legal values allowed by the Standard. I believe that most users won't even notice these changes, for the following reasons: 1) Getting Derby to implicitly cast to BOOLEAN involves writing a very contrived query whose point is to trick Derby into returning an unsupported data type. 2) No existing tests failed with this patch. Touches the following files: ---------- M java/engine/org/apache/derby/impl/sql/compile/BooleanTypeCompiler.java Don't allow numerics to be stored in BOOLEANs. ---------- M java/engine/org/apache/derby/iapi/types/SQLBoolean.java Raise an error if, at run time, you try to cast a bad String to BOOLEAN. ---------- M java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java Regression test to verify the Standard behavior.
          Hide
          Rick Hillegas added a comment -

          Committed derby-4684-01-ab-implicitCastsToBoolean.diff at subversion revision 951047.

          Show
          Rick Hillegas added a comment - Committed derby-4684-01-ab-implicitCastsToBoolean.diff at subversion revision 951047.

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development