1 --转载地址:http://www.cnblogs.com/windtail/archive/2012/01/08/2623191.html 2 require"luasql.sqlite3" 3 function enumSimpleTable(t) 4 print"-------------------" 5 fork,v in pairs(t) do 6 print(k, " = ", v) 7 end 8 print"-------------------\n" 9 end 10 11 function rows(cur) 12 return function(cur) 13 localt = {} 14 if(nil~= cur:fetch(t, 'a')) then return t 15 else 16 return nil 17 end 18 end 19 cur 20 end 21 22 env = assert(luasql.sqlite3()) 23 db =assert(env:connect("test.db")) 24 25 db:setautocommit(false) 26 res = assert(db:execute [[CREATE TABLEpeople(name text, sex text)]]) 27 res = assert(db:execute [[INSERT INTOpeople VALUES('程序猿','男')]]) 28 res = assert(db:execute [[INSERT INTOpeople VALUES('程序猿老婆', '女')]]) 29 assert(db:commit()) 30 31 32 res = assert(db:execute [[SELECT * FROMpeople]]) 33 colnames = res:getcolnames() 34 coltypes = res:getcoltypes() 35 enumSimpleTable(colnames) 36 enumSimpleTable(coltypes) 37 38 for r in rows(res) do 39 enumSimpleTable(r) 40 end 41 42 res:close() 43 db:close() 44 env:close()
标签:end,cur,res,db,assert,lua,luaForWin,sqlite3 From: https://www.cnblogs.com/chenyalin/p/16877992.html