Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly close resources for call procedure failure #715

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import static io.ballerina.stdlib.sql.utils.Utils.getDefaultStreamConstraint;
import static io.ballerina.stdlib.sql.utils.Utils.getSqlQuery;
import static io.ballerina.stdlib.sql.utils.Utils.updateProcedureCallExecutionResult;
import static io.ballerina.stdlib.sql.utils.Utils.closeResources;

/**
* This class holds the utility methods involved with executing the call statements.
Expand Down Expand Up @@ -116,9 +117,9 @@
return ErrorGenerator.getSQLApplicationError(
"SQL Client is already closed, hence further operations are not allowed");
}
Connection connection;
CallableStatement statement;
ResultSet resultSet;
Connection connection = null;
CallableStatement statement = null;
ResultSet resultSet = null;
String sqlQuery = null;
try {
sqlQuery = getSqlQuery(paramSQLString);
Expand Down Expand Up @@ -168,11 +169,14 @@
procedureCallResult.addNativeData(RESULT_SET_COUNT_NATIVE_DATA_FIELD, resultSetCount);
return procedureCallResult;
} catch (SQLException e) {
closeResources(isWithinTrxBlock, resultSet, statement, connection);
return ErrorGenerator.getSQLDatabaseError(e,
String.format("Error while executing SQL query: %s. ", sqlQuery));
} catch (ApplicationError e) {
closeResources(isWithinTrxBlock, resultSet, statement, connection);
return ErrorGenerator.getSQLApplicationError(e);
} catch (Throwable th) {
closeResources(isWithinTrxBlock, resultSet, statement, connection);

Check warning on line 179 in native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/CallProcessor.java

View check run for this annotation

Codecov / codecov/patch

native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/CallProcessor.java#L179

Added line #L179 was not covered by tests
return ErrorGenerator.getSQLError(th, String.format("Error while executing SQL query: %s. ", sqlQuery));
}
} else {
Expand Down
Loading