Return `null` when applicable from `getGeneratedKeys`

Currently, there is no way to check if `getGeneratedKeys` returned `null`.  Instead, when trying to call `ResultSet.next()` a `NullPointerException` is thrown.

This method [should return an empty `ResultSet` when there are no generated keys]( https://docs.oracle.com/javase/8/docs/api/java/sql/Statement.html#getGeneratedKeys--), but not all JDBC drivers do (like [Apache](4253dcf4aa/java/org.apache.derby.client/org/apache/derby/client/am/ClientStatement.java (L271)) [Derby](4253dcf4aa/java/org.apache.derby.client/org/apache/derby/client/am/ClientStatement.java (L1378-L1394)))  In these cases, I think the safest option is to return `null`, which can then be checked (and is checked in popular JDBC libraries [like JOOQ.](181d838797/jOOQ/src/main/java/org/jooq/impl/AbstractDMLQuery.java (L1350-L1352)))
pull/2180/head
Eric Peterson 11 months ago committed by GitHub
parent 0a6ccdb334
commit 6bb7d8759d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -227,8 +227,13 @@ public abstract class ProxyStatement implements Statement
public ResultSet getGeneratedKeys() throws SQLException
{
var resultSet = delegate.getGeneratedKeys();
if (proxyResultSet == null || ((ProxyResultSet) proxyResultSet).delegate != resultSet) {
proxyResultSet = ProxyFactory.getProxyResultSet(connection, this, resultSet);
if (resultSet != null) {
if (proxyResultSet == null || ((ProxyResultSet) proxyResultSet).delegate != resultSet) {
proxyResultSet = ProxyFactory.getProxyResultSet(connection, this, resultSet);
}
}
else {
proxyResultSet = null;
}
return proxyResultSet;
}

Loading…
Cancel
Save