开发者

What's the least expensive way to get the number of rows (data) in a SQLite DB?

When I need to get the number of row(data) inside a SQLite database, I run the following pseudo code.

cmd = "SELECT Count(*) FROM benchmark"
res = runcommand(cmd)
read res to get result.

But, I'm not sure if it's the best way to go. What would be the optimum way to get the number of开发者_如何学Python data in a SQLite DB? I use python for accessing SQLite.


Your query is correct but I would add an alias to make it easier to refer to the result:

SELECT COUNT(*) AS cnt FROM benchmark

Regarding this line:

count size of res

You don't want to count the number of rows in the result set - there will always be only one row. Just read the result out from the column cnt of the first row.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜