On 10 Apr 2015, at 9:35am, Paolo Bolzoni <paolo.bolzoni.brown at gmail.com> wrote:
> The subject already says it all, I was wondering what is the best > practice for a prepared statement that need to be used an unknown > number of times. > > It is better to reset and step (as many times as needed) or step > and reset after? Or there is no real difference? The first _step() command after _prepare() and _bind(), and the first _step() after a _reset(), do database access and figure-out the strategy for accessing the correct rows. The results of this are stored for later use. It can also, depending on the command, lock the database. The _reset() command releases this storage and any locks. (It does not unbind any bound parameters.) So I would recommend that you do _reset() as soon as you know you don't need any more _step() in the current query/execution. The second of your two alternatives. Lastly, you should call _finalize() on a statement before closing your connection, even if the last thing you did with it was _reset(). _finalize() releases memory used by bound variables, and also the memory used to store the statement itself. It's equivalent to _close() for the statement or to deleting an object. Simon.

