lua-users home
lua-l archive

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


	 Hi Mike

 Ah.  I need, at this point, to work with odbc, as I am currently querying
 against mssql and db2/400.  I had previously tried to create a higher
 level abstraction, similar in some respect to yours, but was running up
 againt the same problems, so I backed off and have been using luasql
 directly.  I hadn't actually tried any of the native drivers, as they
 wouldn't be useful to me, at least on any of my current projects.
	Another approach could be to just return the cursor
to the caller and let the programmer explicitly closes it:

-- Untested code
function select (self, columns, tabname, cond, extra, mode)
	local stmt = sql.select (columns, tabname, cond, extra)
	local cur = assertexec (self, stmt)
	return function ()
		-- This table must be created inside this function or it could
		-- make `selectall' to return the same row every time.
		local t
		if mode then t = {} end
		return cur:fetch (t, mode)
	end, cur
end

...

local iter, cur = db:select ("*", "table", nil, nil, "a")
for row in iter do
...
end
cur:close()

	 Regards,
		 Tomás