Skip to content

Commit

Permalink
Removing additional availability checks that are met in SQift 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jereme authored and cnoon committed Nov 30, 2018
1 parent 2e0ab34 commit 5f82ca9
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 118 deletions.
7 changes: 1 addition & 6 deletions Source/Connection/Functions/Function.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 1 addition & 7 deletions Tests/Tests/Connection/Functions/BusyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
202 changes: 99 additions & 103 deletions Tests/Tests/Connection/Functions/TraceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 0 additions & 2 deletions Tests/Tests/Connection/StatementTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")

Expand Down

0 comments on commit 5f82ca9

Please sign in to comment.