Cp200205@[EMAIL PROTECTED]
wrote:
>> The fetching of the result sequence is not really a logical
>> part of the generation of events from the result sequence,
>> hence combining that (and the free of the result sequence)
>> into a single procedure may not be the way to go.
>
> I thought it work kind of well:
>
> every person := dbi_conn_find(conn, "SELECT * FROM people") do
> displayPerson(person)
>
> That prevented me from having to deal with having a var for storing the
> result, doing the actual query, and freeing the query when I was done
> with it.
Oh, I know, that is attractive. And you can still write dbi_conn_find()
that way for the situation where you want all results displayed. Or,
write
a procedure that applies displayPerson to every result:
applyToRes(conn, "SELECT * FROM people", displayPerson)
procedure applyToRes(conn, sql, func)
res := dbi_conn_query(conn, sql)
every func(dbi_result_fetch_next_table(res))
dbi_result_free(res)
end
which has the same drawback as the original [only works 'right' when
you want all of them displayed]. *But* consider the following version:
procedure applyToRes(conn, sql, func, limit)
res := dbi_conn_query(conn, sql)
if \limit then
every func(dbi_result_fetch_next_table(res))\limit
else
every func(dbi_result_fetch_next_table(res))
dbi_result_free(res)
end
so, if you want only the first result:
applyToRes(conn, "SELECT * FROM people", displayPerson, 1)
Of course, once you allow this, then you could more efficiently write:
procedure applyToRes(conn, sql, func, limit)
if \limit then sql ||:= " LIMIT "||limit
res := dbi_conn_query(conn, sql)
every func(dbi_result_fetch_next_table(res))
dbi_result_free(res)
end
> However, I see now that's not possible, so I'll just omit the function
> and use:
>
> res := dbi_conn_query(conn, "SELECT * FROM people")
> every person := dbi_result_fetch_next_table(res) do
> displayPerson(person)
> dbi_result_free(res)
>
> Add's two more lines and a declared var, no huge deal, just though the
> other was rather nice.
You can also write:
res := dbi_conn_query(conn, "SELECT * FROM people")
every displayPerson(dbi_result_fetch_next_table(res))
dbi_result_free(res)
which gets rid of one variable (just a different one than before).
And, if you're feeling perverse, consider:
res := dbi_conn_query(conn, "SELECT * FROM people")
every displayPerson(
(dbi_result_fetch_next_table|dbi_result_free)(res))
which works if dbi_result_free() always fails. Not
that I'd wish that on any sane human, mind you...
--
Steve Wampler -- swampler@[EMAIL PROTECTED]
gods that smiled on your birth are now laughing out loud.


|