@@ -186,7 +186,7 @@ protected void closing(Connection c) {
186
186
* @throws SQLException if error occurs obtaining connection
187
187
*/
188
188
protected Connection initConnection () throws SQLException {
189
- if (db == null ) {
189
+ if (db == null || db . isClosed () ) {
190
190
db = ds .getConnection ();
191
191
}
192
192
return db ;
@@ -435,6 +435,12 @@ protected void createDatabase(Configuration config) throws SQLException {
435
435
}
436
436
}
437
437
438
+ /**
439
+ * Drop this database
440
+ * @throws SQLException if a database error occured
441
+ */
442
+ abstract protected void dropDatabase () throws SQLException ;
443
+
438
444
protected void setConnectionOnTables (Connection db ) {
439
445
440
446
weightTable .setConnection (db );
@@ -1201,8 +1207,8 @@ public boolean initialize() {
1201
1207
}
1202
1208
else if (msg .contains ("authentication failed" ) ||
1203
1209
msg .contains ("requires a valid client certificate" )) {
1204
- lasterror =
1205
- new BSimError ( ErrorCategory . Authentication , "Could not authenticate with database" );
1210
+ lasterror = new BSimError ( ErrorCategory . Authentication ,
1211
+ "Could not authenticate with database" );
1206
1212
}
1207
1213
else if (msg .contains ("does not exist" ) && !msg .contains (" role " )) {
1208
1214
lasterror = new BSimError (ErrorCategory .Nodatabase , cause .getMessage ());
@@ -1572,6 +1578,9 @@ else if (query instanceof QueryExeInfo q) {
1572
1578
else if (query instanceof QueryExeCount q ) {
1573
1579
fdbQueryExeCount (q );
1574
1580
}
1581
+ else if (query instanceof DropDatabase q ) {
1582
+ fdbDatabaseDrop (q );
1583
+ }
1575
1584
else if (query instanceof CreateDatabase q ) {
1576
1585
fdbDatabaseCreate (q );
1577
1586
}
@@ -1622,7 +1631,8 @@ public QueryResponseRecord query(BSimQuery<?> query) {
1622
1631
1623
1632
lasterror = null ;
1624
1633
try {
1625
- if (!(query instanceof CreateDatabase ) && !initialize ()) {
1634
+ if (!(query instanceof CreateDatabase ) && !(query instanceof DropDatabase ) &&
1635
+ !initialize ()) {
1626
1636
lasterror = new BSimError (ErrorCategory .Nodatabase , "The database does not exist" );
1627
1637
return null ;
1628
1638
}
@@ -2087,6 +2097,29 @@ private void fdbQueryChildren(QueryChildren query) throws LSHException, SQLExcep
2087
2097
}
2088
2098
}
2089
2099
2100
+ private void fdbDatabaseDrop (DropDatabase query ) throws LSHException {
2101
+ ResponseDropDatabase response = query .getResponse ();
2102
+ if (query .databaseName == null ) {
2103
+ throw new LSHException ("Missing databaseName for drop database" );
2104
+ }
2105
+ if (!query .databaseName .equals (ds .getServerInfo ().getDBName ())) {
2106
+ throw new UnsupportedOperationException ("drop database name must match" );
2107
+ }
2108
+ response .dropSuccessful = true ; // Response parameters assuming success
2109
+ response .errorMessage = null ;
2110
+ try {
2111
+ dropDatabase ();
2112
+ }
2113
+ catch (SQLException e ) {
2114
+ String msg = e .getMessage ();
2115
+ if (msg .indexOf ("database \" " + query .databaseName + "\" does not exist" ) > 0 ) {
2116
+ return ; // missing database
2117
+ }
2118
+ response .dropSuccessful = false ;
2119
+ response .errorMessage = e .getMessage ();
2120
+ }
2121
+ }
2122
+
2090
2123
/**
2091
2124
* Entry point for the CreateDatabase command
2092
2125
* @param query the query to execute
0 commit comments