sqlite count rows of tables identified by subquery

I used the following shell syntax to blindly get counts from tables in a database I was debugging.

db="database.db"
for i in `sqlite3 "$db" "SELECT name FROM sqlite_master WHERE 
type='table';"`; do echo -n $i\ \=\ ; sqlite3 "$db" "SELECT 
COUNT(*) FROM $i;"; done

cols = 0
sqlite_sequence = 0
datacols = 17
hits = 0
host = 0
document = 0
admin = 2
comments = 0

If you want to know these values for debugging purposes, look at the output of the sqlite3_analyzer tool.

If you want to use these values in your program, you have to generate the queries dynamically in your program.

Tags:

Sqlite