diff --git a/GRDB/DBValue.swift b/GRDB/DBValue.swift index 42a83c6b0..ee85eb6be 100644 --- a/GRDB/DBValue.swift +++ b/GRDB/DBValue.swift @@ -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)) diff --git a/GRDB/Row.swift b/GRDB/Row.swift index 58612036e..21cea49dc 100644 --- a/GRDB/Row.swift +++ b/GRDB/Row.swift @@ -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: