本文介绍了sqlite-如何获得单行结果? (luaSQLite3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从sql语句获取单行结果(例如,以表/数组的形式).使用Lua Sqlite(LuaSQLite3).例如,这个:
How can I get a single row result (e.g. in form of a table/array) back from a sql statement. Using Lua Sqlite (LuaSQLite3). For example this one:
SELECT * FROM sqlite_master WHERE name ='myTable';
到目前为止,我注意到:
So far I note:
- 使用"nrows"/"rows"可以使迭代器返回
- 使用"exec"似乎没有返回结果(?)
具体问题如下:
问题1-如何获取单行(例如第一行)结果?
Q1 - How to get a single row (say first row) result back?
Q2-如何获得行数? (例如num_rows_returned = db:XXXX(sql))
Q2 - How to get row count? (e.g. num_rows_returned = db:XXXX(sql))
推荐答案
以下是获取返回计数的演示:
Here is a demo of getting the returned count:
> require "lsqlite3"
> db = sqlite3.open":memory:"
> db:exec "create table foo (x,y,z);"
> for x in db:urows "select count(*) from foo" do print(x) end
0
> db:exec "insert into foo values (10,11,12);"
> for x in db:urows "select count(*) from foo" do print(x) end
1
>
这篇关于sqlite-如何获得单行结果? (luaSQLite3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!