Changeset: 0d3537514b4e for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0d3537514b4e Modified Files: java/ChangeLog.Feb2013 java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java Branch: Feb2013 Log Message:
PreparedStatement: properly handle null for setXXX() methods, bug #3288 diffs (98 lines): diff --git a/java/ChangeLog.Feb2013 b/java/ChangeLog.Feb2013 --- a/java/ChangeLog.Feb2013 +++ b/java/ChangeLog.Feb2013 @@ -1,3 +1,7 @@ # ChangeLog file for java # This file is updated with Maddlog +* Thu May 23 2013 Fabian Groffen <fab...@monetdb.org> +- Allow PreparedStatement.setXXX() methods to be called with null + arguments, bug #3288 + diff --git a/java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java b/java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java --- a/java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java +++ b/java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java @@ -1155,6 +1155,11 @@ public class MonetPreparedStatement int length) throws SQLException { + if (reader == null) { + setNull(parameterIndex, -1); + return; + } + CharBuffer tmp = CharBuffer.allocate(length); try { reader.read(tmp); @@ -1223,6 +1228,11 @@ public class MonetPreparedStatement * @throws SQLException if a database access error occurs */ public void setClob(int i, Clob x) throws SQLException { + if (x == null) { + setNull(i, -1); + return; + } + // simply serialise the CLOB into a variable for now... far from // efficient, but might work for a few cases... // be on your marks: we have to cast the length down! @@ -1262,6 +1272,11 @@ public class MonetPreparedStatement * @throws SQLException if a database access error occurs */ public void setClob(int i, Reader reader, long length) throws SQLException { + if (reader == null) { + setNull(i, -1); + return; + } + // simply serialise the CLOB into a variable for now... far from // efficient, but might work for a few cases... CharBuffer buf = CharBuffer.allocate((int)length); // have to down cast :( @@ -1306,6 +1321,11 @@ public class MonetPreparedStatement public void setDate(int parameterIndex, java.sql.Date x, Calendar cal) throws SQLException { + if (x == null) { + setNull(parameterIndex, -1); + return; + } + if (cal == null) { setValue(parameterIndex, "date '" + x.toString() + "'"); } else { @@ -2098,6 +2118,11 @@ public class MonetPreparedStatement * @throws SQLException if a database access error occurs */ public void setString(int parameterIndex, String x) throws SQLException { + if (x == null) { + setNull(parameterIndex, -1); + return; + } + setValue( parameterIndex, "'" + x.replaceAll("\\\\", "\\\\\\\\").replaceAll("'", "\\\\'") + "'" @@ -2150,6 +2175,11 @@ public class MonetPreparedStatement public void setTime(int index, Time x, Calendar cal) throws SQLException { + if (x == null) { + setNull(index, -1); + return; + } + boolean hasTimeZone = monetdbType[getParamIdx(index)].endsWith("tz"); if (hasTimeZone) { // timezone shouldn't matter, since the server is timezone @@ -2205,6 +2235,11 @@ public class MonetPreparedStatement public void setTimestamp(int index, Timestamp x, Calendar cal) throws SQLException { + if (x == null) { + setNull(index, -1); + return; + } + boolean hasTimeZone = monetdbType[getParamIdx(index)].endsWith("tz"); if (hasTimeZone) { // timezone shouldn't matter, since the server is timezone _______________________________________________ checkin-list mailing list checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list