Skip to content

Commit c9e42e4

Browse files
committed
Fix OracleArrayTest and import.sql
See gvenzl/oci-oracle-free#48 (comment) Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
1 parent a6bdd02 commit c9e42e4

2 files changed

Lines changed: 7 additions & 27 deletions

File tree

vertx-oracle-client/src/test/java/tests/oracleclient/OracleArrayTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public void setUp() throws Exception {
3232
public void testStringArray(TestContext ctx) {
3333
String[] elements = {"str1", "str2", "str3"};
3434
pool.withConnection(conn -> {
35-
Object stringsArray = ((OracleConnection) conn).createArray("StringArrayType", elements);
36-
String insertSql = "INSERT INTO StringsArrayTable( id, stringsArray) VALUES (?, ?)";
35+
Object stringsArray = ((OracleConnection) conn).createArray("STRING_ARRAY", elements);
36+
String insertSql = "INSERT INTO test_collections( id, string_array_element) VALUES (?, ?)";
3737
return conn.preparedQuery(insertSql).execute(Tuple.of(1, stringsArray));
3838
}).onComplete(ctx.asyncAssertSuccess());
3939
}

vertx-oracle-client/src/test/resources/tck/import.sql

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -171,35 +171,15 @@ CREATE TABLE passenger
171171
);
172172

173173

174-
-- These are the sql commands executed by ORM to facilitate support for String[] array type
175-
CREATE OR REPLACE TYPE StringArrayType AS VARYING array(127) of varchar2(255 char);
174+
CREATE OR REPLACE TYPE STRING_ARRAY AS VARYING ARRAY(127) of VARCHAR2(255 char);
175+
/
176176

177-
CREATE TABLE StringsArrayTable
177+
CREATE TABLE test_collections
178178
(
179-
id number(10,0),
180-
stringarrayelement StringArrayType,
179+
id number(10, 0),
180+
string_array_element STRING_ARRAY,
181181
primary key (id)
182182
);
183183

184-
-- The following is ORM-generated DDL to manage various array use situations in embedded and type conversion situations and may or may not be relevant at the moment
185-
--create or replace function StringArrayType_cmp(a in StringArrayType, b in StringArrayType) return number deterministic is begin if a is null or b is null then return null; end if; for i in 1 .. least(a.count,b.count) loop if a(i) is null or b(i) is null then return null;elsif a(i)>b(i) then return 1;elsif a(i)<b(i) then return -1; end if; end loop; if a.count=b.count then return 0; elsif a.count>b.count then return 1; else return -1; end if; end;
186-
--create or replace function StringArrayType_distinct(a in StringArrayType, b in StringArrayType) return number deterministic is begin if a is null and b is null then return 0; end if; if a is null or b is null or a.count <> b.count then return 1; end if; for i in 1 .. a.count loop if (a(i) is null)<>(b(i) is null) or a(i)<>b(i) then return 1; end if; end loop; return 0; end;
187-
--create or replace function StringArrayType_position(arr in StringArrayType, elem in varchar2, startPos in number default 1) return number deterministic is begin if arr is null then return null; end if; if elem is null then for i in startPos .. arr.count loop if arr(i) is null then return i; end if; end loop; else for i in startPos .. arr.count loop if arr(i)=elem then return i; end if; end loop; end if; return 0; end;
188-
--create or replace function StringArrayType_length(arr in StringArrayType) return number deterministic is begin if arr is null then return null; end if; return arr.count; end;
189-
--create or replace function StringArrayType_concat(arr0 in StringArrayType,arr1 in StringArrayType,arr2 in StringArrayType default StringArrayType(),arr3 in StringArrayType default StringArrayType(),arr4 in StringArrayType default StringArrayType()) return StringArrayType deterministic is res StringArrayType; begin if arr0 is null or arr1 is null or arr2 is null or arr3 is null or arr4 is null then return null; end if; select * bulk collect into res from (select * from table(arr0) union all select * from table(arr1) union all select * from table(arr2) union all select * from table(arr3) union all select * from table(arr4)); return res; end;
190-
--create or replace function StringArrayType_contains(haystack in StringArrayType, needle in StringArrayType, nullable in number) return number deterministic is found number(1,0); begin if haystack is null or needle is null then return null; end if; for i in 1 .. needle.count loop found := 0; for j in 1 .. haystack.count loop if nullable = 1 and needle(i) is null and haystack(j) is null or needle(i)=haystack(j) then found := 1; exit; end if; end loop; if found = 0 then return 0; end if;end loop; return 1; end;
191-
--create or replace function StringArrayType_overlaps(haystack in StringArrayType, needle in StringArrayType, nullable in number) return number deterministic is begin if haystack is null or needle is null then return null; end if; if needle.count = 0 then return 1; end if; for i in 1 .. needle.count loop for j in 1 .. haystack.count loop if nullable = 1 and needle(i) is null and haystack(j) is null or needle(i)=haystack(j) then return 1; end if; end loop; end loop; return 0; end;
192-
--create or replace function StringArrayType_get(arr in StringArrayType, idx in number) return varchar2 deterministic is begin if arr is null or idx is null or arr.count < idx then return null; end if; return arr(idx); end;
193-
--create or replace function StringArrayType_set(arr in StringArrayType, idx in number, elem in varchar2) return StringArrayType deterministic is res StringArrayType:=StringArrayType(); begin if arr is not null then for i in 1 .. arr.count loop res.extend; res(i) := arr(i); end loop; for i in arr.count+1 .. idx loop res.extend; end loop; else for i in 1 .. idx loop res.extend; end loop; end if; res(idx) := elem; return res; end;
194-
--create or replace function StringArrayType_remove(arr in StringArrayType, elem in varchar2) return StringArrayType deterministic is res StringArrayType:=StringArrayType(); begin if arr is null then return null; end if; if elem is null then for i in 1 .. arr.count loop if arr(i) is not null then res.extend; res(res.last) := arr(i); end if; end loop; else for i in 1 .. arr.count loop if arr(i) is null or arr(i)<>elem then res.extend; res(res.last) := arr(i); end if; end loop; end if; return res; end;
195-
--create or replace function StringArrayType_remove_index(arr in StringArrayType, idx in number) return StringArrayType deterministic is res StringArrayType:=StringArrayType(); begin if arr is null or idx is null then return arr; end if; for i in 1 .. arr.count loop if i<>idx then res.extend; res(res.last) := arr(i); end if; end loop; return res; end;
196-
--create or replace function StringArrayType_slice(arr in StringArrayType, startIdx in number, endIdx in number) return StringArrayType deterministic is res StringArrayType:=StringArrayType(); begin if arr is null or startIdx is null or endIdx is null then return null; end if; for i in startIdx .. least(arr.count,endIdx) loop res.extend; res(res.last) := arr(i); end loop; return res; end;
197-
--create or replace function StringArrayType_replace(arr in StringArrayType, old in varchar2, elem in varchar2) return StringArrayType deterministic is res StringArrayType:=StringArrayType(); begin if arr is null then return null; end if; if old is null then for i in 1 .. arr.count loop res.extend; res(res.last) := coalesce(arr(i),elem); end loop; else for i in 1 .. arr.count loop res.extend; if arr(i) = old then res(res.last) := elem; else res(res.last) := arr(i); end if; end loop; end if; return res; end;
198-
--create or replace function StringArrayType_trim(arr in StringArrayType, elems number) return StringArrayType deterministic is res StringArrayType:=StringArrayType(); begin if arr is null or elems is null then return null; end if; if arr.count < elems then raise_application_error (-20000, 'number of elements to trim must be between 0 and '||arr.count); end if;for i in 1 .. arr.count-elems loop res.extend; res(i) := arr(i); end loop; return res; end;
199-
--create or replace function StringArrayType_fill(elem in varchar2, elems number) return StringArrayType deterministic is res StringArrayType:=StringArrayType(); begin if elems is null then return null; end if; if elems<0 then raise_application_error (-20000, 'number of elements must be greater than or equal to 0'); end if;for i in 1 .. elems loop res.extend; res(i) := elem; end loop; return res; end;
200-
--create or replace function StringArrayType_positions(arr in StringArrayType, elem in varchar2) return sdo_ordinate_array deterministic is res sdo_ordinate_array:=sdo_ordinate_array(); begin if arr is null then return null; end if; if elem is null then for i in 1 .. arr.count loop if arr(i) is null then res.extend; res(res.last):=i; end if; end loop; else for i in 1 .. arr.count loop if arr(i)=elem then res.extend; res(res.last):=i; end if; end loop; end if; return res; end;
201-
--create or replace function StringArrayType_to_string(arr in StringArrayType, sep in varchar2) return varchar2 deterministic is res varchar2(4000):=''; begin if arr is null or sep is null then return null; end if; for i in 1 .. arr.count loop if arr(i) is not null then if length(res)<>0 then res:=res||sep; end if; res:=res||arr(i); end if; end loop; return res; end;
202-
203-
204184
-- Don't forget to commit...
205185
COMMIT;

0 commit comments

Comments
 (0)