Skip to content

Commit

Permalink
Improve error message when passing null array
Browse files Browse the repository at this point in the history
  • Loading branch information
lahirusamith committed Sep 16, 2021
1 parent 4eeb31c commit 386ce64
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ballerina/tests/11-custom-object-type-test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ isolated function insertNestedTableNull() returns error? {
VALUES (${pk}, ${students}, ${grades})`;
sql:ExecutionResult|sql:Error result = executeQuery(insertQuery);
if result is sql:ApplicationError {
test:assertTrue(result.message().includes("Invalid parameter: null is passed as value for SQL type: varray"));
test:assertTrue(result.message().includes("Invalid parameter: null is passed as value for SQL type: nested table"));
} else {
test:assertFail("Database Error expected.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ protected void setCustomSqlTypedParam(Connection connection, PreparedStatement p
setOracleObject(connection, preparedStatement, index, value);
break;
case Constants.Types.CustomTypes.VARRAY:
setArray(connection, preparedStatement, index, value, "varray");
break;
case Constants.Types.CustomTypes.NESTED_TABLE:
setVarray(connection, preparedStatement, index, value);
setArray(connection, preparedStatement, index, value, "nested table");
break;
default:
throw Utils.throwInvalidParameterError(value, sqlType);
Expand Down Expand Up @@ -183,10 +185,11 @@ private void setOracleObject(Connection connection, PreparedStatement preparedSt
preparedStatement.setObject(index, oracleObject);
}

private void setVarray(Connection connection, PreparedStatement preparedStatement, int index, Object value)
private void setArray(Connection connection, PreparedStatement preparedStatement, int index, Object value,
String type)
throws SQLException, DataError {
if (value == null) {
throw Utils.throwInvalidParameterError(null, "varray");
throw Utils.throwInvalidParameterError(null, type);
}
Array oracleArray = ConverterUtils.convertVarray(connection, value);
preparedStatement.setArray(index, oracleArray);
Expand Down

0 comments on commit 386ce64

Please sign in to comment.