fukamachi / cl-dbi

Database independent interface for Common Lisp
201 stars 28 forks source link

Freeing query resources #30

Open mtstickney opened 8 years ago

mtstickney commented 8 years ago

I was working on an ODBC driver for cl-dbi the other day, and I've run into a snag: the driver has to allocate some (foreign) resources to execute a query, which need to be freed after results have been fetched, but there's no obvious place to do this. It seems like there are three cases:

  1. Callers use EXECUTE and FETCH directly.
  2. Callers use DO-SQL or FETCH-ALL, but signal a condition before all results are fetched.
  3. Callers use DO-SQL or FETCH-ALL, and fetch all results normally.

3 is easy to do, but 1 & 2 are harder. The thing that comes to mind is that cl-dbi needs a FREE-QUERY counterpart to EXECUTE (and probably some kind of WITH-QUERY macro), but that would mean an API change. Thoughts?

fukamachi commented 8 years ago

Thank you for pointing out. CL-DBI fetches rows after the query execution and stores them in a private slot by default, so it wouldn't always be a problem. However, since CL-DBI is a lower-level DB interface, it may be preferable to have a method to free a query object.