forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLite3ExplainGenerator.java
More file actions
36 lines (30 loc) · 1.12 KB
/
SQLite3ExplainGenerator.java
File metadata and controls
36 lines (30 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package sqlancer.sqlite3.gen;
import sqlancer.Randomly;
import sqlancer.common.query.SQLQueryAdapter;
import sqlancer.sqlite3.SQLite3GlobalState;
import sqlancer.sqlite3.SQLite3Provider;
import sqlancer.sqlite3.SQLite3Provider.Action;
public final class SQLite3ExplainGenerator {
private SQLite3ExplainGenerator() {
}
public static SQLQueryAdapter explain(SQLite3GlobalState globalState) throws Exception {
StringBuilder sb = new StringBuilder();
sb.append("EXPLAIN ");
if (Randomly.getBoolean()) {
sb.append("QUERY PLAN ");
}
Action action;
do {
action = Randomly.fromOptions(SQLite3Provider.Action.values());
} while (action == Action.EXPLAIN);
SQLQueryAdapter query = action.getQuery(globalState);
sb.append(query);
return new SQLQueryAdapter(sb.toString(), query.getExpectedErrors());
}
public static String explain(String selectStr) throws Exception {
StringBuilder sb = new StringBuilder();
sb.append("EXPLAIN QUERY PLAN ");
sb.append(selectStr);
return sb.toString();
}
}