Content-Length: 332425 | pFad | http://github.com/sqlancer/sqlancer/commit/5766078e2715f861655b7707cd5b734b89550b37

C4 Add a clearer execution statement · sqlancer/sqlancer@5766078 · GitHub
Skip to content

Commit 5766078

Browse files
committed
Add a clearer execution statement
1 parent d28c960 commit 5766078

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/sqlancer/postgres/PostgresProvider.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -276,27 +276,31 @@ public SQLConnection createDatabase(PostgresGlobalState globalState) throws SQLE
276276
Connection con = DriverManager.getConnection("jdbc:" + entryURL, username, password);
277277
globalState.getState().logStatement(String.format("\\c %s;", entryDatabaseName));
278278

279-
createDatabaseCommand = getCreateDatabaseCommand(globalState);
280-
281-
// postgres 13+ supports force
279+
String dropCommand = "DROP DATABASE";
282280
if (Randomly.getBoolean()) {
283-
globalState.getState().logStatement("DROP DATABASE IF EXISTS " + databaseName);
284-
try (Statement s = con.createStatement()) {
285-
s.execute("DROP DATABASE FORCE IF EXISTS " + databaseName);
286-
} catch (SQLException e) {
287-
// If force fails, fall back to regular drop
281+
dropCommand += " FORCE";
282+
}
283+
dropCommand += " IF EXISTS " + databaseName;
284+
285+
globalState.getState().logStatement(dropCommand + ";");
286+
try (Statement s = con.createStatement()) {
287+
s.execute(dropCommand);
288+
} catch (SQLException e) {
289+
// If force fails, fall back to regular drop
290+
if (dropCommand.contains("FORCE")) {
291+
String fallbackDrop = "DROP DATABASE IF EXISTS " + databaseName;
292+
globalState.getState().logStatement(fallbackDrop + ";");
288293
try (Statement s = con.createStatement()) {
289-
s.execute("DROP DATABASE IF EXISTS " + databaseName);
294+
s.execute(fallbackDrop);
290295
}
291-
}
292-
} else {
293-
globalState.getState().logStatement("DROP DATABASE IF EXISTS " + databaseName);
294-
try (Statement s = con.createStatement()) {
295-
s.execute("DROP DATABASE IF EXISTS " + databaseName);
296+
} else {
297+
throw e;
296298
}
297299
}
298300

299-
// Execute the create database command
301+
// Create database section
302+
createDatabaseCommand = getCreateDatabaseCommand(globalState);
303+
globalState.getState().logStatement(createDatabaseCommand + ";");
300304
try (Statement s = con.createStatement()) {
301305
s.execute(createDatabaseCommand);
302306
}

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/5766078e2715f861655b7707cd5b734b89550b37

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy