nramenta / dabble

Lightweight wrapper and collection of helpers for MySQLi
MIT License
13 stars 4 forks source link

Invalid seek position #4

Closed anoxic closed 9 years ago

anoxic commented 9 years ago

Hello, I am getting the following error when trying to use $dabble->first() on an empty query.

invalid seek position (0)

And the trace

#0 [..]vendor/dabble/dabble/src/Dabble/Result.php(342): Dabble\Result->seek(0)
#1 [..]vendor/dabble/dabble/src/Dabble/Result.php(237): Dabble\Result->rewind(0)
#2 [..]/Transaction.php(311): Dabble\Result->first()

It's simple enough to get around by getting the count first, but I think another response may be more appropriate than an exception within dabbles' calls. I would lean towards returning false, but there are certainly other options.

nramenta commented 9 years ago

This change was introduced by 2a3dd78. I've made some changes to remedy this situation:

Result::seek strictly returns true or false, without throwing any exceptions. Furthermore, to closely follow mysqli, calls to the Result::fetch method -- indirectly through Result::first and Result::last -- return null (instead of false as you proposed) if you try to fetch from an empty result set.

anoxic commented 9 years ago

I just noticed this wasn't closed yet. Thank you, this works well!