Skip to content

Commit a2c700a

Browse files
committed
[SQLite] Prefix schema classes
1 parent 5789b99 commit a2c700a

34 files changed

+260
-260
lines changed

src/sqlancer/DatabaseFacade.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.sql.DriverManager;
66
import java.sql.SQLException;
77

8-
import sqlancer.sqlite3.schema.SQLite3Schema.Table;
8+
import sqlancer.sqlite3.schema.SQLite3Schema.SQLite3Table;
99

1010
public class DatabaseFacade {
1111

@@ -26,7 +26,7 @@ public static Connection getConnection() throws SQLException {
2626
return DriverManager.getConnection(url, "lama", "lamalama123!");
2727
}
2828

29-
public static String queryStringToGetRandomTableRow(Table table) {
29+
public static String queryStringToGetRandomTableRow(SQLite3Table table) {
3030
return String.format("SELECT %s, %s FROM %s ORDER BY RANDOM() LIMIT 1", table.getColumnsAsString(),
3131
table.getColumnsAsString(c -> "typeof(" + c.getName() + ")"), table.getName());
3232
}

src/sqlancer/sqlite3/SQLite3Helper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
import java.sql.Statement;
66

77
import sqlancer.sqlite3.schema.SQLite3Schema;
8-
import sqlancer.sqlite3.schema.SQLite3Schema.Table;
8+
import sqlancer.sqlite3.schema.SQLite3Schema.SQLite3Table;
99

1010
public class SQLite3Helper {
1111

1212

1313

14-
public static void dropTable(Connection con, Table table) throws SQLException {
14+
public static void dropTable(Connection con, SQLite3Table table) throws SQLException {
1515
try (Statement s = con.createStatement()) {
1616
s.execute("DROP TABLE IF EXISTS " + table.getName());
1717
}
1818
}
1919

2020
public static void deleteAllTables(Connection con) throws SQLException {
2121
SQLite3Schema previousSchema = SQLite3Schema.fromConnection(con);
22-
for (Table t : previousSchema.getDatabaseTables()) {
22+
for (SQLite3Table t : previousSchema.getDatabaseTables()) {
2323
dropTable(con, t);
2424
}
2525
}

src/sqlancer/sqlite3/SQLite3Provider.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
import sqlancer.sqlite3.gen.dml.SQLite3UpdateGenerator;
5050
import sqlancer.sqlite3.schema.SQLite3Schema;
5151
import sqlancer.sqlite3.schema.SQLite3Schema.SQLite3Column;
52-
import sqlancer.sqlite3.schema.SQLite3Schema.Table;
53-
import sqlancer.sqlite3.schema.SQLite3Schema.Table.TableKind;
52+
import sqlancer.sqlite3.schema.SQLite3Schema.SQLite3Table;
53+
import sqlancer.sqlite3.schema.SQLite3Schema.SQLite3Table.TableKind;
5454

5555
public class SQLite3Provider implements DatabaseProvider<SQLite3GlobalState> {
5656

@@ -78,7 +78,7 @@ public static enum Action {
7878
DROP_VIEW(SQLite3ViewGenerator::dropView), //
7979
EXPLAIN(SQLite3ExplainGenerator::explain), //
8080
CHECK_RTREE_TABLE((g) -> {
81-
Table table = g.getSchema().getRandomTableOrBailout(t -> t.getName().startsWith("r"));
81+
SQLite3Table table = g.getSchema().getRandomTableOrBailout(t -> t.getName().startsWith("r"));
8282
String format = String.format("SELECT rtreecheck('%s');", table.getName());
8383
return new QueryAdapter(format);
8484
}), //
@@ -87,7 +87,7 @@ public static enum Action {
8787
CREATE_TRIGGER(SQLite3CreateTriggerGenerator::create), //
8888
MANIPULATE_STAT_TABLE((g) -> {
8989
List<SQLite3Column> columns = new ArrayList<>();
90-
Table t = new Table("sqlite_stat1", columns, TableKind.MAIN, false, 1, false, false, false);
90+
SQLite3Table t = new SQLite3Table("sqlite_stat1", columns, TableKind.MAIN, false, 1, false, false, false);
9191
if (Randomly.getBoolean()) {
9292
return SQLite3DeleteGenerator.deleteContent(g, t);
9393
} else {
@@ -332,7 +332,7 @@ public void generateAndTestDatabase(SQLite3GlobalState globalState) throws SQLEx
332332
manager.incrementCreateDatabase();
333333
TestOracle oracle = globalState.getSqliteOptions().oracle.create(globalState);
334334
if (oracle.onlyWorksForNonEmptyTables()) {
335-
for (Table table : globalState.getSchema().getDatabaseTables()) {
335+
for (SQLite3Table table : globalState.getSchema().getDatabaseTables()) {
336336
int nrRows = SQLite3Schema.getNrRows(con, table.getName());
337337
if (nrRows == 0) {
338338
throw new IgnoreMeException();
@@ -360,7 +360,7 @@ public void generateAndTestDatabase(SQLite3GlobalState globalState) throws SQLEx
360360
}
361361

362362
private void checkTablesForGeneratedColumnLoops(Connection con, SQLite3Schema newSchema) throws SQLException {
363-
for (Table table : newSchema.getDatabaseTables()) {
363+
for (SQLite3Table table : newSchema.getDatabaseTables()) {
364364
Query q = new QueryAdapter("SELECT * FROM " + table.getName(),
365365
Arrays.asList("needs an odd number of arguments", " requires an even number of arguments",
366366
"generated column loop", "integer overflow", "malformed JSON",
@@ -445,9 +445,9 @@ public void printDatabaseSpecificState(FileWriter writer, StateToReproduce state
445445
if (specificState.getRandomRowValues() != null) {
446446
List<SQLite3Column> columnList = specificState.getRandomRowValues().keySet().stream()
447447
.collect(Collectors.toList());
448-
List<Table> tableList = columnList.stream().map(c -> c.getTable()).distinct().sorted()
448+
List<SQLite3Table> tableList = columnList.stream().map(c -> c.getTable()).distinct().sorted()
449449
.collect(Collectors.toList());
450-
for (Table t : tableList) {
450+
for (SQLite3Table t : tableList) {
451451
sb.append("-- " + t.getName() + "\n");
452452
List<SQLite3Column> columnsForTable = columnList.stream().filter(c -> c.getTable().equals(t))
453453
.collect(Collectors.toList());

src/sqlancer/sqlite3/ast/SQLite3Aggregate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import sqlancer.Randomly;
99
import sqlancer.sqlite3.SQLite3Provider;
1010
import sqlancer.sqlite3.schema.SQLite3DataType;
11-
import sqlancer.sqlite3.schema.SQLite3Schema.SQLite3Column.CollateSequence;
11+
import sqlancer.sqlite3.schema.SQLite3Schema.SQLite3Column.SQLite3CollateSequence;
1212

1313
/**
1414
* @see https://www.sqlite.org/lang_aggfunc.html
@@ -129,7 +129,7 @@ public List<SQLite3Expression> getExpr() {
129129
}
130130

131131
@Override
132-
public CollateSequence getExplicitCollateSequence() {
132+
public SQLite3CollateSequence getExplicitCollateSequence() {
133133
return null;
134134
// return expr.getExplicitCollateSequence();
135135
}

src/sqlancer/sqlite3/ast/SQLite3Case.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.util.Optional;
44

5-
import sqlancer.sqlite3.schema.SQLite3Schema.SQLite3Column.CollateSequence;
5+
import sqlancer.sqlite3.schema.SQLite3Schema.SQLite3Column.SQLite3CollateSequence;
66

77
public abstract class SQLite3Case extends SQLite3Expression {
88

@@ -41,7 +41,7 @@ public SQLite3Expression getElseExpr() {
4141
return elseExpr;
4242
}
4343

44-
protected CollateSequence getExplicitCasePairAndElseCollate() {
44+
protected SQLite3CollateSequence getExplicitCasePairAndElseCollate() {
4545
for (CasePair c : pairs) {
4646
if (c.getCond().getExplicitCollateSequence() != null) {
4747
return c.getCond().getExplicitCollateSequence();
@@ -63,7 +63,7 @@ public SQLite3CaseWithoutBaseExpression(CasePair[] pairs, SQLite3Expression else
6363
}
6464

6565
@Override
66-
public CollateSequence getExplicitCollateSequence() {
66+
public SQLite3CollateSequence getExplicitCollateSequence() {
6767
return getExplicitCasePairAndElseCollate();
6868
}
6969

@@ -98,7 +98,7 @@ public SQLite3CaseWithBaseExpression(SQLite3Expression baseExpr, CasePair[] pair
9898
}
9999

100100
@Override
101-
public CollateSequence getExplicitCollateSequence() {
101+
public SQLite3CollateSequence getExplicitCollateSequence() {
102102
if (baseExpr.getExplicitCollateSequence() != null) {
103103
return baseExpr.getExplicitCollateSequence();
104104
} else {
@@ -121,7 +121,7 @@ public SQLite3Constant getExpectedValue() {
121121
if (whenComparisonValue == null) {
122122
return null;
123123
}// TODO collate
124-
CollateSequence seq;
124+
SQLite3CollateSequence seq;
125125
if (baseExpr.getExplicitCollateSequence() != null) {
126126
seq = baseExpr.getExplicitCollateSequence();
127127
} else if (whenComparisonValue.getExplicitCollateSequence() != null) {
@@ -131,7 +131,7 @@ public SQLite3Constant getExpectedValue() {
131131
} else if (whenComparisonValue.getImplicitCollateSequence() != null) {
132132
seq = c.getCond().getImplicitCollateSequence();
133133
} else {
134-
seq = CollateSequence.BINARY;
134+
seq = SQLite3CollateSequence.BINARY;
135135
}
136136
ConstantTuple newVals = applyAffinities(baseExpr.getAffinity(), c.getCond().getAffinity(), baseExpr.getExpectedValue(), c.getCond().getExpectedValue());
137137
SQLite3Constant equals = newVals.left.applyEquals(newVals.right, seq);

src/sqlancer/sqlite3/ast/SQLite3Constant.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sqlancer.Randomly;
88
import sqlancer.sqlite3.SQLite3Visitor;
99
import sqlancer.sqlite3.schema.SQLite3DataType;
10-
import sqlancer.sqlite3.schema.SQLite3Schema.SQLite3Column.CollateSequence;
10+
import sqlancer.sqlite3.schema.SQLite3Schema.SQLite3Column.SQLite3CollateSequence;
1111

1212
public abstract class SQLite3Constant extends SQLite3Expression {
1313

@@ -29,7 +29,7 @@ public SQLite3DataType getDataType() {
2929
}
3030

3131
@Override
32-
public SQLite3Constant applyEquals(SQLite3Constant right, CollateSequence collate) {
32+
public SQLite3Constant applyEquals(SQLite3Constant right, SQLite3CollateSequence collate) {
3333
return SQLite3Constant.createNullConstant();
3434
}
3535

@@ -54,7 +54,7 @@ public SQLite3Constant castToBoolean() {
5454
}
5555

5656
@Override
57-
public SQLite3Constant applyLess(SQLite3Constant right, CollateSequence collate) {
57+
public SQLite3Constant applyLess(SQLite3Constant right, SQLite3CollateSequence collate) {
5858
return SQLite3Constant.createNullConstant();
5959
}
6060

@@ -89,7 +89,7 @@ public SQLite3DataType getDataType() {
8989
}
9090

9191
@Override
92-
public SQLite3Constant applyEquals(SQLite3Constant right, CollateSequence collate) {
92+
public SQLite3Constant applyEquals(SQLite3Constant right, SQLite3CollateSequence collate) {
9393
if (right instanceof SQLite3RealConstant) {
9494
if (Double.isInfinite(right.asDouble())) {
9595
return SQLite3Constant.createFalse();
@@ -128,7 +128,7 @@ public SQLite3Constant castToBoolean() {
128128
}
129129

130130
@Override
131-
public SQLite3Constant applyLess(SQLite3Constant right, CollateSequence collate) {
131+
public SQLite3Constant applyLess(SQLite3Constant right, SQLite3CollateSequence collate) {
132132
if (right.isNull()) {
133133
return right;
134134
} else if (right.getDataType() == SQLite3DataType.TEXT || right.getDataType() == SQLite3DataType.BINARY) {
@@ -180,7 +180,7 @@ public SQLite3DataType getDataType() {
180180
}
181181

182182
@Override
183-
public SQLite3Constant applyEquals(SQLite3Constant right, CollateSequence collate) {
183+
public SQLite3Constant applyEquals(SQLite3Constant right, SQLite3CollateSequence collate) {
184184
if (right instanceof SQLite3RealConstant) {
185185
return SQLite3Constant.createBoolean(value == right.asDouble());
186186
} else if (right instanceof SQLite3IntConstant) {
@@ -219,7 +219,7 @@ public SQLite3Constant castToBoolean() {
219219
}
220220

221221
@Override
222-
public SQLite3Constant applyLess(SQLite3Constant right, CollateSequence collate) {
222+
public SQLite3Constant applyLess(SQLite3Constant right, SQLite3CollateSequence collate) {
223223
if (right.isNull()) {
224224
return right;
225225
} else if (right.getDataType() == SQLite3DataType.TEXT || right.getDataType() == SQLite3DataType.BINARY) {
@@ -274,7 +274,7 @@ public SQLite3DataType getDataType() {
274274

275275

276276
@Override
277-
public SQLite3Constant applyEquals(SQLite3Constant right, CollateSequence collate) {
277+
public SQLite3Constant applyEquals(SQLite3Constant right, SQLite3CollateSequence collate) {
278278
if (right.isNull()) {
279279
return SQLite3Constant.createNullConstant();
280280
} else if (right instanceof SQLite3TextConstant) {
@@ -382,7 +382,7 @@ public SQLite3Constant castToBoolean() {
382382
}
383383

384384
@Override
385-
public SQLite3Constant applyLess(SQLite3Constant right, CollateSequence collate) {
385+
public SQLite3Constant applyLess(SQLite3Constant right, SQLite3CollateSequence collate) {
386386
if (right.isNull()) {
387387
return right;
388388
} else if (right.getDataType() == SQLite3DataType.BINARY) {
@@ -467,7 +467,7 @@ String getStringRepresentation() {
467467
}
468468

469469
@Override
470-
public SQLite3Constant applyEquals(SQLite3Constant right, CollateSequence collate) {
470+
public SQLite3Constant applyEquals(SQLite3Constant right, SQLite3CollateSequence collate) {
471471
if (right.isNull()) {
472472
return SQLite3Constant.createNullConstant();
473473
} else if (right.getDataType() == SQLite3DataType.BINARY) {
@@ -493,7 +493,7 @@ public SQLite3Constant castToBoolean() {
493493
}
494494

495495
@Override
496-
public SQLite3Constant applyLess(SQLite3Constant right, CollateSequence collate) {
496+
public SQLite3Constant applyLess(SQLite3Constant right, SQLite3CollateSequence collate) {
497497
if (right.isNull()) {
498498
return right;
499499
} else if (right.getDataType() == SQLite3DataType.TEXT || right.getDataType() == SQLite3DataType.INT
@@ -573,7 +573,7 @@ public SQLite3Constant getExpectedValue() {
573573
}
574574

575575
@Override
576-
public CollateSequence getExplicitCollateSequence() {
576+
public SQLite3CollateSequence getExplicitCollateSequence() {
577577
return null;
578578
}
579579

@@ -598,14 +598,14 @@ public static SQLite3Constant createBoolean(boolean tr) {
598598
return new SQLite3Constant.SQLite3IntConstant(tr ? 1 : 0);
599599
}
600600

601-
public abstract SQLite3Constant applyEquals(SQLite3Constant right, CollateSequence collate);
601+
public abstract SQLite3Constant applyEquals(SQLite3Constant right, SQLite3CollateSequence collate);
602602

603-
public abstract SQLite3Constant applyLess(SQLite3Constant right, CollateSequence collate);
603+
public abstract SQLite3Constant applyLess(SQLite3Constant right, SQLite3CollateSequence collate);
604604

605605
public abstract SQLite3Constant castToBoolean();
606606

607607
public SQLite3Constant applyEquals(SQLite3Constant right) {
608-
return applyEquals(right, CollateSequence.BINARY);
608+
return applyEquals(right, SQLite3CollateSequence.BINARY);
609609
}
610610

611611
public boolean isReal() {

0 commit comments

Comments
 (0)