readTable method
Read every row of the named user table. Both rowid tables and
WITHOUT ROWID tables are supported. For a rowid table the row's
rowid is the primary key alias; for a WITHOUT ROWID table the
returned rowid is always 0 (rows are keyed by their own columns).
Implementation
List<SqliteRow> readTable(String tableName) {
SqliteSchemaRow? schema;
for (final s in readSchema()) {
if (s.type == 'table' && s.name == tableName) {
schema = s;
break;
}
}
if (schema == null) {
throw StateError('No such table: $tableName');
}
// A WITHOUT ROWID table is stored as an INDEX B-tree (page types
// 0x02/0x0a) whose cells carry the full row record. Detect that by
// peeking the root page's type.
final rootPage = page(schema.rootPage);
final rootType = rootPage[schema.rootPage == 1 ? 100 : 0];
if (rootType == 0x02 || rootType == 0x0a) {
// Each entry IS the row record. rowid is unused (set to 0).
return [
for (final entry in _walkIndexBTree(schema.rootPage))
SqliteRow(0, entry),
];
}
return _walkTableBTree(schema.rootPage).toList();
}