Skip to content

Commit

Permalink
net-sf-ucanaccess-fork: Improve naming of database objects
Browse files Browse the repository at this point in the history
  • Loading branch information
spannm committed Nov 24, 2023
1 parent 5b1d956 commit 04aa1cd
Show file tree
Hide file tree
Showing 22 changed files with 299 additions and 304 deletions.
50 changes: 24 additions & 26 deletions src/test/java/net/ucanaccess/jdbc/AccessLikeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,41 @@ 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", singleRec("dd1"));
checkQuery("SELECT * FROM q_like2 ORDER BY campo2", singleRec("dd1"));
}

@ParameterizedTest(name = "[{index}] {0}")
@MethodSource("net.ucanaccess.type.AccessVersion#getDefaultAccessVersion()")
void testLikeExternal(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);

String tableName = "T21";
try (UcanaccessStatement st = ucanaccess.createStatement()) {
st.executeUpdate("CREATE TABLE " + tableName + " (id COUNTER PRIMARY KEY, descr MEMO)");
st.executeUpdate("CREATE TABLE t_like3 (id COUNTER PRIMARY KEY, descr MEMO)");

for (String val : List.of(
"dsdsds", "aa", "aBa", "aBBBa", "PB123", "PZ123", "a*a", "A*a", "ss#sss", "*", "132B", "138", "138#")) {
st.execute("INSERT INTO T21 (descr) VALUES('" + val + "')");
st.execute("INSERT INTO t_like3 (descr) VALUES('" + val + "')");
}
checkQuery("SELECT descr FROM T21 WHERE descr LIKE 'a[*]a' ORDER BY ID",

checkQuery("SELECT descr FROM t_like3 WHERE descr LIKE 'a[*]a' ORDER BY ID",
recs(rec("a*a"), rec("A*a")));

checkQuery("SELECT descr FROM T21 WHERE descr LIKE \"a*a\" AND '1'='1' AND (descr) like \"a*a\" ORDER BY ID",
checkQuery("SELECT descr FROM t_like3 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")));

checkQuery("SELECT * FROM T21 WHERE descr LIKE 'a%a'",
checkQuery("SELECT * FROM t_like3 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);
checkQuery("SELECT descr FROM t_like3 WHERE descr LIKE 'P[A-F]###'", singleRec("PB123"));
checkQuery("SELECT descr FROM t_like3 WHERE (t_like3.descr\n) \nLIKE 'P[!A-F]###' AND '1'='1'", singleRec("PZ123"));
checkQuery("SELECT * FROM t_like3 WHERE descr='aba'", singleRec(3, "aBa"));
checkQuery("SELECT descr FROM t_like3 WHERE descr LIKE '13[1-4][A-F]'", singleRec("132B"));
checkQuery("SELECT descr FROM t_like3 WHERE descr LIKE '13[!1-4]'", singleRec("138"));
checkQuery("SELECT descr FROM t_like3 WHERE descr LIKE '%s[#]%'", singleRec("ss#sss"));
checkQuery("SELECT descr FROM t_like3 WHERE descr LIKE '###'", singleRec("138"));
checkQuery("SELECT descr FROM t_like3 WHERE descr LIKE '###[#]'", singleRec("138#"));
checkQuery("SELECT descr FROM t_like3 WHERE descr LIKE '###[#]'", singleRec("138#"));
checkQuery("SELECT descr FROM t_like3 WHERE ((descr LIKE '###[#]'))", singleRec("138#"));
st.execute("DROP TABLE t_like3");
}
}

Expand All @@ -64,16 +63,15 @@ void testLikeExternal(AccessVersion _accessVersion) throws SQLException, IOExcep
void testNotLikeExternal(AccessVersion _accessVersion) throws SQLException {
init(_accessVersion);

String tableName = "Tx21";
try (UcanaccessStatement st = ucanaccess.createStatement()) {
st.executeUpdate("CREATE TABLE " + tableName + " (id COUNTER PRIMARY KEY, descr MEMO)");
st.executeUpdate("CREATE TABLE " + "t_like4" + " (id COUNTER PRIMARY KEY, descr MEMO)");

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",
st.execute("INSERT INTO t_like4(descr) VALUES('t11114')");
st.execute("INSERT INTO t_like4(descr) VALUES('t1111C')");
st.execute("INSERT INTO t_like4(descr) VALUES('t1111')");
checkQuery("SELECT DESCR FROM t_like4 WHERE descr NOT LIKE \"t#####\" ORDER BY id",
recs(rec("t1111C"), rec("t1111")));
st.execute("DROP TABLE " + tableName);
st.execute("DROP TABLE t_like4");
}
}
}
36 changes: 18 additions & 18 deletions src/test/java/net/ucanaccess/jdbc/AggregateFunctionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,80 +19,80 @@ class AggregateFunctionsTest extends UcanaccessBaseTest {
protected void init(AccessVersion _accessVersion) throws SQLException {
super.init(_accessVersion);

executeStatements("CREATE TABLE t235 (id INTEGER, descr TEXT(400), num NUMERIC(12,3), date0 DATETIME)",
"INSERT INTO t235 (id, descr, num, date0) VALUES(1234, 'Show must go off',-1110.55446,#11/22/2003 10:42:58 PM#)",
"INSERT INTO t235 (id, descr, num, date0) VALUES(12344, 'Show must go up and down',-113.55446,#11/22/2006 10:42:58 PM#)");
executeStatements("CREATE TABLE t_aggrfunc (id INTEGER, descr TEXT(400), num NUMERIC(12,3), date0 DATETIME)",
"INSERT INTO t_aggrfunc (id, descr, num, date0) VALUES(1234, 'Show must go off',-1110.55446,#11/22/2003 10:42:58 PM#)",
"INSERT INTO t_aggrfunc (id, descr, num, date0) VALUES(12344, 'Show must go up and down',-113.55446,#11/22/2006 10:42:58 PM#)");
}

@ParameterizedTest(name = "[{index}] {0}")
@EnumSource(value = AccessVersion.class)
void testDCount(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);

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",
checkQuery("SELECT id, DCount('*', 't_aggrfunc', '1=1') FROM [t_aggrfunc]", recs(rec(1234, 2), rec(12344, 2)));
checkQuery("SELECT id AS [WW \"SS], DCount('descr', 't_aggrfunc', '1=1') FROM t_aggrfunc",
recs(rec(1234, 2), rec(12344, 2)));
checkQuery("SELECT DCount('*', 't235', '1=1') ", singleRec(2));
checkQuery("SELECT DCount('*', 't_aggrfunc', '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')", singleRec(13578));
checkQuery("SELECT DSum('id', 't_aggrfunc', '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')", singleRec(12344));
checkQuery("SELECT DMax('id', 't_aggrfunc')", singleRec(12344));
}

@ParameterizedTest(name = "[{index}] {0}")
@EnumSource(value = AccessVersion.class)
void testDMin(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);
checkQuery("SELECT DMin('id', 't235')", singleRec(1234));
checkQuery("SELECT DMin('id', 't_aggrfunc')", singleRec(1234));
}

@ParameterizedTest(name = "[{index}] {0}")
@EnumSource(value = AccessVersion.class)
void testDAvg(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);
checkQuery("SELECT DAvg('id', 't235')", singleRec(6789));
checkQuery("SELECT DAvg('id', 't_aggrfunc')", 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", singleRec("Show must go up and down"));
checkQuery("SELECT last(NUM) FROM t235", singleRec(-113.5540));
dumpQueryResult("SELECT last(date0) FROM t235");
checkQuery("SELECT last(descr) FROM t_aggrfunc", singleRec("Show must go up and down"));
checkQuery("SELECT last(NUM) FROM t_aggrfunc", singleRec(-113.5540));
dumpQueryResult("SELECT last(date0) FROM t_aggrfunc");
}

@ParameterizedTest(name = "[{index}] {0}")
@EnumSource(value = AccessVersion.class)
void testFirst(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);
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");
checkQuery("SELECT first(descr) FROM t_aggrfunc", singleRec("Show must go off"));
checkQuery("SELECT first(NUM) FROM t_aggrfunc", singleRec(-1110.5540));
dumpQueryResult("SELECT first(date0) FROM t_aggrfunc");
}

@ParameterizedTest(name = "[{index}] {0}")
@EnumSource(value = AccessVersion.class)
void testDLast(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);
checkQuery("SELECT DLast('descr', 't235')", singleRec("Show must go up and down"));
checkQuery("SELECT DLast('descr', 't_aggrfunc')", 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') ", singleRec("Show must go off"));
checkQuery("SELECT DFirst('descr', 't_aggrfunc') ", singleRec("Show must go off"));
}

}
14 changes: 7 additions & 7 deletions src/test/java/net/ucanaccess/jdbc/AliasTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AliasTest extends UcanaccessBaseTest {
@Override
protected void init(AccessVersion _accessVersion) throws SQLException {
super.init(_accessVersion);
executeStatements("CREATE TABLE Talias (id LONG, descr MEMO, Actuación TEXT)");
executeStatements("CREATE TABLE t_alias (id LONG, descr MEMO, Actuación TEXT)");
}

@ParameterizedTest(name = "[{index}] {0}")
Expand All @@ -22,8 +22,8 @@ void testBig(AccessVersion _accessVersion) throws SQLException {
init(_accessVersion);
try (UcanaccessStatement st = ucanaccess.createStatement()) {
int id = 6666554;
st.execute("INSERT INTO Talias (id, descr) VALUES( " + id + ",'t')");
ResultSet rs = st.executeQuery("SELECT descr AS [cipol%'&la] FROM Talias WHERE descr<>'ciao'&'bye'&'pippo'");
st.execute("INSERT INTO t_alias (id, descr) VALUES( " + id + ",'t')");
ResultSet rs = st.executeQuery("SELECT descr AS [cipol%'&la] FROM t_alias WHERE descr<>'ciao'&'bye'&'pippo'");
rs.next();
getLogger().debug("metaData columnLabel(1): {}", rs.getMetaData().getColumnLabel(1));
getLogger().debug("getObject: {}", rs.getObject("cipol%'&la"));
Expand All @@ -35,8 +35,8 @@ void testBig(AccessVersion _accessVersion) throws SQLException {
void testAccent(AccessVersion _accessVersion) throws SQLException {
init(_accessVersion);
try (UcanaccessStatement st = ucanaccess.createStatement()) {
st.execute("INSERT INTO Talias (id, Actuación) VALUES(1, 'X')");
ResultSet rs = st.executeQuery("SELECT [Actuación] AS Actuació8_0_0_ FROM Talias ");
st.execute("INSERT INTO t_alias (id, Actuación) VALUES(1, 'X')");
ResultSet rs = st.executeQuery("SELECT [Actuación] AS Actuació8_0_0_ FROM t_alias ");
rs.next();
getLogger().debug("metaData columnLabel(1): {}", rs.getMetaData().getColumnLabel(1));
getLogger().debug("getObject: {}", rs.getObject("Actuació8_0_0_"));
Expand All @@ -48,8 +48,8 @@ void testAccent(AccessVersion _accessVersion) throws SQLException {
void testAsin(AccessVersion _accessVersion) throws SQLException {
init(_accessVersion);
try (UcanaccessStatement st = ucanaccess.createStatement()) {
st.execute("CREATE TABLE xxxx (asin TEXT, ff TEXT)");
dumpQueryResult("SELECT asin, ff FROM xxxx");
st.execute("CREATE TABLE t_asin (asin TEXT, ff TEXT)");
dumpQueryResult("SELECT asin, ff FROM t_asin");
}
}

Expand Down
17 changes: 9 additions & 8 deletions src/test/java/net/ucanaccess/jdbc/BatchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,36 @@ class BatchTest extends UcanaccessBaseTest {
@Override
protected void init(AccessVersion _accessVersion) throws SQLException {
super.init(_accessVersion);
executeStatements("CREATE TABLE Tb (id LONG, name TEXT, age LONG)",
"INSERT INTO Tb VALUES(1, 'Sophia', 33)");
executeStatements(
"CREATE TABLE t_batch (id LONG, name TEXT, age LONG)",
"INSERT INTO t_batch VALUES(1, 'Sophia', 33)");
}

@ParameterizedTest(name = "[{index}] {0}")
@EnumSource(value = AccessVersion.class)
void testBatch(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);
try (UcanaccessStatement st = ucanaccess.createStatement()) {
st.addBatch("UPDATE Tb SET [name]='ccc'");
st.addBatch("UPDATE Tb SET age=95");
st.addBatch("UPDATE t_batch SET [name]='ccc'");
st.addBatch("UPDATE t_batch SET age=95");
st.executeBatch();
checkQuery("SELECT * FROM tb");
checkQuery("SELECT * FROM t_batch");
}
}

@ParameterizedTest(name = "[{index}] {0}")
@EnumSource(value = AccessVersion.class)
void testBatchPS(AccessVersion _accessVersion) throws SQLException, IOException {
void testBatchPreparedStatement(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);
try (PreparedStatement st = ucanaccess.prepareStatement("UPDATE Tb SET [name]=?,age=? ")) {
try (PreparedStatement st = ucanaccess.prepareStatement("UPDATE t_batch SET [name]=?,age=? ")) {
st.setString(1, "ciao");
st.setInt(2, 23);
st.addBatch();
st.setString(1, "ciao1");
st.setInt(2, 43);
st.addBatch();
st.executeBatch();
checkQuery("SELECT * FROM tb");
checkQuery("SELECT * FROM t_batch");
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/net/ucanaccess/jdbc/BigintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ void testBigintInsert(AccessVersion _accessVersion) throws Exception {
Long expected = 3000000000L;

try (UcanaccessStatement st = ucanaccess.createStatement()) {
st.execute("CREATE TABLE table1 (entry TEXT(50) PRIMARY KEY, x BIGINT)");
String sql = String.format("INSERT INTO table1 (entry, x) VALUES ('3 billion', %d)", expected);
st.execute("CREATE TABLE t_bigint (entry TEXT(50) PRIMARY KEY, x BIGINT)");
String sql = String.format("INSERT INTO t_bigint (entry, x) VALUES ('3 billion', %d)", expected);
st.execute(sql);
}

Expand All @@ -31,7 +31,7 @@ void testBigintInsert(AccessVersion _accessVersion) throws Exception {
.withImmediatelyReleaseResources()
.build();
UcanaccessStatement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT x FROM table1 WHERE entry='3 billion'")) {
ResultSet rs = st.executeQuery("SELECT x FROM t_bigint WHERE entry='3 billion'")) {
rs.next();
Long actual = rs.getLong("x");
assertEquals(expected, actual);
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/net/ucanaccess/jdbc/ByteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ class ByteTest extends UcanaccessBaseTest {
protected void init(AccessVersion _accessVersion) throws SQLException {
super.init(_accessVersion);
executeStatements(
"CREATE TABLE tblMain (ID int NOT NULL PRIMARY KEY,company TEXT NOT NULL, Closed byte); ",
"INSERT INTO tblMain (id,company) VALUES(1, 'pippo')",
"UPDATE tblMain SET closed=255");
"CREATE TABLE t_byte (ID int NOT NULL PRIMARY KEY, company TEXT NOT NULL, Closed byte); ",
"INSERT INTO t_byte (id,company) VALUES(1, 'pippo')",
"UPDATE t_byte SET closed=255");
}

@ParameterizedTest(name = "[{index}] {0}")
@EnumSource(value = AccessVersion.class)
void testCreate(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);
dumpQueryResult("SELECT * FROM tblMain");
checkQuery("SELECT * FROM tblMain");
dumpQueryResult("SELECT * FROM t_byte");
checkQuery("SELECT * FROM t_byte");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CloseOnCompletionTest extends UcanaccessBaseTest {
void testCloseOnCompletion(AccessVersion _accessVersion) throws SQLException {
init(_accessVersion);

try (PreparedStatement st = ucanaccess.prepareStatement("CREATE TABLE pluto1 (id varchar(23))")) {
try (PreparedStatement st = ucanaccess.prepareStatement("CREATE TABLE t_cloc (id varchar(23))")) {
st.closeOnCompletion();
st.execute();
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/net/ucanaccess/jdbc/ColumnOrderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void testColumnOrder1(AccessVersion _accessVersion) throws Exception {
init(_accessVersion);

try (Connection uca = createUcanaccessConnection();
PreparedStatement ps = uca.prepareStatement("INSERT INTO t1 values (?, ?, ?)")) {
PreparedStatement ps = uca.prepareStatement("INSERT INTO t_columnorder values (?, ?, ?)")) {
ps.setInt(3, 3);
ps.setDate(2, new Date(System.currentTimeMillis()));
ps.setString(1, "This is the display order");
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/net/ucanaccess/jdbc/CreateDatabaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ void testNewDatabase(AccessVersion _accessVersion) throws Exception {

try (UcanaccessStatement st = conn.createStatement()) {
executeStatements(st,
"CREATE TABLE AAA (baaaa TEXT(3) PRIMARY KEY, A LONG DEFAULT 3, C TEXT(4))",
"INSERT INTO AAA(baaaa, c) VALUES ('33A','G' )",
"INSERT INTO AAA VALUES ('33B',111,'G' )");
"CREATE TABLE t_createdb (baaaa TEXT(3) PRIMARY KEY, A LONG DEFAULT 3, C TEXT(4))",
"INSERT INTO t_createdb(baaaa, c) VALUES ('33A','G' )",
"INSERT INTO t_createdb VALUES ('33B',111,'G' )");
}
dumpQueryResult("SELECT * FROM AAA");
dumpQueryResult("SELECT * FROM t_createdb");
}

}
Loading

0 comments on commit 04aa1cd

Please sign in to comment.