Skip to content

Commit

Permalink
Merge pull request #52 from thibaultCha/fix/auto_paging-error
Browse files Browse the repository at this point in the history
[fix] accessing nil rows in auto_paging. Fix #50
  • Loading branch information
jbochi committed Mar 30, 2015
2 parents 8291c1a + fedf2a6 commit 822711e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 14 additions & 0 deletions spec/functional_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,20 @@ describe("cassandra", function()

assert.same(1, page_tracker)
end)

it("should return valid parameters if no results found", function()
-- No results ~= no rows. This test validates the behaviour of err being
-- returned if no results are returned (most likely because of an invalid query)
local page_tracker = 0
for _, rows, page, err in session:execute("SELECT * FROM pagination_test_table WHERE id = 500", nil, {auto_paging=true}) do
assert.truthy(err) -- id is not a valid column
page_tracker = page_tracker + 1
end

-- Assert the loop has been run once.
assert.same(1, page_tracker)
end)

end)
end)

Expand Down
11 changes: 8 additions & 3 deletions src/cassandra.lua
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,14 @@ function _M:execute(query, args, options)
})
page = page + 1

-- Allow the iterator to return the latest fetched rows
local paging_state = rows.meta.paging_state
if paging_state == nil and #rows > 0 then
-- If we have some results, retrieve the paging_state
local paging_state
if rows ~= nil then
paging_state = rows.meta.paging_state
end

-- Allow the iterator to return the latest page of rows or an error
if err or (paging_state == nil and rows and #rows > 0) then
paging_state = false
end

Expand Down

0 comments on commit 822711e

Please sign in to comment.