db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henning P. Schmiedehausen" <...@intermeta.de>
Subject The dreaded BIT and PostgreSQL
Date Mon, 03 Nov 2003 16:46:16 GMT
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());
     }
 
     /**









-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
hps@intermeta.de        +49 9131 50 654 0   http://www.intermeta.de/

Java, perl, Solaris, Linux, xSP Consulting, Web Services 
freelance consultant -- Jakarta Turbine Development  -- hero for hire

"Dominate!! Dominate!! Eat your young and aggregate! I have grotty silicon!" 
      -- AOL CD when played backwards  (User Friendly - 200-10-15)

---------------------------------------------------------------------
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