GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — opt: support new features in SQLite by bajinsheng · Pull Request #654 · sqlancer/sqlancer

opt: support new features in SQLite #654

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.

Sign up for GitHub

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
bajinsheng merged 3 commits into sqlancer:master from bajinsheng:master
Dec 18, 2022

Uh oh!

There was an error while loading. Please reload this page.

Merged

opt: support new features in SQLite #654

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
27615f1
opt: support maximum number of table/index
Dec 17, 2022
9f5dbd9
opt: support explain interface
Dec 17, 2022
1a40509
opt: add new Actions
Dec 17, 2022
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

7 changes: 7 additions & 0 deletions 7 src/sqlancer/sqlite3/SQLite3Options.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ public class SQLite3Options implements DBMSSpecificOptions<SQLite3OracleFactory>
"--execute-queries" }, description = "Specifies whether the query in the fuzzer should be executed", arity = 1)
public boolean executeQuery = true;

@Parameter(names = {
"--max-num-tables" }, description = "The maximum number of tables/virtual tables/ rtree tables/ views that can be created")
public int maxNumTables = 10;

@Parameter(names = { "--max-num-indexes" }, description = "The maximum number of indexes that can be created")
public int maxNumIndexes = 20;

public enum SQLite3OracleFactory implements OracleFactory<SQLite3GlobalState> {
PQS {
@Override
Expand Down
60 changes: 34 additions & 26 deletions 60 src/sqlancer/sqlite3/SQLite3Provider.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -58,47 +58,50 @@ public SQLite3Provider() {
}

public enum Action implements AbstractAction<SQLite3GlobalState> {
PRAGMA(SQLite3PragmaGenerator::insertPragma), //
INDEX(SQLite3IndexGenerator::insertIndex), //
INSERT(SQLite3InsertGenerator::insertRow), //
VACUUM(SQLite3VacuumGenerator::executeVacuum), //
REINDEX(SQLite3ReindexGenerator::executeReindex), //
ANALYZE(SQLite3AnalyzeGenerator::generateAnalyze), //
DELETE(SQLite3DeleteGenerator::deleteContent), //
PRAGMA(SQLite3PragmaGenerator::insertPragma), // 0
Comment thread

@mrigger mrigger Dec 18, 2022

Copy link
Copy Markdown
Contributor

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.

Not sure why we are numbering the actions here?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bajinsheng bajinsheng Dec 18, 2022

Copy link
Copy Markdown
Collaborator Author

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.

I number these actions for debugging. The enumeration variable only includes index information in execution, and these numbers help me to quickly locate which action is selected and executed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
CREATE_INDEX(SQLite3IndexGenerator::insertIndex), // 1
CREATE_VIEW(SQLite3ViewGenerator::generate), // 2
CREATE_TRIGGER(SQLite3CreateTriggerGenerator::create), // 3
CREATE_TABLE(SQLite3TableGenerator::createRandomTableStatement), // 4
CREATE_VIRTUALTABLE(SQLite3CreateVirtualFTSTableGenerator::createRandomTableStatement), // 5
CREATE_RTREETABLE(SQLite3CreateVirtualRtreeTabelGenerator::createRandomTableStatement), // 6
INSERT(SQLite3InsertGenerator::insertRow), // 7
DELETE(SQLite3DeleteGenerator::deleteContent), // 8
ALTER(SQLite3AlterTable::alterTable), // 9
UPDATE(SQLite3UpdateGenerator::updateRow), // 10
DROP_INDEX(SQLite3DropIndexGenerator::dropIndex), // 11
DROP_TABLE(SQLite3DropTableGenerator::dropTable), // 12
DROP_VIEW(SQLite3ViewGenerator::dropView), // 13
VACUUM(SQLite3VacuumGenerator::executeVacuum), // 14
REINDEX(SQLite3ReindexGenerator::executeReindex), // 15
ANALYZE(SQLite3AnalyzeGenerator::generateAnalyze), // 16
EXPLAIN(SQLite3ExplainGenerator::explain), // 17
CHECK_RTREE_TABLE((g) -> {
SQLite3Table table = g.getSchema().getRandomTableOrBailout(t -> t.getName().startsWith("r"));
String format = String.format("SELECT rtreecheck('%s');", table.getName());
return new SQLQueryAdapter(format, ExpectedErrors.from("The database file is locked"));
}), // 18
VIRTUAL_TABLE_ACTION(SQLite3VirtualFTSTableCommandGenerator::create), // 19
MANIPULATE_STAT_TABLE(SQLite3StatTableGenerator::getQuery), // 20
TRANSACTION_START(SQLite3TransactionGenerator::generateBeginTransaction) {
@Override
public boolean canBeRetried() {
return false;
}

}, //
ALTER(SQLite3AlterTable::alterTable), //
DROP_INDEX(SQLite3DropIndexGenerator::dropIndex), //
UPDATE(SQLite3UpdateGenerator::updateRow), //
}, // 21
ROLLBACK_TRANSACTION(SQLite3TransactionGenerator::generateRollbackTransaction) {
@Override
public boolean canBeRetried() {
return false;
}
}, //
}, // 22
COMMIT(SQLite3TransactionGenerator::generateCommit) {
@Override
public boolean canBeRetried() {
return false;
}
}, //
DROP_TABLE(SQLite3DropTableGenerator::dropTable), //
DROP_VIEW(SQLite3ViewGenerator::dropView), //
EXPLAIN(SQLite3ExplainGenerator::explain), //
CHECK_RTREE_TABLE((g) -> {
SQLite3Table table = g.getSchema().getRandomTableOrBailout(t -> t.getName().startsWith("r"));
String format = String.format("SELECT rtreecheck('%s');", table.getName());
return new SQLQueryAdapter(format, ExpectedErrors.from("The database file is locked"));
}), //
VIRTUAL_TABLE_ACTION(SQLite3VirtualFTSTableCommandGenerator::create), //
CREATE_VIEW(SQLite3ViewGenerator::generate), //
CREATE_TRIGGER(SQLite3CreateTriggerGenerator::create), //
MANIPULATE_STAT_TABLE(SQLite3StatTableGenerator::getQuery);
}; // 23

private final SQLQueryProvider<SQLite3GlobalState> sqlQueryProvider;

Expand Down Expand Up @@ -146,7 +149,7 @@ private static int mapActions(SQLite3GlobalState globalState, Action a) {
case MANIPULATE_STAT_TABLE:
nrPerformed = r.getInteger(0, 5);
break;
case INDEX:
case CREATE_INDEX:
nrPerformed = r.getInteger(0, 5);
break;
case VIRTUAL_TABLE_ACTION:
Expand All @@ -156,6 +159,11 @@ private static int mapActions(SQLite3GlobalState globalState, Action a) {
case PRAGMA:
nrPerformed = r.getInteger(0, 20);
break;
case CREATE_TABLE:
case CREATE_VIRTUALTABLE:
case CREATE_RTREETABLE:
nrPerformed = 0;
break;
case TRANSACTION_START:
case REINDEX:
case ANALYZE:
Expand Down
9 changes: 9 additions & 0 deletions 9 src/sqlancer/sqlite3/gen/SQLite3CreateVirtualRtreeTabelGenerator.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import sqlancer.IgnoreMeException;
import sqlancer.Randomly;
import sqlancer.common.DBMSCommon;
import sqlancer.common.query.ExpectedErrors;
Expand All @@ -15,6 +16,14 @@ public final class SQLite3CreateVirtualRtreeTabelGenerator {
private SQLite3CreateVirtualRtreeTabelGenerator() {
}

public static SQLQueryAdapter createRandomTableStatement(SQLite3GlobalState globalState) {
if (globalState.getSchema().getTables().getTables()
.size() > globalState.getDbmsSpecificOptions().maxNumTables) {
throw new IgnoreMeException();
}
return createTableStatement(globalState.getSchema().getFreeRtreeTableName(), globalState);
}

public static SQLQueryAdapter createTableStatement(String rTreeTableName, SQLite3GlobalState globalState) {
ExpectedErrors errors = new ExpectedErrors();
List<SQLite3Column> columns = new ArrayList<>();
Expand Down
7 changes: 7 additions & 0 deletions 7 src/sqlancer/sqlite3/gen/SQLite3ExplainGenerator.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ public static SQLQueryAdapter explain(SQLite3GlobalState globalState) throws Exc
return new SQLQueryAdapter(sb.toString(), query.getExpectedErrors());
}

public static String explain(String selectStr) throws Exception {
StringBuilder sb = new StringBuilder();
sb.append("EXPLAIN QUERY PLAN ");
sb.append(selectStr);
return sb.toString();
}

}
10 changes: 10 additions & 0 deletions 10 src/sqlancer/sqlite3/gen/ddl/SQLite3CreateVirtualFTSTableGenerator.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import java.util.Arrays;
import java.util.List;

import sqlancer.IgnoreMeException;
import sqlancer.Randomly;
import sqlancer.common.DBMSCommon;
import sqlancer.common.query.ExpectedErrors;
import sqlancer.common.query.SQLQueryAdapter;
import sqlancer.sqlite3.SQLite3GlobalState;

public class SQLite3CreateVirtualFTSTableGenerator {

Expand All @@ -20,6 +22,14 @@ public SQLite3CreateVirtualFTSTableGenerator(String tableName, Randomly r) {
this.r = r;
}

public static SQLQueryAdapter createRandomTableStatement(SQLite3GlobalState globalState) {
if (globalState.getSchema().getTables().getTables()
.size() > globalState.getDbmsSpecificOptions().maxNumTables) {
throw new IgnoreMeException();
}
return createTableStatement(globalState.getSchema().getFreeVirtualTableName(), globalState.getRandomly());
}

public static SQLQueryAdapter createTableStatement(String tableName, Randomly r) {
return new SQLite3CreateVirtualFTSTableGenerator(tableName, r).create();
}
Expand Down
4 changes: 4 additions & 0 deletions 4 src/sqlancer/sqlite3/gen/ddl/SQLite3IndexGenerator.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.sql.SQLException;
import java.util.List;

import sqlancer.IgnoreMeException;
import sqlancer.Randomly;
import sqlancer.common.query.ExpectedErrors;
import sqlancer.common.query.SQLQueryAdapter;
Expand All @@ -23,6 +24,9 @@ public class SQLite3IndexGenerator {
private final SQLite3GlobalState globalState;

public static SQLQueryAdapter insertIndex(SQLite3GlobalState globalState) throws SQLException {
if (globalState.getSchema().getIndexNames().size() >= globalState.getDbmsSpecificOptions().maxNumIndexes) {
throw new IgnoreMeException();
}
return new SQLite3IndexGenerator(globalState).create();
}

Expand Down
9 changes: 9 additions & 0 deletions 9 src/sqlancer/sqlite3/gen/ddl/SQLite3TableGenerator.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.stream.Collectors;

import sqlancer.IgnoreMeException;
import sqlancer.Randomly;
import sqlancer.common.DBMSCommon;
import sqlancer.common.query.ExpectedErrors;
Expand Down Expand Up @@ -46,6 +47,14 @@ public SQLite3TableGenerator(String tableName, SQLite3GlobalState globalState) {
this.existingSchema = globalState.getSchema();
}

public static SQLQueryAdapter createRandomTableStatement(SQLite3GlobalState globalState) {
if (globalState.getSchema().getTables().getTables()
.size() > globalState.getDbmsSpecificOptions().maxNumTables) {
throw new IgnoreMeException();
}
return createTableStatement(globalState.getSchema().getFreeTableName(), globalState);
}

public static SQLQueryAdapter createTableStatement(String tableName, SQLite3GlobalState globalState) {
SQLite3TableGenerator sqLite3TableGenerator = new SQLite3TableGenerator(tableName, globalState);
sqLite3TableGenerator.start();
Expand Down
5 changes: 5 additions & 0 deletions 5 src/sqlancer/sqlite3/gen/ddl/SQLite3ViewGenerator.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.sql.SQLException;

import sqlancer.IgnoreMeException;
import sqlancer.Randomly;
import sqlancer.common.DBMSCommon;
import sqlancer.common.query.ExpectedErrors;
Expand Down Expand Up @@ -29,6 +30,10 @@ public static SQLQueryAdapter dropView(SQLite3GlobalState globalState) {
}

public static SQLQueryAdapter generate(SQLite3GlobalState globalState) throws SQLException {
if (globalState.getSchema().getTables().getTables()
.size() >= globalState.getDbmsSpecificOptions().maxNumTables) {
throw new IgnoreMeException();
}
StringBuilder sb = new StringBuilder();
sb.append("CREATE");
if (globalState.getDbmsSpecificOptions().testTempTables && Randomly.getBoolean()) {
Expand Down
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.