db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From William Kemper <wkem...@franchise.com>
Subject Re: The dreaded BIT and PostgreSQL
Date Mon, 03 Nov 2003 17:53:00 GMT
I'll second the motion.  Our application uses torque 3.0.2 and when we 
switched from mssql to postgres, the first thing I had to do was fix the 
postgres adapter's boolean string.  However, I used 't' and 'f' instead of 
"true" and "false".  But certainly, postgres does not use '1' and '0' to 
represent booleans.

On Monday 03 November 2003 8:46 am, Henning P. Schmiedehausen wrote:
> Hi,
>
> the following situation. I have a table definition for a postgres
> database that has the following column definition:
>
> [...]
>     <column name="PROJEKTDATEN_LOCKED" required="true" type="BIT"
> javaName="Locked"/> [...]
>
> When building a Criteria for the "PROJEKTDATEN" table (e.g. deleting)
> then a criteria is built that contains a PROJEKTDATEN.PROJEKTDATEN_LOCKED =
> <something>
>
> For PostgreSQL, the "something" must be true or false.
>
> But Torque generates 1 and 0 (true == 1, false == 0). Which leads
> to "cannot convert between boolean and integer, you need an explict
> cast" from the database.
>
> The choice of "0" and "1" is useful if the underlying column is not a
> real boolean column but an integer column (which is the choice with
> databases that don't have a real boolean type).
>
> The real solution would be if Torque looks at the column map and
> generated true and false for boolean columns and 0/1 for integer or
> other types. However, Torque isn't that clever.
>
> If you apply the following patch to the 3.1 branch, then some
> operations with criterias (most prominent: doDelete(<objecttype> obj)
> in the generated peers) will work with boolean column. But this breaks
> the behaviour where adding a "false" to a criteria put a "0" into an
> integer column and a "true" puts a "1". So this is a breaking change.
>
> Personally, I'd very much prefer applying this patch to Torque (3.2
> and 3.1) because IMHO it fixes a bug.
>
> Discussion wanted.
>
> 	Regards
> 		Henning
>
> Index: src/java/org/apache/torque/adapter/DBPostgres.java
> ===================================================================
> RCS file:
> /home/cvs/db-torque/src/java/org/apache/torque/adapter/DBPostgres.java,v
> retrieving revision 1.16
> diff -u -b -r1.16 DBPostgres.java
> --- src/java/org/apache/torque/adapter/DBPostgres.java	25 Aug 2003 21:56:10
> -0000	1.16 +++ src/java/org/apache/torque/adapter/DBPostgres.java	3 Nov
> 2003 16:35:41 -0000 @@ -180,6 +180,6 @@
>       */
>      public String getBooleanString(Boolean b)
>      {
> -        return (b == null) ? "0" : (Boolean.TRUE.equals(b) ? "1" : "0");
> +        return (b == null) ? "false" : (Boolean.TRUE.equals(b) ? "true" :
> "false"); }
>  }
> Index: src/test/org/apache/torque/util/CriteriaTest.java
> ===================================================================
> RCS file:
> /home/cvs/db-torque/src/test/org/apache/torque/util/CriteriaTest.java,v
> retrieving revision 1.20
> diff -u -b -r1.20 CriteriaTest.java
> --- src/test/org/apache/torque/util/CriteriaTest.java	18 Jul 2003 20:11:48
> -0000	1.20 +++ src/test/org/apache/torque/util/CriteriaTest.java	3 Nov 2003
> 16:35:41 -0000 @@ -313,7 +313,7 @@
>              fail("Exception thrown in DBFactory");
>          }
>
> -        assertEquals("TABLE.COLUMN=1", cc.toString());
> +        assertEquals("TABLE.COLUMN=true", cc.toString());
>      }
>
>      /**


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message