resolveSqliteRowLookup function
Resolves the row-lookup strategy for table (omp's
resolveTableRowLookup).
Implementation
SqliteRowLookup resolveSqliteRowLookup(SqliteDatabase db, String table) {
final pkColumns = [
for (final row in _getTableInfoRows(db, table))
if ((row['pk']! as int) > 0) row,
]..sort((a, b) => (a['pk']! as int).compareTo(b['pk']! as int));
if (pkColumns.length == 1) {
final column = pkColumns.first;
return SqlitePkLookup(column['name']! as String, column['type']! as String);
}
if (pkColumns.length > 1) {
throw StateError(
"SQLite table '$table' has a composite primary key; use '?where=' "
'instead',
);
}
final schema = getSqliteTableSchema(db, table);
if (RegExp(r'\bWITHOUT\s+ROWID\b', caseSensitive: false).hasMatch(schema)) {
throw StateError(
"SQLite table '$table' does not expose ROWID; use '?where=' instead",
);
}
return const SqliteRowidLookup();
}