Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/sqlancer/schema/AbstractTableColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ public U getType() {

@Override
public String toString() {
return String.format("%s.%s: %s", table.getName(), getName(), getType());
if (table == null) {
return String.format("%s: %s", getName(), getType());
} else {
return String.format("%s.%s: %s", table.getName(), getName(), getType());
}
}

@Override
Expand Down
22 changes: 10 additions & 12 deletions src/sqlancer/sqlite3/schema/SQLite3Schema.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,18 +409,11 @@ public static SQLite3Schema fromConnection(Connection con) throws SQLException {
SQLite3Table t = new SQLite3Table(tableName, databaseColumns,
tableType.contentEquals("temp_table") ? TableKind.TEMP : TableKind.MAIN, withoutRowid,
nrRows, isView, isVirtual, isReadOnly);
try (Statement s3 = con.createStatement()) {
try (ResultSet rs3 = s3.executeQuery("SELECT typeof(rowid) FROM " + tableName)) {
if (rs3.next() && !isView /* TODO: can we still do something with it? */) {
String dataType = rs3.getString(1);
SQLite3DataType columnType = getColumnType(dataType);
boolean generated = dataType.toUpperCase().contains("GENERATED AS");
String rowId = Randomly.fromOptions("rowid", "_rowid_", "oid");
SQLite3Column rowid = new SQLite3Column(rowId, columnType, true, null, generated);
t.addRowid(rowid);
rowid.setTable(t);
}
}
if (isRowIdTable(withoutRowid, isView, isVirtual)) {
String rowId = Randomly.fromOptions("rowid", "_rowid_", "oid");
SQLite3Column rowid = new SQLite3Column(rowId, SQLite3DataType.INT, true, null, true);
t.addRowid(rowid);
rowid.setTable(t);
}
for (SQLite3Column c : databaseColumns) {
c.setTable(t);
Expand All @@ -445,6 +438,11 @@ public static SQLite3Schema fromConnection(Connection con) throws SQLException {
return new SQLite3Schema(databaseTables, indexNames);
}

// https://www.sqlite.org/rowidtable.html
private static boolean isRowIdTable(boolean withoutRowid, boolean isView, boolean isVirtual) {
return !isView && !isVirtual && !withoutRowid;
}

private static List<SQLite3Column> getTableColumns(Connection con, String tableName, String sql, boolean isView,
boolean isDbStatsTable) throws SQLException {
List<SQLite3Column> databaseColumns = new ArrayList<>();
Expand Down