Skip to content

Commit

Permalink
Improve naming of database objects in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spannm committed Jul 6, 2024
1 parent c88c969 commit 9bc2ddf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/test/java/net/ucanaccess/jdbc/AlterTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ void testAddColumn(AccessVersion _accessVersion) throws SQLException, IOExceptio
executeStatements(st,
"ALTER TABLE [22 alterTableTest123] ADD COLUMN [ci ci] TEXT(100) NOT NULL DEFAULT 'PIPPO'",
"ALTER TABLE [22 alterTableTest123] ADD COLUMN [健康] decimal (23,5) ",
"ALTER TABLE [22 alterTableTest123] ADD COLUMN [£健康] numeric (23,6) default 13.031955 NOT NULL");
assertThatThrownBy(() -> st.execute("ALTER TABLE [22 alterTableTest123] ADD COLUMN defaultwwwdefault numeric (23,6) NOT NULL"))
"ALTER TABLE [22 alterTableTest123] ADD COLUMN [£健康] numeric (23,6) DEFAULT 13.031955 NOT NULL");
assertThatThrownBy(() -> st.execute("ALTER TABLE [22 alterTableTest123] ADD COLUMN defaultwwwdefault NUMERIC(23,6) NOT NULL"))
.isInstanceOf(UcanaccessSQLException.class)
.hasMessageContaining("When adding a new column");
executeStatements(st,
Expand Down Expand Up @@ -251,7 +251,7 @@ void testMiscellaneous(AccessVersion _accessVersion) throws SQLException {
st.execute("DROP TABLE tx ");
st.execute("DROP TABLE tx1 ");

st.execute("CREATE TABLE tx (id COUNTER PRIMARY KEY, [my best friend] LONG, [my worst friend] SINGLE, [Is Pippo] TEXT(100), [Is not Pippo] TEXT default \"what's this?\")");
st.execute("CREATE TABLE tx (id COUNTER PRIMARY KEY, [my best friend] LONG, [my worst friend] SINGLE, [Is Pippo] TEXT(100), [Is not Pippo] TEXT DEFAULT \"what's this?\")");
st.execute("CREATE TABLE tx1 (n1 LONG, [n 2] TEXT)");
st.execute("ALTER TABLE tx1 ADD PRIMARY KEY (n1, [n 2])");
st.execute("ALTER TABLE tx ADD FOREIGN KEY ([my best friend], [Is Pippo]) REFERENCES tx1(n1, [n 2]) ON DELETE SET NULL");
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/net/ucanaccess/jdbc/CreateDatabaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ void testNewDatabase(AccessVersion _accessVersion) throws Exception {

try (UcanaccessStatement st = conn.createStatement()) {
executeStatements(st,
"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')");
"CREATE TABLE t_createdb (col_pk TEXT(3) PRIMARY KEY, col2 LONG DEFAULT 3, col3 TEXT(4))",
"INSERT INTO t_createdb (col_pk, col3) VALUES ('33A', 'G')",
"INSERT INTO t_createdb VALUES ('33B', 111, 'G')");
}
dumpQueryResult("SELECT * FROM t_createdb");
}
Expand Down
61 changes: 32 additions & 29 deletions src/test/java/net/ucanaccess/jdbc/CreateTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ class CreateTableTest extends UcanaccessBaseTest {

private void createAsSelect() throws SQLException {
try (UcanaccessStatement st = ucanaccess.createStatement()) {
st.executeUpdate("CREATE TABLE AAA_BIS as (SELECT baaaa, a, c FROM AAA) WITH DATA");
checkQuery("SELECT * FROM AAA_bis ORDER BY baaaa",
st.executeUpdate("CREATE TABLE tbl_bis as (SELECT baaaa, a, c FROM tbl1) WITH DATA");
checkQuery("SELECT * FROM tbl_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");

st.executeUpdate("CREATE TABLE tbl_quadris as (SELECT tbl1.baaaa, tbl_bis.baaaa as xxx FROM tbl1, tbl_bis) WITH DATA");
dumpQueryResult("SELECT * FROM tbl_quadris ORDER BY baaaa");
}
}

private void createAsSelect2() throws SQLException {
try (UcanaccessStatement 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");
checkQuery("SELECT * FROM AAA_tris ORDER BY baaaa",
st.executeUpdate("CREATE TABLE tbl_tris as (SELECT baaaa, a, c FROM tbl1) WITH NO DATA");
st.execute("INSERT INTO tbl_tris SELECT * FROM tbl_bis");
checkQuery("SELECT * FROM tbl_tris ORDER BY baaaa",
recs(rec("33A", 3, "G"), rec("33B", 111, "G")));
}
}
Expand All @@ -53,22 +54,22 @@ private void createPs() throws SQLException {
private void createSimple() throws SQLException {
try (UcanaccessStatement st = ucanaccess.createStatement()) {
executeStatements(st,
"INSERT INTO AAA(baaaa, c) VALUES ('33A', 'G')",
"INSERT INTO AAA(baaaa, a, c) VALUES ('33B', 111, 'G')");
checkQuery("SELECT baaaa, a, c FROM AAA ORDER BY baaaa",
"INSERT INTO tbl1(baaaa, c) VALUES ('33A', 'G')",
"INSERT INTO tbl1(baaaa, a, c) VALUES ('33B', 111, 'G')");
checkQuery("SELECT baaaa, a, c FROM tbl1 ORDER BY baaaa",
recs(rec("33A", 3, "G"), rec("33B", 111, "G")));
}
}

void defaults() throws Exception {
try (UcanaccessStatement st = ucanaccess.createStatement()) {
ResultSet rs = st.executeQuery("SELECT D, E FROM AAA");
ResultSet rs = st.executeQuery("SELECT D, E FROM tbl1");
while (rs.next()) {
assertNotNull(rs.getObject(1));
assertNotNull(rs.getObject(2));
}
Database db = ucanaccess.getDbIO();
Table tb = db.getTable("AAA");
Table tb = db.getTable("tbl1");
PropertyMap pm = tb.getColumn("d").getProperties();
assertEquals("now()", pm.getValue(PropertyMap.DEFAULT_VALUE_PROP));
PropertyMap pm1 = tb.getColumn("a").getProperties();
Expand All @@ -85,40 +86,42 @@ void defaults() throws Exception {
void setDPK() throws SQLException {
try (UcanaccessStatement st = ucanaccess.createStatement()) {
executeStatements(st,
"CREATE TABLE dkey(c COUNTER, number NUMERIC(23,5), PRIMARY KEY (c, number))",
"CREATE TABLE dunique(c TEXT, number NUMERIC(23,5), UNIQUE (c, number))");
"CREATE TABLE tbl_dkey(c COUNTER, number NUMERIC(23,5), PRIMARY KEY (c, number))",
"CREATE TABLE tbl_dunique(c TEXT, number NUMERIC(23,5), UNIQUE (c, number))");
}

ucanaccess.setAutoCommit(false);

try (UcanaccessStatement st = ucanaccess.createStatement()) {
executeStatements(st,
"INSERT INTO dunique VALUES('ddl forces commit', 2.3)",
"CREATE TABLE dtrx(c TEXT, number NUMERIC(23,5), UNIQUE(c, number))",
"INSERT INTO dtrx VALUES('I''ll be forgotten sob sob', 55555.3)",
"ALTER TABLE dtrx ADD CONSTRAINT pk_dtrx PRIMARY KEY (c, number)");
"INSERT INTO tbl_dunique VALUES('ddl forces commit', 2.3)",
"CREATE TABLE tbl_dtrx(c TEXT, number NUMERIC(23,5), UNIQUE(c, number))",
"INSERT INTO tbl_dtrx VALUES('I''ll be forgotten sob sob', 55555.3)",
"ALTER TABLE tbl_dtrx ADD CONSTRAINT pk_dtrx PRIMARY KEY (c, number)");
} catch (Exception _ex) {
ucanaccess.rollback();
}

try (UcanaccessStatement st = ucanaccess.createStatement()) {
executeStatements(st,
"INSERT INTO dtrx VALUES('Hi all', 444.3)",
"INSERT INTO dtrx VALUES('Hi all', 4454.3)");
"INSERT INTO tbl_dtrx VALUES('Hi all', 444.3)",
"INSERT INTO tbl_dtrx VALUES('Hi all', 4454.3)");
}

dumpQueryResult("SELECT * FROM dtrx");
dumpQueryResult("SELECT * FROM dunique");
dumpQueryResult("SELECT * FROM tbl_dtrx");
dumpQueryResult("SELECT * FROM tbl_dunique");
ucanaccess.commit();
checkQuery("SELECT * FROM dunique");
checkQuery("SELECT * FROM dtrx");
checkQuery("SELECT * FROM tbl_dunique");
checkQuery("SELECT * FROM tbl_dtrx");
}

void setTableProperties() throws SQLException {
try (UcanaccessStatement st = ucanaccess.createStatement()) {
st.execute("CREATE TABLE tbl(c COUNTER PRIMARY KEY, " + "number NUMERIC(23,5) DEFAULT -4.6 NOT NULL, "
+ "txt1 TEXT(23) DEFAULT 'ciao', blank TEXT DEFAULT ' ', dt DATE DEFAULT date(), txt2 TEXT(33),"
+ "txt3 TEXT)");
st.execute("CREATE TABLE tbl(c COUNTER PRIMARY KEY, "
+ "number NUMERIC(23,5) DEFAULT -4.6 NOT NULL, "
+ "txt1 TEXT(23) DEFAULT 'ciao', blank TEXT DEFAULT ' ', "
+ "dt DATE DEFAULT date(), txt2 TEXT(33),"
+ "txt3 TEXT)");
}
}

Expand Down Expand Up @@ -149,7 +152,7 @@ void testCreate(AccessVersion _accessVersion) throws Exception {
init(_accessVersion);

executeStatements(
"CREATE \nTABLE AAA( baaaa \nTEXT PRIMARY KEY, A LONG DEFAULT 3 NOT NULL, C TEXT(255) NOT NULL, "
"CREATE \nTABLE tbl1( baaaa \nTEXT PRIMARY KEY, A LONG DEFAULT 3 NOT NULL, C TEXT(255) NOT NULL, "
+ "d DATETIME DEFAULT now(), e TEXT DEFAULT 'l''aria')");

createSimple();
Expand All @@ -161,7 +164,7 @@ void testCreate(AccessVersion _accessVersion) throws Exception {
defaults();
notNullBug();

executeStatements("DROP TABLE AAA");
executeStatements("DROP TABLE tbl1");
}

@ParameterizedTest(name = "[{index}] {0}")
Expand Down

0 comments on commit 9bc2ddf

Please sign in to comment.