Uploaded image for project: 'Torque'
  1. Torque
  2. TORQUE-59

correctBooleans() overwrites complex boolean criteria

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.2
    • 3.3
    • Runtime
    • None
    • MySQL 5

    Description

      If you have a table with a nullable boolean column:

      <column name="test" type="booleanint" size="1"/>

      and create a criteria like this:

      Criterion c1 = criteria.getNewCriterion(TEST, false, Criteria.EQUAL);
      Criterion c2 = criteria.getNewCriterion(TEST, null, Criteria.ISNULL);
      criteria.add(c1.or(c2));

      then the createQueryString returns the correct toString() result with

      ...WHERE (TEST = 0 or TEST IS NULL) ...

      but when you call doSelect(), it sends just TEST = 0 to the database.

      The problem is in the generated correctBooleans(Criteria) method. It checks if the Criteria contains one of the boolean column and replaces the criterion with an int value. So, in the above situation it removes the Criteria.ISNULL part...that is not expected.

      .....
      if (criteria.containsKey(TEST))
      {
      Object possibleBoolean = criteria.get(TEST);
      if (possibleBoolean instanceof Boolean)

      { criteria.add(TEST, ((Boolean) possibleBoolean).booleanValue() ? 1 : 0); }

      }

      The only possible workaround is to use the integer value (0,1) in the criterion (Criterion c1 = criteria.getNewCriterion(TEST, 0, Criteria.EQUAL) ). But this is not expected, because it is database specific.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            tfischer Thomas Fox
            trickert Thoralf Rickert
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment