diff --git a/Sources/SQLite/Core/Statement.swift b/Sources/SQLite/Core/Statement.swift index dc91d3d8..237d4812 100644 --- a/Sources/SQLite/Core/Statement.swift +++ b/Sources/SQLite/Core/Statement.swift @@ -208,7 +208,7 @@ public protocol FailableIterator : IteratorProtocol { extension FailableIterator { public func next() -> Element? { - return try! failableNext() + return try? failableNext() } } diff --git a/Sources/SQLite/Typed/Query.swift b/Sources/SQLite/Typed/Query.swift index f6ef6df8..fd7cc5c2 100644 --- a/Sources/SQLite/Typed/Query.swift +++ b/Sources/SQLite/Typed/Query.swift @@ -919,15 +919,19 @@ extension Connection { public func prepare(_ query: QueryType) throws -> AnySequence { let expression = query.expression + let statement = try prepare(expression.template, expression.bindings) let columnNames = try columnNamesForQuery(query) + + // testStatement with failableNext() is used to try and throw error when arise + let testStatement = try prepare(expression.template, expression.bindings) + let _ = try testStatement.failableNext().map { Row(columnNames, $0) } return AnySequence { AnyIterator { statement.next().map { Row(columnNames, $0) } } } } - public func prepareRowIterator(_ query: QueryType) throws -> RowIterator { let expression = query.expression