-
Notifications
You must be signed in to change notification settings - Fork 397
Add DeleteGenerator for MariaDB #1275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mrigger
merged 4 commits into
sqlancer:main
from
Mohab-Sobhy:feat/mariadb-add-delete-generator
Nov 23, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c58cc46
Add DeleteGenerator for MariaDB
Mohab-Sobhy fde4da7
Format code to fix linter error
Mohab-Sobhy 18ab560
Fix Checkstyle violations and add expected errors for invalid regex i…
Mohab-Sobhy 35105ec
Modify DELETE generation probability
Mohab-Sobhy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| package sqlancer.mariadb.gen; | ||
|
|
||
| import java.util.Collections; | ||
|
|
||
| import sqlancer.Randomly; | ||
| import sqlancer.common.query.ExpectedErrors; | ||
| import sqlancer.common.query.SQLQueryAdapter; | ||
| import sqlancer.common.schema.AbstractTables; | ||
| import sqlancer.mariadb.MariaDBSchema; | ||
| import sqlancer.mariadb.MariaDBSchema.MariaDBColumn; | ||
| import sqlancer.mariadb.MariaDBSchema.MariaDBTable; | ||
| import sqlancer.mariadb.ast.MariaDBVisitor; | ||
|
|
||
| public final class MariaDBDeleteGenerator { | ||
|
|
||
| private MariaDBDeleteGenerator() { | ||
| } | ||
|
|
||
| public static SQLQueryAdapter delete(MariaDBSchema schema, Randomly r) { | ||
| MariaDBTable table = schema.getRandomTable(); | ||
|
|
||
| MariaDBExpressionGenerator expressionGenerator = new MariaDBExpressionGenerator(r); | ||
|
|
||
| AbstractTables<MariaDBTable, MariaDBColumn> tablesAndColumns = new AbstractTables<>( | ||
| Collections.singletonList(table)); | ||
| expressionGenerator.setTablesAndColumns(tablesAndColumns); | ||
|
|
||
| ExpectedErrors errors = new ExpectedErrors(); | ||
|
|
||
| errors.add("foreign key constraint fails"); | ||
| errors.add("cannot delete or update a parent row"); | ||
| errors.add("Data truncated"); | ||
| errors.add("Division by 0"); | ||
| errors.add("Incorrect value"); | ||
|
|
||
| StringBuilder sb = new StringBuilder("DELETE"); | ||
|
|
||
| if (Randomly.getBooleanWithRatherLowProbability()) { | ||
| sb.append(" LOW_PRIORITY"); | ||
| } | ||
| if (Randomly.getBooleanWithRatherLowProbability()) { | ||
| sb.append(" QUICK"); | ||
| } | ||
| if (Randomly.getBooleanWithRatherLowProbability()) { | ||
| sb.append(" IGNORE"); | ||
| } | ||
|
|
||
| sb.append(" FROM "); | ||
| sb.append(table.getName()); | ||
|
|
||
| if (Randomly.getBoolean()) { | ||
| sb.append(" WHERE "); | ||
| if (Randomly.getBooleanWithRatherLowProbability()) { | ||
| sb.append(MariaDBVisitor.asString(MariaDBExpressionGenerator.getRandomConstant(r))); | ||
| } else { | ||
| sb.append(MariaDBVisitor.asString(expressionGenerator.getRandomExpression())); | ||
| } | ||
| } | ||
|
|
||
| // ORDER BY + LIMIT | ||
| if (Randomly.getBooleanWithRatherLowProbability() && !table.getColumns().isEmpty()) { | ||
| sb.append(" ORDER BY "); | ||
| sb.append(Randomly.fromList(table.getColumns()).getName()); | ||
| if (Randomly.getBoolean()) { | ||
| sb.append(Randomly.getBoolean() ? " ASC" : " DESC"); | ||
| } | ||
| } | ||
|
|
||
| if (Randomly.getBooleanWithRatherLowProbability()) { | ||
| sb.append(" LIMIT "); | ||
| sb.append(Randomly.getNotCachedInteger(1, 10)); | ||
| } | ||
|
|
||
| // RETURNING clause (MariaDB >= 10.5) | ||
| if (Randomly.getBooleanWithRatherLowProbability()) { | ||
| sb.append(" RETURNING "); | ||
| if (Randomly.getBooleanWithRatherLowProbability()) { | ||
| sb.append(MariaDBVisitor.asString(MariaDBExpressionGenerator.getRandomConstant(r))); | ||
| } else { | ||
| sb.append(MariaDBVisitor.asString(expressionGenerator.getRandomExpression())); | ||
| } | ||
| } | ||
|
|
||
| String query = sb.toString(); | ||
| if (query.contains("RLIKE") || query.contains("REGEXP")) { | ||
| errors.add("Regex error"); | ||
| errors.add("quantifier does not follow a repeatable item"); | ||
| errors.add("Got error"); | ||
| } | ||
|
|
||
| return new SQLQueryAdapter(query, errors); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we could also generate them with a low probability? This logic will include 10
DELETEstatements into every test case, rather than probabilistically generate some for some test cases, so tables are likely to be empty for many test cases.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrigger Thanks for the suggestion — I’ve updated the DELETE logic accordingly.
Sorry for the late reply, I was caught up with midterm exams.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, thanks for the PR!