playframework/Play20 — pull request #263 by soro (2012-04-26 15:40:15+00:00)
Title: Close statements explicitly for some calls and also prevent leak on apply (Anorm)

Not sure if you want to merge this as is, but I thought I'd submit an actual fix instead of just pointing to something (although I might be wrong of course).

It seems to me that the statement isn't correctly closed if the stream returned by apply isn't fully consumed, since the close on the statement will only be invoked by the unfold once the end is reached.
If a consumer of the api writes something like SQL(...)()...headOption, this unfortunately will never happen.
Unfortunately fixing this requires a small API change, since now the user will have to pass the consuming function to the SQL apply method, but I don't feel that is really that much of an inconvenience.

The other changes are just closing the statement explicitly upon invocation of execute or executeUpdate. I think BoneCP might do the right thing here even if they are not explicitly closed, but I'm not so sure this will be the case for other pools or older versions and as far as I know it is considered good form to close statements explicitly. I also don't think consumers of the API will expect the statement to still be open after having invoked execute (execute1 excluded).