What SQL can be used to list the tables, and the rows within those tables in an SQLite database file - once I have attached it with the
Use:
import sqlite3
TABLE_LIST_QUERY = "SELECT * FROM sqlite_master where type='table'"
It appears you need to go through the sqlite_master table, like this:
SELECT * FROM dbname.sqlite_master WHERE type='table';
And then manually go through each table with a SELECT
or similar to look at the rows.
The .DUMP
and .SCHEMA
commands doesn't appear to see the database at all.
There is a command available for this on the SQLite command line:
.tables ?PATTERN? List names of tables matching a LIKE pattern
Which converts to the following SQL:
SELECT name FROM sqlite_master
WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%'
UNION ALL
SELECT name FROM sqlite_temp_master
WHERE type IN ('table','view')
ORDER BY 1
To list the tables you can also do:
SELECT name FROM sqlite_master
WHERE type='table';
The ".schema" commando will list available tables and their rows, by showing you the statement used to create said tables:
sqlite> create table_a (id int, a int, b int); sqlite> .schema table_a CREATE TABLE table_a (id int, a int, b int);
.da to see all databases - one called 'main'
tables of this database can be seen by
SELECT distinct tbl_name from sqlite_master order by 1;
The attached databases need prefixes you chose with AS in the statement ATTACH e.g. aa (, bb, cc...) so:
SELECT distinct tbl_name from aa.sqlite_master order by 1;
Note that here you get the views as well. To exclude these add where type = 'table' before ' order'