Menu

#16 override default BooleanValueObject

sqlbuilder-2.1.2
closed
None
1
2016-01-30
2015-12-31
Anonymous
No

The BooleanValueObject replaces booleans with integers.
Some databases (ahem, postgres) throw an error when you true and compare an integer and a boolean.

So the java code:

query.addCondition(BinaryCondition
.equalTo(aCol, true));

evaluates to

(myTable.myCol = 1)

which causes postgres to complain:

ERROR: operator does not exist: boolean = integer

I can fix this with:

query.addCondition(BinaryCondition
.equalTo(aCol, new CustomSql(true)));

but it would be nice to override this, somehow.

Rich MacDonald
(Same guy who posted the CTE question the other day.)

Discussion

  • James Ahlborn

    James Ahlborn - 2016-01-01

    Yeah, boolean is a bit of a mess in sql. looks like boolean support is very uneven among the various major dbs. i think oracle was the db we were using when we originally wrote SqlBuilder, and oracle has no boolean data type. Unfortunately, SqlBuilder doesn't have any notion of a dialect, so it's not clear what the best solution is here. Obivously, the SQL 92 spec compliant solution is TRUE and FALSE.

     
  • James Ahlborn

    James Ahlborn - 2016-01-30
    • status: open --> closed
    • assigned_to: James Ahlborn
    • Group: Unassigned --> sqlbuilder-2.1.2
     
  • James Ahlborn

    James Ahlborn - 2016-01-30

    I added the system property "com.healthmarketscience.sqlbuilder.useBooleanLiterals" which, if enabled, will cause sqlbuilder to use sql boolean literals TRUE and FALSE instead of 1 and 0.

    fixed in trunk, will be in the 2.1.2 release.

     

Log in to post a comment.