> procedure dbi_conn_find(dbi_conn, sql)
> local res, row
> res := dbi_conn_query(dbi_conn, sql)
> every row := dbi_result_fetch_next_table(res) do {
> suspend row
> }
> dbi_result_free(res)
> end
>
> The result *must* be freed. So, with the above procedure, the following
> works just fine:
>
> every row := dbi_conn_find(conn, "SELECT * FROM people WHERE name =
> 'JOHN'") do
> write_person(row)
>
> However:
>
> first := dbi_conn_find(conn, "SELECT * FROM people WHERE name =
> 'JOHN'")
>
> will fail to call "dbi_result_free".
>
> Any thoughts on how to handle this?
When a generator suspends, it can't assume it will ever be resumed.
For the example you gave, I'd probably read fetch all the results
into an array, close the database connection, and then generate the
array contents. Of course, that assumes that the results can fit
in memory reasonably.
---------------------------------------------------------------------------
Gregg Townsend Staff Scientist The University of Arizona
gmt@[EMAIL PROTECTED]
Computer Science Tucson, Arizona, USA


|