forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLite3AnalyzeGenerator.java
More file actions
41 lines (35 loc) · 1.29 KB
/
SQLite3AnalyzeGenerator.java
File metadata and controls
41 lines (35 loc) · 1.29 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
37
38
39
40
41
package sqlancer.sqlite3.gen;
import sqlancer.Randomly;
import sqlancer.common.query.ExpectedErrors;
import sqlancer.common.query.SQLQueryAdapter;
import sqlancer.sqlite3.SQLite3GlobalState;
public final class SQLite3AnalyzeGenerator {
private SQLite3AnalyzeGenerator() {
}
private enum AnalyzeTarget {
SCHEMA, TABLE, INDEX, SQL_MASTER
}
public static SQLQueryAdapter generateAnalyze(SQLite3GlobalState globalState) {
final StringBuilder sb = new StringBuilder("ANALYZE");
if (Randomly.getBoolean()) {
sb.append(" ");
switch (Randomly.fromOptions(AnalyzeTarget.values())) {
case INDEX:
sb.append(globalState.getSchema().getRandomIndexOrBailout());
break;
case SCHEMA:
sb.append(Randomly.fromOptions("main", "temp"));
break;
case SQL_MASTER:
sb.append("sqlite_master");
break;
case TABLE:
sb.append(globalState.getSchema().getRandomTableOrBailout().getName());
break;
default:
throw new AssertionError();
}
}
return new SQLQueryAdapter(sb.toString(), ExpectedErrors.from("The database file is locked"));
}
}