Content-Length: 317380 | pFad | http://github.com/sqlancer/sqlancer/commit/0d6d264521c8136dcd1e2319b9e5a67eb786aee3

E4 Merge pull request #1229 from yaojiejia/psql_v13_drop_db_force · sqlancer/sqlancer@0d6d264 · GitHub
Skip to content

Commit 0d6d264

Browse files
authored
Merge pull request #1229 from yaojiejia/psql_v13_drop_db_force
Add support for Drop Database Force in Postgres v13
2 parents 49c7358 + ebda730 commit 0d6d264

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/sqlancer/postgres/PostgresProvider.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,33 @@ public SQLConnection createDatabase(PostgresGlobalState globalState) throws SQLE
279279
}
280280
Connection con = DriverManager.getConnection("jdbc:" + entryURL, username, password);
281281
globalState.getState().logStatement(String.format("\\c %s;", entryDatabaseName));
282-
globalState.getState().logStatement("DROP DATABASE IF EXISTS " + databaseName);
283-
createDatabaseCommand = getCreateDatabaseCommand(globalState);
284-
globalState.getState().logStatement(createDatabaseCommand);
282+
283+
String dropCommand = "DROP DATABASE";
284+
boolean forceDrop = Randomly.getBoolean();
285+
if (forceDrop) {
286+
dropCommand += " FORCE";
287+
}
288+
dropCommand += " IF EXISTS " + databaseName;
289+
290+
globalState.getState().logStatement(dropCommand + ";");
285291
try (Statement s = con.createStatement()) {
286-
s.execute("DROP DATABASE IF EXISTS " + databaseName);
292+
s.execute(dropCommand);
293+
} catch (SQLException e) {
294+
// If force fails, fall back to regular drop
295+
if (forceDrop) {
296+
String fallbackDrop = "DROP DATABASE IF EXISTS " + databaseName;
297+
globalState.getState().logStatement(fallbackDrop + ";");
298+
try (Statement s = con.createStatement()) {
299+
s.execute(fallbackDrop);
300+
}
301+
} else {
302+
throw e;
303+
}
287304
}
305+
306+
// Create database section
307+
createDatabaseCommand = getCreateDatabaseCommand(globalState);
308+
globalState.getState().logStatement(createDatabaseCommand + ";");
288309
try (Statement s = con.createStatement()) {
289310
s.execute(createDatabaseCommand);
290311
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/sqlancer/sqlancer/commit/0d6d264521c8136dcd1e2319b9e5a67eb786aee3

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy