SQLiteError.sql gives the failed SQL query

This commit is contained in:
Gwendal Roué committed 2015-07-01 19:47:58 +02:00
1 parent 5951079ecc
commit cbc306f9d5
4 files changed
+11 -9

No files matched your search

+7 -5
View File
@@ -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)
}
}
}
+1 -1
View File
@@ -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
}
}
+2 -2
View File
@@ -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() {
+1 -1
View File
@@ -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)
}
}
}