Skip to content

Commit 5f82ca9

Browse files
jeremecnoon
authored andcommitted
Removing additional availability checks that are met in SQift 4.0
1 parent 2e0ab34 commit 5f82ca9

File tree

4 files changed

+101
-118
lines changed

4 files changed

+101
-118
lines changed

Source/Connection/Functions/Function.swift

+1-6
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,7 @@ extension Connection {
364364
data.withUnsafeBytes { sqlite3_result_blob64(context, $0, UInt64(data.count), SQLITE_TRANSIENT) }
365365

366366
case .zeroData(let length):
367-
if #available(iOS 10.0, macOS 10.12.0, tvOS 10.0, watchOS 3.0, *) {
368-
sqlite3_result_zeroblob64(context, length)
369-
} else {
370-
let clampedLength = Int32(exactly: length) ?? Int32.max
371-
sqlite3_result_zeroblob(context, clampedLength)
372-
}
367+
sqlite3_result_zeroblob64(context, length)
373368

374369
case .error(let message, let code):
375370
sqlite3_result_error(context, message, Int32(message.utf8.count))

Tests/Tests/Connection/Functions/BusyTests.swift

+1-7
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class BusyTestCase: BaseConnectionTestCase {
4242
var checkpointError: Error?
4343

4444
// When
45-
let timeout: TimeInterval
4645

4746
// CN (8/21/17) - I can't find a way around this issue. It seems that iOS 10 and 11 might have a
4847
// simulator bug or potentially a bug in SQLite where the timeout is actually in nanoseconds instead
@@ -52,12 +51,7 @@ class BusyTestCase: BaseConnectionTestCase {
5251
//
5352
// I also tested using `PRAGMA busy_timeout = 2000` and the same behavior is observed. I can't find
5453
// any information about this online which is odd, but we should really avoid using this in production.
55-
if #available(iOS 10.0, macOS 10.12, tvOS 10.0, *) {
56-
timeout = 20_000.0
57-
// try connection.execute("PRAGMA busy_timeout = 2000")
58-
} else {
59-
timeout = 2.0
60-
}
54+
let timeout: TimeInterval = 20_000.0
6155

6256
try connection.busyHandler(.timeout(timeout)) // throws SQLITE_BUSY error if this is disabled
6357

Tests/Tests/Connection/Functions/TraceTests.swift

+99-103
Original file line numberDiff line numberDiff line change
@@ -14,121 +14,117 @@ import XCTest
1414

1515
class TraceTestCase: BaseTestCase {
1616
func testThatConnectionCanTraceStatementEventExecution() throws {
17-
if #available(iOS 10.0, macOS 10.12.0, tvOS 10.0, watchOS 3.0, *) {
18-
// Given
19-
var connection: Connection? = try Connection(storageLocation: storageLocation)
20-
21-
let mask = (
22-
Connection.TraceEvent.statementMask |
23-
Connection.TraceEvent.profileMask |
24-
Connection.TraceEvent.rowMask |
25-
Connection.TraceEvent.connectionClosedMask
26-
)
27-
28-
var traceEvents: [Connection.TraceEvent] = []
29-
30-
// When
31-
connection?.traceEvent(mask: mask) { event in
32-
traceEvents.append(event)
17+
// Given
18+
var connection: Connection? = try Connection(storageLocation: storageLocation)
19+
20+
let mask = (
21+
Connection.TraceEvent.statementMask |
22+
Connection.TraceEvent.profileMask |
23+
Connection.TraceEvent.rowMask |
24+
Connection.TraceEvent.connectionClosedMask
25+
)
26+
27+
var traceEvents: [Connection.TraceEvent] = []
28+
29+
// When
30+
connection?.traceEvent(mask: mask) { event in
31+
traceEvents.append(event)
32+
}
33+
34+
try connection?.execute("CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)")
35+
try connection?.prepare("INSERT INTO agents VALUES(?, ?)").bind(1, "Sterling Archer").run()
36+
try connection?.prepare("INSERT INTO agents VALUES(?, ?)").bind(2, "Lana Kane").run()
37+
try connection?.stepAll("SELECT * FROM agents")
38+
39+
connection = nil
40+
41+
// Then
42+
if traceEvents.count == 11 {
43+
XCTAssertEqual(traceEvents[0].rawValue, "Statement")
44+
XCTAssertEqual(traceEvents[1].rawValue, "Profile")
45+
XCTAssertEqual(traceEvents[2].rawValue, "Statement")
46+
XCTAssertEqual(traceEvents[3].rawValue, "Profile")
47+
XCTAssertEqual(traceEvents[4].rawValue, "Statement")
48+
XCTAssertEqual(traceEvents[5].rawValue, "Profile")
49+
XCTAssertEqual(traceEvents[6].rawValue, "Statement")
50+
XCTAssertEqual(traceEvents[7].rawValue, "Row")
51+
XCTAssertEqual(traceEvents[8].rawValue, "Row")
52+
XCTAssertEqual(traceEvents[9].rawValue, "Profile")
53+
XCTAssertEqual(traceEvents[10].rawValue, "ConnectionClosed")
54+
55+
if case let .statement(statement, sql) = traceEvents[0] {
56+
XCTAssertEqual(statement, "CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)")
57+
XCTAssertEqual(sql, "CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)")
58+
}
59+
60+
if case let .profile(statement, seconds) = traceEvents[1] {
61+
XCTAssertEqual(statement, "CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)")
62+
XCTAssertGreaterThanOrEqual(seconds, 0.0)
63+
}
64+
65+
if case let .statement(statement, sql) = traceEvents[2] {
66+
XCTAssertEqual(statement, "INSERT INTO agents VALUES(1, \'Sterling Archer\')")
67+
XCTAssertEqual(sql, "INSERT INTO agents VALUES(?, ?)")
68+
}
69+
70+
if case let .profile(statement, seconds) = traceEvents[3] {
71+
XCTAssertEqual(statement, "INSERT INTO agents VALUES(1, \'Sterling Archer\')")
72+
XCTAssertGreaterThanOrEqual(seconds, 0.0)
73+
}
74+
75+
if case let .statement(statement, sql) = traceEvents[4] {
76+
XCTAssertEqual(statement, "INSERT INTO agents VALUES(2, \'Lana Kane\')")
77+
XCTAssertEqual(sql, "INSERT INTO agents VALUES(?, ?)")
78+
}
79+
80+
if case let .profile(statement, seconds) = traceEvents[5] {
81+
XCTAssertEqual(statement, "INSERT INTO agents VALUES(2, \'Lana Kane\')")
82+
XCTAssertGreaterThanOrEqual(seconds, 0.0)
83+
}
84+
85+
if case let .statement(statement, sql) = traceEvents[6] {
86+
XCTAssertEqual(statement, "SELECT * FROM agents")
87+
XCTAssertEqual(sql, "SELECT * FROM agents")
88+
}
89+
90+
if case let .row(statement) = traceEvents[7] {
91+
XCTAssertEqual(statement, "SELECT * FROM agents")
92+
}
93+
94+
if case let .row(statement) = traceEvents[8] {
95+
XCTAssertEqual(statement, "SELECT * FROM agents")
3396
}
3497

35-
try connection?.execute("CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)")
36-
try connection?.prepare("INSERT INTO agents VALUES(?, ?)").bind(1, "Sterling Archer").run()
37-
try connection?.prepare("INSERT INTO agents VALUES(?, ?)").bind(2, "Lana Kane").run()
38-
try connection?.stepAll("SELECT * FROM agents")
39-
40-
connection = nil
41-
42-
// Then
43-
if traceEvents.count == 11 {
44-
XCTAssertEqual(traceEvents[0].rawValue, "Statement")
45-
XCTAssertEqual(traceEvents[1].rawValue, "Profile")
46-
XCTAssertEqual(traceEvents[2].rawValue, "Statement")
47-
XCTAssertEqual(traceEvents[3].rawValue, "Profile")
48-
XCTAssertEqual(traceEvents[4].rawValue, "Statement")
49-
XCTAssertEqual(traceEvents[5].rawValue, "Profile")
50-
XCTAssertEqual(traceEvents[6].rawValue, "Statement")
51-
XCTAssertEqual(traceEvents[7].rawValue, "Row")
52-
XCTAssertEqual(traceEvents[8].rawValue, "Row")
53-
XCTAssertEqual(traceEvents[9].rawValue, "Profile")
54-
XCTAssertEqual(traceEvents[10].rawValue, "ConnectionClosed")
55-
56-
if case let .statement(statement, sql) = traceEvents[0] {
57-
XCTAssertEqual(statement, "CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)")
58-
XCTAssertEqual(sql, "CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)")
59-
}
60-
61-
if case let .profile(statement, seconds) = traceEvents[1] {
62-
XCTAssertEqual(statement, "CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)")
63-
XCTAssertGreaterThanOrEqual(seconds, 0.0)
64-
}
65-
66-
if case let .statement(statement, sql) = traceEvents[2] {
67-
XCTAssertEqual(statement, "INSERT INTO agents VALUES(1, \'Sterling Archer\')")
68-
XCTAssertEqual(sql, "INSERT INTO agents VALUES(?, ?)")
69-
}
70-
71-
if case let .profile(statement, seconds) = traceEvents[3] {
72-
XCTAssertEqual(statement, "INSERT INTO agents VALUES(1, \'Sterling Archer\')")
73-
XCTAssertGreaterThanOrEqual(seconds, 0.0)
74-
}
75-
76-
if case let .statement(statement, sql) = traceEvents[4] {
77-
XCTAssertEqual(statement, "INSERT INTO agents VALUES(2, \'Lana Kane\')")
78-
XCTAssertEqual(sql, "INSERT INTO agents VALUES(?, ?)")
79-
}
80-
81-
if case let .profile(statement, seconds) = traceEvents[5] {
82-
XCTAssertEqual(statement, "INSERT INTO agents VALUES(2, \'Lana Kane\')")
83-
XCTAssertGreaterThanOrEqual(seconds, 0.0)
84-
}
85-
86-
if case let .statement(statement, sql) = traceEvents[6] {
87-
XCTAssertEqual(statement, "SELECT * FROM agents")
88-
XCTAssertEqual(sql, "SELECT * FROM agents")
89-
}
90-
91-
if case let .row(statement) = traceEvents[7] {
92-
XCTAssertEqual(statement, "SELECT * FROM agents")
93-
}
94-
95-
if case let .row(statement) = traceEvents[8] {
96-
XCTAssertEqual(statement, "SELECT * FROM agents")
97-
}
98-
99-
if case let .profile(statement, seconds) = traceEvents[9] {
100-
XCTAssertEqual(statement, "SELECT * FROM agents")
101-
XCTAssertGreaterThanOrEqual(seconds, 0.0)
102-
}
103-
} else {
104-
XCTFail("traceEvents count should be 11")
98+
if case let .profile(statement, seconds) = traceEvents[9] {
99+
XCTAssertEqual(statement, "SELECT * FROM agents")
100+
XCTAssertGreaterThanOrEqual(seconds, 0.0)
105101
}
102+
} else {
103+
XCTFail("traceEvents count should be 11")
106104
}
107105
}
108106

109107
func testThatConnectionCanTraceStatementEventExecutionUsingMask() throws {
110-
if #available(iOS 10.0, macOS 10.12.0, tvOS 10.0, watchOS 3.0, *) {
111-
// Given
112-
var connection: Connection? = try Connection(storageLocation: storageLocation)
113-
var traceEvents: [Connection.TraceEvent] = []
108+
// Given
109+
var connection: Connection? = try Connection(storageLocation: storageLocation)
110+
var traceEvents: [Connection.TraceEvent] = []
114111

115-
let mask = Connection.TraceEvent.statementMask | Connection.TraceEvent.profileMask
112+
let mask = Connection.TraceEvent.statementMask | Connection.TraceEvent.profileMask
116113

117-
// When
118-
connection?.traceEvent(mask: mask) { event in
119-
traceEvents.append(event)
120-
}
114+
// When
115+
connection?.traceEvent(mask: mask) { event in
116+
traceEvents.append(event)
117+
}
121118

122-
try connection?.execute("CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)")
123-
try connection?.prepare("INSERT INTO agents VALUES(?, ?)").bind(1, "Sterling Archer").run()
124-
try connection?.prepare("INSERT INTO agents VALUES(?, ?)").bind(2, "Lana Kane").run()
125-
try connection?.stepAll("SELECT * FROM agents")
119+
try connection?.execute("CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)")
120+
try connection?.prepare("INSERT INTO agents VALUES(?, ?)").bind(1, "Sterling Archer").run()
121+
try connection?.prepare("INSERT INTO agents VALUES(?, ?)").bind(2, "Lana Kane").run()
122+
try connection?.stepAll("SELECT * FROM agents")
126123

127-
connection = nil
124+
connection = nil
128125

129-
// Then
130-
XCTAssertEqual(traceEvents.count, 8)
131-
}
126+
// Then
127+
XCTAssertEqual(traceEvents.count, 8)
132128
}
133129
}
134130

Tests/Tests/Connection/StatementTests.swift

-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ class StatementTestCase: BaseConnectionTestCase {
7171
}
7272

7373
func testThatStatementCanReturnExpandedSQLBoundWithParameters() throws {
74-
guard #available(iOS 10.0, macOS 10.12.0, tvOS 10.0, watchOS 3.0, *) else { return }
75-
7674
// Given
7775
try connection.execute("CREATE TABLE person(id INTEGER PRIMARY KEY, first_name TEXT NOT NULL)")
7876

0 commit comments

Comments
 (0)