lua-users home
lua-l archive

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


	Hi saeid rezaee

I search a script in lua that prints the values of sql table . suppose we have a table in sql that contains over 1000 record , this script must open table and prints these 1000 records.
thank for any help
	First, you have to define how to connect to the database.
Usually this choice also adds the ability to make queries.
	I use LuaSQL and Dado to connect to Postgres:

-- untested code
local dado = require"dado"
db = dado.connect("database-name", "database-user", "database-password") -- postgres is default

local fields = "*"
local tabs = "table-name"
local cond = nil -- gets everything
local extra = nil -- 'order by', 'group by' etc.

local counter = 0
for row in db:select(fields, tabs, cond, extra, 'a') do
	-- 'a' means: give me a table indexed by the names of the columns
	counter = counter + 1 -- this counter is unnecessary :-)
	print("line", counter)
	for i, v in pairs(row) do
		print (i, v)
	end
end
db:close()

	Hope it helps
		Tomás