mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-28 04:24:20 +00:00
Specialize StatementColumnConvertible cursors
This commit is contained in:
1 parent
18e9b1b9aa
commit
e2c9734df1
6 files changed
+21
-10
No files matched your search
@@ -588,6 +588,7 @@ extension Database {
|
||||
/// Returns the authorizer that should be used during statement execution
|
||||
/// (this allows preventing the truncate optimization when there exists a
|
||||
/// transaction observer for row deletion).
|
||||
@usableFromInline
|
||||
func statementWillExecute(_ statement: Statement) throws -> StatementAuthorizer? {
|
||||
// Two things must prevent the statement from executing: aborted
|
||||
// transactions, and database suspension.
|
||||
@@ -603,6 +604,7 @@ extension Database {
|
||||
|
||||
/// May throw a cancelled commit error, if a transaction observer cancels
|
||||
/// an empty transaction.
|
||||
@usableFromInline
|
||||
func statementDidExecute(_ statement: Statement) throws {
|
||||
if statement.invalidatesDatabaseSchemaCache {
|
||||
clearSchemaCache()
|
||||
@@ -612,6 +614,7 @@ extension Database {
|
||||
}
|
||||
|
||||
/// Always throws an error
|
||||
@usableFromInline
|
||||
func statementDidFail(_ statement: Statement, withResultCode resultCode: Int32) throws -> Never {
|
||||
// Failed statements can not be reused, because sqlite3_reset won't
|
||||
// be able to restore the statement to its initial state:
|
||||
|
||||
@@ -248,6 +248,7 @@ public struct DatabaseError: Error, CustomStringConvertible, CustomNSError {
|
||||
///
|
||||
/// This initializer is not public because library user is not supposed to
|
||||
/// be exposed to raw result codes.
|
||||
@usableFromInline
|
||||
init(resultCode: CInt, message: String? = nil, sql: String? = nil, arguments: StatementArguments? = nil) {
|
||||
self.init(resultCode: ResultCode(rawValue: resultCode), message: message, sql: sql, arguments: arguments)
|
||||
}
|
||||
|
||||
@@ -146,6 +146,7 @@ struct RowDecodingContext {
|
||||
}
|
||||
|
||||
/// Convenience initializer
|
||||
@usableFromInline
|
||||
init(statement: Statement, index: Int) {
|
||||
self.key = .columnIndex(index)
|
||||
self.row = Row(copiedFromSQLiteStatement: statement.sqliteStatement, statement: statement)
|
||||
|
||||
@@ -58,6 +58,7 @@ public final class Statement {
|
||||
sqlite3_stmt_readonly(sqliteStatement) != 0
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
unowned let database: Database
|
||||
|
||||
/// Cache for index(ofColumn:). Keys are lowercase.
|
||||
|
||||
@@ -3,6 +3,7 @@ import Glibc
|
||||
#endif
|
||||
|
||||
/// A protocol around sqlite3_set_authorizer
|
||||
@usableFromInline
|
||||
protocol StatementAuthorizer: AnyObject {
|
||||
func authorize(
|
||||
_ actionCode: Int32,
|
||||
|
||||
@@ -129,14 +129,15 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// }
|
||||
/// }
|
||||
public final class FastDatabaseValueCursor<Value: DatabaseValueConvertible & StatementColumnConvertible> : Cursor {
|
||||
private enum _State {
|
||||
@usableFromInline
|
||||
enum _State {
|
||||
case idle, busy, done, failed
|
||||
}
|
||||
|
||||
private let _statement: Statement
|
||||
private let _columnIndex: Int32
|
||||
private let _sqliteStatement: SQLiteStatement
|
||||
private var _state = _State.idle
|
||||
@usableFromInline let _statement: Statement
|
||||
@usableFromInline let _columnIndex: Int32
|
||||
@usableFromInline let _sqliteStatement: SQLiteStatement
|
||||
@usableFromInline var _state = _State.idle
|
||||
|
||||
init(statement: Statement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws {
|
||||
_statement = statement
|
||||
@@ -162,6 +163,7 @@ public final class FastDatabaseValueCursor<Value: DatabaseValueConvertible & Sta
|
||||
try? _statement.reset()
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func next() throws -> Value? {
|
||||
switch _state {
|
||||
case .done:
|
||||
@@ -212,14 +214,15 @@ public final class FastDatabaseValueCursor<Value: DatabaseValueConvertible & Sta
|
||||
public final class FastNullableDatabaseValueCursor<Value>: Cursor
|
||||
where Value: DatabaseValueConvertible & StatementColumnConvertible
|
||||
{
|
||||
private enum _State {
|
||||
@usableFromInline
|
||||
enum _State {
|
||||
case idle, busy, done, failed
|
||||
}
|
||||
|
||||
private let _statement: Statement
|
||||
private let _columnIndex: Int32
|
||||
private let _sqliteStatement: SQLiteStatement
|
||||
private var _state = _State.idle
|
||||
@usableFromInline let _statement: Statement
|
||||
@usableFromInline let _columnIndex: Int32
|
||||
@usableFromInline let _sqliteStatement: SQLiteStatement
|
||||
@usableFromInline var _state = _State.idle
|
||||
|
||||
init(statement: Statement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws {
|
||||
_statement = statement
|
||||
@@ -245,6 +248,7 @@ where Value: DatabaseValueConvertible & StatementColumnConvertible
|
||||
try? _statement.reset()
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func next() throws -> Value?? {
|
||||
switch _state {
|
||||
case .done:
|
||||
|
||||
Reference in new issue
Block a user