Skip to content

Commit 31f667f

Browse files
committed
Pod lint fixes
1 parent 8096e9b commit 31f667f

File tree

2 files changed

+50
-47
lines changed

2 files changed

+50
-47
lines changed

Sources/SQLite/Core/Connection.swift

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -415,17 +415,17 @@ public final class Connection {
415415
///
416416
/// db.trace { SQL in print(SQL) }
417417
public func trace(_ callback: ((String) -> Void)?) {
418-
#if SQLITE_SWIFT_SQLCIPHER || os(Linux)
418+
if #available(iOS 10.0, OSX 10.12, tvOS 10.0, watchOS 3.0, *) {
419+
trace_v2(callback)
420+
} else {
419421
trace_v1(callback)
420-
#else
421-
if #available(iOS 10.0, OSX 10.12, tvOS 10.0, watchOS 3.0, *) {
422-
trace_v2(callback)
423-
} else {
424-
trace_v1(callback)
425-
}
426-
#endif
422+
}
427423
}
428424

425+
@available(OSX, deprecated: 10.2)
426+
@available(iOS, deprecated: 10.0)
427+
@available(watchOS, deprecated: 3.0)
428+
@available(tvOS, deprecated: 10.0)
429429
fileprivate func trace_v1(_ callback: ((String) -> Void)?) {
430430
guard let callback = callback else {
431431
sqlite3_trace(handle, nil /* xCallback */, nil /* pCtx */)
@@ -447,8 +447,36 @@ public final class Connection {
447447
trace = box
448448
}
449449

450+
@available(iOS 10.0, OSX 10.12, tvOS 10.0, watchOS 3.0, *)
451+
fileprivate func trace_v2(_ callback: ((String) -> Void)?) {
452+
guard let callback = callback else {
453+
// If the X callback is NULL or if the M mask is zero, then tracing is disabled.
454+
sqlite3_trace_v2(handle, 0 /* mask */, nil /* xCallback */, nil /* pCtx */)
455+
trace = nil
456+
return
457+
}
450458

451-
459+
let box: Trace = { (pointer: UnsafeRawPointer) in
460+
callback(String(cString: pointer.assumingMemoryBound(to: UInt8.self)))
461+
}
462+
sqlite3_trace_v2(handle, UInt32(SQLITE_TRACE_STMT) /* mask */,
463+
{
464+
// A trace callback is invoked with four arguments: callback(T,C,P,X).
465+
// The T argument is one of the SQLITE_TRACE constants to indicate why the
466+
// callback was invoked. The C argument is a copy of the context pointer.
467+
// The P and X arguments are pointers whose meanings depend on T.
468+
(T: UInt32, C: UnsafeMutableRawPointer?, P: UnsafeMutableRawPointer?, X: UnsafeMutableRawPointer?) in
469+
if let P = P,
470+
let expandedSQL = sqlite3_expanded_sql(OpaquePointer(P)) {
471+
unsafeBitCast(C, to: Trace.self)(expandedSQL)
472+
sqlite3_free(expandedSQL)
473+
}
474+
return Int32(0) // currently ignored
475+
},
476+
unsafeBitCast(box, to: UnsafeMutableRawPointer.self) /* pCtx */
477+
)
478+
trace = box
479+
}
452480

453481
fileprivate typealias Trace = @convention(block) (UnsafeRawPointer) -> Void
454482
fileprivate var trace: Trace?
@@ -712,39 +740,3 @@ extension Result : CustomStringConvertible {
712740
}
713741
}
714742
}
715-
716-
#if !SQLITE_SWIFT_SQLCIPHER && !os(Linux)
717-
@available(iOS 10.0, OSX 10.12, tvOS 10.0, watchOS 3.0, *)
718-
extension Connection {
719-
fileprivate func trace_v2(_ callback: ((String) -> Void)?) {
720-
guard let callback = callback else {
721-
// If the X callback is NULL or if the M mask is zero, then tracing is disabled.
722-
sqlite3_trace_v2(handle, 0 /* mask */, nil /* xCallback */, nil /* pCtx */)
723-
trace = nil
724-
return
725-
}
726-
727-
let box: Trace = { (pointer: UnsafeRawPointer) in
728-
callback(String(cString: pointer.assumingMemoryBound(to: UInt8.self)))
729-
}
730-
sqlite3_trace_v2(handle,
731-
UInt32(SQLITE_TRACE_STMT) /* mask */,
732-
{
733-
// A trace callback is invoked with four arguments: callback(T,C,P,X).
734-
// The T argument is one of the SQLITE_TRACE constants to indicate why the
735-
// callback was invoked. The C argument is a copy of the context pointer.
736-
// The P and X arguments are pointers whose meanings depend on T.
737-
(T: UInt32, C: UnsafeMutableRawPointer?, P: UnsafeMutableRawPointer?, X: UnsafeMutableRawPointer?) in
738-
if let P = P,
739-
let expandedSQL = sqlite3_expanded_sql(OpaquePointer(P)) {
740-
unsafeBitCast(C, to: Trace.self)(expandedSQL)
741-
sqlite3_free(expandedSQL)
742-
}
743-
return Int32(0) // currently ignored
744-
},
745-
unsafeBitCast(box, to: UnsafeMutableRawPointer.self) /* pCtx */
746-
)
747-
trace = box
748-
}
749-
}
750-
#endif

Tests/SQLiteTests/QueryTests.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,11 @@ class QueryIntegrationTests : SQLiteTestCase {
541541
let id = try! db.run(users.insertMany([[email <- "[email protected]"], [email <- "[email protected]"]]))
542542
XCTAssertEqual(2, id)
543543
}
544-
544+
545545
func test_upsert() throws {
546+
guard db.satisfiesMinimumVersion(minor: 24) else { return }
546547
let fetchAge = { () throws -> Int? in
547-
return try self.db.pluck(self.users.filter(self.email == "[email protected]")).flatMap { $0[self.age] }
548+
try self.db.pluck(self.users.filter(self.email == "[email protected]")).flatMap { $0[self.age] }
548549
}
549550

550551
let id = try db.run(users.upsert(email <- "[email protected]", age <- 30, onConflictOf: email))
@@ -613,3 +614,13 @@ class QueryIntegrationTests : SQLiteTestCase {
613614
}
614615
}
615616
}
617+
618+
private extension Connection {
619+
func satisfiesMinimumVersion(minor: Int, patch: Int = 0) -> Bool {
620+
guard let version = try? scalar("SELECT sqlite_version()") as? String else { return false }
621+
let components = version.split(separator: ".", maxSplits: 3).compactMap { Int($0) }
622+
guard components.count == 3 else { return false }
623+
624+
return components[1] >= minor && components[2] >= patch
625+
}
626+
}

0 commit comments

Comments
 (0)