mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Statement.fetchCursor() no longer throws. TODO: Type.fetchCursor(statement) should not throw
This commit is contained in:
1 parent
9523b88d77
commit
2cec3f29d1
6 files changed
+9
-8
No files matched your search
@@ -116,7 +116,7 @@ extension DatabaseValueConvertible {
|
||||
public static func fetchCursor(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DatabaseCursor<Self> {
|
||||
// Metal rows can be reused. And reusing them yields better performance.
|
||||
let row = try Row(statement: statement).adaptedRow(adapter: adapter, statement: statement)
|
||||
return try statement.fetchCursor(arguments: arguments) { () -> Self in
|
||||
return statement.fetchCursor(arguments: arguments) { () -> Self in
|
||||
let dbv: DatabaseValue = row.value(atIndex: 0)
|
||||
if let value = Self.fromDatabaseValue(dbv) {
|
||||
return value
|
||||
@@ -158,7 +158,7 @@ extension DatabaseValueConvertible {
|
||||
public static func fetchOne(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? {
|
||||
// Metal rows can be reused. And reusing them yields better performance.
|
||||
let row = try Row(statement: statement).adaptedRow(adapter: adapter, statement: statement)
|
||||
let cursor = try statement.fetchCursor(arguments: arguments) { () -> Self? in
|
||||
let cursor = statement.fetchCursor(arguments: arguments) { () -> Self? in
|
||||
let dbv: DatabaseValue = row.value(atIndex: 0)
|
||||
if let value = Self.fromDatabaseValue(dbv) {
|
||||
return value
|
||||
@@ -330,7 +330,7 @@ extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DatabaseCursor<Wrapped?> {
|
||||
let row = try Row(statement: statement).adaptedRow(adapter: adapter, statement: statement)
|
||||
return try statement.fetchCursor(arguments: arguments) { () -> Wrapped? in
|
||||
return statement.fetchCursor(arguments: arguments) { () -> Wrapped? in
|
||||
let dbv: DatabaseValue = row.value(atIndex: 0)
|
||||
if let value = Wrapped.fromDatabaseValue(dbv) {
|
||||
return value
|
||||
|
||||
+1
-1
@@ -537,7 +537,7 @@ extension Row {
|
||||
public static func fetchCursor(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DatabaseCursor<Row> {
|
||||
// Metal rows can be reused. And reusing them yields better performance.
|
||||
let row = try Row(statement: statement).adaptedRow(adapter: adapter, statement: statement)
|
||||
return try statement.fetchCursor(arguments: arguments) { row }
|
||||
return statement.fetchCursor(arguments: arguments) { row }
|
||||
}
|
||||
|
||||
/// Returns an array of rows fetched from a prepared statement.
|
||||
|
||||
@@ -253,7 +253,7 @@ public final class SelectStatement : Statement {
|
||||
}
|
||||
|
||||
/// Creates a DatabaseCursor
|
||||
func fetchCursor<Element>(arguments: StatementArguments? = nil, element: @escaping () throws -> Element) throws -> DatabaseCursor<Element> {
|
||||
func fetchCursor<Element>(arguments: StatementArguments? = nil, element: @escaping () throws -> Element) -> DatabaseCursor<Element> {
|
||||
// Check that cursor is built on a valid queue.
|
||||
SchedulingWatchdog.preconditionValidQueue(database, "Database was not used on the correct thread.")
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
// We'll read from leftmost column at index 0, unless adapter mangles columns
|
||||
let columnIndex = try Int32(adapter?.baseColumIndex(adaptedIndex: 0, with: statement) ?? 0)
|
||||
let sqliteStatement = statement.sqliteStatement
|
||||
return try statement.fetchCursor(arguments: arguments) {
|
||||
return statement.fetchCursor(arguments: arguments) {
|
||||
if sqlite3_column_type(sqliteStatement, columnIndex) == SQLITE_NULL {
|
||||
throw DatabaseError(code: SQLITE_ERROR, message: "could not convert database value NULL to \(Self.self)", sql: statement.sql, arguments: arguments)
|
||||
}
|
||||
@@ -113,7 +113,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
// We'll read from leftmost column at index 0, unless adapter mangles columns
|
||||
let columnIndex = try Int32(adapter?.baseColumIndex(adaptedIndex: 0, with: statement) ?? 0)
|
||||
let sqliteStatement = statement.sqliteStatement
|
||||
let cursor = try statement.fetchCursor(arguments: arguments) { () -> Self? in
|
||||
let cursor = statement.fetchCursor(arguments: arguments) { () -> Self? in
|
||||
if sqlite3_column_type(sqliteStatement, columnIndex) == SQLITE_NULL {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ extension RowConvertible {
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DatabaseCursor<Self> {
|
||||
let row = try Row(statement: statement).adaptedRow(adapter: adapter, statement: statement)
|
||||
return try statement.fetchCursor(arguments: arguments) {
|
||||
return statement.fetchCursor(arguments: arguments) {
|
||||
var value = self.init(row: row)
|
||||
value.awakeFromFetch(row: row)
|
||||
return value
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
- [ ] Type.fetchCursor(statement) should not throw
|
||||
- [ ] Think about supporting Cursor's underestimatedCount, which could speed up Array(cursor)
|
||||
- [ ] FetchedRecordsController: handle fetch errors
|
||||
- [ ] Swift 3.0.2 (Xcode 8.2): "Type inference will properly unwrap optionals when used with generics and implicitly-unwrapped optionals." Maybe this fixes `row.value(named: "foo") as? Int`?
|
||||
|
||||
Reference in new issue
Block a user