This commit is contained in:
Gwendal Roué committed 2022-01-16 14:50:55 +01:00
1 parent 42d29b305e
commit b53b43b1fc
5 files changed
+24 -22

No files matched your search

+2 -2
View File
@@ -143,7 +143,7 @@ public final class DatabaseValueCursor<Value: DatabaseValueConvertible>: Databas
}
// Assume cursor is created for immediate iteration: reset and set arguments
statement.reset(withArguments: arguments)
try statement.reset(withArguments: arguments)
}
deinit {
@@ -188,7 +188,7 @@ public final class NullableDatabaseValueCursor<Value: DatabaseValueConvertible>:
}
// Assume cursor is created for immediate iteration: reset and set arguments
statement.reset(withArguments: arguments)
try statement.reset(withArguments: arguments)
}
deinit {
+1 -1
View File
@@ -1211,7 +1211,7 @@ public final class RowCursor: DatabaseCursor {
self._row = try Row(statement: statement).adapted(with: adapter, layout: statement)
// Assume cursor is created for immediate iteration: reset and set arguments
statement.reset(withArguments: arguments)
try statement.reset(withArguments: arguments)
}
deinit {
+18 -16
View File
@@ -129,15 +129,6 @@ public final class Statement {
sqlite3_finalize(sqliteStatement)
}
final func reset() throws {
SchedulingWatchdog.preconditionValidQueue(database)
let code = sqlite3_reset(sqliteStatement)
guard code == SQLITE_OK else {
throw DatabaseError(resultCode: code, message: database.lastErrorMessage, sql: sql)
}
}
// MARK: Arguments
private var argumentsNeedValidation = true
@@ -278,14 +269,24 @@ public final class Statement {
}
}
func reset(withArguments arguments: StatementArguments?) {
// MARK: Execution
func reset() throws {
SchedulingWatchdog.preconditionValidQueue(database)
let code = sqlite3_reset(sqliteStatement)
guard code == SQLITE_OK else {
throw DatabaseError(resultCode: code, message: database.lastErrorMessage, sql: sql)
}
}
func reset(withArguments arguments: StatementArguments?) throws {
// Force arguments validity: it is a programmer error to provide
// arguments that do not match the statement.
if let arguments = arguments {
try! setArguments(arguments)
try setArguments(arguments)
} else if argumentsNeedValidation {
try! reset()
try! validateArguments(self.arguments)
try reset()
try validateArguments(self.arguments)
}
}
@@ -294,8 +295,7 @@ public final class Statement {
/// - parameter arguments: Optional statement arguments.
/// - throws: A DatabaseError whenever an SQLite error occurs.
public func execute(arguments: StatementArguments? = nil) throws {
SchedulingWatchdog.preconditionValidQueue(database)
reset(withArguments: arguments)
try reset(withArguments: arguments)
try database.withAuthorizer(database.statementWillExecute(self)) {
// Iterate all rows, since they may execute side effects.
while true {
@@ -472,7 +472,9 @@ final class StatementCursor: DatabaseCursor {
// Use Statement.makeCursor() instead
init(statement: Statement, arguments: StatementArguments? = nil) throws {
self.statement = statement
statement.reset(withArguments: arguments)
// Assume cursor is created for immediate iteration: reset and set arguments
try statement.reset(withArguments: arguments)
}
deinit {
+2 -2
View File
@@ -157,7 +157,7 @@ where Value: DatabaseValueConvertible & StatementColumnConvertible
}
// Assume cursor is created for immediate iteration: reset and set arguments
statement.reset(withArguments: arguments)
try statement.reset(withArguments: arguments)
}
deinit {
@@ -206,7 +206,7 @@ where Value: DatabaseValueConvertible & StatementColumnConvertible
}
// Assume cursor is created for immediate iteration: reset and set arguments
statement.reset(withArguments: arguments)
try statement.reset(withArguments: arguments)
}
deinit {
+1 -1
View File
@@ -523,7 +523,7 @@ public final class RecordCursor<Record: FetchableRecord>: DatabaseCursor {
init(statement: Statement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws {
self.statement = statement
row = try Row(statement: statement).adapted(with: adapter, layout: statement)
statement.reset(withArguments: arguments)
try statement.reset(withArguments: arguments)
}
deinit {