Skip to content

Commit

Permalink
Add CursorInOutParameter type
Browse files Browse the repository at this point in the history
  • Loading branch information
aashikam committed Apr 4, 2024
1 parent 4c4f148 commit b27702d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
21 changes: 20 additions & 1 deletion ballerina/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -1352,8 +1352,27 @@ public class InOutParameter {
} external;
}

# Represents a Cursor InOut Parameter in `sql:ParameterizedCallQuery`.
public class CursorInOutParameter {
Value 'in;

// value should be stream<record{}, sql:error>
public isolated function init() {
self.'in = ();
}

Check warning on line 1362 in ballerina/types.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/types.bal#L1361-L1362

Added lines #L1361 - L1362 were not covered by tests

# Gets the cursor value.
#
# + rowType - The `typedesc` of the record to which the result needs to be returned
# + return - The cursor stream of records in the `rowType` type
public isolated function get(typedesc<record {}> rowType = <>) returns stream <rowType, Error?> = @java:Method {
'class: "io.ballerina.stdlib.sql.nativeimpl.OutParameterProcessor",
name: "getOutCursorValue"
} external;

Check warning on line 1371 in ballerina/types.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/types.bal#L1371

Added line #L1371 was not covered by tests
}

# Generic type that can be passed to `sql:ParameterizedCallQuery` to indicate procedure/function parameters.
public type Parameter Value|InOutParameter|OutParameter|CursorOutParameter;
public type Parameter Value|InOutParameter|OutParameter|CursorOutParameter|CursorInOutParameter;

# The object constructed through backtick surrounded strings. Dynamic parameters of `sql:Parameter` type can be indicated using `${<variable name>}`
# such as `` `The sql:ParameterizedQuery is ${variable_name}` ``.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ private static void setCallParameters(Connection connection, CallableStatement s
String objectType = TypeUtils.getType(objectValue).getName();
if (objectType.equals(Constants.ParameterObject.INOUT_PARAMETER)) {
parameterType = Constants.ParameterObject.INOUT_PARAMETER;
} else if (objectType.endsWith("InOutParameter")) {
parameterType = Constants.ParameterObject.INOUT_PARAMETER;

Check warning on line 198 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#L198

Added line #L198 was not covered by tests
} else if (objectType.endsWith("OutParameter")) {
parameterType = Constants.ParameterObject.OUT_PARAMETER;
} else {
Expand All @@ -205,7 +207,7 @@ private static void setCallParameters(Connection connection, CallableStatement s
case Constants.ParameterObject.INOUT_PARAMETER:
Object innerObject = objectValue.get(Constants.ParameterObject.IN_VALUE_FIELD);
sqlType = statementParameterProcessor.setSQLValueParam(connection, statement,
index, innerObject, true);
index, innerObject, true, objectType);
outputParamTypes.put(index, sqlType);
statement.registerOutParameter(index, sqlType);
break;
Expand All @@ -216,11 +218,11 @@ private static void setCallParameters(Connection connection, CallableStatement s
break;
default:
statementParameterProcessor.setSQLValueParam(connection, statement, index,
object, false);
object, false, "");
}
} else {
statementParameterProcessor.setSQLValueParam(connection, statement, index, object,
false);
false, "");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,18 @@ public void setParams(Connection connection, PreparedStatement preparedStatement
for (int i = 0; i < arrayValue.size(); i++) {
Object object = arrayValue.get(i);
int index = i + 1;
setSQLValueParam(connection, preparedStatement, index, object, false);
setSQLValueParam(connection, preparedStatement, index, object, false, "");
}
}

public int setSQLValueParam(Connection connection, PreparedStatement preparedStatement, int index, Object object,
boolean returnType) throws DataError, SQLException {
boolean returnType, String objectType) throws DataError, SQLException {
try {
if (object == null) {
if (objectType.equals("CursorInOutParameter")) {
preparedStatement.setObject(index, null);
return Types.REF_CURSOR;

Check warning on line 216 in native/src/main/java/io/ballerina/stdlib/sql/parameterprocessor/AbstractStatementParameterProcessor.java

View check run for this annotation

Codecov / codecov/patch

native/src/main/java/io/ballerina/stdlib/sql/parameterprocessor/AbstractStatementParameterProcessor.java#L215-L216

Added lines #L215 - L216 were not covered by tests
}
preparedStatement.setNull(index, Types.NULL);
return Types.NULL;
} else if (object instanceof BString) {
Expand Down

0 comments on commit b27702d

Please sign in to comment.