mirror of https://github.com/AMT-Cheif/drift.git
Fix crash when variables appear more than once
This commit is contained in:
parent
df05e643e0
commit
02a8dabd63
|
@ -71,7 +71,9 @@ class PureDefaults extends Table {
|
|||
'allTodosWithCategory': 'SELECT t.*, c.id as catId, c."desc" as catDesc '
|
||||
'FROM todos t INNER JOIN categories c ON c.id = t.category',
|
||||
'deleteTodoById': 'DELETE FROM todos WHERE id = ?',
|
||||
'withIn': 'SELECT * FROM todos WHERE title = ?2 OR id IN ? OR title = ?1'
|
||||
'withIn': 'SELECT * FROM todos WHERE title = ?2 OR id IN ? OR title = ?1',
|
||||
'search':
|
||||
'SELECT * FROM todos WHERE CASE WHEN -1 = :id THEN 1 ELSE id = :id END',
|
||||
},
|
||||
)
|
||||
class TodoDb extends _$TodoDb {
|
||||
|
|
|
@ -1270,6 +1270,38 @@ abstract class _$TodoDb extends GeneratedDatabase {
|
|||
}).map((rows) => rows.map(_rowToTodoEntry).toList());
|
||||
}
|
||||
|
||||
TodoEntry _rowToTodoEntry(QueryRow row) {
|
||||
return TodoEntry(
|
||||
id: row.readInt('id'),
|
||||
title: row.readString('title'),
|
||||
content: row.readString('content'),
|
||||
targetDate: row.readDateTime('target_date'),
|
||||
category: row.readInt('category'),
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<TodoEntry>> search(
|
||||
int id,
|
||||
{@Deprecated('No longer needed with Moor 1.6 - see the changelog for details')
|
||||
QueryEngine operateOn}) {
|
||||
return (operateOn ?? this).customSelect(
|
||||
'SELECT * FROM todos WHERE CASE WHEN -1 = :id THEN 1 ELSE id = :id END',
|
||||
variables: [
|
||||
Variable.withInt(id),
|
||||
]).then((rows) => rows.map(_rowToTodoEntry).toList());
|
||||
}
|
||||
|
||||
Stream<List<TodoEntry>> watchSearch(int id) {
|
||||
return customSelectStream(
|
||||
'SELECT * FROM todos WHERE CASE WHEN -1 = :id THEN 1 ELSE id = :id END',
|
||||
variables: [
|
||||
Variable.withInt(id),
|
||||
],
|
||||
readsFrom: {
|
||||
todosTable
|
||||
}).map((rows) => rows.map(_rowToTodoEntry).toList());
|
||||
}
|
||||
|
||||
@override
|
||||
List<TableInfo> get allTables => [
|
||||
todosTable,
|
||||
|
|
|
@ -195,7 +195,8 @@ class QueryWriter {
|
|||
var lastIndex = 0;
|
||||
|
||||
for (var sqlVar in vars) {
|
||||
final moorVar = query.variables.singleWhere((f) => f.variable == sqlVar);
|
||||
final moorVar = query.variables
|
||||
.singleWhere((f) => f.variable.resolvedIndex == sqlVar.resolvedIndex);
|
||||
if (!moorVar.isArray) continue;
|
||||
|
||||
// write everything that comes before this var into the buffer
|
||||
|
|
Loading…
Reference in New Issue