From 5f82ca9cebaf89a5bd5c83c16db5ce7084ea6e15 Mon Sep 17 00:00:00 2001 From: Jereme Claussen Date: Fri, 30 Nov 2018 12:13:29 -0800 Subject: [PATCH] Removing additional availability checks that are met in SQift 4.0 --- Source/Connection/Functions/Function.swift | 7 +- .../Connection/Functions/BusyTests.swift | 8 +- .../Connection/Functions/TraceTests.swift | 202 +++++++++--------- Tests/Tests/Connection/StatementTests.swift | 2 - 4 files changed, 101 insertions(+), 118 deletions(-) diff --git a/Source/Connection/Functions/Function.swift b/Source/Connection/Functions/Function.swift index c4371c3..314b016 100644 --- a/Source/Connection/Functions/Function.swift +++ b/Source/Connection/Functions/Function.swift @@ -364,12 +364,7 @@ extension Connection { data.withUnsafeBytes { sqlite3_result_blob64(context, $0, UInt64(data.count), SQLITE_TRANSIENT) } case .zeroData(let length): - if #available(iOS 10.0, macOS 10.12.0, tvOS 10.0, watchOS 3.0, *) { - sqlite3_result_zeroblob64(context, length) - } else { - let clampedLength = Int32(exactly: length) ?? Int32.max - sqlite3_result_zeroblob(context, clampedLength) - } + sqlite3_result_zeroblob64(context, length) case .error(let message, let code): sqlite3_result_error(context, message, Int32(message.utf8.count)) diff --git a/Tests/Tests/Connection/Functions/BusyTests.swift b/Tests/Tests/Connection/Functions/BusyTests.swift index eefd29a..2028d25 100644 --- a/Tests/Tests/Connection/Functions/BusyTests.swift +++ b/Tests/Tests/Connection/Functions/BusyTests.swift @@ -42,7 +42,6 @@ class BusyTestCase: BaseConnectionTestCase { var checkpointError: Error? // When - let timeout: TimeInterval // CN (8/21/17) - I can't find a way around this issue. It seems that iOS 10 and 11 might have a // simulator bug or potentially a bug in SQLite where the timeout is actually in nanoseconds instead @@ -52,12 +51,7 @@ class BusyTestCase: BaseConnectionTestCase { // // I also tested using `PRAGMA busy_timeout = 2000` and the same behavior is observed. I can't find // any information about this online which is odd, but we should really avoid using this in production. - if #available(iOS 10.0, macOS 10.12, tvOS 10.0, *) { - timeout = 20_000.0 - // try connection.execute("PRAGMA busy_timeout = 2000") - } else { - timeout = 2.0 - } + let timeout: TimeInterval = 20_000.0 try connection.busyHandler(.timeout(timeout)) // throws SQLITE_BUSY error if this is disabled diff --git a/Tests/Tests/Connection/Functions/TraceTests.swift b/Tests/Tests/Connection/Functions/TraceTests.swift index bcf2f61..55cb87b 100644 --- a/Tests/Tests/Connection/Functions/TraceTests.swift +++ b/Tests/Tests/Connection/Functions/TraceTests.swift @@ -14,121 +14,117 @@ import XCTest class TraceTestCase: BaseTestCase { func testThatConnectionCanTraceStatementEventExecution() throws { - if #available(iOS 10.0, macOS 10.12.0, tvOS 10.0, watchOS 3.0, *) { - // Given - var connection: Connection? = try Connection(storageLocation: storageLocation) - - let mask = ( - Connection.TraceEvent.statementMask | - Connection.TraceEvent.profileMask | - Connection.TraceEvent.rowMask | - Connection.TraceEvent.connectionClosedMask - ) - - var traceEvents: [Connection.TraceEvent] = [] - - // When - connection?.traceEvent(mask: mask) { event in - traceEvents.append(event) + // Given + var connection: Connection? = try Connection(storageLocation: storageLocation) + + let mask = ( + Connection.TraceEvent.statementMask | + Connection.TraceEvent.profileMask | + Connection.TraceEvent.rowMask | + Connection.TraceEvent.connectionClosedMask + ) + + var traceEvents: [Connection.TraceEvent] = [] + + // When + connection?.traceEvent(mask: mask) { event in + traceEvents.append(event) + } + + try connection?.execute("CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)") + try connection?.prepare("INSERT INTO agents VALUES(?, ?)").bind(1, "Sterling Archer").run() + try connection?.prepare("INSERT INTO agents VALUES(?, ?)").bind(2, "Lana Kane").run() + try connection?.stepAll("SELECT * FROM agents") + + connection = nil + + // Then + if traceEvents.count == 11 { + XCTAssertEqual(traceEvents[0].rawValue, "Statement") + XCTAssertEqual(traceEvents[1].rawValue, "Profile") + XCTAssertEqual(traceEvents[2].rawValue, "Statement") + XCTAssertEqual(traceEvents[3].rawValue, "Profile") + XCTAssertEqual(traceEvents[4].rawValue, "Statement") + XCTAssertEqual(traceEvents[5].rawValue, "Profile") + XCTAssertEqual(traceEvents[6].rawValue, "Statement") + XCTAssertEqual(traceEvents[7].rawValue, "Row") + XCTAssertEqual(traceEvents[8].rawValue, "Row") + XCTAssertEqual(traceEvents[9].rawValue, "Profile") + XCTAssertEqual(traceEvents[10].rawValue, "ConnectionClosed") + + if case let .statement(statement, sql) = traceEvents[0] { + XCTAssertEqual(statement, "CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)") + XCTAssertEqual(sql, "CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)") + } + + if case let .profile(statement, seconds) = traceEvents[1] { + XCTAssertEqual(statement, "CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)") + XCTAssertGreaterThanOrEqual(seconds, 0.0) + } + + if case let .statement(statement, sql) = traceEvents[2] { + XCTAssertEqual(statement, "INSERT INTO agents VALUES(1, \'Sterling Archer\')") + XCTAssertEqual(sql, "INSERT INTO agents VALUES(?, ?)") + } + + if case let .profile(statement, seconds) = traceEvents[3] { + XCTAssertEqual(statement, "INSERT INTO agents VALUES(1, \'Sterling Archer\')") + XCTAssertGreaterThanOrEqual(seconds, 0.0) + } + + if case let .statement(statement, sql) = traceEvents[4] { + XCTAssertEqual(statement, "INSERT INTO agents VALUES(2, \'Lana Kane\')") + XCTAssertEqual(sql, "INSERT INTO agents VALUES(?, ?)") + } + + if case let .profile(statement, seconds) = traceEvents[5] { + XCTAssertEqual(statement, "INSERT INTO agents VALUES(2, \'Lana Kane\')") + XCTAssertGreaterThanOrEqual(seconds, 0.0) + } + + if case let .statement(statement, sql) = traceEvents[6] { + XCTAssertEqual(statement, "SELECT * FROM agents") + XCTAssertEqual(sql, "SELECT * FROM agents") + } + + if case let .row(statement) = traceEvents[7] { + XCTAssertEqual(statement, "SELECT * FROM agents") + } + + if case let .row(statement) = traceEvents[8] { + XCTAssertEqual(statement, "SELECT * FROM agents") } - try connection?.execute("CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)") - try connection?.prepare("INSERT INTO agents VALUES(?, ?)").bind(1, "Sterling Archer").run() - try connection?.prepare("INSERT INTO agents VALUES(?, ?)").bind(2, "Lana Kane").run() - try connection?.stepAll("SELECT * FROM agents") - - connection = nil - - // Then - if traceEvents.count == 11 { - XCTAssertEqual(traceEvents[0].rawValue, "Statement") - XCTAssertEqual(traceEvents[1].rawValue, "Profile") - XCTAssertEqual(traceEvents[2].rawValue, "Statement") - XCTAssertEqual(traceEvents[3].rawValue, "Profile") - XCTAssertEqual(traceEvents[4].rawValue, "Statement") - XCTAssertEqual(traceEvents[5].rawValue, "Profile") - XCTAssertEqual(traceEvents[6].rawValue, "Statement") - XCTAssertEqual(traceEvents[7].rawValue, "Row") - XCTAssertEqual(traceEvents[8].rawValue, "Row") - XCTAssertEqual(traceEvents[9].rawValue, "Profile") - XCTAssertEqual(traceEvents[10].rawValue, "ConnectionClosed") - - if case let .statement(statement, sql) = traceEvents[0] { - XCTAssertEqual(statement, "CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)") - XCTAssertEqual(sql, "CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)") - } - - if case let .profile(statement, seconds) = traceEvents[1] { - XCTAssertEqual(statement, "CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)") - XCTAssertGreaterThanOrEqual(seconds, 0.0) - } - - if case let .statement(statement, sql) = traceEvents[2] { - XCTAssertEqual(statement, "INSERT INTO agents VALUES(1, \'Sterling Archer\')") - XCTAssertEqual(sql, "INSERT INTO agents VALUES(?, ?)") - } - - if case let .profile(statement, seconds) = traceEvents[3] { - XCTAssertEqual(statement, "INSERT INTO agents VALUES(1, \'Sterling Archer\')") - XCTAssertGreaterThanOrEqual(seconds, 0.0) - } - - if case let .statement(statement, sql) = traceEvents[4] { - XCTAssertEqual(statement, "INSERT INTO agents VALUES(2, \'Lana Kane\')") - XCTAssertEqual(sql, "INSERT INTO agents VALUES(?, ?)") - } - - if case let .profile(statement, seconds) = traceEvents[5] { - XCTAssertEqual(statement, "INSERT INTO agents VALUES(2, \'Lana Kane\')") - XCTAssertGreaterThanOrEqual(seconds, 0.0) - } - - if case let .statement(statement, sql) = traceEvents[6] { - XCTAssertEqual(statement, "SELECT * FROM agents") - XCTAssertEqual(sql, "SELECT * FROM agents") - } - - if case let .row(statement) = traceEvents[7] { - XCTAssertEqual(statement, "SELECT * FROM agents") - } - - if case let .row(statement) = traceEvents[8] { - XCTAssertEqual(statement, "SELECT * FROM agents") - } - - if case let .profile(statement, seconds) = traceEvents[9] { - XCTAssertEqual(statement, "SELECT * FROM agents") - XCTAssertGreaterThanOrEqual(seconds, 0.0) - } - } else { - XCTFail("traceEvents count should be 11") + if case let .profile(statement, seconds) = traceEvents[9] { + XCTAssertEqual(statement, "SELECT * FROM agents") + XCTAssertGreaterThanOrEqual(seconds, 0.0) } + } else { + XCTFail("traceEvents count should be 11") } } func testThatConnectionCanTraceStatementEventExecutionUsingMask() throws { - if #available(iOS 10.0, macOS 10.12.0, tvOS 10.0, watchOS 3.0, *) { - // Given - var connection: Connection? = try Connection(storageLocation: storageLocation) - var traceEvents: [Connection.TraceEvent] = [] + // Given + var connection: Connection? = try Connection(storageLocation: storageLocation) + var traceEvents: [Connection.TraceEvent] = [] - let mask = Connection.TraceEvent.statementMask | Connection.TraceEvent.profileMask + let mask = Connection.TraceEvent.statementMask | Connection.TraceEvent.profileMask - // When - connection?.traceEvent(mask: mask) { event in - traceEvents.append(event) - } + // When + connection?.traceEvent(mask: mask) { event in + traceEvents.append(event) + } - try connection?.execute("CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)") - try connection?.prepare("INSERT INTO agents VALUES(?, ?)").bind(1, "Sterling Archer").run() - try connection?.prepare("INSERT INTO agents VALUES(?, ?)").bind(2, "Lana Kane").run() - try connection?.stepAll("SELECT * FROM agents") + try connection?.execute("CREATE TABLE agents(id INTEGER PRIMARY KEY, name TEXT)") + try connection?.prepare("INSERT INTO agents VALUES(?, ?)").bind(1, "Sterling Archer").run() + try connection?.prepare("INSERT INTO agents VALUES(?, ?)").bind(2, "Lana Kane").run() + try connection?.stepAll("SELECT * FROM agents") - connection = nil + connection = nil - // Then - XCTAssertEqual(traceEvents.count, 8) - } + // Then + XCTAssertEqual(traceEvents.count, 8) } } diff --git a/Tests/Tests/Connection/StatementTests.swift b/Tests/Tests/Connection/StatementTests.swift index e90d38c..eb80509 100644 --- a/Tests/Tests/Connection/StatementTests.swift +++ b/Tests/Tests/Connection/StatementTests.swift @@ -71,8 +71,6 @@ class StatementTestCase: BaseConnectionTestCase { } func testThatStatementCanReturnExpandedSQLBoundWithParameters() throws { - guard #available(iOS 10.0, macOS 10.12.0, tvOS 10.0, watchOS 3.0, *) else { return } - // Given try connection.execute("CREATE TABLE person(id INTEGER PRIMARY KEY, first_name TEXT NOT NULL)")