forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathH2DeleteGenerator.java
More file actions
33 lines (28 loc) · 1.17 KB
/
H2DeleteGenerator.java
File metadata and controls
33 lines (28 loc) · 1.17 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
package sqlancer.h2;
import sqlancer.Randomly;
import sqlancer.common.query.ExpectedErrors;
import sqlancer.common.query.SQLQueryAdapter;
import sqlancer.h2.H2Provider.H2GlobalState;
import sqlancer.h2.H2Schema.H2Table;
public final class H2DeleteGenerator {
private H2DeleteGenerator() {
}
public static SQLQueryAdapter getQuery(H2GlobalState globalState) {
StringBuilder sb = new StringBuilder("DELETE FROM ");
ExpectedErrors errors = new ExpectedErrors();
H2Table table = globalState.getSchema().getRandomTable(t -> !t.isView());
sb.append(table.getName());
if (Randomly.getBoolean()) {
sb.append(" WHERE ");
sb.append(H2ToStringVisitor.asString(
new H2ExpressionGenerator(globalState).setColumns(table.getColumns()).generateExpression()));
}
if (Randomly.getBoolean()) {
sb.append(" LIMIT ");
sb.append(H2ToStringVisitor.asString(new H2ExpressionGenerator(globalState).generateConstant()));
}
H2Errors.addExpressionErrors(errors);
H2Errors.addDeleteErrors(errors);
return new SQLQueryAdapter(sb.toString(), errors);
}
}