Skip to content

Commit 76ad0d8

Browse files
committed
Allow statements to reiterate
Signed-off-by: Stephen Celis <[email protected]>
1 parent fc0cf38 commit 76ad0d8

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

SQLite Tests/StatementTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ class StatementTests: XCTestCase {
163163
XCTAssertEqual(3, count)
164164
}
165165

166+
func test_generate_allowsReuse() {
167+
InsertUsers(db, "alice", "betsy", "cindy")
168+
var count = 0
169+
let stmt = db.prepare("SELECT id FROM users")
170+
for row in stmt { count++ }
171+
for row in stmt { count++ }
172+
XCTAssertEqual(6, count)
173+
}
174+
166175
func test_cursor_returnsValues() {
167176
InsertUser(db, "alice")
168177
let stmt = db.prepare("SELECT id, email FROM users")

SQLite/Statement.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ public final class Statement {
197197
// MARK: - SequenceType
198198
extension Statement: SequenceType {
199199

200-
public func generate() -> Statement { return self }
200+
public func generate() -> Statement {
201+
reset(clearBindings: false)
202+
return self
203+
}
201204

202205
}
203206

0 commit comments

Comments
 (0)