Permalink
Browse files

fix: synchronize Statement#result field access to make #close() more …

…thread-safe
  • Loading branch information...
vlsi committed Nov 26, 2017
1 parent 04c5dbb commit 41392481d5f2c7f89d783a535ade2d3afb565654
@@ -87,7 +87,11 @@ public boolean executeWithFlags(int flags) throws SQLException {
PSQLState.NO_DATA);
}

ResultSet rs = result.getResultSet();
ResultSet rs;
synchronized (this) {
checkClosed();
rs = result.getResultSet();
}
if (!rs.next()) {
throw new PSQLException(GT.tr("A CallableStatement was executed with nothing returned."),
PSQLState.NO_DATA);
@@ -146,7 +150,9 @@ public boolean executeWithFlags(int flags) throws SQLException {

}
rs.close();
result = null;
synchronized (this) {
result = null;
}
return false;
}

@@ -118,12 +118,7 @@
throw new PSQLException(GT.tr("No results were returned by the query."), PSQLState.NO_DATA);
}

if (result.getNext() != null) {
throw new PSQLException(GT.tr("Multiple ResultSets were returned by the query."),
PSQLState.TOO_MANY_RESULTS);
}

return result.getResultSet();
return getSingleResultSet();
}

public int executeUpdate(String p_sql) throws SQLException {
@@ -135,17 +130,7 @@ public int executeUpdate(String p_sql) throws SQLException {
public int executeUpdate() throws SQLException {
executeWithFlags(QueryExecutor.QUERY_NO_RESULTS);

ResultWrapper iter = result;
while (iter != null) {
if (iter.getResultSet() != null) {
throw new PSQLException(GT.tr("A result was returned when none was expected."),
PSQLState.TOO_MANY_RESULTS);

}
iter = iter.getNext();
}

return getUpdateCount();
return getNoResultUpdateCount();
}

public boolean execute(String p_sql) throws SQLException {
@@ -168,7 +153,10 @@ public boolean executeWithFlags(int flags) throws SQLException {

execute(preparedQuery, preparedParameters, flags);

return (result != null && result.getResultSet() != null);
synchronized (this) {
checkClosed();
return (result != null && result.getResultSet() != null);
}
} finally {
defaultTimeZone = null;
}
Oops, something went wrong.

0 comments on commit 4139248

Please sign in to comment.