ToBoolean method return correct Boolean values as per JDBC spec

Lists: pgsql-jdbcpgsql-patches
From: Kim Ho <kho(at)redhat(dot)com>
To: pgsql-jdbc-list <pgsql-jdbc(at)postgresql(dot)org>, PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: ToBoolean method return correct Boolean values as per JDBC spec
Date: 2003-06-18 18:02:56
Message-ID: 1055959376.13891.57.camel@topanga.toronto.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc pgsql-patches

Problem:
- The toBoolean() method treats all input strings that start with T, t,
or 1 as true. For instance, "The sun is not a star." is evaluated as
true...
However, booleans are only supposed to be true if the
value of the input string is equalsignorecase "True".
I've left in a single character string "1" and
a single character string "t" (or "T") for backwards compatibility.

new Boolean("this is not a boolean") produces a Boolean object that
represents false.

However, when you insert 'this is not a boolean' into a CHAR column and
use getBoolean to extract it, it returns true.

Fix:
- Different check in toBoolean()

Cheers,

Kim

Attachment Content-Type Size
fixtoboolean.diff text/plain 914 bytes

From: Kim Ho <kho(at)redhat(dot)com>
To: pgsql-jdbc-list <pgsql-jdbc(at)postgresql(dot)org>
Subject: UPDATED Re: ToBoolean method return correct Boolean values as per JDBC spec
Date: 2003-07-03 18:35:19
Message-ID: 1057257319.4299.33.camel@topanga.toronto.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc pgsql-patches

On Wed, 2003-06-18 at 14:02, Kim Ho wrote:
> Problem:
> - The toBoolean() method treats all input strings that start with T, t,
> or 1 as true. For instance, "The sun is not a star." is evaluated as
> true...
> However, booleans are only supposed to be true if the
> value of the input string is equalsignorecase "True".
> I've left in a single character string "1" and
> a single character string "t" (or "T") for backwards compatibility.
>
> new Boolean("this is not a boolean") produces a Boolean object that
> represents false.
>
Now accepts things like 1.0 from Double columns and whatnot.

> However, when you insert 'this is not a boolean' into a CHAR column and
> use getBoolean to extract it, it returns true.
>
> Fix:
> - Different check in toBoolean()
>

Attachment Content-Type Size
fixtoboolean.diff text/plain 1020 bytes

From: Barry Lind <blind(at)xythos(dot)com>
To: Kim Ho <kho(at)redhat(dot)com>
Cc: pgsql-jdbc-list <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: ToBoolean method return correct Boolean values as per
Date: 2003-09-17 07:00:55
Message-ID: 3F6806A7.90302@xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc pgsql-patches

Patch applied.

thanks,
--Barry

Kim Ho wrote:
> Problem:
> - The toBoolean() method treats all input strings that start with T, t,
> or 1 as true. For instance, "The sun is not a star." is evaluated as
> true...
> However, booleans are only supposed to be true if the
> value of the input string is equalsignorecase "True".
> I've left in a single character string "1" and
> a single character string "t" (or "T") for backwards compatibility.
>
> new Boolean("this is not a boolean") produces a Boolean object that
> represents false.
>
> However, when you insert 'this is not a boolean' into a CHAR column and
> use getBoolean to extract it, it returns true.
>
> Fix:
> - Different check in toBoolean()
>
> Cheers,
>
> Kim
>
>
> ------------------------------------------------------------------------
>
> ? cloudscape.LOG
> Index: org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
> ===================================================================
> RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java,v
> retrieving revision 1.12
> diff -c -p -c -p -r1.12 AbstractJdbc1ResultSet.java
> *** org/postgresql/jdbc1/AbstractJdbc1ResultSet.java 3 May 2003 20:40:45 -0000 1.12
> --- org/postgresql/jdbc1/AbstractJdbc1ResultSet.java 18 Jun 2003 14:22:43 -0000
> *************** public abstract class AbstractJdbc1Resul
> *** 766,773 ****
> {
> if (s != null)
> {
> ! int c = s.charAt(0);
> ! return ((c == 't') || (c == 'T') || (c == '1'));
> }
> return false; // SQL NULL
> }
> --- 766,773 ----
> {
> if (s != null)
> {
> ! s = s.trim();
> ! return (s.equalsIgnoreCase("true") || s.equals("1") || s.equalsIgnoreCase("t"));
> }
> return false; // SQL NULL
> }
>
>
> ------------------------------------------------------------------------
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings