SQLite Forum

Does table have rowid?
Login
That is very interesting Richard -- I never thought of that -- though it is obvious.

I took a different tack and added additional columns to the table_list and table_info pragma's to extract more info from the schema and to rename the object types slightly:

```
sqlite> select * from pragma_table_list;
┌────────┬────────┬────────────────────┬───────┬────┬─────┬─────┬────┬────┬───────┬──────┐
│ schema │  type  │        name        │ ncols │ ro │ eph │ rid │ pk │ ai │ named │ shad │
├────────┼────────┼────────────────────┼───────┼────┼─────┼─────┼────┼────┼───────┼──────┤
│ main   │ table  │ sqlite_master      │ 5     │ 1  │ 0   │ 1   │ 0  │ 0  │ 0     │ 0    │
│ temp   │ view   │ SysForeignKeys     │ 0     │ 0  │ 0   │ 0   │ 0  │ 0  │ 0     │ 0    │
│ temp   │ view   │ SysTriggers        │ 0     │ 0  │ 0   │ 0   │ 0  │ 0  │ 0     │ 0    │
│ temp   │ view   │ SysIndexColumns    │ 0     │ 0  │ 0   │ 0   │ 0  │ 0  │ 0     │ 0    │
│ temp   │ view   │ SysIndexes         │ 0     │ 0  │ 0   │ 0   │ 0  │ 0  │ 0     │ 0    │
│ temp   │ view   │ SysColumns         │ 0     │ 0  │ 0   │ 0   │ 0  │ 0  │ 0     │ 0    │
│ temp   │ view   │ SysTables          │ 0     │ 0  │ 0   │ 0   │ 0  │ 0  │ 0     │ 0    │
│ temp   │ view   │ SysObjects         │ 0     │ 0  │ 0   │ 0   │ 0  │ 0  │ 0     │ 0    │
│ temp   │ view   │ SysDatabases       │ 0     │ 0  │ 0   │ 0   │ 0  │ 0  │ 0     │ 0    │
│ temp   │ table  │ sqlite_temp_master │ 5     │ 1  │ 0   │ 1   │ 0  │ 0  │ 0     │ 0    │
│ _tz_   │ view   │ TZ_Lookup          │ 0     │ 0  │ 0   │ 0   │ 0  │ 0  │ 0     │ 0    │
│ _tz_   │ view   │ TZ_AllZones        │ 0     │ 0  │ 0   │ 0   │ 0  │ 0  │ 0     │ 0    │
│ _tz_   │ vtable │ tz_geopoly         │ 0     │ 0  │ 0   │ 1   │ 0  │ 0  │ 0     │ 0    │
│ _tz_   │ table  │ sqlite_master      │ 5     │ 1  │ 0   │ 1   │ 0  │ 0  │ 0     │ 0    │
│ _tz_   │ table  │ sqlite_stat1       │ 3     │ 0  │ 0   │ 1   │ 0  │ 0  │ 0     │ 0    │
│ _tz_   │ table  │ sqlite_stat4       │ 6     │ 0  │ 0   │ 1   │ 0  │ 0  │ 0     │ 0    │
│ _tz_   │ table  │ tz_geopoly_rowid   │ 4     │ 0  │ 0   │ 1   │ 1  │ 0  │ 1     │ 0    │
│ _tz_   │ table  │ tz_geopoly_node    │ 2     │ 0  │ 0   │ 1   │ 1  │ 0  │ 1     │ 0    │
│ _tz_   │ table  │ TZ_ZoneData        │ 5     │ 0  │ 0   │ 1   │ 0  │ 0  │ 0     │ 0    │
│ _tz_   │ table  │ TZ_Version         │ 2     │ 0  │ 0   │ 1   │ 0  │ 0  │ 0     │ 0    │
│ _tz_   │ table  │ tz_geopoly_parent  │ 2     │ 0  │ 0   │ 1   │ 1  │ 0  │ 1     │ 0    │
│ _tz_   │ table  │ TZ_Countries       │ 2     │ 0  │ 0   │ 0   │ 1  │ 0  │ 0     │ 0    │
│ _tz_   │ table  │ TZ_Zones           │ 6     │ 0  │ 0   │ 1   │ 1  │ 0  │ 1     │ 0    │
│ main   │ etable │ pragma_table_list  │ 11    │ 0  │ 0   │ 1   │ 0  │ 0  │ 0     │ 0    │
└────────┴────────┴────────────────────┴───────┴────┴─────┴─────┴────┴────┴───────┴──────┘
sqlite> pragma table_xinfo('tz_zones');
┌─────┬──────────────┬─────────┬─────────┬────────┬─────────┬────────────┬────┬───────┬─────────┬────────┐
│ cid │     name     │  type   │   aff   │  coll  │ notnull │ dflt_value │ pk │ rowid │ autoinc │ hidden │
├─────┼──────────────┼─────────┼─────────┼────────┼─────────┼────────────┼────┼───────┼─────────┼────────┤
│ 0   │ ID           │ INTEGER │ INTEGER │        │ 0       │            │ 1  │ 1     │ 0       │ 0      │
│ 1   │ Country_Code │ text    │ TEXT    │ nocase │ 0       │            │ 0  │ 0     │ 0       │ 0      │
│ 2   │ Area         │ text    │ TEXT    │ nocase │ 0       │            │ 0  │ 0     │ 0       │ 0      │
│ 3   │ Location     │ text    │ TEXT    │ nocase │ 0       │            │ 0  │ 0     │ 0       │ 0      │
│ 4   │ City         │ text    │ TEXT    │ nocase │ 0       │            │ 0  │ 0     │ 0       │ 0      │
│ 5   │ Zone         │ text    │ TEXT    │ nocase │ 1       │            │ 0  │ 0     │ 0       │ 0      │
└─────┴──────────────┴─────────┴─────────┴────────┴─────────┴────────────┴────┴───────┴─────────┴────────┘
sqlite> pragma table_xinfo('tz_countries');
┌─────┬─────────┬──────┬──────┬────────┬─────────┬────────────┬────┬───────┬─────────┬────────┐
│ cid │  name   │ type │ aff  │  coll  │ notnull │ dflt_value │ pk │ rowid │ autoinc │ hidden │
├─────┼─────────┼──────┼──────┼────────┼─────────┼────────────┼────┼───────┼─────────┼────────┤
│ 0   │ Code    │ text │ TEXT │ nocase │ 1       │            │ 1  │ 0     │ 0       │ 0      │
│ 1   │ Country │ text │ TEXT │ nocase │ 1       │            │ 0  │ 0     │ 0       │ 0      │
└─────┴─────────┴──────┴──────┴────────┴─────────┴────────────┴────┴───────┴─────────┴────────┘
sqlite> pragma table_xinfo('sqlite_master');
┌─────┬──────────┬──────┬─────────┬──────┬─────────┬────────────┬────┬───────┬─────────┬────────┐
│ cid │   name   │ type │   aff   │ coll │ notnull │ dflt_value │ pk │ rowid │ autoinc │ hidden │
├─────┼──────────┼──────┼─────────┼──────┼─────────┼────────────┼────┼───────┼─────────┼────────┤
│ -1  │          │      │ INTEGER │      │ 0       │            │ 1  │ 1     │ 0       │ 1      │
│ 0   │ type     │ text │ TEXT    │      │ 0       │            │ 0  │ 0     │ 0       │ 0      │
│ 1   │ name     │ text │ TEXT    │      │ 0       │            │ 0  │ 0     │ 0       │ 0      │
│ 2   │ tbl_name │ text │ TEXT    │      │ 0       │            │ 0  │ 0     │ 0       │ 0      │
│ 3   │ rootpage │ int  │ INTEGER │      │ 0       │            │ 0  │ 0     │ 0       │ 0      │
│ 4   │ sql      │ text │ TEXT    │      │ 0       │            │ 0  │ 0     │ 0       │ 0      │
└─────┴──────────┴──────┴─────────┴──────┴─────────┴────────────┴────┴───────┴─────────┴────────┘
```

and added a database_info pragma that produced a similarly named output of all objects visible in the currently loaded schema:

```
sqlite> pragma database_info;
┌────────┬────────┬─────────────────────────────────┐
│ schema │  type  │              name               │
├────────┼────────┼─────────────────────────────────┤
│ main   │ table  │ sqlite_master                   │
│ temp   │ view   │ SysForeignKeys                  │
│ temp   │ view   │ SysTriggers                     │
│ temp   │ view   │ SysIndexColumns                 │
│ temp   │ view   │ SysIndexes                      │
│ temp   │ view   │ SysColumns                      │
│ temp   │ view   │ SysTables                       │
│ temp   │ view   │ SysObjects                      │
│ temp   │ view   │ SysDatabases                    │
│ temp   │ table  │ sqlite_temp_master              │
│ _tz_   │ view   │ TZ_Lookup                       │
│ _tz_   │ view   │ TZ_AllZones                     │
│ _tz_   │ vtable │ tz_geopoly                      │
│ _tz_   │ table  │ sqlite_master                   │
│ _tz_   │ table  │ sqlite_stat1                    │
│ _tz_   │ table  │ sqlite_stat4                    │
│ _tz_   │ table  │ tz_geopoly_rowid                │
│ _tz_   │ table  │ tz_geopoly_node                 │
│ _tz_   │ table  │ TZ_ZoneData                     │
│ _tz_   │ table  │ TZ_Version                      │
│ _tz_   │ table  │ tz_geopoly_parent               │
│ _tz_   │ table  │ TZ_Countries                    │
│ _tz_   │ table  │ TZ_Zones                        │
│ _tz_   │ index  │ TZ_ZoneStart                    │
│ _tz_   │ index  │ sqlite_autoindex_TZ_Countries_1 │
│ _tz_   │ index  │ sqlite_autoindex_TZ_Countries_2 │
│ _tz_   │ index  │ TZ_Country                      │
│ _tz_   │ index  │ TZ_ZonesCountry                 │
│ _tz_   │ index  │ TZ_ZonesArea                    │
│ _tz_   │ index  │ TZ_ZonesLocation                │
│ _tz_   │ index  │ sqlite_autoindex_TZ_Zones_1     │
│ _tz_   │ index  │ TZ_ZonesCity                    │
│ _tz_   │ index  │ TZ_ZoneOffset                   │
│ _tz_   │ index  │ TZ_ZoneDataID                   │
│ main   │ etable │ pragma_table_list               │
└────────┴────────┴─────────────────────────────────┘
```
"etable" equates to a eponymous virtual table module and I attribute it to "main" even though it exists quite independently of any schema name;

"vtable" is a virtual table which is merely a different attribute of a table (like a view) detected when one cursors through the tables in-memory schema;

"trigger" is also in the in-memory schema but since there is not one defined in this sample it does not show up.

I also added a rudimentary trigger_list pragma that obtains some information for triggers given schema.table.  I haven't added a trigger_info pragma because I have not managed to figure out how to display interesting information about a specific trigger (such as for the ON conditions, for example).

This allows my "catalog views" to all work (across all attached schemas) without necessitating any dynamic execution (aka eval) capabilities to the codebase.