提交 da02ea7d authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add null checks to JdbcResultSet.updateSQLXML()

上级 84069e20
......@@ -3577,7 +3577,12 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
debugCode("updateSQLXML("+columnIndex+", x);");
}
checkClosed();
Value v = conn.createClob(xmlObject.getCharacterStream(), -1);
Value v;
if (xmlObject == null) {
v = ValueNull.INSTANCE;
} else {
v = conn.createClob(xmlObject.getCharacterStream(), -1);
}
update(columnIndex, v);
} catch (Exception e) {
throw logAndConvert(e);
......@@ -3599,7 +3604,12 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
debugCode("updateSQLXML("+quote(columnLabel)+", x);");
}
checkClosed();
Value v = conn.createClob(xmlObject.getCharacterStream(), -1);
Value v;
if (xmlObject == null) {
v = ValueNull.INSTANCE;
} else {
v = conn.createClob(xmlObject.getCharacterStream(), -1);
}
update(columnLabel, v);
} catch (Exception e) {
throw logAndConvert(e);
......
......@@ -163,6 +163,8 @@ public class TestSQLXML extends TestDb {
testSettersImpl(sqlxml);
// something illegal
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, sqlxml).setResult(Result.class);
// null
testSettersImpl(null);
}
private void assertXML(String actual) {
......@@ -172,36 +174,44 @@ public class TestSQLXML extends TestDb {
assertEquals(XML, actual);
}
private void testSettersImplAssert(SQLXML sqlxml) throws SQLException {
ResultSet rs = stat.executeQuery("SELECT X FROM TEST");
assertTrue(rs.next());
SQLXML v = rs.getSQLXML(1);
if (sqlxml != null) {
assertXML(v.getString());
} else {
assertNull(v);
}
}
void testSettersImpl(SQLXML sqlxml) throws SQLException {
PreparedStatement prep = conn.prepareStatement("UPDATE TEST SET X = ?");
prep.setSQLXML(1, sqlxml);
assertEquals(1, prep.executeUpdate());
ResultSet rs = stat.executeQuery("SELECT X FROM TEST");
assertTrue(rs.next());
assertXML(rs.getSQLXML(1).getString());
testSettersImplAssert(sqlxml);
prep.setObject(1, sqlxml);
assertEquals(1, prep.executeUpdate());
rs = stat.executeQuery("SELECT X FROM TEST");
assertTrue(rs.next());
assertXML(rs.getSQLXML(1).getString());
testSettersImplAssert(sqlxml);
Statement st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
rs = st.executeQuery("SELECT * FROM TEST FOR UPDATE");
ResultSet rs = st.executeQuery("SELECT * FROM TEST FOR UPDATE");
assertTrue(rs.next());
rs.updateSQLXML(2, sqlxml);
rs.updateRow();
rs = stat.executeQuery("SELECT X FROM TEST");
testSettersImplAssert(sqlxml);
rs = st.executeQuery("SELECT * FROM TEST FOR UPDATE");
assertTrue(rs.next());
assertXML(rs.getSQLXML(1).getString());
rs.updateSQLXML("X", sqlxml);
rs.updateRow();
testSettersImplAssert(sqlxml);
rs = st.executeQuery("SELECT * FROM TEST FOR UPDATE");
assertTrue(rs.next());
rs.updateObject(2, sqlxml);
rs.updateRow();
rs = stat.executeQuery("SELECT X FROM TEST");
assertTrue(rs.next());
assertXML(rs.getSQLXML(1).getString());
testSettersImplAssert(sqlxml);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论