Skip to content

Commit

Permalink
Merge pull request #760 from ballerina-platform/danesh-dev
Browse files Browse the repository at this point in the history
Fix the out parameter test failuer in Postgres DB
  • Loading branch information
daneshk authored Dec 9, 2024
2 parents c57df5b + 44f2240 commit e02c018
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 128 deletions.
6 changes: 3 additions & 3 deletions ballerina/tests/call-procedures-test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ function testOutParameterReturingErrorWhenResultIsClosed() returns error? {
check ret.close();
string|Error err = paraVarchar.get(string);
test:assertTrue(err is Error);
test:assertTrue((<Error>err).message().startsWith("Failed to read OUT parameter value."));
test:assertTrue((<Error>err).message().startsWith("Failed to read parameter value."));
check dbClient.close();
}

Expand All @@ -1601,6 +1601,6 @@ function testInOutParameterReturingErrorWhenResultIsClosed() returns error? {
check ret.close();
string|Error err = paraVarchar.get(string);
test:assertTrue(err is Error);
test:assertTrue((<Error>err).message().startsWith("Failed to read INOUT parameter value."));
test:assertTrue((<Error>err).message().startsWith("Failed to read parameter value."));
check dbClient.close();
}
}
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- [Fix strand hanging when strand count exceeds BALLERINA_SQL_MAX_POOL_SIZE](https://github.com/ballerina-platform/ballerina-library/issues/7244)
- [Fix stored procedure call having output parameter failing with result set closed error](https://github.com/ballerina-platform/ballerina-library/issues/7255)
- [Fix stored procedure call having output parameter failing in PostgreSQL](https://github.com/ballerina-platform/ballerina-library/issues/7380)
- [Fix stored procedure call having output parameter failing in OracleDB](https://github.com/ballerina-platform/ballerina-library/issues/7445)


## [1.14.1] - 2024-08-29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@

import static io.ballerina.stdlib.sql.Constants.PARAMETER_INDEX_META_DATA;
import static io.ballerina.stdlib.sql.Constants.PROCEDURE_CALL_RESULT;
import static io.ballerina.stdlib.sql.Constants.ParameterObject;
import static io.ballerina.stdlib.sql.Constants.REF_CURSOR_VALUE_NATIVE_DATA;
import static io.ballerina.stdlib.sql.Constants.RESULT_PARAMETER_PROCESSOR;
import static io.ballerina.stdlib.sql.Constants.STATEMENT_NATIVE_DATA_FIELD;
Expand All @@ -69,35 +68,18 @@ private OutParameterProcessor() {
}

public static Object getOutParameterValue(BObject result, BTypedesc typeDesc) {
try {
populateOutParameter(result);
} catch (SQLException | ApplicationError e) {
return ErrorGenerator.getSQLError(e, "Failed to read OUT parameter value.");
}

return get(result, typeDesc, DefaultResultParameterProcessor.getInstance(), "OutParameter");
}

public static BStream getOutCursorValue(BObject result, BTypedesc typeDesc) {
try {
populateOutParameter(result);
} catch (SQLException | ApplicationError e) {
return getErrorStream(typeDesc,
ErrorGenerator.getSQLError(e, "Failed to read parameter value."));
}
return get(result, typeDesc, DefaultResultParameterProcessor.getInstance());
}

public static Object getInOutParameterValue(BObject result, BTypedesc typeDesc) {
try {
populateOutParameter(result);
} catch (SQLException | ApplicationError e) {
return ErrorGenerator.getSQLError(e, "Failed to read INOUT parameter value.");
}
return get(result, typeDesc, DefaultResultParameterProcessor.getInstance(), "InOutParameter");
}

private static void populateOutParameter(BObject parameter) throws SQLException, ApplicationError {
private static Object populateOutParameter(BObject parameter) throws SQLException, ApplicationError {
int paramIndex = (int) parameter.getNativeData(PARAMETER_INDEX_META_DATA);
int sqlType = (int) parameter.getNativeData(Constants.ParameterObject.SQL_TYPE_NATIVE_DATA);
CallableStatement statement = (CallableStatement) parameter.getNativeData(STATEMENT_NATIVE_DATA_FIELD);
Expand Down Expand Up @@ -147,12 +129,18 @@ private static void populateOutParameter(BObject parameter) throws SQLException,
case Types.SQLXML -> resultParameterProcessor.processXML(statement, paramIndex);
default -> resultParameterProcessor.processCustomOutParameters(statement, paramIndex, sqlType);
};
parameter.addNativeData(ParameterObject.VALUE_NATIVE_DATA, result);
return result;
}

public static BStream get(BObject result, Object recordType,
AbstractResultParameterProcessor resultParameterProcessor) {
Object value = result.getNativeData(Constants.ParameterObject.VALUE_NATIVE_DATA);
Object value;
try {
value = populateOutParameter(result);
} catch (SQLException | ApplicationError e) {
return getErrorStream(recordType,
ErrorGenerator.getSQLError(e, "Failed to read parameter value."));
}
RecordType streamConstraint = (RecordType) TypeUtils.getReferredType(
((BTypedesc) recordType).getDescribingType());
return resultParameterProcessor.convertCursorValue((ResultSet) value, streamConstraint);
Expand All @@ -161,7 +149,12 @@ public static BStream get(BObject result, Object recordType,
public static Object get(BObject result, BTypedesc typeDesc,
AbstractResultParameterProcessor resultParameterProcessor, String parameterType) {
int sqlType = (int) result.getNativeData(Constants.ParameterObject.SQL_TYPE_NATIVE_DATA);
Object value = result.getNativeData(Constants.ParameterObject.VALUE_NATIVE_DATA);
Object value;
try {
value = populateOutParameter(result);
} catch (SQLException | ApplicationError e) {
return ErrorGenerator.getSQLError(e, "Failed to read parameter value.");
}
Type ballerinaType = TypeUtils.getReferredType(typeDesc.getDescribingType());
try {
if (ballerinaType.getTag() == TypeTags.UNION_TAG) {
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion native/src/test/resources/testng.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<classes>
<class name="io.ballerina.stdlib.sql.datasource.PoolKeyTest"/>
<class name="io.ballerina.stdlib.sql.exception.ApplicationErrorTest"/>
<class name="io.ballerina.stdlib.sql.nativeimpl.OutParameterProcessorTest"/>
<class name="io.ballerina.stdlib.sql.parameterprocessor.DefaultResultParameterProcessorTest"/>
<class name="io.ballerina.stdlib.sql.parameterprocessor.DefaultStatementParameterProcessorTest"/>
<class name="io.ballerina.stdlib.sql.transaction.SQLTransactionContextTest"/>
Expand Down

0 comments on commit e02c018

Please sign in to comment.