Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
aashikam committed Mar 16, 2024
1 parent 0453d12 commit cc216fc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ballerina/tests/call-procedure-tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import ballerina/sql;
import ballerina/test;
import ballerina/io;

@test:Config {
groups: ["procedures"]
Expand Down Expand Up @@ -44,6 +45,23 @@ function testNumericProcedureCall() returns error? {
test:assertEquals(check queryProcedureClient(query, NumericProcedureRecord), expectedDataRow, "Numeric Call procedure insert and query did not match.");
}

@test:Config {
groups: ["procedures"]
}
function testStoredProcedureWithCursor() returns error? {
Client dbClient = check new (jdbcUrl, user, password);
transaction {
sql:CursorOutParameter mycursor = new ();
sql:ProcedureCallResult result = check dbClient->call(`{CALL GetUserInfo(${mycursor})}`);
stream<record {}, sql:Error?> resultSet = mycursor.get();
check commit;
check from record {} user in resultSet
do {
io:println(user);
};
}
}

function callProcedure(sql:ParameterizedCallQuery sqlQuery, typedesc<record {}>[] rowTypes = []) returns sql:ProcedureCallResult|error {
Client dbClient = check new (jdbcUrl, user, password);
sql:ProcedureCallResult result = check dbClient->call(sqlQuery, rowTypes);
Expand Down
13 changes: 13 additions & 0 deletions ballerina/tests/setup-tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ function beforeFunction() returns error? {
(2, 'JaneSmith', '[email protected]', 30),
(3, 'BobJohnson', '[email protected]', 22);
`);

_ = check dbClient->execute(`
CREATE OR REPLACE FUNCTION GetUserInfo(OUT curName refcursor)
LANGUAGE plpgsql
AS $$
BEGIN
OPEN curName FOR
SELECT user_id, username, email, age
FROM users;
END;
$$;
`);

check dbClient.close();
}

Expand Down

0 comments on commit cc216fc

Please sign in to comment.