From 7934c93cbed4471e55924631fa92a83b4c32e395 Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Wed, 16 May 2001 17:22:25 +0000
Subject: [PATCH] This patch fixes a bug which occurs when setObject(1,obj) is
 called and obj is of type Object, and is null

Dave Cramer
---
 .../jdbc/org/postgresql/jdbc1/PreparedStatement.java      | 8 ++++++++
 .../jdbc/org/postgresql/jdbc2/PreparedStatement.java      | 8 ++++++++
 2 files changed, 16 insertions(+)

diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/PreparedStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc1/PreparedStatement.java
index 70a0b91dbd5..84efeb09a06 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/PreparedStatement.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/PreparedStatement.java
@@ -455,6 +455,10 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
 	 */
 	public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException
 	{
+		if (x == null){
+			setNull(parameterIndex,Types.OTHER);
+			return;
+		}
 		switch (targetSqlType)
 		{
 			case Types.TINYINT:
@@ -506,6 +510,10 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
    */
 	public void setObject(int parameterIndex, Object x) throws SQLException
 	{
+		if (x == null){
+			setNull(parameterIndex,Types.OTHER);
+			return;
+		}
 		if (x instanceof String)
 			setString(parameterIndex, (String)x);
 		else if (x instanceof BigDecimal)
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java
index 5cf51527552..f204490533c 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java
@@ -515,6 +515,10 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
 	 */
 	public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException
 	{
+		if (x == null){
+			setNull(parameterIndex,Types.OTHER);
+			return;
+		}
 		switch (targetSqlType)
 		{
 			case Types.TINYINT:
@@ -566,6 +570,10 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
    */
 	public void setObject(int parameterIndex, Object x) throws SQLException
 	{
+		if (x == null){
+			setNull(parameterIndex,Types.OTHER);
+			return;
+		}
 		if (x instanceof String)
 			setString(parameterIndex, (String)x);
 		else if (x instanceof BigDecimal)
-- 
GitLab