Skip to content

Commit e0a33d2

Browse files
committed
Updated OSGeo-Live test utility to remove the test table upon success of test.
1 parent e8c317d commit e0a33d2

File tree

1 file changed

+26
-2
lines changed
  • tools/osgeo-postgis-jdbc-test-util/src/main/java/net/postgis/osgeo/util

1 file changed

+26
-2
lines changed

tools/osgeo-postgis-jdbc-test-util/src/main/java/net/postgis/osgeo/util/Main.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public Main(final String jdbcUrl,
5353
if (createTestTable(testTablePrefix)) {
5454
if (testSQL()) {
5555
logger.debug("All tests passed");
56+
dropTestTable();
5657
}
5758
}
5859
}
@@ -105,7 +106,6 @@ private boolean createTestTable(final String testTablePrefix) {
105106
boolean tableExists = false;
106107
try {
107108
DatabaseMetaData databaseMetaData = connection.getMetaData();
108-
109109
try (ResultSet resultSet = databaseMetaData.getTables(null, null, testTableName.toLowerCase(), new String[] {"TABLE"})) {
110110
while (resultSet.next()) {
111111
tableExists = true;
@@ -118,7 +118,7 @@ private boolean createTestTable(final String testTablePrefix) {
118118
testPass = true;
119119
} catch (SQLException se) {
120120
logger.error(
121-
"Caught SQLException attempting to create a test table: {} {}",
121+
"Caught SQLException attempting to create the test table: {} {}",
122122
se.getClass().getName(),
123123
se.getMessage()
124124
);
@@ -127,6 +127,30 @@ private boolean createTestTable(final String testTablePrefix) {
127127
}
128128

129129

130+
private void dropTestTable() {
131+
final String dropSQL = "drop table " + testTableName;
132+
logger.debug("Dropping test table");
133+
boolean tableExists = false;
134+
try {
135+
DatabaseMetaData databaseMetaData = connection.getMetaData();
136+
try (ResultSet resultSet = databaseMetaData.getTables(null, null, testTableName.toLowerCase(), new String[] {"TABLE"})) {
137+
while (resultSet.next()) {
138+
tableExists = true;
139+
}
140+
}
141+
if (tableExists) {
142+
statement.execute(dropSQL);
143+
}
144+
} catch (SQLException se) {
145+
logger.error(
146+
"Caught SQLException attempting to drop the test table: {} {}",
147+
se.getClass().getName(),
148+
se.getMessage()
149+
);
150+
}
151+
}
152+
153+
130154
private boolean testDatatypeRegistration() {
131155
boolean testPass = false;
132156
logger.debug("Adding geometric type entries...");

0 commit comments

Comments
 (0)