forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMySQLDeleteGenerator.java
More file actions
57 lines (49 loc) · 2.09 KB
/
MySQLDeleteGenerator.java
File metadata and controls
57 lines (49 loc) · 2.09 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
49
50
51
52
53
54
55
56
57
package sqlancer.mysql.gen;
import java.util.Arrays;
import sqlancer.Randomly;
import sqlancer.common.query.ExpectedErrors;
import sqlancer.common.query.SQLQueryAdapter;
import sqlancer.mysql.MySQLErrors;
import sqlancer.mysql.MySQLGlobalState;
import sqlancer.mysql.MySQLSchema.MySQLTable;
import sqlancer.mysql.MySQLVisitor;
public class MySQLDeleteGenerator {
private final StringBuilder sb = new StringBuilder();
private final MySQLGlobalState globalState;
public MySQLDeleteGenerator(MySQLGlobalState globalState) {
this.globalState = globalState;
}
public static SQLQueryAdapter delete(MySQLGlobalState globalState) {
return new MySQLDeleteGenerator(globalState).generate();
}
private SQLQueryAdapter generate() {
MySQLTable randomTable = globalState.getSchema().getRandomTable();
MySQLExpressionGenerator gen = new MySQLExpressionGenerator(globalState).setColumns(randomTable.getColumns());
ExpectedErrors errors = new ExpectedErrors();
sb.append("DELETE");
if (Randomly.getBoolean()) {
sb.append(" LOW_PRIORITY");
}
if (Randomly.getBoolean()) {
sb.append(" QUICK");
}
if (Randomly.getBoolean()) {
sb.append(" IGNORE");
}
// TODO: support partitions
sb.append(" FROM ");
sb.append(randomTable.getName());
if (Randomly.getBoolean()) {
sb.append(" WHERE ");
sb.append(MySQLVisitor.asString(gen.generateExpression()));
MySQLErrors.addExpressionErrors(errors);
}
errors.addAll(Arrays.asList("doesn't have this option",
"Truncated incorrect DOUBLE value" /*
* ignore as a workaround for https://bugs.mysql.com/bug.php?id=95997
*/, "Truncated incorrect INTEGER value",
"Truncated incorrect DECIMAL value", "Data truncated for functional index"));
// TODO: support ORDER BY
return new SQLQueryAdapter(sb.toString(), errors);
}
}