Bool support

This commit is contained in:
Gwendal Roué committed 2015-07-01 05:57:26 +02:00
1 parent 73e9d79e1a
commit cf58123725
2 files changed
+16

No files matched your search

+7
View File
@@ -12,6 +12,13 @@ public protocol DBValue {
func bindInStatement(statement: Statement, atIndex index:Int)
}
extension Bool: DBValue {
public func bindInStatement(statement: Statement, atIndex index: Int) {
let code = sqlite3_bind_int(statement.cStatement, Int32(index), Int32(self ? 1 : 0))
assert(code == SQLITE_OK)
}
}
extension Int: DBValue {
public func bindInStatement(statement: Statement, atIndex index: Int) {
let code = sqlite3_bind_int64(statement.cStatement, Int32(index), Int64(self))
+9
View File
@@ -13,6 +13,15 @@ public struct Row {
self.statement = statement
}
public func boolAtIndex(index: Int) -> Bool? {
switch sqlite3_column_type(statement.cStatement, Int32(index)) {
case SQLITE_NULL:
return nil
default:
return sqlite3_column_int(statement.cStatement, Int32(index)) != 0
}
}
public func intAtIndex(index: Int) -> Int? {
switch sqlite3_column_type(statement.cStatement, Int32(index)) {
case SQLITE_NULL: