Skip to content

Commit e5e0490

Browse files
committed
[SQLite] Add a method to the expression generator that returns an expression with known result
1 parent 8acc72e commit e5e0490

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

src/sqlancer/sqlite3/gen/SQLite3ExpressionGenerator.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,4 +654,12 @@ public SQLite3Expression isNull(SQLite3Expression expr) {
654654
return new SQLite3PostfixUnaryOperation(PostfixUnaryOperator.ISNULL, expr);
655655
}
656656

657+
public SQLite3Expression generateResultKnownExpression() {
658+
SQLite3Expression expr;
659+
do {
660+
expr = generateExpression();
661+
} while (expr.getExpectedValue() == null);
662+
return expr;
663+
}
664+
657665
}

src/sqlancer/sqlite3/oracle/SQLite3PivotedQuerySynthesisOracle.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,8 @@ public SQLite3Select getQuery(SQLite3GlobalState globalState) throws SQLExceptio
110110
errors.add("second argument to nth_value must be a positive integer");
111111
}
112112
if (Randomly.getBoolean()) {
113-
SQLite3Expression randomExpression;
114-
do {
115-
randomExpression = new SQLite3ExpressionGenerator(globalState).setColumns(columns)
116-
.generateExpression();
117-
} while (randomExpression.getExpectedValue() == null);
113+
SQLite3Expression randomExpression = new SQLite3ExpressionGenerator(globalState).setColumns(columns)
114+
.generateResultKnownExpression();
118115
colExpressions.add(randomExpression);
119116
} else {
120117
colExpressions.add(colName);
@@ -259,16 +256,14 @@ private SQLite3Expression generateWhereClauseThatContainsRowValue(List<SQLite3Co
259256
private SQLite3Expression generateNewExpression(List<SQLite3Column> columns, SQLite3RowValue rw) {
260257
do {
261258
SQLite3Expression expr = new SQLite3ExpressionGenerator(globalState).setRowValue(rw).setColumns(columns)
262-
.generateExpression();
263-
if (expr.getExpectedValue() != null) {
264-
if (expr.getExpectedValue().isNull()) {
265-
return new SQLite3PostfixUnaryOperation(PostfixUnaryOperator.ISNULL, expr);
266-
}
267-
if (SQLite3Cast.isTrue(expr.getExpectedValue()).get()) {
268-
return expr;
269-
} else {
270-
return new SQLite3UnaryOperation(UnaryOperator.NOT, expr);
271-
}
259+
.generateResultKnownExpression();
260+
if (expr.getExpectedValue().isNull()) {
261+
return new SQLite3PostfixUnaryOperation(PostfixUnaryOperator.ISNULL, expr);
262+
}
263+
if (SQLite3Cast.isTrue(expr.getExpectedValue()).get()) {
264+
return expr;
265+
} else {
266+
return new SQLite3UnaryOperation(UnaryOperator.NOT, expr);
272267
}
273268
} while (true);
274269
}

0 commit comments

Comments
 (0)