Hi Vagner and Dewey

Using assertexec from Dado and ODBC driver (ms-sql server), I could iterate
this way:

local cur = db:assertexec("exec your_stored_procedure_name")
local row = cur:fetch ({}, "a")
while row do
-- do something
row = cur:fetch ({}, "a")
end
cur:close()
        You could also use for:

local cur = db:assertexec"exec your_stored_procedure_name"
for first, second, ..., last in cur.fetch, cur do
        -- do something with the values first, second, ..., last
end
cur:close()

        Or, better yet, you could define a function to do that kind of
stuff for you:

-- untested !!
function dado.execsp (self, spname, mode)
        local stmt = "exec "..spname
        local cur = dado.assertexec (stmt)
        return function ()
                local t
                if mode then t = {} end
                return cur:fetch (t, mode)
        end, cur
end
-- This code is copied from dado.select()

        Anyway, I think your original concern about stored procedures in
general are not a problem of Dado (which just wraps LuaSQL drivers), but
of the drivers' implementations.  If the stored procedure works just like
any select query, then I think you could use the above code or the one
suggested by Vagner.  Once I received a patch for LuaSQL that allowed
stored procedure which works with two cursors to get its values correctly
retrieved.  Unfortunately, I could not generalize the patch, since it only
worked for a particular driver...  Well, if that is your case, I cannot
help you, and I would say the solution would not be that simple.

        Regards,
                Tomás
_______________________________________________
Kepler-Project mailing list
Kepler-Project@lists.luaforge.net
http://lists.luaforge.net/cgi-bin/mailman/listinfo/kepler-project
http://www.keplerproject.org/

Reply via email to