tags:

views:

49

answers:

1

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 data in a SQLite DB? I use python for accessing SQLite.

+1  A: 

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.

Mark Byers
@Mark : You are correct, I got something wrong, I changed it. Thanks.
prosseek