mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
SQLiteError.sql gives the failed SQL query
This commit is contained in:
1 parent
5951079ecc
commit
cbc306f9d5
4 files changed
+11
-9
No files matched your search
@@ -12,13 +12,15 @@ public struct SQLiteError : ErrorType {
|
||||
|
||||
public var code: Int { return _code }
|
||||
public let message: String?
|
||||
public let sql: String?
|
||||
|
||||
init(code: Int32, message: String? = nil) {
|
||||
init(code: Int32, message: String? = nil, sql: String? = nil) {
|
||||
self._code = Int(code)
|
||||
self.message = message
|
||||
self.sql = sql
|
||||
}
|
||||
|
||||
init(code: Int32, cConnection: CConnection) {
|
||||
init(code: Int32, cConnection: CConnection, sql: String? = nil) {
|
||||
let message: String?
|
||||
let cString = sqlite3_errmsg(cConnection)
|
||||
if cString == nil {
|
||||
@@ -26,12 +28,12 @@ public struct SQLiteError : ErrorType {
|
||||
} else {
|
||||
message = String.fromCString(cString)
|
||||
}
|
||||
self.init(code: code, message: message)
|
||||
self.init(code: code, message: message, sql: sql)
|
||||
}
|
||||
|
||||
static func checkCResultCode(code: Int32, cConnection: CConnection) throws {
|
||||
static func checkCResultCode(code: Int32, cConnection: CConnection, sql: String? = nil) throws {
|
||||
if code != SQLITE_OK {
|
||||
throw SQLiteError(code: code, cConnection: cConnection)
|
||||
throw SQLiteError(code: code, cConnection: cConnection, sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public class SelectStatement : Statement {
|
||||
case SQLITE_ROW:
|
||||
return Row(statement: self, unsafe: unsafe)
|
||||
default:
|
||||
try! SQLiteError.checkCResultCode(code, cConnection: self.database.cConnection)
|
||||
try! SQLiteError.checkCResultCode(code, cConnection: self.database.cConnection, sql: self.sql)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class Statement {
|
||||
self.database = database
|
||||
self.databaseQueueID = dispatch_get_specific(DatabaseQueue.databaseQueueIDKey)
|
||||
let code = sqlite3_prepare_v2(database.cConnection, sql, -1, &cStatement, nil)
|
||||
try SQLiteError.checkCResultCode(code, cConnection: database.cConnection)
|
||||
try SQLiteError.checkCResultCode(code, cConnection: database.cConnection, sql: sql)
|
||||
}
|
||||
|
||||
deinit {
|
||||
@@ -59,7 +59,7 @@ public class Statement {
|
||||
|
||||
public func reset() throws {
|
||||
let code = sqlite3_reset(cStatement)
|
||||
try SQLiteError.checkCResultCode(code, cConnection: database.cConnection)
|
||||
try SQLiteError.checkCResultCode(code, cConnection: database.cConnection, sql: sql)
|
||||
}
|
||||
|
||||
public func clearBindings() {
|
||||
|
||||
@@ -19,7 +19,7 @@ public class UpdateStatement : Statement {
|
||||
// the statement has finished executing successfully
|
||||
break
|
||||
default:
|
||||
try SQLiteError.checkCResultCode(code, cConnection: database.cConnection)
|
||||
try SQLiteError.checkCResultCode(code, cConnection: database.cConnection, sql: sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user