Author: kahatlen
Date: Wed Jul 12 05:24:18 2006
New Revision: 421255
URL: http://svn.apache.org/viewvc?rev=421255&view=rev
Log:
DERBY-1476: PreparedStatement.setNull(int,int) should throw
SQLFeatureNotSupportedException for unsupported types
derby-1476-v1.diff adds a call to checkForSupportedDataType() in
setNull(). It also moves that call in setObject() after 'if (obj ==
null) { setNull(pos, type); return; }' in order to avoid double
checking. New test cases have been added to SetObjectUnsupportedTest
so that it tests setObject(int,Object,int),
setObject(int,Object,int,int), setNull(int,int) and
setNull(int,int,String).
Modified:
db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/SetObjectUnsupportedTest.java
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java?rev=421255&r1=421254&r2=421255&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java Wed
Jul 12 05:24:18 2006
@@ -408,6 +408,7 @@
// also used by DBMD methods
void setNullX(int parameterIndex, int jdbcType) throws SqlException {
+ checkForSupportedDataType(jdbcType);
super.checkForClosedStatement(); // investigate what can be pushed up to setNull
parameterIndex = checkSetterPreconditions(parameterIndex);
parameterMetaData_.clientParamtertype_[parameterIndex - 1] = jdbcType;
@@ -1215,13 +1216,14 @@
int targetJdbcType,
int scale) throws SqlException {
parameterIndex = checkSetterPreconditions(parameterIndex);
- checkForSupportedDataType(targetJdbcType);
checkForValidScale(scale);
if (x == null) {
setNullX(parameterIndex, targetJdbcType);
return;
}
+
+ checkForSupportedDataType(targetJdbcType);
// JDBC Spec specifies that conversion should occur on the client if
// the targetJdbcType is specified.
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java?rev=421255&r1=421254&r2=421255&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
Wed Jul 12 05:24:18 2006
@@ -311,6 +311,7 @@
*/
public void setNull(int parameterIndex, int sqlType) throws SQLException {
+ checkForSupportedDataType(sqlType);
checkStatus();
int jdbcTypeId = getParameterJDBCType(parameterIndex);
@@ -1011,12 +1012,12 @@
public final void setObject(int parameterIndex, Object x, int targetSqlType, int scale)
throws SQLException {
- checkForSupportedDataType(targetSqlType);
-
if (x == null) {
setNull(parameterIndex, targetSqlType);
return;
}
+
+ checkForSupportedDataType(targetSqlType);
int paramJDBCType = getParameterJDBCType(parameterIndex);
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/SetObjectUnsupportedTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/SetObjectUnsupportedTest.java?rev=421255&r1=421254&r2=421255&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/SetObjectUnsupportedTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/SetObjectUnsupportedTest.java
Wed Jul 12 05:24:18 2006
@@ -29,7 +29,7 @@
import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
/**
- * Tests that calling <code>setObject()</code> with
+ * Tests that calling <code>setObject()</code> and <code>setNull()</code>
with
* <code>sqlTargetType</code> set to an unsupported type fails with
* <code>SQLFeatureNotSupportedException</code>.
*
@@ -81,7 +81,8 @@
/**
* Test that <code>setObject()</code> with the specified
- * <code>sqlTargetType</code>.
+ * <code>sqlTargetType</code> throws
+ * <code>SQLFeatureNotSupportedException</code>.
*
* @exception SQLException if a database error occurs
*/
@@ -93,6 +94,61 @@
} catch (SQLFeatureNotSupportedException e) {
// expected exception
}
+ ps.close();
+ }
+
+ /**
+ * Test that <code>setObject()</code> with the specified
+ * <code>sqlTargetType</code> throws
+ * <code>SQLFeatureNotSupportedException</code>.
+ *
+ * @exception SQLException if a database error occurs
+ */
+ public void testUnsupportedSetObjectWithScale() throws SQLException {
+ PreparedStatement ps = prepare();
+ try {
+ ps.setObject(1, null, typeInfo.type, 0);
+ fail("No exception thrown.");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected exception
+ }
+ ps.close();
+ }
+
+ /**
+ * Test that <code>setNull()</code> with the specified
+ * <code>sqlTargetType</code> throws
+ * <code>SQLFeatureNotSupportedException</code>.
+ *
+ * @exception SQLException if a database error occurs
+ */
+ public void testUnsupportedSetNull() throws SQLException {
+ PreparedStatement ps = prepare();
+ try {
+ ps.setNull(1, typeInfo.type);
+ fail("No exception thrown.");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected exception
+ }
+ ps.close();
+ }
+
+ /**
+ * Test that <code>setNull()</code> with the specified
+ * <code>sqlTargetType</code> throws
+ * <code>SQLFeatureNotSupportedException</code>.
+ *
+ * @exception SQLException if a database error occurs
+ */
+ public void testUnsupportedSetNullWithTypeName() throws SQLException {
+ PreparedStatement ps = prepare();
+ try {
+ ps.setNull(1, typeInfo.type, typeInfo.name);
+ fail("No exception thrown.");
+ } catch (SQLFeatureNotSupportedException e) {
+ // expected exception
+ }
+ ps.close();
}
/**
@@ -125,6 +181,14 @@
for (TypeInfo typeInfo : TYPES) {
suite.addTest(new SetObjectUnsupportedTest
("testUnsupportedSetObject", typeInfo, callable));
+ suite.addTest(new SetObjectUnsupportedTest
+ ("testUnsupportedSetObjectWithScale",
+ typeInfo, callable));
+ suite.addTest(new SetObjectUnsupportedTest
+ ("testUnsupportedSetNull", typeInfo, callable));
+ suite.addTest(new SetObjectUnsupportedTest
+ ("testUnsupportedSetNullWithTypeName",
+ typeInfo, callable));
}
return suite;
}
|