forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLite3SpecialStringGenerator.java
More file actions
43 lines (37 loc) · 1.55 KB
/
Copy pathSQLite3SpecialStringGenerator.java
File metadata and controls
43 lines (37 loc) · 1.55 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
package sqlancer.sqlite3;
import sqlancer.Randomly;
public final class SQLite3SpecialStringGenerator {
private SQLite3SpecialStringGenerator() {
}
private enum Options {
TIME_DATE_REGEX, NOW, DATE_TIME, TIME_MODIFIER, FLOAT
}
public static String generate() {
StringBuilder sb = new StringBuilder();
switch (Randomly.fromOptions(Options.values())) {
case TIME_DATE_REGEX: // https://www.sqlite.org/lang_datefunc.html
return Randomly.fromOptions("%d", "%f", "%H", "%j", "%J", "%m", "%M", "%s", "%S", "%w", "%W", "%Y", "%%");
case NOW:
return "now";
case DATE_TIME:
long notCachedInteger = Randomly.getNotCachedInteger(1, 10);
for (int i = 0; i < notCachedInteger; i++) {
if (Randomly.getBoolean()) {
sb.append(Randomly.getNonCachedInteger());
} else {
sb.append(Randomly.getNotCachedInteger(0, 2000));
}
sb.append(Randomly.fromOptions(":", "-", " ", "T"));
}
return sb.toString();
case TIME_MODIFIER:
sb.append(Randomly.fromOptions("days", "hours", "minutes", "seconds", "months", "years", "start of month",
"start of year", "start of day", "weekday", "unixepoch", "utc"));
return sb.toString();
case FLOAT:
return Randomly.fromOptions("NaN", "Infinity", "-Infinity", "1e500000", "1-500000");
default:
throw new AssertionError();
}
}
}