Applied patch from Kim Ho at redhat to improve boolean and bit handling
authorBarry Lind <barry@xythos.com>
Wed, 17 Sep 2003 05:07:38 +0000 (05:07 +0000)
committerBarry Lind <barry@xythos.com>
Wed, 17 Sep 2003 05:07:38 +0000 (05:07 +0000)
in the jdbc driver

 Modified Files:
  jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java
  jdbc/org/postgresql/jdbc3/AbstractJdbc3Statement.java

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

index f4ce833d41cad9088cf770f7ba6a94a748383eb7..bed028eee75c5ccf266140d1404f07b8e40b26fe 100644 (file)
@@ -917,7 +917,7 @@ public abstract class AbstractJdbc1Statement implements BaseStatement
         */
        public void setBoolean(int parameterIndex, boolean x) throws SQLException
        {
-               bind(parameterIndex, x ? "'t'" : "'f'", PG_BOOLEAN);
+               bind(parameterIndex, x ? "'1'" : "'0'", PG_BOOLEAN);
        }
 
        /*
@@ -1551,11 +1551,15 @@ public abstract class AbstractJdbc1Statement implements BaseStatement
                        case Types.BIT:
                                if (x instanceof Boolean)
                                {
-                                       bind(parameterIndex, ((Boolean)x).booleanValue() ? "TRUE" : "FALSE", PG_TEXT);
+                                       bind(parameterIndex, ((Boolean)x).booleanValue() ? "'1'" : "'0'", PG_BOOLEAN);
+                               }
+                               else if (x instanceof String)
+                               {
+                                       bind(parameterIndex, Boolean.valueOf(x.toString()).booleanValue() ? "'1'" : "'0'", PG_BOOLEAN);
                                }
                                else if (x instanceof Number)
                                {
-                                       bind(parameterIndex, ((Number)x).intValue()==1 ? "TRUE" : "FALSE", PG_TEXT);
+                                       bind(parameterIndex, ((Number)x).intValue()==1 ? "'1'" : "'0'", PG_BOOLEAN);
                                }
                                else
                                {
index 1a4a90172c70306817d4c74b8624e66a38838ab6..a97efcb433e5f2b2cc34a2bde26cbcc474e9f6b9 100644 (file)
@@ -1359,5 +1359,16 @@ public abstract class AbstractJdbc3Statement extends org.postgresql.jdbc2.Abstra
        {
                throw org.postgresql.Driver.notImplemented();
        }
+       
+       public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException
+       {
+               switch (targetSqlType)
+               {
+                       case Types.BOOLEAN:
+                               super.setObject(parameterIndex, x, Types.BIT, scale);
+                       default:
+                               super.setObject(parameterIndex, x, targetSqlType, scale);
+               }
+       }
 
 }