Skip to content

Commit 0671b65

Browse files
author
Barry Lind
committed
Applied patch from Kim Ho at redhat to improve boolean and bit handling
in the jdbc driver Modified Files: jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java jdbc/org/postgresql/jdbc3/AbstractJdbc3Statement.java
1 parent ce90c0f commit 0671b65

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.sql.Types;
2727
import java.util.Vector;
2828

29-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.36 2003/09/13 04:02:15 barry Exp $
29+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.37 2003/09/17 05:07:37 barry Exp $
3030
* This class defines methods of the jdbc1 specification. This class is
3131
* extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2
3232
* methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement
@@ -917,7 +917,7 @@ public void setNull(int parameterIndex, int sqlType) throws SQLException
917917
*/
918918
public void setBoolean(int parameterIndex, boolean x) throws SQLException
919919
{
920-
bind(parameterIndex, x ? "'t'" : "'f'", PG_BOOLEAN);
920+
bind(parameterIndex, x ? "'1'" : "'0'", PG_BOOLEAN);
921921
}
922922

923923
/*
@@ -1551,11 +1551,15 @@ else if (x instanceof Integer || x instanceof Long ||
15511551
case Types.BIT:
15521552
if (x instanceof Boolean)
15531553
{
1554-
bind(parameterIndex, ((Boolean)x).booleanValue() ? "TRUE" : "FALSE", PG_TEXT);
1554+
bind(parameterIndex, ((Boolean)x).booleanValue() ? "'1'" : "'0'", PG_BOOLEAN);
1555+
}
1556+
else if (x instanceof String)
1557+
{
1558+
bind(parameterIndex, Boolean.valueOf(x.toString()).booleanValue() ? "'1'" : "'0'", PG_BOOLEAN);
15551559
}
15561560
else if (x instanceof Number)
15571561
{
1558-
bind(parameterIndex, ((Number)x).intValue()==1 ? "TRUE" : "FALSE", PG_TEXT);
1562+
bind(parameterIndex, ((Number)x).intValue()==1 ? "'1'" : "'0'", PG_BOOLEAN);
15591563
}
15601564
else
15611565
{

src/interfaces/jdbc/org/postgresql/jdbc3/AbstractJdbc3Statement.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.sql.*;
66
import java.util.Calendar;
77

8-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/AbstractJdbc3Statement.java,v 1.2 2002/09/06 21:23:06 momjian Exp $
8+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/AbstractJdbc3Statement.java,v 1.3 2003/09/17 05:07:38 barry Exp $
99
* This class defines methods of the jdbc3 specification. This class extends
1010
* org.postgresql.jdbc2.AbstractJdbc2Statement which provides the jdbc2
1111
* methods. The real Statement class (for jdbc2) is org.postgresql.jdbc3.Jdbc3Statement
@@ -1359,5 +1359,16 @@ public java.net.URL getURL(String parameterName) throws SQLException
13591359
{
13601360
throw org.postgresql.Driver.notImplemented();
13611361
}
1362+
1363+
public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException
1364+
{
1365+
switch (targetSqlType)
1366+
{
1367+
case Types.BOOLEAN:
1368+
super.setObject(parameterIndex, x, Types.BIT, scale);
1369+
default:
1370+
super.setObject(parameterIndex, x, targetSqlType, scale);
1371+
}
1372+
}
13621373

13631374
}

0 commit comments

Comments
 (0)