ToBoolean method return correct Boolean values as per JDBC spec

Started by Kim Hoabout 23 years ago3 messagespatches
Jump to latest
#1Kim Ho
kho@redhat.com

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

Attachments:

fixtoboolean.difftext/plain; charset=UTF-8; name=fixtoboolean.diffDownload+4-4
#2Kim Ho
kho@redhat.com
In reply to: Kim Ho (#1)
UPDATED Re: ToBoolean method return correct Boolean values as per JDBC spec

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.

Show quoted text

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

Attachments:

fixtoboolean.difftext/plain; charset=UTF-8; name=fixtoboolean.diffDownload+11-11
#3Barry Lind
barry@xythos.com
In reply to: Kim Ho (#1)
Re: ToBoolean method return correct Boolean values as per

Patch applied.

thanks,
--Barry

Kim Ho wrote:

Show quoted text

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