From 8af0ea9dc137d39f44d40c7b5246f24f06c3a03d Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Mon, 11 Jun 2001 22:12:00 +0000
Subject: [PATCH]   Got two patches that were found by folks on the Castor
 list, that we'd like to submit.  These were done for the jdbc2 driver.  The
 first one is for support of the Types.BIT in the PreparedStatement class. 
 The following lines need to be inserted in the switch statment, at around
 line 530:

	(Prepared statment, line 554, before the default: switch
	case Types.BIT:
	     if (x instanceof Boolean) {
	          set(parameterIndex, ((Boolean)x).booleanValue() ? "TRUE" : "FALSE");
	     } else {
	          throw new PSQLException("postgresql.prep.type");
	     }
	     break;


	The second one is dealing with blobs,

	inserted in PreparedStatemant.java (After previous patch line, 558):
	         case Types.BINARY:
	         case Types.VARBINARY:
	                              setObject(parameterIndex,x);
	                              break;
	and in ResultSet.java (Around line 857):
	        case Types.BINARY:
	        case Types.VARBINARY:
	                        return getBytes(columnIndex);

Ned Wolpert <ned.wolpert@knowledgenet.com>
---
 .../jdbc/org/postgresql/jdbc1/PreparedStatement.java  | 11 +++++++++++
 .../jdbc/org/postgresql/jdbc1/ResultSet.java          |  3 +++
 .../jdbc/org/postgresql/jdbc2/PreparedStatement.java  | 11 +++++++++++
 .../jdbc/org/postgresql/jdbc2/ResultSet.java          |  3 +++
 4 files changed, 28 insertions(+)

diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/PreparedStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc1/PreparedStatement.java
index 84efeb09a06..e4c50f13af9 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/PreparedStatement.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/PreparedStatement.java
@@ -489,6 +489,17 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
 			case Types.TIMESTAMP:
 				setTimestamp(parameterIndex, (Timestamp)x);
 				break;
+			case Types.BIT:
+				if (x instanceof Boolean) {
+					set(parameterIndex, ((Boolean)x).booleanValue() ? "TRUE" : "FALSE");
+				} else {
+					throw new PSQLException("postgresql.prep.type");
+				}
+				break;
+			case Types.BINARY:
+			case Types.VARBINARY:
+				setObject(parameterIndex,x);
+				break;
 			case Types.OTHER:
 				setString(parameterIndex, ((PGobject)x).getValue());
 				break;
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java
index 98af07b0b63..bfbded0f01c 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java
@@ -806,6 +806,9 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
 	return getTime(columnIndex);
       case Types.TIMESTAMP:
 	return getTimestamp(columnIndex);
+      case Types.BINARY:
+      case Types.VARBINARY:
+	return getBytes(columnIndex);   
       default:
 	return connection.getObject(field.getTypeName(), getString(columnIndex));
       }
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java
index f204490533c..af73fee3626 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java
@@ -549,6 +549,17 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
 			case Types.TIMESTAMP:
 				setTimestamp(parameterIndex, (Timestamp)x);
 				break;
+			case Types.BIT:
+				if (x instanceof Boolean) {
+					set(parameterIndex, ((Boolean)x).booleanValue() ? "TRUE" : "FALSE");
+				} else {
+					throw new PSQLException("postgresql.prep.type");
+				}
+				break;
+			case Types.BINARY:
+			case Types.VARBINARY:
+				setObject(parameterIndex,x);
+				break;
 			case Types.OTHER:
 				setString(parameterIndex, ((PGobject)x).getValue());
 				break;
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
index 81605deec8e..5bf11e3c3eb 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
@@ -855,6 +855,9 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
 	return getTime(columnIndex);
       case Types.TIMESTAMP:
 	return getTimestamp(columnIndex);
+      case Types.BINARY:
+      case Types.VARBINARY:
+	return getBytes(columnIndex);   
       default:
 	return connection.getObject(field.getTypeName(), getString(columnIndex));
       }
-- 
GitLab