Skip to content

Commit

Permalink
Rename Error to SQLiteError
Browse files Browse the repository at this point in the history
  • Loading branch information
atdrendel committed Jul 15, 2020
1 parent f016a5e commit e4bdb28
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 27 deletions.
16 changes: 8 additions & 8 deletions Sources/SQLite/Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public final class Database {

let result = try _execute(sql, statement: statement, arguments: arguments)
if result.isEmpty == false {
throw Error.onWrite(result)
throw SQLiteError.onWrite(result)
}
}
}
Expand Down Expand Up @@ -289,7 +289,7 @@ extension Database {
private func _observe(_ sql: SQL, arguments: SQLiteArguments = [:], queue: DispatchQueue = .main,
block: @escaping (Array<SQLiteRow>) -> Void) throws -> (AnyObject, Array<SQLiteRow>) {
assert(isOnDatabaseQueue)
guard self.canObserveDatabase else { throw Error.onObserveWithoutColumnMetadata }
guard self.canObserveDatabase else { throw SQLiteError.onObserveWithoutColumnMetadata }
let statement = try prepare(sql)
try statement.bind(arguments: arguments)
let observer = try _monitor.observe(statement: statement, queue: queue, block: block)
Expand All @@ -299,7 +299,7 @@ extension Database {
do {
let (result, output) = try statement.evaluate()
if result != SQLITE_DONE && result != SQLITE_INTERRUPT {
throw Error.onStep(result, sql)
throw SQLiteError.onStep(result, sql)
}
return (observer, output)
} catch {
Expand All @@ -319,7 +319,7 @@ extension Database {
let (result, output) = try statement.evaluate()

if result != SQLITE_DONE && result != SQLITE_INTERRUPT {
throw Error.onStep(result, sql)
throw SQLiteError.onStep(result, sql)
}

return output
Expand All @@ -340,7 +340,7 @@ extension Database {
let result = sqlite3_prepare_v2(_connection, sql, -1, &optionalStatement, nil)
guard SQLITE_OK == result, let statement = optionalStatement else {
sqlite3_finalize(optionalStatement)
throw Error.onPrepareStatement(result, sql)
throw SQLiteError.onPrepareStatement(result, sql)
}
return statement
}
Expand All @@ -367,13 +367,13 @@ extension Database {

guard SQLITE_OK == result else {
Database.close(optionalConnection)
let error = Error.onOpen(result, path)
let error = SQLiteError.onOpen(result, path)
assertionFailure(error.description)
throw error
}

guard let connection = optionalConnection else {
let error = Error.onOpen(SQLITE_INTERNAL, path)
let error = SQLiteError.onOpen(SQLITE_INTERNAL, path)
assertionFailure(error.description)
throw error
}
Expand All @@ -389,7 +389,7 @@ extension Database {
// clean up the SQLite database connection when the transactions that
// were preventing the close are finalized.
// https://sqlite.org/c3ref/close.html
let error = Error.onClose(result)
let error = SQLiteError.onClose(result)
assertionFailure(error.description)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/SQLite/Monitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Monitor {
func observe(statement: Statement, queue: DispatchQueue = .main,
block: @escaping (Array<SQLiteRow>) -> Void) throws -> AnyObject {
guard let database = _database else {
throw Error.onInternalError("Database is missing")
throw SQLiteError.onInternalError("Database is missing")
}

let tables = try tablesToObserve(for: statement, in: database)
Expand Down Expand Up @@ -93,7 +93,7 @@ extension Monitor {
extension Monitor {
private func tablesToObserve(for statement: OpaquePointer,
in database: Database) throws -> Set<String> {
guard let sql = sqlite3_sql(statement) else { throw Error.onGetSQL }
guard let sql = sqlite3_sql(statement) else { throw SQLiteError.onGetSQL }
let explain = "EXPLAIN QUERY PLAN \(String(cString: sql));"
let queryPlan = try database.execute(raw: explain)
return QueryPlanParser.tables(in: queryPlan, matching: try database.tables())
Expand Down
6 changes: 3 additions & 3 deletions Sources/SQLite/OpaquePointer+SQLite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extension Statement {
for (key, value) in arguments {
let name = ":\(key)"
let index = sqlite3_bind_parameter_index(self, name)
guard index != 0 else { throw Error.onGetParameterIndex(key) }
guard index != 0 else { throw SQLiteError.onGetParameterIndex(key) }
try bind(value: value, to: index)
}
}
Expand All @@ -29,7 +29,7 @@ extension Statement {
}

if SQLITE_OK != result {
throw Error.onBindParameter(result, index, value)
throw SQLiteError.onBindParameter(result, index, value)
}
}

Expand Down Expand Up @@ -78,7 +78,7 @@ extension Statement {
guard let cString = sqlite3_column_text(self, column) else { return .null }
return .text(String(cString: cString))
default:
throw Error.onGetColumnType(type)
throw SQLiteError.onGetColumnType(type)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SQLite/Publisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct Publisher: Combine.Publisher {

public func receive<S: Subscriber>(subscriber: S) where Failure == S.Failure, Output == S.Input {
guard let database = _database else {
return subscriber.receive(completion: .failure(Error.onSubscribeWithoutDatabase))
return subscriber.receive(completion: .failure(SQLiteError.onSubscribeWithoutDatabase))
}

do {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SQLite3

public enum Error: Swift.Error {
public enum SQLiteError: Error {
case onInternalError(String)
case onOpen(Int32, String)
case onClose(Int32)
Expand All @@ -24,7 +24,7 @@ public enum Error: Swift.Error {
case onSubscribeWithoutDatabase
}

extension Error: CustomStringConvertible {
extension SQLiteError: CustomStringConvertible {
public var description: String {
func string(for code: Int32) -> String {
return String(cString: sqlite3_errstr(code))
Expand Down
14 changes: 7 additions & 7 deletions Sources/SQLite/SQLiteRow+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ extension Dictionary where Dictionary.Key == String, Dictionary.Value == SQLiteV

public func value<V>(for key: String) throws -> V {
if String.self == V.self {
guard let value = self[key]?.stringValue else { throw Error.onDecodingRow(key) }
guard let value = self[key]?.stringValue else { throw SQLiteError.onDecodingRow(key) }
return value as! V
} else if Int.self == V.self {
guard let value = self[key]?.intValue else { throw Error.onDecodingRow(key) }
guard let value = self[key]?.intValue else { throw SQLiteError.onDecodingRow(key) }
return value as! V
} else if Bool.self == V.self {
guard let value = self[key]?.boolValue else { throw Error.onDecodingRow(key) }
guard let value = self[key]?.boolValue else { throw SQLiteError.onDecodingRow(key) }
return value as! V
} else if Double.self == V.self {
guard let value = self[key]?.doubleValue else { throw Error.onDecodingRow(key) }
guard let value = self[key]?.doubleValue else { throw SQLiteError.onDecodingRow(key) }
return value as! V
} else if Data.self == V.self {
guard let value = self[key]?.dataValue else { throw Error.onDecodingRow(key) }
guard let value = self[key]?.dataValue else { throw SQLiteError.onDecodingRow(key) }
return value as! V
} else if Int64.self == V.self {
guard let value = self[key]?.int64Value else { throw Error.onDecodingRow(key) }
guard let value = self[key]?.int64Value else { throw SQLiteError.onDecodingRow(key) }
return value as! V
} else if Optional<String>.self == V.self {
return self[key]?.stringValue as! V
Expand All @@ -45,7 +45,7 @@ extension Dictionary where Dictionary.Key == String, Dictionary.Value == SQLiteV
} else if Optional<Int64>.self == V.self {
return self[key]?.int64Value as! V
} else {
throw Error.onInvalidDecodingType(String(describing: V.self))
throw SQLiteError.onInvalidDecodingType(String(describing: V.self))
}
}
}
4 changes: 2 additions & 2 deletions Tests/SQLiteTests/DatabaseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class DatabaseTests: XCTestCase {
XCTAssertNoThrow(try database.execute(raw: _createTableWithTypesafeBlob))
XCTAssertNoThrow(try database.write(_insertIDAndData, arguments: one))
XCTAssertThrowsError(try database.write(_insertIDAndData, arguments: two)) { (error) in
if case Error.onStep(let code, _) = error {
if case SQLiteError.onStep(let code, _) = error {
XCTAssertEqual(SQLITE_CONSTRAINT, code)
} else {
XCTFail("'\(error)' should be 'Error.onStep'")
Expand All @@ -147,7 +147,7 @@ class DatabaseTests: XCTestCase {

XCTAssertNoThrow(try database.execute(raw: _createTableWithBlob))
XCTAssertThrowsError(try database.write(_insertIDAndData, arguments: one)) { (error) in
if case Error.onStep(let code, _) = error {
if case SQLiteError.onStep(let code, _) = error {
XCTAssertEqual(SQLITE_CONSTRAINT, code)
} else {
XCTFail("'\(error)' should be 'Error.onStep'")
Expand Down
2 changes: 1 addition & 1 deletion Tests/SQLiteTests/ObserveTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ObserveTests: XCTestCase {
do {
token = try database.observe("NOPE;", block: onUpdatePeople)
XCTFail()
} catch Error.onPrepareStatement {
} catch SQLiteError.onPrepareStatement {
} catch {
XCTFail()
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SQLiteTests/PublisherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PublisherTests: XCTestCase {
case .finished:
XCTFail("Should have completed with error")
case .failure(let error):
guard case Error.onPrepareStatement = error else {
guard case SQLiteError.onPrepareStatement = error else {
return XCTFail("Incorrect error: \(error)")
}
}
Expand Down

0 comments on commit e4bdb28

Please sign in to comment.