From 1d92b732503c388bfb9a6c586f9065fcf6d3a122 Mon Sep 17 00:00:00 2001 From: Markus Spann Date: Fri, 17 Nov 2023 15:59:01 +0100 Subject: [PATCH] net-sf-ucanaccess-fork: Syntactic sugar for readibility of unit tests --- .../net/ucanaccess/jdbc/AccessLikeTest.java | 40 +- .../net/ucanaccess/jdbc/AddFunctionTest.java | 2 +- .../jdbc/AggregateFunctionsTest.java | 28 +- .../net/ucanaccess/jdbc/AlterTableTest.java | 10 +- .../java/net/ucanaccess/jdbc/BlobOleTest.java | 4 +- .../ucanaccess/jdbc/CalculatedFieldTest.java | 10 +- .../ucanaccess/jdbc/ConcatNullsFalseTest.java | 2 +- .../ucanaccess/jdbc/ConcatNullsTrueTest.java | 2 +- .../java/net/ucanaccess/jdbc/CounterTest.java | 21 +- .../net/ucanaccess/jdbc/CreateTableTest.java | 12 +- .../java/net/ucanaccess/jdbc/CrudTest.java | 16 +- .../net/ucanaccess/jdbc/DropTableTest.java | 17 +- .../java/net/ucanaccess/jdbc/FloatTest.java | 2 +- .../net/ucanaccess/jdbc/FunctionsTest.java | 388 ++++++++---------- .../ucanaccess/jdbc/GeneratedKeys1Test.java | 2 +- .../ucanaccess/jdbc/LoadTypesAccessTest.java | 19 +- .../net/ucanaccess/jdbc/MetaDataTest.java | 13 +- .../net/ucanaccess/jdbc/ParametersTest.java | 8 +- .../java/net/ucanaccess/jdbc/RegexTest.java | 18 +- .../ucanaccess/test/UcanaccessBaseTest.java | 56 ++- 20 files changed, 333 insertions(+), 337 deletions(-) diff --git a/src/test/java/net/ucanaccess/jdbc/AccessLikeTest.java b/src/test/java/net/ucanaccess/jdbc/AccessLikeTest.java index 6633bf75..e448bbb5 100644 --- a/src/test/java/net/ucanaccess/jdbc/AccessLikeTest.java +++ b/src/test/java/net/ucanaccess/jdbc/AccessLikeTest.java @@ -21,7 +21,7 @@ protected String getAccessPath() { @MethodSource("net.ucanaccess.type.AccessVersion#getDefaultAccessVersion()") void testLike(AccessVersion _accessVersion) throws SQLException, IOException { init(_accessVersion); - checkQuery("SELECT * FROM query1 ORDER BY campo2", "dd1"); + checkQuery("SELECT * FROM query1 ORDER BY campo2", singleRec("dd1")); } @ParameterizedTest(name = "[{index}] {0}") @@ -37,26 +37,25 @@ void testLikeExternal(AccessVersion _accessVersion) throws SQLException, IOExcep "dsdsds", "aa", "aBa", "aBBBa", "PB123", "PZ123", "a*a", "A*a", "ss#sss", "*", "132B", "138", "138#")) { st.execute("INSERT INTO T21 (descr) VALUES('" + val + "')"); } - Object[][] ver = {{"a*a"}, {"A*a"}}; - checkQuery("SELECT descr FROM T21 WHERE descr LIKE 'a[*]a' ORDER BY ID", ver); + + checkQuery("SELECT descr FROM T21 WHERE descr LIKE 'a[*]a' ORDER BY ID", + recs(rec("a*a"), rec("A*a"))); - ver = new Object[][] {{"aa"}, {"aBa"}, {"aBBBa"}, {"a*a"}, {"A*a"}}; - checkQuery("SELECT descr FROM T21 WHERE descr LIKE \"a*a\" AND '1'='1' AND (descr) like \"a*a\" ORDER BY ID", ver); + checkQuery("SELECT descr FROM T21 WHERE descr LIKE \"a*a\" AND '1'='1' AND (descr) like \"a*a\" ORDER BY ID", + recs(rec("aa"), rec("aBa"), rec("aBBBa"), rec("a*a"), rec("A*a"))); - ver = new Object[][] {{2, "aa"}, {3, "aBa"}, {4, "aBBBa"}, {7, "a*a"}, {8, "A*a"}}; - checkQuery("SELECT * FROM T21 WHERE descr LIKE 'a%a'", ver); - - checkQuery("SELECT descr FROM T21 WHERE descr LIKE 'P[A-F]###'", "PB123"); - checkQuery("SELECT descr FROM T21 WHERE (T21.descr\n) \nLIKE 'P[!A-F]###' AND '1'='1'", "PZ123"); - checkQuery("SELECT * FROM T21 WHERE descr='aba'", 3, "aBa"); - checkQuery("SELECT descr FROM T21 WHERE descr LIKE '13[1-4][A-F]'", "132B"); - checkQuery("SELECT descr FROM T21 WHERE descr LIKE '13[!1-4]'", "138"); - checkQuery("SELECT descr FROM T21 WHERE descr LIKE '%s[#]%'", "ss#sss"); - checkQuery("SELECT descr FROM T21 WHERE descr LIKE '###'", "138"); - checkQuery("SELECT descr FROM T21 WHERE descr LIKE '###[#]'", "138#"); - - checkQuery("SELECT descr FROM T21 WHERE descr LIKE '###[#]'", "138#"); - checkQuery("SELECT descr FROM T21 WHERE ((descr LIKE '###[#]'))", "138#"); + checkQuery("SELECT * FROM T21 WHERE descr LIKE 'a%a'", + recs(rec(2, "aa"), rec(3, "aBa"), rec(4, "aBBBa"), rec(7, "a*a"), rec(8, "A*a"))); + checkQuery("SELECT descr FROM T21 WHERE descr LIKE 'P[A-F]###'", singleRec("PB123")); + checkQuery("SELECT descr FROM T21 WHERE (T21.descr\n) \nLIKE 'P[!A-F]###' AND '1'='1'", singleRec("PZ123")); + checkQuery("SELECT * FROM T21 WHERE descr='aba'", singleRec(3, "aBa")); + checkQuery("SELECT descr FROM T21 WHERE descr LIKE '13[1-4][A-F]'", singleRec("132B")); + checkQuery("SELECT descr FROM T21 WHERE descr LIKE '13[!1-4]'", singleRec("138")); + checkQuery("SELECT descr FROM T21 WHERE descr LIKE '%s[#]%'", singleRec("ss#sss")); + checkQuery("SELECT descr FROM T21 WHERE descr LIKE '###'", singleRec("138")); + checkQuery("SELECT descr FROM T21 WHERE descr LIKE '###[#]'", singleRec("138#")); + checkQuery("SELECT descr FROM T21 WHERE descr LIKE '###[#]'", singleRec("138#")); + checkQuery("SELECT descr FROM T21 WHERE ((descr LIKE '###[#]'))", singleRec("138#")); st.execute("DROP TABLE " + tableName); } } @@ -73,7 +72,8 @@ void testNotLikeExternal(AccessVersion _accessVersion) throws SQLException { st.execute("INSERT INTO Tx21(descr) VALUES('t11114')"); st.execute("INSERT INTO Tx21(descr) VALUES('t1111C')"); st.execute("INSERT INTO Tx21(descr) VALUES('t1111')"); - checkQuery("SELECT DESCR FROM Tx21 WHERE descr NOT LIKE \"t#####\" ORDER BY id", new Object[][] {{"t1111C"}, {"t1111"}}); + checkQuery("SELECT DESCR FROM Tx21 WHERE descr NOT LIKE \"t#####\" ORDER BY id", + recs(rec("t1111C"), rec("t1111"))); st.execute("DROP TABLE " + tableName); } } diff --git a/src/test/java/net/ucanaccess/jdbc/AddFunctionTest.java b/src/test/java/net/ucanaccess/jdbc/AddFunctionTest.java index 4132a308..33ce3b91 100644 --- a/src/test/java/net/ucanaccess/jdbc/AddFunctionTest.java +++ b/src/test/java/net/ucanaccess/jdbc/AddFunctionTest.java @@ -33,7 +33,7 @@ void testAddFunction(AccessVersion _accessVersion) throws Exception { ucanaccess.addFunctions(AddFunctions.class); dumpQueryResult("SELECT pluto('hello', ' world ', NOW()) FROM t_add_function"); - checkQuery("SELECT CONCAT('Hello World, ', 'Ucanaccess') FROM t_add_function", "Hello World, Ucanaccess"); + checkQuery("SELECT CONCAT('Hello World, ', 'Ucanaccess') FROM t_add_function", singleRec("Hello World, Ucanaccess")); executeStatements("DROP TABLE t_add_function"); } diff --git a/src/test/java/net/ucanaccess/jdbc/AggregateFunctionsTest.java b/src/test/java/net/ucanaccess/jdbc/AggregateFunctionsTest.java index 87d3a812..08c89a09 100644 --- a/src/test/java/net/ucanaccess/jdbc/AggregateFunctionsTest.java +++ b/src/test/java/net/ucanaccess/jdbc/AggregateFunctionsTest.java @@ -35,46 +35,46 @@ void afterEachTest() throws SQLException { void testDCount(AccessVersion _accessVersion) throws SQLException, IOException { init(_accessVersion); - checkQuery("SELECT id, DCount('*', 't235', '1=1') FROM [t235]", new Object[][] {{1234, 2}, {12344, 2}}); - checkQuery("SELECT id as [WW \"SS], DCount('descr', 't235', '1=1')from t235", - new Object[][] {{1234, 2}, {12344, 2}}); - checkQuery("SELECT DCount('*', 't235', '1=1') ", 2); + checkQuery("SELECT id, DCount('*', 't235', '1=1') FROM [t235]", recs(rec(1234, 2), rec(12344, 2))); + checkQuery("SELECT id AS [WW \"SS], DCount('descr', 't235', '1=1') FROM t235", + recs(rec(1234, 2), rec(12344, 2))); + checkQuery("SELECT DCount('*', 't235', '1=1') ", singleRec(2)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testDSum(AccessVersion _accessVersion) throws SQLException, IOException { init(_accessVersion); - checkQuery("SELECT DSum('id', 't235', '1=1')", 13578); + checkQuery("SELECT DSum('id', 't235', '1=1')", singleRec(13578)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testDMax(AccessVersion _accessVersion) throws SQLException, IOException { init(_accessVersion); - checkQuery("SELECT DMax('id', 't235')", 12344); + checkQuery("SELECT DMax('id', 't235')", singleRec(12344)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testDMin(AccessVersion _accessVersion) throws SQLException, IOException { init(_accessVersion); - checkQuery("SELECT DMin('id', 't235')", 1234); + checkQuery("SELECT DMin('id', 't235')", singleRec(1234)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testDAvg(AccessVersion _accessVersion) throws SQLException, IOException { init(_accessVersion); - checkQuery("SELECT DAvg('id', 't235')", 6789); + checkQuery("SELECT DAvg('id', 't235')", singleRec(6789)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testLast(AccessVersion _accessVersion) throws SQLException, IOException { init(_accessVersion); - checkQuery("SELECT last(descr) FROM t235", "Show must go up and down"); - checkQuery("SELECT last(NUM) FROM t235", -113.5540); + checkQuery("SELECT last(descr) FROM t235", singleRec("Show must go up and down")); + checkQuery("SELECT last(NUM) FROM t235", singleRec(-113.5540)); dumpQueryResult("SELECT last(date0) FROM t235"); } @@ -82,8 +82,8 @@ void testLast(AccessVersion _accessVersion) throws SQLException, IOException { @EnumSource(value = AccessVersion.class) void testFirst(AccessVersion _accessVersion) throws SQLException, IOException { init(_accessVersion); - checkQuery("SELECT first(descr) FROM t235", "Show must go off"); - checkQuery("SELECT first(NUM) FROM t235", -1110.5540); + checkQuery("SELECT first(descr) FROM t235", singleRec("Show must go off")); + checkQuery("SELECT first(NUM) FROM t235", singleRec(-1110.5540)); dumpQueryResult("SELECT first(date0) FROM t235"); } @@ -91,14 +91,14 @@ void testFirst(AccessVersion _accessVersion) throws SQLException, IOException { @EnumSource(value = AccessVersion.class) void testDLast(AccessVersion _accessVersion) throws SQLException, IOException { init(_accessVersion); - checkQuery("SELECT DLast('descr', 't235')", "Show must go up and down"); + checkQuery("SELECT DLast('descr', 't235')", singleRec("Show must go up and down")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testDFirst(AccessVersion _accessVersion) throws SQLException, IOException { init(_accessVersion); - checkQuery("SELECT DFirst('descr', 't235') ", "Show must go off"); + checkQuery("SELECT DFirst('descr', 't235') ", singleRec("Show must go off")); } } diff --git a/src/test/java/net/ucanaccess/jdbc/AlterTableTest.java b/src/test/java/net/ucanaccess/jdbc/AlterTableTest.java index 2276c640..ed3ea776 100644 --- a/src/test/java/net/ucanaccess/jdbc/AlterTableTest.java +++ b/src/test/java/net/ucanaccess/jdbc/AlterTableTest.java @@ -245,10 +245,10 @@ void testMiscellaneous(AccessVersion _accessVersion) throws SQLException, IOExce st.execute("ALTER TABLE tx ADD FOREIGN KEY ([my best friend], [Is Pippo]) REFERENCES tx1(n1, [n 2]) ON DELETE CASCADE"); st.execute("INSERT INTO tx1 values(1,\"ciao\")"); st.execute("INSERT INTO tx ([my best friend], [my worst friend], [Is Pippo]) values(1, 2, \"ciao\")"); - checkQuery("SELECT COUNT(*) FROM tx", 1); + checkQuery("SELECT COUNT(*) FROM tx", singleRec(1)); st.execute("DELETE FROM tx1"); checkQuery("SELECT COUNT(*) FROM tx"); - checkQuery("SELECT COUNT(*) FROM tx", 0); + checkQuery("SELECT COUNT(*) FROM tx", singleRec(0)); st.execute("DROP TABLE tx "); st.execute("DROP TABLE tx1 "); @@ -258,10 +258,10 @@ void testMiscellaneous(AccessVersion _accessVersion) throws SQLException, IOExce st.execute("ALTER TABLE tx ADD FOREIGN KEY ([my best friend], [Is Pippo]) REFERENCES tx1(n1, [n 2]) ON DELETE SET NULL"); st.execute("INSERT INTO tx1 VALUES(1, \"ciao\")"); st.execute("INSERT INTO tx ([my best friend], [my worst friend], [Is Pippo]) VALUES(1, 2, \"ciao\")"); - checkQuery("SELECT COUNT(*) FROM tx", 1); + checkQuery("SELECT COUNT(*) FROM tx", singleRec(1)); st.execute("DELETE FROM tx1"); - checkQuery("SELECT COUNT(*) FROM tx", 1); - checkQuery("SELECT * FROM tx", 1, null, 2.0, null, "what's this?"); + checkQuery("SELECT COUNT(*) FROM tx", singleRec(1)); + checkQuery("SELECT * FROM tx", singleRec(1, null, 2.0, null, "what's this?")); st.execute("CREATE UNIQUE INDEX IDX111 ON tx ([my best friend])"); assertThatThrownBy(() -> st.execute("INSERT INTO tx ([my best friend], [my worst friend], [Is Pippo]) values(1, 2, \"ciao\")")) diff --git a/src/test/java/net/ucanaccess/jdbc/BlobOleTest.java b/src/test/java/net/ucanaccess/jdbc/BlobOleTest.java index ee664cb8..e8f8f05b 100644 --- a/src/test/java/net/ucanaccess/jdbc/BlobOleTest.java +++ b/src/test/java/net/ucanaccess/jdbc/BlobOleTest.java @@ -59,14 +59,14 @@ void testBlobOle(AccessVersion _accessVersion) throws SQLException, IOException byte[] fileBytes = Files.readAllBytes(imgFileTemp.toPath()); - checkQuery("SELECT * FROM t_ole_test", new Object[][] {{1, descr, fileBytes}}); + checkQuery("SELECT * FROM t_ole_test", singleRec(1, descr, fileBytes)); PreparedStatement ps = ucanaccess.prepareStatement("UPDATE t_ole_test SET c_descr=? WHERE c_descr=?"); ps.setString(1, descr + "_OK"); ps.setString(2, descr); ps.executeUpdate(); checkQuery("SELECT * FROM t_ole_test"); - checkQuery("SELECT * FROM t_ole_test", 1, descr + "_OK", fileBytes); + checkQuery("SELECT * FROM t_ole_test", singleRec(1, descr + "_OK", fileBytes)); } try (PreparedStatement ps = ucanaccess.prepareStatement("UPDATE t_ole_test SET c_ole=? WHERE c_descr=?")) { diff --git a/src/test/java/net/ucanaccess/jdbc/CalculatedFieldTest.java b/src/test/java/net/ucanaccess/jdbc/CalculatedFieldTest.java index 104059d2..ec61e6b3 100644 --- a/src/test/java/net/ucanaccess/jdbc/CalculatedFieldTest.java +++ b/src/test/java/net/ucanaccess/jdbc/CalculatedFieldTest.java @@ -39,11 +39,11 @@ void testFunctionBuiltInCall(AccessVersion _accessVersion) throws Exception { dumpQueryResult("SELECT * FROM clcdFlds"); checkQuery("SELECT input, clcd1, clcd2, clcd3, clcd4 FROM clcdFlds ORDER BY id", - new String[][] {{"my", "my", "my", "my", "my"}, - {"myc", "myc", "myc", "myc", "myc"}, - {"mycat", "myc", "myc", "cat", "cat"}, - {"mycattom", "myc", "myc", "tom", "tom"}, - {"", "", "", "", ""}}); + recs(rec("my", "my", "my", "my", "my"), + rec("myc", "myc", "myc", "myc", "myc"), + rec("mycat", "myc", "myc", "cat", "cat"), + rec("mycattom", "myc", "myc", "tom", "tom"), + rec("", "", "", "", ""))); // inserting NULL into a calculated column containing a STRING formula is not permitted assertThatThrownBy(() -> st.execute("INSERT INTO clcdFlds (input) VALUES (null)")) diff --git a/src/test/java/net/ucanaccess/jdbc/ConcatNullsFalseTest.java b/src/test/java/net/ucanaccess/jdbc/ConcatNullsFalseTest.java index 7d3dff66..2f4f7367 100644 --- a/src/test/java/net/ucanaccess/jdbc/ConcatNullsFalseTest.java +++ b/src/test/java/net/ucanaccess/jdbc/ConcatNullsFalseTest.java @@ -22,7 +22,7 @@ protected UcanaccessConnectionBuilder buildConnection() { @MethodSource("net.ucanaccess.type.AccessVersion#getDefaultAccessVersion()") void testConcat(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT 'aa2'& null FROM dual", new Object[][] {{"aa2"}}); + checkQuery("SELECT 'aa2'& null FROM dual", singleRec("aa2")); } } diff --git a/src/test/java/net/ucanaccess/jdbc/ConcatNullsTrueTest.java b/src/test/java/net/ucanaccess/jdbc/ConcatNullsTrueTest.java index c6082c61..f262b638 100644 --- a/src/test/java/net/ucanaccess/jdbc/ConcatNullsTrueTest.java +++ b/src/test/java/net/ucanaccess/jdbc/ConcatNullsTrueTest.java @@ -26,7 +26,7 @@ protected UcanaccessConnectionBuilder buildConnection() { @MethodSource("net.ucanaccess.type.AccessVersion#getDefaultAccessVersion()") void testConcat(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT 'aa2'& null FROM dual", new Object[][] {{null}}); + checkQuery("SELECT 'aa2'& null FROM dual", recs(rec((Object) null))); } } diff --git a/src/test/java/net/ucanaccess/jdbc/CounterTest.java b/src/test/java/net/ucanaccess/jdbc/CounterTest.java index eaecff5c..1af8c6d0 100644 --- a/src/test/java/net/ucanaccess/jdbc/CounterTest.java +++ b/src/test/java/net/ucanaccess/jdbc/CounterTest.java @@ -50,17 +50,16 @@ void testCreateTypes(AccessVersion _accessVersion) throws SQLException { } dumpQueryResult("SELECT * FROM t_counter"); - Object[][] ver = { - {-1, "A", null, null}, - {3, "C", null, null}, - {4, "D", null, null}, - {5, "E", null, null}, - {6, "F", null, null}, - {7, "G", null, null}, - {8, "H", null, null}, - {9, "I", null, null} - }; - checkQuery("SELECT * FROM t_counter ORDER BY cntr", ver); + checkQuery("SELECT * FROM t_counter ORDER BY cntr", recs( + rec(-1, "A", null, null), + rec(3, "C", null, null), + rec(4, "D", null, null), + rec(5, "E", null, null), + rec(6, "F", null, null), + rec(7, "G", null, null), + rec(8, "H", null, null), + rec(9, "I", null, null) + )); } diff --git a/src/test/java/net/ucanaccess/jdbc/CreateTableTest.java b/src/test/java/net/ucanaccess/jdbc/CreateTableTest.java index 699f672f..28dc5928 100644 --- a/src/test/java/net/ucanaccess/jdbc/CreateTableTest.java +++ b/src/test/java/net/ucanaccess/jdbc/CreateTableTest.java @@ -31,8 +31,8 @@ protected String getAccessPath() { private void createAsSelect() throws SQLException { try (Statement st = ucanaccess.createStatement()) { st.executeUpdate("CREATE TABLE AAA_BIS as (SELECT baaaa,a,c FROM AAA) WITH DATA"); - Object[][] ver = {{"33A", 3, "G"}, {"33B", 111, "G"}}; - checkQuery("SELECT * FROM AAA_bis ORDER BY baaaa", ver); + checkQuery("SELECT * FROM AAA_bis ORDER BY baaaa", + recs(rec("33A", 3, "G"), rec("33B", 111, "G"))); st.executeUpdate("CREATE TABLE AAA_quadris as (SELECT AAA.baaaa,AAA_BIS.baaaa as xxx FROM AAA,AAA_BIS) WITH DATA"); dumpQueryResult("SELECT * FROM AAA_quadris ORDER BY baaaa"); } @@ -42,8 +42,8 @@ private void createAsSelect2() throws SQLException { try (Statement st = ucanaccess.createStatement()) { st.executeUpdate("CREATE TABLE AAA_TRIS as (SELECT baaaa,a,c FROM AAA) WITH NO DATA"); st.execute("INSERT INTO AAA_TRIS SELECT * FROM AAA_bis"); - Object[][] ver = {{"33A", 3, "G"}, {"33B", 111, "G"}}; - checkQuery("SELECT * FROM AAA_tris ORDER BY baaaa", ver); + checkQuery("SELECT * FROM AAA_tris ORDER BY baaaa", + recs(rec("33A", 3, "G"), rec("33B", 111, "G"))); } } @@ -61,8 +61,8 @@ private void createSimple() throws SQLException { executeStatements(st, "INSERT INTO AAA(baaaa, c) VALUES ('33A', 'G')", "INSERT INTO AAA(baaaa, a, c) VALUES ('33B', 111, 'G')"); - Object[][] ver = {{"33A", 3, "G"}, {"33B", 111, "G"}}; - checkQuery("SELECT baaaa, a, c FROM AAA ORDER BY baaaa", ver); + checkQuery("SELECT baaaa, a, c FROM AAA ORDER BY baaaa", + recs(rec("33A", 3, "G"), rec("33B", 111, "G"))); } } diff --git a/src/test/java/net/ucanaccess/jdbc/CrudTest.java b/src/test/java/net/ucanaccess/jdbc/CrudTest.java index d2ba8024..9952e202 100644 --- a/src/test/java/net/ucanaccess/jdbc/CrudTest.java +++ b/src/test/java/net/ucanaccess/jdbc/CrudTest.java @@ -86,7 +86,7 @@ void testCrudPSBatch(AccessVersion _accessVersion) throws SQLException { ps.executeBatch(); ps.clearBatch(); } - checkQuery("SELECT * FROM t1", new Object[][] {{id1, "Prep1"}, {id2, "Prep2"}}); + checkQuery("SELECT * FROM t1", recs(rec(id1, "Prep1"), rec(id2, "Prep2"))); assertEquals(2, getCount("SELECT COUNT(*) FROM t1 where id in (" + id1 + ", " + id2 + ")"), "Insert failed"); try (PreparedStatement ps = ucanaccess.prepareStatement("DELETE FROM t1")) { @@ -110,7 +110,7 @@ void testUpdatableRS(AccessVersion _accessVersion) throws SQLException { rs.next(); rs.updateString(2, "show must go off"); rs.updateRow(); - checkQuery("SELECT * FROM t1", new Object[][] {{6666554, "show must go off"}}); + checkQuery("SELECT * FROM t1", singleRec(6666554, "show must go off")); st.execute("DELETE FROM t1"); } } @@ -133,8 +133,7 @@ void testDeleteRS(AccessVersion _accessVersion) throws SQLException, IOException rs.deleteRow(); ps.getConnection().commit(); - - checkQuery("SELECT COUNT(*) FROM t1", 0); + checkQuery("SELECT COUNT(*) FROM t1", singleRec(0)); } @ParameterizedTest(name = "[{index}] {0}") @@ -155,8 +154,8 @@ void testInsertRS(AccessVersion _accessVersion) throws SQLException { rs.insertRow(); ps.getConnection().commit(); - Object[][] ver = {{4, "Growing old in rural pleaces"}, {6666554, "tre canarini volano su e cadono"}}; - checkQuery("SELECT * FROM t1 ORDER BY id", ver); + checkQuery("SELECT * FROM t1 ORDER BY id", + recs(rec(4, "Growing old in rural pleaces"), rec(6666554, "tre canarini volano su e cadono"))); st.execute("DELETE FROM t1"); } } @@ -182,7 +181,7 @@ void testInsertRSNoAllSet(AccessVersion _accessVersion) throws SQLException, IOE rs.next(); ps.getConnection().commit(); - checkQuery("SELECT * FROM T2 ORDER BY id", 1, "Growing old in rural places"); + checkQuery("SELECT * FROM T2 ORDER BY id", singleRec(1, "Growing old in rural places")); Statement stat = ucanaccess.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs1 = stat.executeQuery("SELECT * FROM T2 ORDER BY id"); rs1.last(); @@ -208,8 +207,7 @@ void testPartialInsertRS(AccessVersion _accessVersion) throws SQLException { rs.insertRow(); ps.getConnection().commit(); - Object[][] ver = {{1, "Growing old without emotions"}}; - checkQuery("SELECT * FROM T21 ORDER BY id", ver); + checkQuery("SELECT * FROM T21 ORDER BY id", singleRec(1, "Growing old without emotions")); st.execute("DELETE FROM t21"); } } diff --git a/src/test/java/net/ucanaccess/jdbc/DropTableTest.java b/src/test/java/net/ucanaccess/jdbc/DropTableTest.java index fa798c59..0ee2a7fc 100644 --- a/src/test/java/net/ucanaccess/jdbc/DropTableTest.java +++ b/src/test/java/net/ucanaccess/jdbc/DropTableTest.java @@ -7,6 +7,7 @@ import java.sql.SQLException; import java.sql.Statement; +import java.util.List; class DropTableTest extends UcanaccessBaseTest { @@ -17,11 +18,11 @@ protected void init(AccessVersion _accessVersion) throws SQLException { "CREATE TABLE [AAA n] (baaaa TEXT(3) PRIMARY KEY, A INTEGER, C TEXT(4))"); } - void createSimple(String _tableName, String a, Object[][] ver) throws SQLException { + void createSimple(String _tableName, String _a, List> _ver) throws SQLException { try (Statement st = ucanaccess.createStatement()) { - st.execute("INSERT INTO " + _tableName + " VALUES ('33A', 11,'" + a + "')"); - st.execute("INSERT INTO " + _tableName + " VALUES ('33B',111,'" + a + "')"); - checkQuery("SELECT * FROM " + _tableName + " ORDER BY c", ver); + st.execute("INSERT INTO " + _tableName + " VALUES ('33A', 11,'" + _a + "')"); + st.execute("INSERT INTO " + _tableName + " VALUES ('33B',111,'" + _a + "')"); + checkQuery("SELECT * FROM " + _tableName + " ORDER BY c", _ver); } } @@ -31,12 +32,12 @@ void testDrop(AccessVersion _accessVersion) throws SQLException { init(_accessVersion); // ucanaccess.setAutoCommit(false); - createSimple("AAAn", "a", new Object[][] {{"33A", 11, "a"}, {"33B", 111, "a"}}); + createSimple("AAAn", "a", recs(rec("33A", 11, "a"), rec("33B", 111, "a"))); try (Statement st = ucanaccess.createStatement()) { st.executeUpdate("DROP TABLE AAAn"); // ucanaccess.commit(); st.execute("CREATE TABLE AAAn (baaaa TEXT(3) PRIMARY KEY, A INTEGER, C TEXT(4))"); - createSimple("AAAn", "b", new Object[][] {{"33A", 11, "b"}, {"33B", 111, "b"}}); + createSimple("AAAn", "b", recs(rec("33A", 11, "b"), rec("33B", 111, "b"))); dumpQueryResult("SELECT * FROM AAAn"); ucanaccess.commit(); } @@ -48,12 +49,12 @@ void testDropBlank(AccessVersion _accessVersion) throws SQLException { init(_accessVersion); // ucanaccess.setAutoCommit(false); - createSimple("[AAA n]", "a", new Object[][] {{"33A", 11, "a"}, {"33B", 111, "a"}}); + createSimple("[AAA n]", "a", recs(rec("33A", 11, "a"), rec("33B", 111, "a"))); try (Statement st = ucanaccess.createStatement()) { st.executeUpdate("DROP TABLE [AAA n]"); // ucanaccess.commit(); st.execute("CREATE TABLE [AAA n] (baaaa TEXT(3) PRIMARY KEY, A INTEGER, C TEXT(4))"); - createSimple("[AAA n]", "b", new Object[][] {{"33A", 11, "b"}, {"33B", 111, "b"}}); + createSimple("[AAA n]", "b", recs(rec("33A", 11, "b"), rec("33B", 111, "b"))); dumpQueryResult("SELECT * FROM [AAA n]"); ucanaccess.commit(); } diff --git a/src/test/java/net/ucanaccess/jdbc/FloatTest.java b/src/test/java/net/ucanaccess/jdbc/FloatTest.java index 267595eb..25d2b774 100644 --- a/src/test/java/net/ucanaccess/jdbc/FloatTest.java +++ b/src/test/java/net/ucanaccess/jdbc/FloatTest.java @@ -43,7 +43,7 @@ void testCreate(AccessVersion _accessVersion) throws SQLException, IOException { ps.setFloat(1, 4.10011001155f); ps.execute(); checkQuery("SELECT [row] FROM t ORDER BY pk"); - checkQuery("SELECT COUNT(*) FROM t WHERE [row]=4.10011", 2); + checkQuery("SELECT COUNT(*) FROM t WHERE [row]=4.10011", singleRec(2)); dumpQueryResult("SELECT * FROM t ORDER BY pk"); } diff --git a/src/test/java/net/ucanaccess/jdbc/FunctionsTest.java b/src/test/java/net/ucanaccess/jdbc/FunctionsTest.java index 6a29e010..c904d616 100644 --- a/src/test/java/net/ucanaccess/jdbc/FunctionsTest.java +++ b/src/test/java/net/ucanaccess/jdbc/FunctionsTest.java @@ -36,9 +36,9 @@ protected void init(AccessVersion _accessVersion) throws SQLException { @EnumSource(value = AccessVersion.class) void testASC(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT ASC('A') FROM " + TBL, 65); - checkQuery("SELECT ASC('1') FROM " + TBL, 49); - checkQuery("SELECT ASC('u') FROM " + TBL, 117); + checkQuery("SELECT ASC('A') FROM " + TBL, singleRec(65)); + checkQuery("SELECT ASC('1') FROM " + TBL, singleRec(49)); + checkQuery("SELECT ASC('u') FROM " + TBL, singleRec(117)); } @ParameterizedTest(name = "[{index}] {0}") @@ -52,15 +52,14 @@ void testSwitch(AccessVersion _accessVersion) throws Exception { @EnumSource(value = AccessVersion.class) void testATN(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT ATN(3) FROM " + TBL, 1.2490457723982544); + checkQuery("SELECT ATN(3) FROM " + TBL, singleRec(1.2490457723982544)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testNz(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT NZ(null,'lampredotto'),nz('turtelaz','lampredotto'), nz(null, 1.5), nz(2, 2) FROM " + TBL, - "lampredotto", "turtelaz", 1.5, 2); + checkQuery("SELECT NZ(null,'lampredotto'), nz('turtelaz','lampredotto'), nz(null, 1.5), nz(2, 2) FROM " + TBL, singleRec("lampredotto", "turtelaz", 1.5, 2)); } @ParameterizedTest(name = "[{index}] {0}") @@ -68,31 +67,31 @@ void testNz(AccessVersion _accessVersion) throws Exception { void testCBoolean(AccessVersion _accessVersion) throws Exception { init(_accessVersion); checkQuery("SELECT CBOOL(id), CBOOL(1=2), CBOOL('true'), CBOOL('false'), CBOOL(0), CBOOL(-3) FROM " + TBL, - new Object[][] {{true, false, true, false, false, true}}); + singleRec(true, false, true, false, false, true)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testCVar(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT CVAR(8), CVAR(8.44) FROM " + TBL, "8", "8.44"); + checkQuery("SELECT CVAR(8), CVAR(8.44) FROM " + TBL, singleRec("8", "8.44")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testCstr(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT CSTR(date0) FROM " + TBL, "11/22/2003 10:42:58 PM"); - checkQuery("SELECT CSTR(false) FROM " + TBL, "false"); - checkQuery("SELECT CSTR(8) FROM " + TBL, "8"); - checkQuery("SELECT CSTR(8.78787878) FROM " + TBL, "8.78787878"); + checkQuery("SELECT CSTR(date0) FROM " + TBL, singleRec("11/22/2003 10:42:58 PM")); + checkQuery("SELECT CSTR(false) FROM " + TBL, singleRec("false")); + checkQuery("SELECT CSTR(8) FROM " + TBL, singleRec("8")); + checkQuery("SELECT CSTR(8.78787878) FROM " + TBL, singleRec("8.78787878")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testCsign(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT CSIGN(8.53453543) FROM " + TBL, 8.534535); + checkQuery("SELECT CSIGN(8.53453543) FROM " + TBL, singleRec(8.534535)); } @ParameterizedTest(name = "[{index}] {0}") @@ -100,68 +99,65 @@ void testCsign(AccessVersion _accessVersion) throws Exception { void testCDate(AccessVersion _accessVersion) throws Exception { init(_accessVersion); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); - - checkQuery("SELECT CDATE('Apr 6, 2003') FROM " + TBL, sdf.parse("2003-04-06 00:00:00.0")); - - checkQuery("SELECT CDATE('1582-10-15') FROM " + TBL, sdf.parse("1582-10-15 00:00:00.0")); + checkQuery("SELECT CDATE('Apr 6, 2003') FROM " + TBL, recs(rec(sdf.parse("2003-04-06 00:00:00.0")))); + checkQuery("SELECT CDATE('1582-10-15') FROM " + TBL, recs(rec(sdf.parse("1582-10-15 00:00:00.0")))); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testCLong(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT CLONG(8.52), CLONG(8.49), CLONG(5.5) FROM " + TBL, 9, 8, 6); + checkQuery("SELECT CLONG(8.52), CLONG(8.49), CLONG(5.5) FROM " + TBL, singleRec(9, 8, 6)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testCLng(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT CLNG(8.52), CLNG(8.49), CLNG(5.5) FROM " + TBL, 9, 8, 6); + checkQuery("SELECT CLNG(8.52), CLNG(8.49), CLNG(5.5) FROM " + TBL, singleRec(9, 8, 6)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testCDec(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT CDEC(8.45 * 0.005 * 0.01) FROM " + TBL, 0.0004225); + checkQuery("SELECT CDEC(8.45 * 0.005 * 0.01) FROM " + TBL, singleRec(0.0004225)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testCcur(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT CCUR(123.4567812), CCUR(123.4547812) FROM " + TBL, 123.4568, 123.4548); - - checkQuery("SELECT CCUR(0.552222211) * 100 FROM " + TBL, 55.22); + checkQuery("SELECT CCUR(123.4567812), CCUR(123.4547812) FROM " + TBL, singleRec(123.4568, 123.4548)); + checkQuery("SELECT CCUR(0.552222211) * 100 FROM " + TBL, singleRec(55.22)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testCint(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT CINT(8.51), CINT(4.5) FROM " + TBL, 9, 4); + checkQuery("SELECT CINT(8.51), CINT(4.5) FROM " + TBL, singleRec(9, 4)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testChr(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT CHR(65) FROM " + TBL, "A"); + checkQuery("SELECT CHR(65) FROM " + TBL, singleRec("A")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testCos(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT COS(1) FROM " + TBL, 0.5403023058681398); + checkQuery("SELECT COS(1) FROM " + TBL, singleRec(0.5403023058681398)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testCurrentUser(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT CurrentUser() FROM " + TBL, "ucanaccess"); + checkQuery("SELECT CurrentUser() FROM " + TBL, singleRec("ucanaccess")); } @ParameterizedTest(name = "[{index}] {0}") @@ -170,34 +166,20 @@ void testDateAdd(AccessVersion _accessVersion) throws Exception { init(_accessVersion); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); - checkQuery("SELECT DateAdd('YYYY', 4, #11/22/2003 10:42:58 PM#) FROM " + TBL, - sdf.parse("2007-11-22 22:42:58")); - checkQuery("SELECT DateAdd('Q', 3 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, - sdf.parse("2004-08-22 22:42:58")); - checkQuery("SELECT DateAdd('Y', 451 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, - sdf.parse("2005-02-15 22:42:58")); - checkQuery("SELECT DateAdd('D', 451 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, - sdf.parse("2005-02-15 22:42:58")); - checkQuery("SELECT DateAdd('Y', 45 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, - sdf.parse("2004-01-06 22:42:58")); - checkQuery("SELECT DateAdd('D', 45 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, - sdf.parse("2004-01-06 22:42:58")); - checkQuery("SELECT DateAdd('Y', 4 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, - sdf.parse("2003-11-26 22:42:58")); - checkQuery("SELECT DateAdd('D', 4 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, - sdf.parse("2003-11-26 22:42:58")); - checkQuery("SELECT DateAdd('W', 43 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, - sdf.parse("2004-01-04 22:42:58")); - checkQuery("SELECT DateAdd('W', 1 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, - sdf.parse("2003-11-23 22:42:58")); - checkQuery("SELECT DateAdd('WW', 43 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, - sdf.parse("2004-09-18 22:42:58")); - checkQuery("SELECT DateAdd('H', 400 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, - sdf.parse("2003-12-09 14:42:58")); - checkQuery("SELECT DateAdd('M', 400 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, - sdf.parse("2037-03-22 22:42:58")); - checkQuery("SELECT DateAdd('S', 400 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, - sdf.parse("2003-11-22 22:49:38")); + checkQuery("SELECT DateAdd('YYYY', 4, #11/22/2003 10:42:58 PM#) FROM " + TBL, recs(rec(sdf.parse("2007-11-22 22:42:58")))); + checkQuery("SELECT DateAdd('Q', 3 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, recs(rec(sdf.parse("2004-08-22 22:42:58")))); + checkQuery("SELECT DateAdd('Y', 451 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, recs(rec(sdf.parse("2005-02-15 22:42:58")))); + checkQuery("SELECT DateAdd('D', 451 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, recs(rec(sdf.parse("2005-02-15 22:42:58")))); + checkQuery("SELECT DateAdd('Y', 45 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, recs(rec(sdf.parse("2004-01-06 22:42:58")))); + checkQuery("SELECT DateAdd('D', 45 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, recs(rec(sdf.parse("2004-01-06 22:42:58")))); + checkQuery("SELECT DateAdd('Y', 4 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, recs(rec(sdf.parse("2003-11-26 22:42:58")))); + checkQuery("SELECT DateAdd('D', 4 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, recs(rec(sdf.parse("2003-11-26 22:42:58")))); + checkQuery("SELECT DateAdd('W', 43 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, recs(rec(sdf.parse("2004-01-04 22:42:58")))); + checkQuery("SELECT DateAdd('W', 1 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, recs(rec(sdf.parse("2003-11-23 22:42:58")))); + checkQuery("SELECT DateAdd('WW', 43 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, recs(rec(sdf.parse("2004-09-18 22:42:58")))); + checkQuery("SELECT DateAdd('H', 400 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, recs(rec(sdf.parse("2003-12-09 14:42:58")))); + checkQuery("SELECT DateAdd('M', 400 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, recs(rec(sdf.parse("2037-03-22 22:42:58")))); + checkQuery("SELECT DateAdd('S', 400 ,#11/22/2003 10:42:58 PM#) FROM " + TBL, recs(rec(sdf.parse("2003-11-22 22:49:38")))); } @ParameterizedTest(name = "[{index}] {0}") @@ -211,74 +193,74 @@ void testDate(AccessVersion _accessVersion) throws Exception { @EnumSource(value = AccessVersion.class) void testDay(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT Day(#11/22/2003 10:42:58 PM#) FROM " + TBL, 22); + checkQuery("SELECT Day(#11/22/2003 10:42:58 PM#) FROM " + TBL, singleRec(22)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testExp(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT Exp(3.1), exp(0.4) FROM " + TBL, 22.197951281441636, 1.4918246976412703); + checkQuery("SELECT Exp(3.1), exp(0.4) FROM " + TBL, singleRec(22.197951281441636, 1.4918246976412703d)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testHour(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT Hour(#10:42:58 pM#), Hour(#10:42:58 AM#), Hour(#11/22/2003 10:42:58 PM#) FROM " + TBL, 22, 10, - 22); + checkQuery("SELECT Hour(#10:42:58 pM#), Hour(#10:42:58 AM#), Hour(#11/22/2003 10:42:58 PM#) FROM " + TBL, singleRec(22, 10, 22)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testIif(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery( - "SELECT IIf(IsNull(descr)=true, 'pippo', 'pl''uto'&'\" \" cccc'), IIf(IsNull(descr)=true,'pippo','pl''uto'&'\" \" cccc') FROM " + TBL, - "pl'uto\" \" cccc", "pl'uto\" \" cccc"); - - checkQuery("SELECT IIf(true, false, true) FROM " + TBL, false); - checkQuery("SELECT IIf('pippo'=null, 'capra', 'd''una capra') FROM " + TBL, "d'una capra"); + checkQuery("SELECT IIf(IsNull(descr)=true, 'pippo', 'pl''uto'&'\" \" cccc'), IIf(IsNull(descr)=true,'pippo','pl''uto'&'\" \" cccc') FROM " + TBL, singleRec("pl'uto\" \" cccc", "pl'uto\" \" cccc")); + checkQuery("SELECT IIf(true, false, true) FROM " + TBL, singleRec(false)); + checkQuery("SELECT IIf('pippo'=null, 'capra', 'd''una capra') FROM " + TBL, singleRec("d'una capra")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testInstr(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT InStr('Found on the Net', 'the') FROM " + TBL, 10); - checkQuery("SELECT InStr('Found on the Net', 'f') FROM " + TBL, 1); - checkQuery("SELECT InStr(1, 'Found on the Net', 'f') FROM " + TBL, 1); - checkQuery("SELECT InStr(1, 'Found on the Net', 'f',1) FROM " + TBL, 1); - checkQuery("SELECT InStr(1, 'Found on the Net', 't',0) FROM " + TBL, 10); - checkQuery("SELECT InStr(31, 'Found on the Net', 'f',0) FROM " + TBL, 0); + checkQuery("SELECT InStr('Found on the Net', 'the') FROM " + TBL, singleRec(10)); + checkQuery("SELECT InStr('Found on the Net', 'f') FROM " + TBL, singleRec(1)); + checkQuery("SELECT InStr(1, 'Found on the Net', 'f') FROM " + TBL, singleRec(1)); + checkQuery("SELECT InStr(1, 'Found on the Net', 'f',1) FROM " + TBL, singleRec(1)); + checkQuery("SELECT InStr(1, 'Found on the Net', 't',0) FROM " + TBL, singleRec(10)); + checkQuery("SELECT InStr(31, 'Found on the Net', 'f',0) FROM " + TBL, singleRec(0)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testInstrrev(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT InstrRev('alphabet', 'a') FROM " + TBL, 5); - checkQuery("SELECT InstrRev('alphabet', 'a',-1) FROM " + TBL, 5); - checkQuery("SELECT InstrRev('alphabet', 'a',1) FROM " + TBL, 1); + checkQuery("SELECT InstrRev('alphabet', 'a') FROM " + TBL, singleRec(5)); + checkQuery("SELECT InstrRev('alphabet', 'a',-1) FROM " + TBL, singleRec(5)); + checkQuery("SELECT InstrRev('alphabet', 'a',1) FROM " + TBL, singleRec(1)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testIsDate(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT IsDate(#1/2/2003 10:42:58 PM#) FROM " + TBL, true); - checkQuery("SELECT IsDate(#11/22/2003 10:42:58 PM#) FROM " + TBL, true); - checkQuery("SELECT IsDate('11/22/2003 10:42:58 PM') FROM " + TBL, true); - checkQuery("SELECT IsDate('january 3,2015') FROM " + TBL, true); + checkQuery("SELECT IsDate(#1/2/2003 10:42:58 PM#) FROM " + TBL, singleRec(true)); + + checkQuery("SELECT IsDate(#11/22/2003 10:42:58 PM#) FROM " + TBL, singleRec(true)); + + checkQuery("SELECT IsDate('11/22/2003 10:42:58 PM') FROM " + TBL, singleRec(true)); + + checkQuery("SELECT IsDate('january 3,2015') FROM " + TBL, singleRec(true)); + // fails in JDK8: checkQuery("SELECT isDate('janr 3,2015') FROM " + TBL, false); - checkQuery("SELECT IsDate('03 3,2015') FROM " + TBL, true); - checkQuery("SELECT IsDate('3 3,2015') FROM " + TBL, true); + checkQuery("SELECT IsDate('03 3,2015') FROM " + TBL, singleRec(true)); + checkQuery("SELECT IsDate('3 3,2015') FROM " + TBL, singleRec(true)); // fails in JDK8: checkQuery("SELECT isDate('Fri Feb 10 00:25:09 CET 2012') FROM " + TBL, false); - checkQuery("SELECT IsDate('Fri Feb 10 2012') FROM " + TBL, false); - checkQuery("SELECT IsDate('Fri Feb 10 00:25:09 2012') FROM " + TBL, false); + checkQuery("SELECT IsDate('Fri Feb 10 2012') FROM " + TBL, singleRec(false)); + checkQuery("SELECT IsDate('Fri Feb 10 00:25:09 2012') FROM " + TBL, singleRec(false)); // fails in JDK8: checkQuery("SELECT isDate('Fri Feb 10 00:25:09') FROM " + TBL, false); // fails in JDK8: checkQuery("SELECT isDate('jan 35,2015') FROM " + TBL, false); - checkQuery("SELECT IsDate('Feb 20 01:25:09 PM') FROM " + TBL, true); + checkQuery("SELECT IsDate('Feb 20 01:25:09 PM') FROM " + TBL, singleRec(true)); // fails in JDK8: checkQuery("SELECT isDate('Feb 10 00:25:09') FROM " + TBL, true); // fails in JDK8: checkQuery("SELECT isDate('02 10 00:25:09') FROM " + TBL, true); // fails in JDK8: checkQuery("SELECT isDate('Feb 35 00:25:09') FROM " + TBL, true); @@ -301,63 +283,61 @@ void testSimpleDateFormatLenientTrue(AccessVersion _accessVersion) throws Except @EnumSource(value = AccessVersion.class) void testIsNumber(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT IsNumeric(33) FROM " + TBL, true); - checkQuery("SELECT IsNumeric('33') FROM " + TBL, true); - checkQuery("SELECT IsNumeric('a') FROM " + TBL, false); - checkQuery("SELECT IsNumeric('33d') FROM " + TBL, false); - checkQuery("SELECT IsNumeric(id) FROM " + TBL, true); - checkQuery("SELECT IsNumeric('4,5') FROM " + TBL, true); + checkQuery("SELECT IsNumeric(33) FROM " + TBL, singleRec(true)); + checkQuery("SELECT IsNumeric('33') FROM " + TBL, singleRec(true)); + checkQuery("SELECT IsNumeric('a') FROM " + TBL, singleRec(false)); + checkQuery("SELECT IsNumeric('33d') FROM " + TBL, singleRec(false)); + checkQuery("SELECT IsNumeric(id) FROM " + TBL, singleRec(true)); + checkQuery("SELECT IsNumeric('4,5') FROM " + TBL, singleRec(true)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testLcase(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT LCASE(' SAAxxxx ') FROM " + TBL, " saaxxxx "); + checkQuery("SELECT LCASE(' SAAxxxx ') FROM " + TBL, singleRec(" saaxxxx ")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testLeft(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT Left('Found on the Net', 4), Left(null, 4) FROM " + TBL, "Foun", null); + checkQuery("SELECT Left('Found on the Net', 4), Left(null, 4) FROM " + TBL, singleRec("Foun", null)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testLen(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT len('1222sssss.3hhh'), len(null) FROM " + TBL, 14, null); + checkQuery("SELECT len('1222sssss.3hhh'), len(null) FROM " + TBL, singleRec(14, null)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testLTrim(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT LTRIM(' SSS ') FROM " + TBL, "SSS "); + checkQuery("SELECT LTRIM(' SSS ') FROM " + TBL, singleRec("SSS ")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testMid(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery( - "SELECT Mid ('Found on the Net', 2, 4), Mid ('Found on the Net', 1, 555),Mid(null, 1, 555) FROM " + TBL, - "ound", "Found on the Net", null); + checkQuery("SELECT Mid ('Found on the Net', 2, 4), Mid ('Found on the Net', 1, 555),Mid(null, 1, 555) FROM " + TBL, singleRec("ound", "Found on the Net", null)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testMinute(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT Minute(#10:42:58 pM#),Minute(#10:42:58 AM#),Minute(#11/22/2003 10:42:58 PM#) FROM " + TBL, 42, 42, 42); + checkQuery("SELECT Minute(#10:42:58 pM#),Minute(#10:42:58 AM#),Minute(#11/22/2003 10:42:58 PM#) FROM " + TBL, singleRec(42, 42, 42)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testMonth(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT month(#11/22/2003 10:42:58 PM#) FROM " + TBL, 11); + checkQuery("SELECT month(#11/22/2003 10:42:58 PM#) FROM " + TBL, singleRec(11)); } @ParameterizedTest(name = "[{index}] {0}") @@ -366,7 +346,7 @@ void testNow(AccessVersion _accessVersion) throws Exception { init(_accessVersion); sleepUntilStartOfNewSecond(); Date now = new Date(System.currentTimeMillis() / 1000 * 1000); - checkQuery("SELECT Now() FROM " + TBL, now); + checkQuery("SELECT Now() FROM " + TBL, singleRec(now)); } @ParameterizedTest(name = "[{index}] {0}") @@ -377,7 +357,7 @@ void testTime(AccessVersion _accessVersion) throws Exception { Calendar cl = Calendar.getInstance(); cl.set(Calendar.MILLISECOND, 0); cl.set(1899, 11, 30); - checkQuery("SELECT Time() FROM " + TBL, cl.getTime()); + checkQuery("SELECT Time() FROM " + TBL, recs(rec(cl.getTime()))); } /** @@ -397,118 +377,114 @@ private static void sleepUntilStartOfNewSecond() { @EnumSource(value = AccessVersion.class) void testReplace(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT Replace('alphabet', 'bet', 'hydr') FROM " + TBL, "alphahydr"); + checkQuery("SELECT Replace('alphabet', 'bet', 'hydr') FROM " + TBL, singleRec("alphahydr")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testRight(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT Right('Tech on the Net', 3), Right(null,12) FROM " + TBL, "Net", null); + checkQuery("SELECT Right('Tech on the Net', 3), Right(null,12) FROM " + TBL, singleRec("Net", null)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testRtrim(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT RTRIM(' SSS ') FROM " + TBL, " SSS"); + checkQuery("SELECT RTRIM(' SSS ') FROM " + TBL, singleRec(" SSS")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testSecond(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT Second(#10:42:58 pM#),Second(#10:42:58 AM#),Second(#11/22/2003 10:42:58 PM#) FROM " + TBL, 58, - 58, 58); + checkQuery("SELECT Second(#10:42:58 pM#), Second(#10:42:58 AM#), Second(#11/22/2003 10:42:58 PM#) FROM " + TBL, singleRec(58, 58, 58)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testSin(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT sin(1) FROM " + TBL, 0.8414709848078965); + checkQuery("SELECT sin(1) FROM " + TBL, singleRec(0.8414709848078965)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testSpace(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT space(5) FROM " + TBL, " "); + checkQuery("SELECT space(5) FROM " + TBL, singleRec(" ")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testTrim(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT TRIM(' SSS ') FROM " + TBL, "SSS"); + checkQuery("SELECT TRIM(' SSS ') FROM " + TBL, singleRec("SSS")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testUcase(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT UCASE(' SAAxxxx ') FROM " + TBL, " SAAXXXX "); + checkQuery("SELECT UCASE(' SAAxxxx ') FROM " + TBL, singleRec(" SAAXXXX ")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testVal(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery( - "SELECT val('0.'), Val('hhh'), val('.a'), val('.'), val('.44'), Val('1222.3hhh'), Val('12 22.3hhh'), VAL('-'), VAL('-2,3') FROM " + TBL, - 0.0, 0.0, 0.0, 0.0, 0.44, 1222.3, 1222.3, 0.0, -2.0); + checkQuery("SELECT val('0.'), Val('hhh'), val('.a'), val('.'), val('.44'), Val('1222.3hhh'), Val('12 22.3hhh'), VAL('-'), VAL('-2,3') FROM " + TBL, + singleRec(0.0, 0.0, 0.0, 0.0, 0.44, 1222.3, 1222.3, 0.0, -2.0)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testYear(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT YEAR(#11/22/2003 10:42:58 PM#) FROM " + TBL, 2003); + checkQuery("SELECT YEAR(#11/22/2003 10:42:58 PM#) FROM " + TBL, singleRec(2003)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testDateDiff(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT DateDiff('yyyy',#11/22/1992 10:42:58 PM#,#11/22/2007 10:42:58 AM#) FROM " + TBL, 15); - checkQuery("SELECT DateDiff('y',#11/22/1992 11:00:00 AM#,#11/22/2007 10:00:00 AM#) FROM " + TBL, 5478); - checkQuery("SELECT DateDiff('y',#11/22/1992 11:00:00 AM#,#11/22/2007 12:00:00 AM#) FROM " + TBL, 5478); - checkQuery("SELECT DateDiff('yyyy',#11/22/1992 10:42:58 PM#,#11/22/2007 10:42:58 AM#) FROM " + TBL, 15); - checkQuery("SELECT DateDiff('m',#11/22/2007 11:00:00 AM#,#11/22/2007 10:00:00 AM#) FROM " + TBL, 0); - checkQuery("SELECT DateDiff('m',#11/22/1992 11:00:00 AM#,#08/22/2007 12:00:00 AM#) FROM " + TBL, 177); - checkQuery("SELECT DateDiff('d',#1/1/2004 11:00:00 AM#,#1/3/2004 11:00:00 AM#) FROM " + TBL, 2); - checkQuery("SELECT DateDiff('d',#11/22/1992 11:00:00 AM#,#11/22/2007 10:00:00 AM#) FROM " + TBL, 5478); - checkQuery("SELECT DateDiff('d',#11/22/1992 11:00:00 AM#,#11/22/2007 12:00:00 AM#) FROM " + TBL, 5478); - checkQuery("SELECT DateDiff('w',#11/22/1992 11:00:00 AM#,#11/22/2007 10:00:00 AM#) FROM " + TBL, 782); - checkQuery("SELECT DateDiff('w',#11/22/1992 11:00:00 AM#,#11/22/2007 12:00:00 AM#) FROM " + TBL, 782); - checkQuery("SELECT DateDiff('ww',#11/22/1992 11:00:00 AM#,#11/22/2007 10:00:00 AM#) FROM " + TBL, 782); - checkQuery("SELECT DateDiff('ww',#11/22/1992 11:00:00 AM#,#11/22/2007 12:00:00 AM#) FROM " + TBL, 782); - checkQuery("SELECT DateDiff('ww',#10/22/2007 11:00:00 AM#,#11/22/2007 10:00:00 AM#) FROM " + TBL, 4); - checkQuery("SELECT DateDiff('ww',#07/22/2007 11:00:00 AM#,#11/22/2007 12:00:00 AM#) FROM " + TBL, 17); - checkQuery("SELECT DateDiff('h',#10/22/2007 08:01:00 AM#,#10/22/2006 04:00:00 AM#) FROM " + TBL, -8764); - checkQuery("SELECT DateDiff('h',#10/22/2007 10:07:00 AM#,#10/22/2007 11:07:00 AM#) FROM " + TBL, 1); - checkQuery("SELECT DateDiff('h',#10/22/2007 11:00:00 AM#,#10/22/2007 10:07:00 AM#) FROM " + TBL, -1); - - checkQuery("SELECT DateDiff('n',#10/22/2007 08:00:00 AM#,#10/22/2003 04:00:00 AM#) FROM " + TBL, -2104080); - checkQuery("SELECT DateDiff('h',#10/22/2007 08:00:00 AM#,#10/22/2005 04:00:00 AM#) FROM " + TBL, -17524); + checkQuery("SELECT DateDiff('yyyy',#11/22/1992 10:42:58 PM#,#11/22/2007 10:42:58 AM#) FROM " + TBL, singleRec(15)); + checkQuery("SELECT DateDiff('y',#11/22/1992 11:00:00 AM#,#11/22/2007 10:00:00 AM#) FROM " + TBL, singleRec(5478)); + checkQuery("SELECT DateDiff('y',#11/22/1992 11:00:00 AM#,#11/22/2007 12:00:00 AM#) FROM " + TBL, singleRec(5478)); + checkQuery("SELECT DateDiff('yyyy',#11/22/1992 10:42:58 PM#,#11/22/2007 10:42:58 AM#) FROM " + TBL, singleRec(15)); + checkQuery("SELECT DateDiff('m',#11/22/2007 11:00:00 AM#,#11/22/2007 10:00:00 AM#) FROM " + TBL, singleRec(0)); + checkQuery("SELECT DateDiff('m',#11/22/1992 11:00:00 AM#,#08/22/2007 12:00:00 AM#) FROM " + TBL, singleRec(177)); + checkQuery("SELECT DateDiff('d',#1/1/2004 11:00:00 AM#,#1/3/2004 11:00:00 AM#) FROM " + TBL, singleRec(2)); + checkQuery("SELECT DateDiff('d',#11/22/1992 11:00:00 AM#,#11/22/2007 10:00:00 AM#) FROM " + TBL, singleRec(5478)); + checkQuery("SELECT DateDiff('d',#11/22/1992 11:00:00 AM#,#11/22/2007 12:00:00 AM#) FROM " + TBL, singleRec(5478)); + checkQuery("SELECT DateDiff('w',#11/22/1992 11:00:00 AM#,#11/22/2007 10:00:00 AM#) FROM " + TBL, singleRec(782)); + checkQuery("SELECT DateDiff('w',#11/22/1992 11:00:00 AM#,#11/22/2007 12:00:00 AM#) FROM " + TBL, singleRec(782)); + checkQuery("SELECT DateDiff('ww',#11/22/1992 11:00:00 AM#,#11/22/2007 10:00:00 AM#) FROM " + TBL, singleRec(782)); + checkQuery("SELECT DateDiff('ww',#11/22/1992 11:00:00 AM#,#11/22/2007 12:00:00 AM#) FROM " + TBL, singleRec(782)); + checkQuery("SELECT DateDiff('ww',#10/22/2007 11:00:00 AM#,#11/22/2007 10:00:00 AM#) FROM " + TBL, singleRec(4)); + checkQuery("SELECT DateDiff('ww',#07/22/2007 11:00:00 AM#,#11/22/2007 12:00:00 AM#) FROM " + TBL, singleRec(17)); + checkQuery("SELECT DateDiff('h',#10/22/2007 08:01:00 AM#,#10/22/2006 04:00:00 AM#) FROM " + TBL, singleRec(-8764)); + checkQuery("SELECT DateDiff('h',#10/22/2007 10:07:00 AM#,#10/22/2007 11:07:00 AM#) FROM " + TBL, singleRec(1)); + checkQuery("SELECT DateDiff('h',#10/22/2007 11:00:00 AM#,#10/22/2007 10:07:00 AM#) FROM " + TBL, singleRec(-1)); + checkQuery("SELECT DateDiff('n',#10/22/2007 08:00:00 AM#,#10/22/2003 04:00:00 AM#) FROM " + TBL, singleRec(-2104080)); + checkQuery("SELECT DateDiff('h',#10/22/2007 08:00:00 AM#,#10/22/2005 04:00:00 AM#) FROM " + TBL, singleRec(-17524)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testDatePart(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT DatePart('yyyy',#11/22/1992 10:42:58 PM#) FROM " + TBL, 1992); - checkQuery("SELECT DatePart('q',#11/22/1992 10:42:58 PM#) FROM " + TBL, 4); - checkQuery("SELECT DatePart('d',#11/22/1992 10:42:58 PM#) FROM " + TBL, 22); - checkQuery("SELECT DatePart('y',#11/22/1992 10:42:58 PM#) FROM " + TBL, 327); - checkQuery("SELECT DatePart('ww',#11/22/1992 10:42:58 PM#) FROM " + TBL, 48); - checkQuery("SELECT DatePart('ww',#11/22/2006 10:42:58 PM#,3) FROM " + TBL, 48); - checkQuery("SELECT DatePart('w',#05/8/2013#,7), datePart('ww',#11/22/2006 10:42:58 PM#,6,3) FROM " + TBL, 5, 46); - checkQuery("SELECT DatePart('w',#05/13/1992 10:42:58 PM#) FROM " + TBL, 4); - checkQuery("SELECT DatePart('h',#05/13/1992 10:42:58 PM#) FROM " + TBL, 22); - checkQuery("SELECT DatePart('n',#05/13/1992 10:42:58 PM#) FROM " + TBL, 42); - checkQuery("SELECT DatePart('s',#05/13/1992 10:42:58 PM#) FROM " + TBL, 58); - + checkQuery("SELECT DatePart('yyyy',#11/22/1992 10:42:58 PM#) FROM " + TBL, singleRec(1992)); + checkQuery("SELECT DatePart('q',#11/22/1992 10:42:58 PM#) FROM " + TBL, singleRec(4)); + checkQuery("SELECT DatePart('d',#11/22/1992 10:42:58 PM#) FROM " + TBL, singleRec(22)); + checkQuery("SELECT DatePart('y',#11/22/1992 10:42:58 PM#) FROM " + TBL, singleRec(327)); + checkQuery("SELECT DatePart('ww',#11/22/1992 10:42:58 PM#) FROM " + TBL, singleRec(48)); + checkQuery("SELECT DatePart('ww',#11/22/2006 10:42:58 PM#,3) FROM " + TBL, singleRec(48)); + checkQuery("SELECT DatePart('w',#05/8/2013#,7), datePart('ww',#11/22/2006 10:42:58 PM#,6,3) FROM " + TBL, singleRec(5, 46)); + checkQuery("SELECT DatePart('w',#05/13/1992 10:42:58 PM#) FROM " + TBL, singleRec(4)); + checkQuery("SELECT DatePart('h',#05/13/1992 10:42:58 PM#) FROM " + TBL, singleRec(22)); + checkQuery("SELECT DatePart('n',#05/13/1992 10:42:58 PM#) FROM " + TBL, singleRec(42)); + checkQuery("SELECT DatePart('s',#05/13/1992 10:42:58 PM#) FROM " + TBL, singleRec(58)); } @ParameterizedTest(name = "[{index}] {0}") @@ -516,30 +492,28 @@ void testDatePart(AccessVersion _accessVersion) throws Exception { void testDateSerial(AccessVersion _accessVersion) throws Exception { init(_accessVersion); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); - - checkQuery("SELECT DateSerial(1998,5, 10) FROM " + TBL, sdf.parse("1998-05-10 00:00:00")); - checkQuery("SELECT 'It works, I can''t believe it.' FROM " + TBL + " WHERE #05/13/1992#=dateserial(1992,05,13)", - "It works, I can't believe it."); + checkQuery("SELECT DateSerial(1998,5, 10) FROM " + TBL, recs(rec(sdf.parse("1998-05-10 00:00:00")))); + checkQuery("SELECT 'It works, I can''t believe it.' FROM " + TBL + " WHERE #05/13/1992#=dateserial(1992,05,13)", singleRec("It works, I can't believe it.")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testFormatNumber(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT Format(number,'percent') FROM tblFormat", ""); - checkQuery("SELECT Format(0.981,'percent') FROM " + TBL, "98.10%"); - checkQuery("SELECT Format(num,'fixed') FROM " + TBL, "-1110.55"); - checkQuery("SELECT Format(num,'standard') FROM " + TBL, "-1,110.55"); - checkQuery("SELECT Format(num,'general number') FROM " + TBL, "-1110.554"); - checkQuery("SELECT Format(num,'on/off') FROM " + TBL, "On"); - checkQuery("SELECT Format(num,'true/false') FROM " + TBL, "True"); - checkQuery("SELECT Format(num,'yes/no') FROM " + TBL, "Yes"); - checkQuery("SELECT Format (11111210.6, '#,##0.00') FROM " + TBL, "11,111,210.60"); - checkQuery("SELECT Format (1111111210.6, 'Scientific') FROM " + TBL, "1.11E+09"); - checkQuery("SELECT Format (0.00000000000000015661112106, 'Scientific') FROM " + TBL, "1.57E-16"); + checkQuery("SELECT Format(number,'percent') FROM tblFormat", singleRec("")); + checkQuery("SELECT Format(0.981,'percent') FROM " + TBL, singleRec("98.10%")); + checkQuery("SELECT Format(num,'fixed') FROM " + TBL, singleRec("-1110.55")); + checkQuery("SELECT Format(num,'standard') FROM " + TBL, singleRec("-1,110.55")); + checkQuery("SELECT Format(num,'general number') FROM " + TBL, singleRec("-1110.554")); + checkQuery("SELECT Format(num,'on/off') FROM " + TBL, singleRec("On")); + checkQuery("SELECT Format(num,'true/false') FROM " + TBL, singleRec("True")); + checkQuery("SELECT Format(num,'yes/no') FROM " + TBL, singleRec("Yes")); + checkQuery("SELECT Format (11111210.6, '#,##0.00') FROM " + TBL, singleRec("11,111,210.60")); + checkQuery("SELECT Format (1111111210.6, 'Scientific') FROM " + TBL, singleRec("1.11E+09")); + checkQuery("SELECT Format (0.00000000000000015661112106, 'Scientific') FROM " + TBL, singleRec("1.57E-16")); Locale prevLocale = Locale.getDefault(); Locale.setDefault(Locale.US); - checkQuery("SELECT Format(1.239, 'Currency') FROM " + TBL, "$1.24"); + checkQuery("SELECT Format(1.239, 'Currency') FROM " + TBL, singleRec("$1.24")); Locale.setDefault(prevLocale); } @@ -547,49 +521,44 @@ void testFormatNumber(AccessVersion _accessVersion) throws Exception { @EnumSource(value = AccessVersion.class) void testTimestamp(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT #2006-12-11#=timestamp '2006-12-11 00:00:00' FROM dual", true); - checkQuery("SELECT #2006-12-11 1:2:3#=timestamp '2006-12-11 01:02:03' FROM dual", true); - checkQuery("SELECT #2006-2-1 1:2:3#=timestamp '2006-02-01 01:02:03' FROM dual", true); - checkQuery("SELECT #2/1/2006 1:2:3#=timestamp '2006-02-01 01:02:03' FROM dual", true); - checkQuery("SELECT #12/11/2006 1:2:3#=timestamp '2006-12-11 01:02:03' FROM dual", true); - checkQuery("SELECT #1392-01-10 1:2:3#=timestamp '1392-01-02 01:02:03' FROM dual", true); - - checkQuery("SELECT #12/11/2006 1:2:3 am#=timestamp '2006-12-11 01:02:03' FROM dual", true); - checkQuery("SELECT #12/11/2006 1:2:3 pm#=timestamp '2006-12-11 13:02:03' FROM dual", true); + checkQuery("SELECT #2006-12-11#=timestamp '2006-12-11 00:00:00' FROM dual", singleRec(true)); + checkQuery("SELECT #2006-12-11 1:2:3#=timestamp '2006-12-11 01:02:03' FROM dual", singleRec(true)); + checkQuery("SELECT #2006-2-1 1:2:3#=timestamp '2006-02-01 01:02:03' FROM dual", singleRec(true)); + checkQuery("SELECT #2/1/2006 1:2:3#=timestamp '2006-02-01 01:02:03' FROM dual", singleRec(true)); + checkQuery("SELECT #12/11/2006 1:2:3#=timestamp '2006-12-11 01:02:03' FROM dual", singleRec(true)); + checkQuery("SELECT #1392-01-10 1:2:3#=timestamp '1392-01-02 01:02:03' FROM dual", singleRec(true)); + checkQuery("SELECT #12/11/2006 1:2:3 am#=timestamp '2006-12-11 01:02:03' FROM dual", singleRec(true)); + checkQuery("SELECT #12/11/2006 1:2:3 pm#=timestamp '2006-12-11 13:02:03' FROM dual", singleRec(true)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testFormatDate(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT Format(date, 'Short date') FROM tblFormat", ""); - checkQuery("SELECT Format(#05/13/1994 10:42:58 PM#, 'Long date') FROM " + TBL, "Friday, May 13, 1994"); - - checkQuery("SELECT Format(#05/13/1994 10:42:58 PM#, 'Short date') FROM " + TBL, "5/13/1994"); - checkQuery("SELECT Format(#05/13/1994 10:42:58 AM#, 'Long time') FROM " + TBL, "10:42:58 AM"); - - checkQuery("SELECT Format(#05/13/1994 10:42:58 PM#, 'Short time') FROM " + TBL, "22:42"); - checkQuery("SELECT Format(#05/13/1994 10:42:58 PM#, 'General date') FROM " + TBL, "5/13/1994 10:42:58 PM"); - - checkQuery("SELECT Format(#05/13/1994 10:42:58 PM#, 'Medium date') FROM " + TBL, "13-May-94"); - - checkQuery("SELECT Format(#05/13/1994 10:42:18 PM#, 'Medium time') FROM " + TBL, "10:42 PM"); + checkQuery("SELECT Format(date, 'Short date') FROM tblFormat", singleRec("")); + checkQuery("SELECT Format(#05/13/1994 10:42:58 PM#, 'Long date') FROM " + TBL, singleRec("Friday, May 13, 1994")); + checkQuery("SELECT Format(#05/13/1994 10:42:58 PM#, 'Short date') FROM " + TBL, singleRec("5/13/1994")); + checkQuery("SELECT Format(#05/13/1994 10:42:58 AM#, 'Long time') FROM " + TBL, singleRec("10:42:58 AM")); + checkQuery("SELECT Format(#05/13/1994 10:42:58 PM#, 'Short time') FROM " + TBL, singleRec("22:42")); + checkQuery("SELECT Format(#05/13/1994 10:42:58 PM#, 'General date') FROM " + TBL, singleRec("5/13/1994 10:42:58 PM")); + checkQuery("SELECT Format(#05/13/1994 10:42:58 PM#, 'Medium date') FROM " + TBL, singleRec("13-May-94")); + checkQuery("SELECT Format(#05/13/1994 10:42:18 PM#, 'Medium time') FROM " + TBL, singleRec("10:42 PM")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testSign(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT sign(0), sign(-20.4), sign(4) FROM " + TBL, 0, -1, 1); + checkQuery("SELECT sign(0), sign(-20.4), sign(4) FROM " + TBL, singleRec(0, -1, 1)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testWeekDayName(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT WeekDayName(3) FROM " + TBL, "Tuesday"); - checkQuery("SELECT WeekDayName(3,true) FROM " + TBL, "Tue"); - checkQuery("SELECT WeekdayName (3, TRUE, 2) FROM " + TBL, "Wed"); + checkQuery("SELECT WeekDayName(3) FROM " + TBL, singleRec("Tuesday")); + checkQuery("SELECT WeekDayName(3,true) FROM " + TBL, singleRec("Tue")); + checkQuery("SELECT WeekdayName (3, TRUE, 2) FROM " + TBL, singleRec("Wed")); dumpQueryResult("SELECT WeekdayName(Weekday(#2001-1-1#)) FROM " + TBL); } @@ -597,15 +566,15 @@ void testWeekDayName(AccessVersion _accessVersion) throws Exception { @EnumSource(value = AccessVersion.class) void testMonthName(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT MonthName(3) FROM " + TBL, "March"); - checkQuery("SELECT MonthName(3, true) FROM " + TBL, "Mar"); + checkQuery("SELECT MonthName(3) FROM " + TBL, singleRec("March")); + checkQuery("SELECT MonthName(3, true) FROM " + TBL, singleRec("Mar")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testStr(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT str(id), str(num), str(4.5555555) FROM " + TBL, " 1234", "-1110.554", " 4.5555555"); + checkQuery("SELECT str(id), str(num), str(4.5555555) FROM " + TBL, singleRec(" 1234", "-1110.554", " 4.5555555")); } @ParameterizedTest(name = "[{index}] {0}") @@ -613,31 +582,28 @@ void testStr(AccessVersion _accessVersion) throws Exception { void testDateValue(AccessVersion _accessVersion) throws Exception { init(_accessVersion); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); - - checkQuery("SELECT dateValue(#11/22/2003 10:42:58 PM#) FROM " + TBL, - sdf.parse("2003-11-22 00:00:00.0")); - checkQuery("SELECT dateValue(#11/22/2003 21:42:58 AM#) FROM " + TBL, - sdf.parse("2003-11-22 00:00:00.0")); - checkQuery("SELECT dateValue('6/30/2004') FROM " + TBL, sdf.parse("2004-06-30 00:00:00.0")); + checkQuery("SELECT dateValue(#11/22/2003 10:42:58 PM#) FROM " + TBL, recs(rec(sdf.parse("2003-11-22 00:00:00.0")))); + checkQuery("SELECT dateValue(#11/22/2003 21:42:58 AM#) FROM " + TBL, recs(rec(sdf.parse("2003-11-22 00:00:00.0")))); + checkQuery("SELECT dateValue('6/30/2004') FROM " + TBL, recs(rec(sdf.parse("2004-06-30 00:00:00.0")))); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testFormatString(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT Format(text,'Long date') FROM tblFormat", ""); - checkQuery("SELECT Format('05/13/1994','Long date') FROM " + TBL, "Friday, May 13, 1994"); - checkQuery("SELECT Format(0.6,'percent') FROM " + TBL, "60.00%"); - checkQuery("SELECT Format('0,6','percent') FROM " + TBL, "600.00%"); + checkQuery("SELECT Format(text,'Long date') FROM tblFormat", singleRec("")); + checkQuery("SELECT Format('05/13/1994','Long date') FROM " + TBL, singleRec("Friday, May 13, 1994")); + checkQuery("SELECT Format(0.6,'percent') FROM " + TBL, singleRec("60.00%")); + checkQuery("SELECT Format('0,6','percent') FROM " + TBL, singleRec("600.00%")); // beware of bug http://bugs.java.com/view_bug.do?bug_id=7131459 ! - checkQuery("SELECT Format(48.14251, '.###') FROM " + TBL, "48.143"); + checkQuery("SELECT Format(48.14251, '.###') FROM " + TBL, singleRec("48.143")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testInt(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT int(1111112.5), int(-2.5) FROM " + TBL, 1111112, -3); + checkQuery("SELECT int(1111112.5), int(-2.5) FROM " + TBL, singleRec(1111112, -3)); } @ParameterizedTest(name = "[{index}] {0}") @@ -651,45 +617,43 @@ void testRnd(AccessVersion _accessVersion) throws Exception { @EnumSource(value = AccessVersion.class) void testStrComp(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT StrComp('Cia','Cia') FROM " + TBL, 0); + checkQuery("SELECT StrComp('Cia','Cia') FROM " + TBL, singleRec(0)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testStrConv(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT StrConv('Cia',1) FROM " + TBL, "CIA"); + checkQuery("SELECT StrConv('Cia',1) FROM " + TBL, singleRec("CIA")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testStrReverse(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT StrReverse('ylatI') FROM " + TBL, "Italy"); + checkQuery("SELECT StrReverse('ylatI') FROM " + TBL, singleRec("Italy")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testString(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT String(4,'c') FROM " + TBL, "cccc"); + checkQuery("SELECT String(4,'c') FROM " + TBL, singleRec("cccc")); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testWeekday(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery("SELECT Weekday(#06/27/2013 10:42:58 PM#,1) FROM " + TBL, 5); + checkQuery("SELECT Weekday(#06/27/2013 10:42:58 PM#,1) FROM " + TBL, singleRec(5)); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testFinancial(AccessVersion _accessVersion) throws Exception { init(_accessVersion); - checkQuery( - "SELECT FV(0,100,-100,-10000,-1), DDB(1001100,10020,111,62,5.5), NPer(0.0525,200,1500,233,0.1), IPmt(0.5,4,8,10*1,10000,0.5), PV(0,4,-10000,1000,-1.55),PPmt(0.5,3,7,100000,15000.1),SLN(10000,110000,9),SYD(10000,200,12,4),Pmt(0.08,30,5000,-15000,0.1) FROM " + TBL, - 20000.0, 2234.68083152805, -7.721791247488574, 477.63917525773195, 39000.0, -8042.7461874696455, - -11111.111111111111, 1130.7692307692307, -311.72566612727735); - checkQuery("SELECT Rate(3,200,-610,0,-20,0.1) FROM " + TBL, -0.01630483472667564); + checkQuery("SELECT FV(0,100,-100,-10000,-1), DDB(1001100,10020,111,62,5.5), NPer(0.0525,200,1500,233,0.1), IPmt(0.5,4,8,10*1,10000,0.5), PV(0,4,-10000,1000,-1.55),PPmt(0.5,3,7,100000,15000.1),SLN(10000,110000,9),SYD(10000,200,12,4),Pmt(0.08,30,5000,-15000,0.1) FROM " + TBL, + singleRec(20000.0, 2234.68083152805, -7.721791247488574, 477.63917525773195, 39000.0, -8042.7461874696455, -11111.111111111111, 1130.7692307692307, -311.72566612727735)); + checkQuery("SELECT Rate(3,200,-610,0,-20,0.1) FROM " + TBL, singleRec(-0.01630483472667564)); } } diff --git a/src/test/java/net/ucanaccess/jdbc/GeneratedKeys1Test.java b/src/test/java/net/ucanaccess/jdbc/GeneratedKeys1Test.java index 7e5936e7..6971560d 100644 --- a/src/test/java/net/ucanaccess/jdbc/GeneratedKeys1Test.java +++ b/src/test/java/net/ucanaccess/jdbc/GeneratedKeys1Test.java @@ -46,7 +46,7 @@ void testGeneratedKeys(AccessVersion _accessVersion) throws SQLException, IOExce Statement st = ucanaccess.createStatement(); st.execute("INSERT INTO " + tableName + " (B) VALUES ('W')"); - checkQuery("Select @@identity ", 2); + checkQuery("Select @@identity ", singleRec(2)); ResultSet rs3 = st.getGeneratedKeys(); rs3.next(); assertEquals(2, rs3.getInt(1)); diff --git a/src/test/java/net/ucanaccess/jdbc/LoadTypesAccessTest.java b/src/test/java/net/ucanaccess/jdbc/LoadTypesAccessTest.java index a14c7a7d..712e4c19 100644 --- a/src/test/java/net/ucanaccess/jdbc/LoadTypesAccessTest.java +++ b/src/test/java/net/ucanaccess/jdbc/LoadTypesAccessTest.java @@ -17,28 +17,25 @@ class LoadTypesAccessTest extends UcanaccessBaseTest { protected void init(AccessVersion _accessVersion) throws SQLException { super.init(_accessVersion); executeStatements( - "CREATE TABLE pluto (id LONG, descr MEMO, dt DATETIME,euros CURRENCY,float1 SINGLE, double1 DOUBLE, int1 INTEGER,numeric0 numeric(24,5), numeric1 double) ", - "INSERT INTO pluto (id,descr,dt,euros,float1,double1,int1,numeric0,numeric1 ) VALUES( 1234,'I like trippa with spaghettis bolognese',#10/03/2008 10:34:35 PM#,4.55555,5.6666,6.7,5,0.100051,4.677856)"); + "CREATE TABLE pluto (id LONG, descr MEMO, dt DATETIME,euros CURRENCY,float1 SINGLE, double1 DOUBLE, int1 INTEGER,numeric0 numeric(24,5), numeric1 double) ", + "INSERT INTO pluto (id,descr,dt,euros,float1,double1,int1,numeric0,numeric1 ) VALUES( 1234,'I like trippa with spaghettis bolognese',#10/03/2008 10:34:35 PM#,4.55555,5.6666,6.7,5,0.100051,4.677856)"); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testDate(AccessVersion _accessVersion) throws SQLException, IOException, ParseException { init(_accessVersion); - checkQuery( - "SELECT #10/03/2004# , #11/23/1811#,#10/03/2008 22:34:35#,#10/03/2008 22:34:35 aM#,#10/03/2008 10:34:35 PM# from pluto", - SDF.parse("2004-10-03 00:00:00.0"), SDF.parse("1811-11-23 00:00:00.0"), - SDF.parse("2008-10-03 22:34:35.0"), SDF.parse("2008-10-03 22:34:35.0"), - SDF.parse("2008-10-03 22:34:35.0")); - checkQuery("SELECT #22:34:35#,#10:34:35 AM#,#10:34:35 pM# from pluto", SDF.parse("1899-12-30 22:34:35.0"), - SDF.parse("1899-12-30 10:34:35.0"), SDF.parse("1899-12-30 22:34:35.0")); + checkQuery("SELECT #10/03/2004# , #11/23/1811#,#10/03/2008 22:34:35#,#10/03/2008 22:34:35 aM#,#10/03/2008 10:34:35 PM# from pluto", + recs(rec(SDF.parse("2004-10-03 00:00:00.0"), SDF.parse("1811-11-23 00:00:00.0"), SDF.parse("2008-10-03 22:34:35.0"), SDF.parse("2008-10-03 22:34:35.0"), SDF.parse("2008-10-03 22:34:35.0")))); + checkQuery("SELECT #22:34:35#,#10:34:35 AM#,#10:34:35 pM# from pluto", + recs(rec(SDF.parse("1899-12-30 22:34:35.0"), SDF.parse("1899-12-30 10:34:35.0"), SDF.parse("1899-12-30 22:34:35.0")))); } @ParameterizedTest(name = "[{index}] {0}") @EnumSource(value = AccessVersion.class) void testQuery(AccessVersion _accessVersion) throws SQLException, IOException, ParseException { init(_accessVersion); - checkQuery("SELECT * FROM pluto", 1234, "I like trippa with spaghettis bolognese", - SDF.parse("2008-10-03 22:34:35"), 4.5555, 5.6666, 6.7, 5, 0.10005, 4.677856); + checkQuery("SELECT * FROM pluto", + recs(rec(1234, "I like trippa with spaghettis bolognese", SDF.parse("2008-10-03 22:34:35"), 4.5555, 5.6666, 6.7, 5, 0.10005, 4.677856))); } } diff --git a/src/test/java/net/ucanaccess/jdbc/MetaDataTest.java b/src/test/java/net/ucanaccess/jdbc/MetaDataTest.java index fb2bfefe..07401743 100644 --- a/src/test/java/net/ucanaccess/jdbc/MetaDataTest.java +++ b/src/test/java/net/ucanaccess/jdbc/MetaDataTest.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.sql.SQLException; import java.sql.Statement; +import java.util.List; class MetaDataTest extends UcanaccessBaseTest { @@ -28,12 +29,12 @@ void afterEachTest() throws SQLException { executeStatements("DROP TABLE t_metadata"); } - void createSimple(String a, Object[][] ver) throws SQLException { + void createSimple(String _a, List> _ver) throws SQLException { try (Statement st = ucanaccess.createStatement()) { - st.execute("INSERT INTO t_metadata VALUES ('33A', 11, '" + a + "' )"); - st.execute("INSERT INTO t_metadata VALUES ('33B', 111, '" + a + "' )"); + st.execute("INSERT INTO t_metadata VALUES ('33A', 11, '" + _a + "' )"); + st.execute("INSERT INTO t_metadata VALUES ('33B', 111, '" + _a + "' )"); } - checkQuery("SELECT * FROM t_metadata", ver); + checkQuery("SELECT * FROM t_metadata", _ver); } @ParameterizedTest(name = "[{index}] {0}") @@ -41,12 +42,12 @@ void createSimple(String a, Object[][] ver) throws SQLException { void testDrop(AccessVersion _accessVersion) throws SQLException, IOException { init(_accessVersion); ucanaccess.setAutoCommit(false); - createSimple("a", new Object[][] {{"33A", 11, "a"}, {"33B", 111, "a"}}); + createSimple("a", recs(rec("33A", 11, "a"), rec("33B", 111, "a"))); try (Statement st = ucanaccess.createStatement()) { st.executeUpdate("DROP TABLE t_metadata"); st.execute("CREATE TABLE t_metadata (baaaa TEXT(3) PRIMARY KEY, A INTEGER, C TEXT(4))"); - createSimple("b", new Object[][] {{"33A", 11, "b"}, {"33B", 111, "b"}}); + createSimple("b", recs(rec("33A", 11, "b"), rec("33B", 111, "b"))); ucanaccess.commit(); } diff --git a/src/test/java/net/ucanaccess/jdbc/ParametersTest.java b/src/test/java/net/ucanaccess/jdbc/ParametersTest.java index f36d4d35..0f408871 100644 --- a/src/test/java/net/ucanaccess/jdbc/ParametersTest.java +++ b/src/test/java/net/ucanaccess/jdbc/ParametersTest.java @@ -29,7 +29,7 @@ void testParameters(AccessVersion _accessVersion) throws SQLException, IOExcepti dumpQueryResult("SELECT * FROM z"); dumpQueryResult("SELECT * FROM [queryWithParameters]"); dumpQueryResult("SELECT * FROM table(queryWithParameters(#1971-03-13#,'hi babe'))"); - checkQuery("SELECT COUNT(*) FROM [ab\"\"\"xxx]", 3); + checkQuery("SELECT COUNT(*) FROM [ab\"\"\"xxx]", singleRec(3)); CallableStatement cs = ucanaccess.prepareCall("{call Insert_from_select_abxxx(?,?,?)}"); cs.setString(1, "2"); cs.setString(2, "YeaH!!!!"); @@ -37,7 +37,7 @@ void testParameters(AccessVersion _accessVersion) throws SQLException, IOExcepti cs.executeUpdate(); dumpQueryResult("SELECT * FROM [ab\"\"\"xxx]"); - checkQuery("SELECT COUNT(*) FROM [ab\"\"\"xxx]", 6); + checkQuery("SELECT COUNT(*) FROM [ab\"\"\"xxx]", singleRec(6)); // metaData(); cs = ucanaccess.prepareCall("{call InsertWithFewParameters(?,?,?)}"); @@ -68,9 +68,9 @@ void testParameters(AccessVersion _accessVersion) throws SQLException, IOExcepti cs.setString(2, "Gord"); cs.setString(3, "Basic"); cs.executeUpdate(); - checkQuery("SELECT @@IDENTITY", 2); // verify that we can retrieve the AutoNumber ID + checkQuery("SELECT @@IDENTITY", singleRec(2)); // verify that we can retrieve the AutoNumber ID cs.executeUpdate(); - checkQuery("SELECT @@IDENTITY", 3); // and again, just to be sure + checkQuery("SELECT @@IDENTITY", singleRec(3)); // and again, just to be sure cs = ucanaccess.prepareCall("{call UpdateWhere(?,?)}"); cs.setString(1, "updated"); cs.setString(2, "3x"); diff --git a/src/test/java/net/ucanaccess/jdbc/RegexTest.java b/src/test/java/net/ucanaccess/jdbc/RegexTest.java index f0f84275..837eca5e 100644 --- a/src/test/java/net/ucanaccess/jdbc/RegexTest.java +++ b/src/test/java/net/ucanaccess/jdbc/RegexTest.java @@ -8,6 +8,8 @@ import java.sql.SQLException; import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; class RegexTest extends UcanaccessBaseTest { @@ -33,14 +35,16 @@ void testRegex(AccessVersion _accessVersion) throws SQLException { try (Statement st = ucanaccess.createStatement()) { for (String c : in) { - st.execute(getStatement(c.replaceAll("'", "''"), "'")); - st.execute(getStatement(c.replaceAll("\"", "\"\""), "\"")); + executeStatements(st, + getStatement(c.replaceAll("'", "''"), "'"), + getStatement(c.replaceAll("\"", "\"\""), "\"")); } - String[][] out = new String[in.length * 2][1]; - int k = 0; - for (int j = 0; j < out.length; j++) { - out[j][0] = in[k]; - if (j % 2 == 1) { + + int len = in.length * 2; + List> out = new ArrayList<>(len); + for (int i = 0, k = 0; i < len; i++) { + out.add(List.of(in[k])); + if (i % 2 == 1) { k++; } } diff --git a/src/test/java/net/ucanaccess/test/UcanaccessBaseTest.java b/src/test/java/net/ucanaccess/test/UcanaccessBaseTest.java index fa346c4e..4c3b2c4e 100644 --- a/src/test/java/net/ucanaccess/test/UcanaccessBaseTest.java +++ b/src/test/java/net/ucanaccess/test/UcanaccessBaseTest.java @@ -20,9 +20,13 @@ import java.sql.*; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; +import java.util.stream.Stream; public abstract class UcanaccessBaseTest extends AbstractBaseTest { @@ -64,7 +68,7 @@ protected final File getFileAccDb() { return fileAccDb; } - public void checkQuery(String _query, Object[][] _expected) throws SQLException { + public void checkQuery(String _query, List> _expected) throws SQLException { try (Statement st = ucanaccess.createStatement(); ResultSet rs = st.executeQuery(_query)) { diff(rs, _expected, _query); @@ -88,23 +92,19 @@ public void checkQuery(String _query) throws SQLException, IOException { } } - public void checkQuery(String _query, Object... _expected) throws SQLException { - checkQuery(_query, new Object[][] {_expected}); - } - - private void diff(ResultSet _resultSet, Object[][] _expectedResults, String _expression) throws SQLException { + private void diff(ResultSet _resultSet, List> _expectedResults, String _expression) throws SQLException { int colCountActual = _resultSet.getMetaData().getColumnCount(); - if (_expectedResults.length > 0) { - assertEquals(_expectedResults[0].length, colCountActual); + if (_expectedResults.size() > 0) { + assertEquals(_expectedResults.get(0).size(), colCountActual); } int expIdx = 0; while (_resultSet.next()) { for (int col = 1; col <= colCountActual; col++) { assertThat(expIdx) - .withFailMessage("Matrix with different length was expected: " + _expectedResults.length + " not " + expIdx) - .isLessThan(_expectedResults.length); + .withFailMessage("Matrix with different length was expected: " + _expectedResults.size() + " not " + expIdx) + .isLessThan(_expectedResults.size()); Object actualObj = _resultSet.getObject(col); - Object expectedObj = _expectedResults[expIdx][col - 1]; + Object expectedObj = _expectedResults.get(expIdx).get(col - 1); if (expectedObj == null) { assertNull(actualObj); } else { @@ -132,7 +132,7 @@ private void diff(ResultSet _resultSet, Object[][] _expectedResults, String _exp } expIdx++; } - assertEquals(_expectedResults.length, expIdx, "Matrix with different length was expected"); + assertEquals(_expectedResults.size(), expIdx, "Matrix with different length was expected"); } public void diffResultSets(ResultSet _resultSet, ResultSet _verifyResultSet, String _query) throws SQLException { @@ -405,6 +405,38 @@ protected final void executeStatements(Statement _statement, String... _sqls) th } } + /** + * A single record made up of one column. + */ + protected static final List rec(Object _col) { + List rec = new ArrayList<>(); + rec.add(_col); + return rec; + } + + /** + * A single record made up of one or more columns. + */ + @SafeVarargs + protected static final List rec(Object... _cols) { + return Stream.of(_cols).collect(Collectors.toCollection(ArrayList::new)); + } + + /** + * A list of a single record made up of one or more columns. + */ + protected static List> singleRec(Object... _cols) { + return recs(rec(_cols)); + } + + /** + * A list of records. + */ + @SafeVarargs + protected static final List> recs(List... _recs) { + return Stream.of(_recs).collect(Collectors.toCollection(ArrayList::new)); + } + @AfterEach protected final void afterTestCaseBase() { if (ucanaccess != null) {