I want to migrate my iPhone app to a new database version. Since I don't have some version saved, I need to check if certain column names exist.
This Stackoverflow entry suggests doing the select
SELECT sql FROM sqlite_master
WHERE tbl_name = 'table_name' AND type = 'table'
and parse the result.
Is that the common way? Alternatives?
If you have the sqlite database, use the sqlite3 command line program and these commands:
To list all the tables in the database:
To show the schema for a given
tablename
:will get you a list of all the column names.
If you want the output of your queries to include columns names and be correctly aligned as columns, use these commands in
sqlite3
:You will get output like:
When you run the
sqlite3
cli, typing in:will also give the desired result
Maybe you just want to print the table headers on the console. This is my code: (for each table)