diff --git a/CHANGELOG.md b/CHANGELOG.md index be46813ff..0d5e43553 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Release Notes ============= +## Next Release + +**New** + +- `Row()` initializes an empty row. + + ## 0.22.0 Released october 8, 2015 diff --git a/GRDB Tests/Public/Record/RecordAwakeFromFetchTests.swift b/GRDB Tests/Public/Record/RecordAwakeFromFetchTests.swift index 47ebe944f..ec19c3591 100644 --- a/GRDB Tests/Public/Record/RecordAwakeFromFetchTests.swift +++ b/GRDB Tests/Public/Record/RecordAwakeFromFetchTests.swift @@ -46,7 +46,7 @@ class RecordEventsTests: GRDBTestCase { } func testAwakeFromFetchIsNotTriggeredByInitFromRow() { - let record = EventRecorder(row: Row(dictionary: ["foo":"bar"])) + let record = EventRecorder(row: Row()) XCTAssertEqual(record.awakeFromFetchCount, 0) } diff --git a/GRDB/Core/Row.swift b/GRDB/Core/Row.swift index 34997b1fe..4c5241fa0 100644 --- a/GRDB/Core/Row.swift +++ b/GRDB/Core/Row.swift @@ -17,6 +17,14 @@ public final class Row: CollectionType { // MARK: - Building rows + /** + Builds an empty row. + */ + public init() { + self.sqliteStatement = nil + self.impl = EmptyRowImpl() + } + /** Builds a row from an dictionary of values. */ @@ -558,6 +566,8 @@ public final class Row: CollectionType { /// /// - DictionaryRowImpl: dictionary rows are created by the library users. /// They do not come from the database. + /// + /// - EmptyRowImpl: empty row let impl: RowImpl /// Only metal rows have a SQLiteStatement. @@ -698,7 +708,30 @@ public final class Row: CollectionType { return Row(detachedStatement: statement) } } - + + + // MARK: - EmptyRowImpl + + /// See Row.init() + private struct EmptyRowImpl : RowImpl { + var count: Int { return 0 } + + func databaseValue(atIndex index: Int) -> DatabaseValue { + fatalError("Empty row has no column") + } + + func columnName(atIndex index: Int) -> String { + fatalError("Empty row has no column") + } + + func indexForColumn(named name: String) -> Int? { + return nil + } + + func detachedRow(row: Row) -> Row { + return row + } + } }