Skip to content

Commit ca70c6a

Browse files
authored
fix: broken grammar of LIKELIHOOD (#650)
1 parent b5eb215 commit ca70c6a

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/sqlancer/sqlite3/SQLite3Errors.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public static void addExpectedExpressionErrors(ExpectedErrors errors) {
2121
errors.add("FTS expression tree is too large");
2222
errors.add("String or BLOB exceeds size limit");
2323
errors.add("[SQLITE_ERROR] SQL error or missing database (integer overflow)");
24-
errors.add("second argument to likelihood() must be a constant between 0.0 and 1.0");
2524
errors.add("ORDER BY term out of range");
2625
errors.add("GROUP BY term out of range");
2726
errors.add("not authorized"); // load_extension

src/sqlancer/sqlite3/gen/SQLite3ExpressionGenerator.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,12 @@ private SQLite3Expression getFunction(SQLite3GlobalState globalState, int depth)
547547
nrArgs += Randomly.smallNumber();
548548
}
549549
List<SQLite3Expression> expressions = randomFunction.generateArguments(nrArgs, depth + 1, this);
550+
// The second argument of LIKELIHOOD must be a float number within 0.0 -1.0
551+
if (randomFunction == AnyFunction.LIKELIHOOD) {
552+
SQLite3Expression lastArg = SQLite3Constant.createRealConstant(Randomly.getPercentage());
553+
expressions.remove(expressions.size() - 1);
554+
expressions.add(lastArg);
555+
}
550556
return new SQLite3Expression.Function(randomFunction.toString(),
551557
expressions.toArray(new SQLite3Expression[0]));
552558
}
@@ -604,6 +610,11 @@ private SQLite3Expression getComputableFunction(int depth) {
604610
args[i] = new SQLite3Distinct(args[i]);
605611
}
606612
}
613+
// The second argument of LIKELIHOOD must be a float number within 0.0 -1.0
614+
if (func == ComputableFunction.LIKELIHOOD) {
615+
SQLite3Expression lastArg = SQLite3Constant.createRealConstant(Randomly.getPercentage());
616+
args[args.length - 1] = lastArg;
617+
}
607618
return new SQLite3Function(func, args);
608619
}
609620

0 commit comments

Comments
 (0)