Skip to content

Commit

Permalink
Merge pull request #885 from daneshk/main
Browse files Browse the repository at this point in the history
Add testcases for the ref cursor fix
  • Loading branch information
daneshk committed Mar 11, 2024
2 parents e943e4b + 4ce921b commit 9515ea7
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 14 deletions.
10 changes: 5 additions & 5 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerinax"
name = "oracledb"
version = "1.11.0"
version = "1.11.1"
authors = ["Ballerina"]
keywords = ["database", "client", "network", "SQL", "RDBMS", "OracleDB", "Oracle"]
repository = "https://github.com/ballerina-platform/module-ballerinax-oracledb"
Expand All @@ -15,11 +15,11 @@ graalvmCompatible = true
[[platform.java17.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "oracledb-native"
version = "1.11.0"
path = "../native/build/libs/oracledb-native-1.11.0.jar"
version = "1.11.1"
path = "../native/build/libs/oracledb-native-1.11.1-SNAPSHOT.jar"

[[platform.java17.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "sql-native"
version = "1.11.0"
path = "./lib/sql-native-1.11.0.jar"
version = "1.12.0"
path = "./lib/sql-native-1.12.0.jar"
2 changes: 1 addition & 1 deletion ballerina/CompilerPlugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ id = "oracledb-compiler-plugin"
class = "io.ballerina.stdlib.oracledb.compiler.OracleDBCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/oracledb-compiler-plugin-1.11.0.jar"
path = "../compiler-plugin/build/libs/oracledb-compiler-plugin-1.11.1-SNAPSHOT.jar"
15 changes: 8 additions & 7 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "cache"
version = "3.7.0"
version = "3.7.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "constraint"},
Expand All @@ -35,7 +35,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "constraint"
version = "1.4.0"
version = "1.5.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
Expand All @@ -44,7 +44,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "crypto"
version = "2.5.0"
version = "2.6.2"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
Expand All @@ -71,7 +71,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.10.0"
version = "2.10.6"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -113,6 +113,7 @@ modules = [
org = "ballerina"
name = "jballerina.java"
version = "0.0.0"
scope = "testOnly"
modules = [
{org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"}
]
Expand Down Expand Up @@ -280,7 +281,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "observe"
version = "1.2.0"
version = "1.2.2"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
Expand All @@ -299,7 +300,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "sql"
version = "1.11.0"
version = "1.12.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand Down Expand Up @@ -390,7 +391,7 @@ modules = [
[[package]]
org = "ballerinax"
name = "oracledb"
version = "1.11.0"
version = "1.11.1"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "file"},
Expand Down
81 changes: 81 additions & 0 deletions ballerina/tests/08-procedure-call-test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import ballerina/sql;
import ballerina/test;
import ballerina/jballerina.java;
import ballerina/time;
import ballerina/io;

type StringDataForCall record {
string COL_CHAR;
Expand Down Expand Up @@ -278,6 +279,86 @@ isolated function testCallWithDateTimesOutParams() returns error? {
check oracledbClient.close();
}

type CallStringTypes record {|
decimal ID;
string COL_CHAR;
string COL_NCHAR;
string COL_VARCHAR2;
string COL_VARCHAR;
string COL_NVARCHAR2;
|};

type StringCharType record {|
string COL_CHAR;
|};

@test:Config {
groups: ["procedures"],
dependsOn: [testCallWithStringTypesOutParams]
}
isolated function testCallWithStringTypesCursorOutParams() returns error? {
Client oracledbClient = check new (HOST, USER, PASSWORD, DATABASE, PORT);
decimal id = 1;
sql:CursorOutParameter cursor = new;
sql:ProcedureCallResult ret = check oracledbClient->call(`{call SelectDataWithRefCursorAndNumber(${id}, ${cursor})}`);
stream<CallStringTypes, sql:Error?> resultStream = cursor.get();

CallStringTypes[] result = check from CallStringTypes row in resultStream select row;
io:println("result: ", result);
CallStringTypes expectedDataRow = {
ID: 1,
COL_CHAR: "test0",
COL_NCHAR: "test1",
COL_VARCHAR2: "test2",
COL_VARCHAR: "test3",
COL_NVARCHAR2: "test4"
};
test:assertEquals(result.length(), 1, "Result length did not match.");
test:assertEquals(result[0], expectedDataRow, "Result did not match.");
check ret.close();
check oracledbClient.close();
}

@test:Config {
groups: ["procedures"],
dependsOn: [testCallWithStringTypesOutParams]
}
isolated function testCallWithStringTypesCursorOutParamsWithoutInput() returns error? {
Client oracledbClient = check new (HOST, USER, PASSWORD, DATABASE, PORT);
sql:CursorOutParameter activeCursor = new;
sql:CursorOutParameter upcomingCursor = new;
sql:ProcedureCallResult ret = check oracledbClient->call(`{call SelectStringDataWithRefCursor(${activeCursor}, ${upcomingCursor})}`);

// First cursor - activeCursor
stream<record{}, sql:Error?> resultStream = activeCursor.get();
record{}[] result = check from record{} row in resultStream select row;
io:println("result: ", result);

CallStringTypes expectedDataRow = {
ID: 1,
COL_CHAR: "test0",
COL_NCHAR: "test1",
COL_VARCHAR2: "test2",
COL_VARCHAR: "test3",
COL_NVARCHAR2: "test4"
};
test:assertEquals(result.length(), 4, "Result length did not match.");
test:assertEquals(result[0], expectedDataRow, "Result did not match.");

// Second cursor - upcomingCursor
stream<record{}, sql:Error?> resultStream2 = upcomingCursor.get();
record{}[] result2 = check from record{} row in resultStream2 select row;
io:println("result: ", result2);
StringCharType expectedDataRow2 = {
COL_CHAR: "test0"
};
test:assertEquals(result2.length(), 4, "Result length did not match.");
test:assertEquals(result2[0], expectedDataRow2, "Result did not match.");

check ret.close();
check oracledbClient.close();
}

isolated function callQueryClient(Client oracledbClient, sql:ParameterizedQuery sqlQuery)
returns record {}|error {
stream<record {}, error?> streamData = oracledbClient->query(sqlQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,29 @@ BEGIN
SELECT col_interval_day_to_second INTO p_col_interval_day_to_second FROM CallDateTimeTypes where id = p_id;
END;
/

CREATE OR REPLACE PROCEDURE SelectStringDataWithRefCursor(
oActiveCursor OUT SYS_REFCURSOR,
oUpcomingCursor OUT SYS_REFCURSOR
)
AS
BEGIN
OPEN oActiveCursor FOR
SELECT * FROM CallStringTypes;

OPEN oUpcomingCursor FOR
SELECT col_char FROM CallStringTypes;
END;
/

CREATE OR REPLACE PROCEDURE SelectDataWithRefCursorAndNumber(
p_id IN NUMBER,
oActiveCursor OUT SYS_REFCURSOR
)
AS
BEGIN
OPEN oActiveCursor FOR
SELECT * FROM CallStringTypes where id = p_id;

END;
/
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ballerinaGradlePluginVersion=2.0.1

ballerinaLangVersion=2201.8.0

stdlibSqlVersion=1.11.0
stdlibSqlVersion=1.12.0

# Direct Dependencies
# Level 01
Expand Down

0 comments on commit 9515ea7

Please sign in to comment.