mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
Expose RowCursor.statement, StatementCursor.statement, Statement.index(ofColumn:)
This commit is contained in:
1 parent
2785e69fc1
commit
7939ba6e05
4 files changed
+25
-9
No files matched your search
+10
-2
@@ -163,6 +163,10 @@ Release Notes
|
||||
+ subscript<Value: DatabaseValueConvertible>(_ column: Column) -> Value
|
||||
}
|
||||
|
||||
class SelectStatement {
|
||||
+ func index(ofColumn columnName: String) -> Int?
|
||||
}
|
||||
|
||||
-extension TableMapping {
|
||||
+extension MutablePersistable {
|
||||
@discardableResult static func deleteAll(_ db: Database) throws -> Int
|
||||
@@ -194,8 +198,12 @@ Release Notes
|
||||
+final class NullableColumnCursor<Value: DatabaseValueConvertible & StatementColumnConvertible> : Cursor { }
|
||||
+final class NullableDatabaseValueCursor<Value: DatabaseValueConvertible> : Cursor { }
|
||||
+final class RecordCursor<Record: RowConvertible> : Cursor { }
|
||||
+final class RowCursor : Cursor { }
|
||||
+final class StatementCursor: Cursor { }
|
||||
+final class RowCursor : Cursor {
|
||||
+ let statement: SelectStatement
|
||||
+}
|
||||
+final class StatementCursor: Cursor {
|
||||
+ let statement: SelectStatement
|
||||
+}
|
||||
extension DatabaseValueConvertible {
|
||||
- static func fetchCursor(...) throws -> DatabaseCursor<Self>
|
||||
+ static func fetchCursor(...) throws -> DatabaseValueCursor<Self>
|
||||
|
||||
+2
-2
@@ -494,9 +494,9 @@ extension Row {
|
||||
/// let rows: RowCursor = try Row.fetchCursor(db, "SELECT * FROM players")
|
||||
/// }
|
||||
public final class RowCursor : Cursor {
|
||||
private let statement: SelectStatement
|
||||
private let row: Row // Reused for performance
|
||||
public let statement: SelectStatement
|
||||
private let sqliteStatement: SQLiteStatement
|
||||
private let row: Row // Reused for performance
|
||||
private var done = false
|
||||
|
||||
init(statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws {
|
||||
|
||||
@@ -267,7 +267,7 @@ public final class SelectStatement : Statement {
|
||||
|
||||
/// Returns the index of the leftmost column named `name`, in a
|
||||
/// case-insensitive way.
|
||||
func index(ofColumn name: String) -> Int? {
|
||||
public func index(ofColumn name: String) -> Int? {
|
||||
return columnIndexes[name.lowercased()]
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ public final class SelectStatement : Statement {
|
||||
/// let cursor: StatementCursor = statement.cursor()
|
||||
/// }
|
||||
public final class StatementCursor: Cursor {
|
||||
private let statement: SelectStatement
|
||||
public let statement: SelectStatement
|
||||
private let sqliteStatement: SQLiteStatement
|
||||
private var done = false
|
||||
|
||||
|
||||
@@ -4,6 +4,11 @@ import XCTest
|
||||
#elseif GRDBCUSTOMSQLITE
|
||||
import GRDBCustomSQLite
|
||||
#else
|
||||
#if SWIFT_PACKAGE
|
||||
import CSQLite
|
||||
#else
|
||||
import SQLite3
|
||||
#endif
|
||||
import GRDB
|
||||
#endif
|
||||
|
||||
@@ -12,7 +17,10 @@ class RowFetchTests: GRDBTestCase {
|
||||
func testFetchCursor() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
func test<C: Cursor>(_ cursor: C) throws where C.Element == Row {
|
||||
func test(_ cursor: RowCursor) throws {
|
||||
// Check that RowCursor gives access to the raw SQLite API
|
||||
XCTAssertEqual(String(cString: sqlite3_column_name(cursor.statement.sqliteStatement, 0)), "firstName")
|
||||
|
||||
var row = try cursor.next()!
|
||||
XCTAssertEqual(row["firstName"] as String, "Arthur")
|
||||
XCTAssertEqual(row["lastName"] as String, "Martin")
|
||||
@@ -46,7 +54,7 @@ class RowFetchTests: GRDBTestCase {
|
||||
let customError = NSError(domain: "Custom", code: 0xDEAD)
|
||||
dbQueue.add(function: DatabaseFunction("throw", argumentCount: 0, pure: true) { _ in throw customError })
|
||||
try dbQueue.inDatabase { db in
|
||||
func test<C: Cursor>(_ cursor: C, sql: String) throws where C.Element == Row {
|
||||
func test(_ cursor: RowCursor, sql: String) throws {
|
||||
do {
|
||||
_ = try cursor.next()
|
||||
XCTFail()
|
||||
@@ -87,7 +95,7 @@ class RowFetchTests: GRDBTestCase {
|
||||
func testFetchCursorCompilationFailure() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
func test<C: Cursor>(_ cursor: @autoclosure () throws -> C, sql: String) throws where C.Element == Row {
|
||||
func test(_ cursor: @autoclosure () throws -> RowCursor, sql: String) throws {
|
||||
do {
|
||||
_ = try cursor()
|
||||
XCTFail()
|
||||
|
||||
Reference in new issue
Block a user