Add unit tests
This commit is contained in:
@@ -7,7 +7,7 @@ extension Connection {
|
||||
/// - ``file(path:)``: A database at a specific file path or URI (persistent).
|
||||
/// - ``inMemory``: An in-memory database that exists only in RAM.
|
||||
/// - ``temporary``: A temporary on-disk database deleted when the connection closes.
|
||||
public enum Location {
|
||||
public enum Location: Sendable {
|
||||
/// A database stored at a given file path or URI.
|
||||
///
|
||||
/// Use this for persistent databases located on disk or referenced via SQLite URI.
|
||||
|
||||
@@ -152,7 +152,7 @@ extension Connection: ConnectionProtocol {
|
||||
sqlite3_key(connection, key.keyValue, key.length)
|
||||
}
|
||||
guard status == SQLITE_OK else {
|
||||
throw SQLiteError(connection)
|
||||
throw SQLiteError(code: status, message: "")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,13 +163,15 @@ extension Connection: ConnectionProtocol {
|
||||
sqlite3_rekey(connection, key.keyValue, key.length)
|
||||
}
|
||||
guard status == SQLITE_OK else {
|
||||
throw SQLiteError(connection)
|
||||
throw SQLiteError(code: status, message: "")
|
||||
}
|
||||
}
|
||||
|
||||
public func add(delegate: any ConnectionDelegate) {
|
||||
delegates.append(.init(delegate: delegate))
|
||||
delegates.removeAll { $0.delegate == nil }
|
||||
if !delegates.contains(where: { $0.delegate === delegate }) {
|
||||
delegates.append(.init(delegate: delegate))
|
||||
delegates.removeAll { $0.delegate == nil }
|
||||
}
|
||||
}
|
||||
|
||||
public func remove(delegate: any ConnectionDelegate) {
|
||||
@@ -179,8 +181,10 @@ extension Connection: ConnectionProtocol {
|
||||
}
|
||||
|
||||
public func add(trace delegate: any ConnectionTraceDelegate) {
|
||||
traceDelegates.append(.init(delegate: delegate))
|
||||
traceDelegates.removeAll { $0.delegate == nil }
|
||||
if !traceDelegates.contains(where: { $0.delegate === delegate }) {
|
||||
traceDelegates.append(.init(delegate: delegate))
|
||||
traceDelegates.removeAll { $0.delegate == nil }
|
||||
}
|
||||
}
|
||||
|
||||
public func remove(trace delegate: any ConnectionTraceDelegate) {
|
||||
|
||||
@@ -51,6 +51,19 @@ public final class Statement {
|
||||
// MARK: - StatementProtocol
|
||||
|
||||
extension Statement: StatementProtocol {
|
||||
public var sql: String? {
|
||||
let cSQL = sqlite3_sql(statement)
|
||||
guard let cSQL else { return nil }
|
||||
return String(cString: cSQL)
|
||||
}
|
||||
|
||||
public var expandedSQL: String? {
|
||||
let cSQL = sqlite3_expanded_sql(statement)
|
||||
defer { sqlite3_free(cSQL) }
|
||||
guard let cSQL else { return nil }
|
||||
return String(cString: cSQL)
|
||||
}
|
||||
|
||||
public func parameterCount() -> Int32 {
|
||||
sqlite3_bind_parameter_count(statement)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user