chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] Re: Problem with sqlite3 egg


From: Alejandro Forero Cuervo
Subject: [Chicken-users] Re: Problem with sqlite3 egg
Date: Fri, 10 Aug 2007 11:54:47 -0500
User-agent: Mutt/1.5.16 (2007-06-11)

> if you pass an SQL string to sqlite3:for-each-row as the statement, the
> code compiles this string creating a temporary statement handle which is
> then finalized upon exit from the dynamic scope of sqlite3:for-each-row
> using a dynamic-wind construct.

That makes perfect sense, I understand the problem now.

I've settled down on the following style:

  (define (db-exec db sql)
    (iterator->stream
      (lambda (collect _)
        (receive (stmt rest)
                 (sqlite3:prepare db sql)
          (sqlite3:for-each-row (compose c vector) stmt)
          (sqlite3:finalize! stmt)))))

This is because my code just calls db-exec with the SQL string and the
DB handle and expectes db-exec to return the stream with the results.
If I where to use sqlite3:call-with-temporary-statements, I would have
to make changes to all my code, not just to the db-exec function.

I have one question, though.  In the unlikely chance that a stream
returned by db-exec doesn't get traversed until the end, the call to
sqlite3:finalize! won't be made.  Will the garbage collector take care
of finalizing the sqlite3:statement (by means of a finalizer on the
statement object) anyway?

Thanks for your help, Thomas!

Alejo.
http://azul.freaks-unidos.net/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]