Skip to content

Commit

Permalink
#171: rename ResultCode.code into ResultCode.resultCode (@hartbit's s…
Browse files Browse the repository at this point in the history
…uggestion)
  • Loading branch information
groue committed Feb 26, 2017
1 parent f0d1f23 commit e4a3469
Show file tree
Hide file tree
Showing 35 changed files with 137 additions and 137 deletions.
22 changes: 11 additions & 11 deletions GRDB/Core/Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,15 @@ public final class Database {
var sqliteConnection: SQLiteConnection? = nil
let code = sqlite3_open_v2(path, &sqliteConnection, configuration.SQLiteOpenFlags, nil)
guard code == SQLITE_OK else {
throw DatabaseError(code: ResultCode(rawValue: code), message: String(cString: sqlite3_errmsg(sqliteConnection)))
throw DatabaseError(resultCode: ResultCode(rawValue: code), message: String(cString: sqlite3_errmsg(sqliteConnection)))
}

do {
// Use extended result codes
do {
let code = sqlite3_extended_result_codes(sqliteConnection!, 1)
guard code == SQLITE_OK else {
throw DatabaseError(code: ResultCode(rawValue: code), message: String(cString: sqlite3_errmsg(sqliteConnection)))
throw DatabaseError(resultCode: ResultCode(rawValue: code), message: String(cString: sqlite3_errmsg(sqliteConnection)))
}
}

Expand All @@ -338,7 +338,7 @@ public final class Database {
do {
let code = sqlite3_exec(sqliteConnection, "SELECT * FROM sqlite_master LIMIT 1", nil, nil, nil)
guard code == SQLITE_OK else {
throw DatabaseError(code: ResultCode(rawValue: code), message: String(cString: sqlite3_errmsg(sqliteConnection)))
throw DatabaseError(resultCode: ResultCode(rawValue: code), message: String(cString: sqlite3_errmsg(sqliteConnection)))
}
}
} catch {
Expand Down Expand Up @@ -664,7 +664,7 @@ extension Database {
}
let validateRemainingArguments = {
if !arguments.values.isEmpty {
throw DatabaseError(code: .SQLITE_MISUSE, message: "wrong number of statement arguments: \(initialValuesCount)")
throw DatabaseError(resultCode: .SQLITE_MISUSE, message: "wrong number of statement arguments: \(initialValuesCount)")
}
}

Expand All @@ -690,7 +690,7 @@ extension Database {
var sqliteStatement: SQLiteStatement? = nil
let code = sqlite3_prepare_v2(sqliteConnection, statementStart, -1, &sqliteStatement, &statementEnd)
guard code == SQLITE_OK else {
error = DatabaseError(code: ResultCode(rawValue: code), message: lastErrorMessage, sql: sql)
error = DatabaseError(resultCode: ResultCode(rawValue: code), message: lastErrorMessage, sql: sql)
break
}

Expand Down Expand Up @@ -779,15 +779,15 @@ extension Database {
if let message = error.message {
sqlite3_result_error(context, message, -1)
}
sqlite3_result_error_code(context, error.code.rawValue)
sqlite3_result_error_code(context, error.resultCode.rawValue)
} catch {
sqlite3_result_error(context, "\(error)", -1)
}
}, nil, nil, nil)

guard code == SQLITE_OK else {
// Assume a GRDB bug: there is no point throwing any error.
fatalError(DatabaseError(code: ResultCode(rawValue: code), message: lastErrorMessage).description)
fatalError(DatabaseError(resultCode: ResultCode(rawValue: code), message: lastErrorMessage).description)
}
}

Expand All @@ -802,7 +802,7 @@ extension Database {
nil, nil, nil, nil, nil)
guard code == SQLITE_OK else {
// Assume a GRDB bug: there is no point throwing any error.
fatalError(DatabaseError(code: ResultCode(rawValue: code), message: lastErrorMessage).description)
fatalError(DatabaseError(resultCode: ResultCode(rawValue: code), message: lastErrorMessage).description)
}
}
}
Expand Down Expand Up @@ -891,7 +891,7 @@ extension Database {
}, nil)
guard code == SQLITE_OK else {
// Assume a GRDB bug: there is no point throwing any error.
fatalError(DatabaseError(code: ResultCode(rawValue: code), message: lastErrorMessage).description)
fatalError(DatabaseError(resultCode: ResultCode(rawValue: code), message: lastErrorMessage).description)
}
}

Expand Down Expand Up @@ -960,7 +960,7 @@ extension Database {
sqlite3_key(sqliteConnection, bytes, Int32(data.count))
}
guard code == SQLITE_OK else {
throw DatabaseError(code: code, message: String(cString: sqlite3_errmsg(sqliteConnection)))
throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection)))
}
}

Expand All @@ -979,7 +979,7 @@ extension Database {
sqlite3_rekey(sqliteConnection, bytes, Int32(data.count))
}
guard code == SQLITE_OK else {
throw DatabaseError(code: code, message: String(cString: sqlite3_errmsg(sqliteConnection)))
throw DatabaseError(resultCode: code, message: String(cString: sqlite3_errmsg(sqliteConnection)))
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions GRDB/Core/DatabaseError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ public struct ResultCode : RawRepresentable, Equatable, CustomStringConvertible
public struct DatabaseError : Error {

/// The SQLite error code (see https://www.sqlite.org/c3ref/c_abort.html).
public let code: ResultCode
public let resultCode: ResultCode

public var primaryResultCode: ResultCode {
return code.primaryResultCode
return resultCode.primaryResultCode
}

/// The SQLite error message.
Expand All @@ -144,8 +144,8 @@ public struct DatabaseError : Error {
/// The SQL query that yielded the error (if relevant).
public let sql: String?

public init(code: ResultCode = .SQLITE_ERROR, message: String? = nil, sql: String? = nil, arguments: StatementArguments? = nil) {
self.code = code
public init(resultCode: ResultCode = .SQLITE_ERROR, message: String? = nil, sql: String? = nil, arguments: StatementArguments? = nil) {
self.resultCode = resultCode
self.message = message
self.sql = sql
self.arguments = arguments
Expand All @@ -162,7 +162,7 @@ public struct DatabaseError : Error {
extension DatabaseError: CustomStringConvertible {
/// A textual representation of `self`.
public var description: String {
var description = "SQLite error \(code.rawValue)"
var description = "SQLite error \(resultCode.rawValue)"
if let sql = sql {
description += " with statement `\(sql)`"
}
Expand All @@ -185,7 +185,7 @@ extension DatabaseError : CustomNSError {

/// NSError bridging: the error code within the given domain.
public var errorCode: Int {
return Int(code.rawValue)
return Int(resultCode.rawValue)
}

/// NSError bridging: the user-info dictionary.
Expand Down
2 changes: 1 addition & 1 deletion GRDB/Core/DatabasePool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public final class DatabasePool {
// when kind is not .Passive.
let code = sqlite3_wal_checkpoint_v2(db.sqliteConnection, nil, kind.rawValue, nil, nil)
guard code == SQLITE_OK else {
throw DatabaseError(code: ResultCode(rawValue: code), message: db.lastErrorMessage, sql: nil)
throw DatabaseError(resultCode: ResultCode(rawValue: code), message: db.lastErrorMessage, sql: nil)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions GRDB/Core/DatabaseReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ extension DatabaseReader {
try read { dbFrom in
try writer.write { dbDest in
guard let backup = sqlite3_backup_init(dbDest.sqliteConnection, "main", dbFrom.sqliteConnection, "main") else {
throw DatabaseError(code: dbDest.lastErrorCode, message: dbDest.lastErrorMessage)
throw DatabaseError(resultCode: dbDest.lastErrorCode, message: dbDest.lastErrorMessage)
}
guard Int(bitPattern: backup) != Int(SQLITE_ERROR) else {
throw DatabaseError(code: .SQLITE_ERROR)
throw DatabaseError(resultCode: .SQLITE_ERROR)
}

afterBackupInit?()
Expand All @@ -158,7 +158,7 @@ extension DatabaseReader {
case SQLITE_OK:
afterBackupStep?()
case let code:
throw DatabaseError(code: ResultCode(rawValue: code), message: dbDest.lastErrorMessage)
throw DatabaseError(resultCode: ResultCode(rawValue: code), message: dbDest.lastErrorMessage)
}
}
} catch {
Expand All @@ -170,7 +170,7 @@ extension DatabaseReader {
case SQLITE_OK:
break
case let code:
throw DatabaseError(code: ResultCode(rawValue: code), message: dbDest.lastErrorMessage)
throw DatabaseError(resultCode: ResultCode(rawValue: code), message: dbDest.lastErrorMessage)
}

dbDest.clearSchemaCache()
Expand Down
6 changes: 3 additions & 3 deletions GRDB/Core/DatabaseValueConvertible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ extension DatabaseValueConvertible {
if let value = Self.fromDatabaseValue(dbv) {
return value
} else {
throw DatabaseError(code: .SQLITE_ERROR, message: "could not convert database value \(dbv) to \(Self.self)", sql: statement.sql, arguments: arguments)
throw DatabaseError(resultCode: .SQLITE_ERROR, message: "could not convert database value \(dbv) to \(Self.self)", sql: statement.sql, arguments: arguments)
}
}
}
Expand Down Expand Up @@ -165,7 +165,7 @@ extension DatabaseValueConvertible {
} else if dbv.isNull {
return nil
} else {
throw DatabaseError(code: .SQLITE_ERROR, message: "could not convert database value \(dbv) to \(Self.self)", sql: statement.sql, arguments: arguments)
throw DatabaseError(resultCode: .SQLITE_ERROR, message: "could not convert database value \(dbv) to \(Self.self)", sql: statement.sql, arguments: arguments)
}
}
return try cursor.next() ?? nil
Expand Down Expand Up @@ -336,7 +336,7 @@ extension Optional where Wrapped: DatabaseValueConvertible {
} else if dbv.isNull {
return nil
} else {
throw DatabaseError(code: .SQLITE_ERROR, message: "could not convert database value \(dbv) to \(Wrapped.self)", sql: statement.sql, arguments: arguments)
throw DatabaseError(resultCode: .SQLITE_ERROR, message: "could not convert database value \(dbv) to \(Wrapped.self)", sql: statement.sql, arguments: arguments)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion GRDB/Core/RowAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public struct ColumnMapping : RowAdapter {
.map { (mappedColumn, baseColumn) -> (Int, String) in
guard let index = layout.layoutIndex(ofColumn: baseColumn) else {
let columnNames = layout.layoutColumns.map { $0.1 }
throw DatabaseError(code: .SQLITE_MISUSE, message: "Mapping references missing column \(baseColumn). Valid column names are: \(columnNames.joined(separator: ", ")).")
throw DatabaseError(resultCode: .SQLITE_MISUSE, message: "Mapping references missing column \(baseColumn). Valid column names are: \(columnNames.joined(separator: ", ")).")
}
let baseIndex = layout.layoutColumns[index].0
return (baseIndex, mappedColumn)
Expand Down
20 changes: 10 additions & 10 deletions GRDB/Core/Statement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public class Statement {
}

guard code == SQLITE_OK else {
throw DatabaseError(code: ResultCode(rawValue: code), message: database.lastErrorMessage, sql: sql)
throw DatabaseError(resultCode: ResultCode(rawValue: code), message: database.lastErrorMessage, sql: sql)
}

guard remainingSQL.isEmpty else {
sqlite3_finalize(sqliteStatement)
throw DatabaseError(code: .SQLITE_MISUSE, message: "Multiple statements found. To execute multiple statements, use Database.execute() instead.", sql: sql, arguments: nil)
throw DatabaseError(resultCode: .SQLITE_MISUSE, message: "Multiple statements found. To execute multiple statements, use Database.execute() instead.", sql: sql, arguments: nil)
}

self.database = database
Expand All @@ -86,7 +86,7 @@ public class Statement {
// throwing any error.
let code = sqlite3_reset(sqliteStatement)
guard code == SQLITE_OK else {
fatalError(DatabaseError(code: ResultCode(rawValue: code), message: database.lastErrorMessage, sql: sql).description)
fatalError(DatabaseError(resultCode: ResultCode(rawValue: code), message: database.lastErrorMessage, sql: sql).description)
}
}

Expand Down Expand Up @@ -183,7 +183,7 @@ public class Statement {
// It looks like sqlite3_bind_xxx() functions do not access the file system.
// They should thus succeed, unless a GRDB bug: there is no point throwing any error.
guard code == SQLITE_OK else {
fatalError(DatabaseError(code: ResultCode(rawValue: code), message: database.lastErrorMessage, sql: sql).description)
fatalError(DatabaseError(resultCode: ResultCode(rawValue: code), message: database.lastErrorMessage, sql: sql).description)
}
}

Expand All @@ -194,7 +194,7 @@ public class Statement {
// no point throwing any error.
let code = sqlite3_clear_bindings(sqliteStatement)
guard code == SQLITE_OK else {
fatalError(DatabaseError(code: ResultCode(rawValue: code), message: database.lastErrorMessage, sql: sql).description)
fatalError(DatabaseError(resultCode: ResultCode(rawValue: code), message: database.lastErrorMessage, sql: sql).description)
}
}

Expand Down Expand Up @@ -327,7 +327,7 @@ public final class DatabaseCursor<Element> : Cursor {
return try element()
case let errorCode:
statement.database.selectStatementDidFail(statement)
throw DatabaseError(code: ResultCode(rawValue: errorCode), message: statement.database.lastErrorMessage, sql: statement.sql, arguments: statement.arguments)
throw DatabaseError(resultCode: ResultCode(rawValue: errorCode), message: statement.database.lastErrorMessage, sql: statement.sql, arguments: statement.arguments)
}
}
}
Expand Down Expand Up @@ -432,7 +432,7 @@ public final class UpdateStatement : Statement {
// Let database rethrow eventual transaction observer error:
try database.updateStatementDidFail(self)

throw DatabaseError(code: ResultCode(rawValue: errorCode), message: database.lastErrorMessage, sql: sql, arguments: self.arguments) // Error uses self.arguments, not the optional arguments parameter.
throw DatabaseError(resultCode: ResultCode(rawValue: errorCode), message: database.lastErrorMessage, sql: sql, arguments: self.arguments) // Error uses self.arguments, not the optional arguments parameter.
}
}
}
Expand Down Expand Up @@ -778,20 +778,20 @@ public struct StatementArguments {
if let databaseValue = namedValues[argumentName] {
return databaseValue
} else if values.isEmpty {
throw DatabaseError(code: .SQLITE_MISUSE, message: "missing statement argument: \(argumentName)", sql: statement.sql, arguments: nil)
throw DatabaseError(resultCode: .SQLITE_MISUSE, message: "missing statement argument: \(argumentName)", sql: statement.sql, arguments: nil)
} else {
return values.removeFirst()
}
} else {
if values.isEmpty {
throw DatabaseError(code: .SQLITE_MISUSE, message: "wrong number of statement arguments: \(initialValuesCount)", sql: statement.sql, arguments: nil)
throw DatabaseError(resultCode: .SQLITE_MISUSE, message: "wrong number of statement arguments: \(initialValuesCount)", sql: statement.sql, arguments: nil)
} else {
return values.removeFirst()
}
}
}
if !allowingRemainingValues && !values.isEmpty {
throw DatabaseError(code: .SQLITE_MISUSE, message: "wrong number of statement arguments: \(initialValuesCount)", sql: statement.sql, arguments: nil)
throw DatabaseError(resultCode: .SQLITE_MISUSE, message: "wrong number of statement arguments: \(initialValuesCount)", sql: statement.sql, arguments: nil)
}
return bindings
}
Expand Down
2 changes: 1 addition & 1 deletion GRDB/Core/StatementColumnConvertible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
let sqliteStatement = statement.sqliteStatement
return statement.fetchCursor(arguments: arguments) {
if sqlite3_column_type(sqliteStatement, columnIndex) == SQLITE_NULL {
throw DatabaseError(code: .SQLITE_ERROR, message: "could not convert database value NULL to \(Self.self)", sql: statement.sql, arguments: arguments)
throw DatabaseError(resultCode: .SQLITE_ERROR, message: "could not convert database value NULL to \(Self.self)", sql: statement.sql, arguments: arguments)
}
return Self.init(sqliteStatement: sqliteStatement, index: columnIndex)
}
Expand Down
2 changes: 1 addition & 1 deletion GRDB/FTS/FTS3Pattern.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public struct FTS3Pattern {
}
} catch let error as DatabaseError {
// Remove private SQL & arguments from the thrown error
throw DatabaseError(code: error.code, message: error.message, sql: nil, arguments: nil)
throw DatabaseError(resultCode: error.resultCode, message: error.message, sql: nil, arguments: nil)
}

// Pattern is valid
Expand Down
2 changes: 1 addition & 1 deletion GRDB/FTS/FTS5CustomTokenizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
}
guard code == SQLITE_OK else {
// Assume a GRDB bug: there is no point throwing any error.
fatalError(DatabaseError(code: code, message: lastErrorMessage).description)
fatalError(DatabaseError(resultCode: code, message: lastErrorMessage).description)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion GRDB/FTS/FTS5Pattern.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
}
} catch let error as DatabaseError {
// Remove private SQL & arguments from the thrown error
throw DatabaseError(code: error.code, message: error.message, sql: nil, arguments: nil)
throw DatabaseError(resultCode: error.code, message: error.message, sql: nil, arguments: nil)
}

// Pattern is valid
Expand Down
Loading

0 comments on commit e4a3469

Please sign in to comment.