From b6fc14d9174b22c56a05e265f959ddaffae72316 Mon Sep 17 00:00:00 2001 From: RameshBachiraju <49223707+RameshBachiraju@users.noreply.github.com> Date: Thu, 26 Dec 2019 15:31:30 +0530 Subject: [PATCH 1/2] Update Query.swift Fixing the prepare method to avoid crash --- Sources/SQLite/Typed/Query.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/SQLite/Typed/Query.swift b/Sources/SQLite/Typed/Query.swift index f6ef6df8..aa0b3be3 100644 --- a/Sources/SQLite/Typed/Query.swift +++ b/Sources/SQLite/Typed/Query.swift @@ -922,9 +922,10 @@ extension Connection { let statement = try prepare(expression.template, expression.bindings) let columnNames = try columnNamesForQuery(query) - + + let rows = try statement.failableNext().map { Row(columnNames, $0) } return AnySequence { - AnyIterator { statement.next().map { Row(columnNames, $0) } } + AnyIterator { rows } } } From e1dd57866a7562b5ca584e1c44b2bd50a220c78a Mon Sep 17 00:00:00 2001 From: RameshBachiraju <49223707+RameshBachiraju@users.noreply.github.com> Date: Mon, 30 Dec 2019 17:31:25 +0530 Subject: [PATCH 2/2] Update Query.swift Fixed AnyIterator for crash in prepare statement --- Sources/SQLite/Typed/Query.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Sources/SQLite/Typed/Query.swift b/Sources/SQLite/Typed/Query.swift index aa0b3be3..1c95e968 100644 --- a/Sources/SQLite/Typed/Query.swift +++ b/Sources/SQLite/Typed/Query.swift @@ -923,9 +923,18 @@ extension Connection { let columnNames = try columnNamesForQuery(query) - let rows = try statement.failableNext().map { Row(columnNames, $0) } return AnySequence { - AnyIterator { rows } + return AnyIterator { + do { + if let model = try statement.failableNext() { + return Row(columnNames,model) + } + } catch { + return nil + } + + return nil + } } }