Skip to content

Commit d770710

Browse files
committed
[SQLite] Fix and refactor the detection of the rowid column
1 parent 0484bef commit d770710

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/sqlancer/sqlite3/schema/SQLite3Schema.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -409,18 +409,11 @@ public static SQLite3Schema fromConnection(Connection con) throws SQLException {
409409
SQLite3Table t = new SQLite3Table(tableName, databaseColumns,
410410
tableType.contentEquals("temp_table") ? TableKind.TEMP : TableKind.MAIN, withoutRowid,
411411
nrRows, isView, isVirtual, isReadOnly);
412-
try (Statement s3 = con.createStatement()) {
413-
try (ResultSet rs3 = s3.executeQuery("SELECT typeof(rowid) FROM " + tableName)) {
414-
if (rs3.next() && !isView /* TODO: can we still do something with it? */) {
415-
String dataType = rs3.getString(1);
416-
SQLite3DataType columnType = getColumnType(dataType);
417-
boolean generated = dataType.toUpperCase().contains("GENERATED AS");
418-
String rowId = Randomly.fromOptions("rowid", "_rowid_", "oid");
419-
SQLite3Column rowid = new SQLite3Column(rowId, columnType, true, null, generated);
420-
t.addRowid(rowid);
421-
rowid.setTable(t);
422-
}
423-
}
412+
if (isRowIdTable(withoutRowid, isView, isVirtual)) {
413+
String rowId = Randomly.fromOptions("rowid", "_rowid_", "oid");
414+
SQLite3Column rowid = new SQLite3Column(rowId, SQLite3DataType.INT, true, null, true);
415+
t.addRowid(rowid);
416+
rowid.setTable(t);
424417
}
425418
for (SQLite3Column c : databaseColumns) {
426419
c.setTable(t);
@@ -445,6 +438,11 @@ public static SQLite3Schema fromConnection(Connection con) throws SQLException {
445438
return new SQLite3Schema(databaseTables, indexNames);
446439
}
447440

441+
// https://www.sqlite.org/rowidtable.html
442+
private static boolean isRowIdTable(boolean withoutRowid, boolean isView, boolean isVirtual) {
443+
return !isView && !isVirtual && !withoutRowid;
444+
}
445+
448446
private static List<SQLite3Column> getTableColumns(Connection con, String tableName, String sql, boolean isView,
449447
boolean isDbStatsTable) throws SQLException {
450448
List<SQLite3Column> databaseColumns = new ArrayList<>();

0 commit comments

Comments
 (0)