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

Add CursorInOutParameter type #706

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
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 @@
} 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 @@
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 @@
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 @@
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 @@
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
Loading