require "luasql.odbc" env = assert(luasql.odbc()) -- MSSQLというODBC DSNに接続 conn = assert(env:connect("MSSQL", "sa", "password")) -- クエリーを実行 cur = assert(conn:execute( "select company_id, company_name from company")) -- 返された行を表示 row = cur:fetch ({}, "a") while row do print([[会社ID:]] .. row.company_id .. [[ 会社名: ]] .. row.company_name) row = cur:fetch (row, "a") end -- 閉じる cur:close() conn:close() env:close()
動作環境
Lua for Windows 5.1.4, Microsoft SQL Server 2008 R2 SP1 Express