forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLite3ReindexGenerator.java
More file actions
48 lines (43 loc) · 1.58 KB
/
SQLite3ReindexGenerator.java
File metadata and controls
48 lines (43 loc) · 1.58 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
42
43
44
45
46
47
48
package sqlancer.sqlite3.gen;
import sqlancer.Randomly;
import sqlancer.common.query.ExpectedErrors;
import sqlancer.common.query.SQLQueryAdapter;
import sqlancer.sqlite3.SQLite3GlobalState;
import sqlancer.sqlite3.schema.SQLite3Schema;
/**
* @see <a href="https://www.sqlite.org/lang_reindex.html">REINDEX</a>
*/
public final class SQLite3ReindexGenerator {
private SQLite3ReindexGenerator() {
}
private enum Target {
TABLE, INDEX, COLLATION_NAME
}
public static SQLQueryAdapter executeReindex(SQLite3GlobalState globalState) {
SQLite3Schema s = globalState.getSchema();
StringBuilder sb = new StringBuilder("REINDEX");
ExpectedErrors errors = new ExpectedErrors();
errors.add("The database file is locked");
Target t = Randomly.fromOptions(Target.values());
if (Randomly.getBoolean()) {
sb.append(" ");
switch (t) {
case INDEX:
sb.append(s.getRandomIndexOrBailout());
// temp table
errors.add("unable to identify the object to be reindexed");
break;
case COLLATION_NAME:
sb.append(Randomly.fromOptions("BINARY", "NOCASE", "RTRIM"));
break;
case TABLE:
sb.append(" ");
sb.append(s.getRandomTableOrBailout(tab -> !tab.isTemp() && !tab.isView()).getName());
break;
default:
throw new AssertionError(t);
}
}
return new SQLQueryAdapter(sb.toString(), errors, true);
}
}