Skip to content

Commit 571f9a5

Browse files
committed
Don't drop offset when fetching first row
Fixes stephencelis#110. Signed-off-by: Stephen Celis <stephen@stephencelis.com>
1 parent 38b50fc commit 571f9a5

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

SQLite Tests/QueryTests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ class QueryTests: SQLiteTestCase {
285285
AssertSQL("SELECT * FROM \"users\" LIMIT 1")
286286
}
287287

288+
func test_first_withOffset_retainsOffset() {
289+
insertUsers("alice", "betsy")
290+
291+
XCTAssertEqual(2, users.limit(2, offset: 1).first![id])
292+
AssertSQL("SELECT * FROM \"users\" LIMIT 1 OFFSET 1")
293+
}
294+
288295
func test_isEmpty_returnsWhetherOrNotTheQueryIsEmpty() {
289296
XCTAssertTrue(users.isEmpty)
290297

SQLite/Query.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ public struct Query {
731731

732732
/// The first row (or nil if the query returns no rows).
733733
public var first: Row? {
734-
var generator = limit(1).generate()
734+
var generator = limit(to: 1, offset: limit?.offset).generate()
735735
return generator.next()
736736
}
737737

0 commit comments

Comments
 (0)