Empty Row() initializer

This commit is contained in:
Gwendal Roué committed 2015-10-10 21:04:20 +02:00
1 parent b7ae2b33ee
commit aa59b24bb5
3 files changed
+42 -2

No files matched your search

+7
View File
@@ -1,6 +1,13 @@
Release Notes
=============
## Next Release
**New**
- `Row()` initializes an empty row.
## 0.22.0
Released october 8, 2015
@@ -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)
}
+34 -1
View File
@@ -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
}
}
}