How to find SQLITE database file version

I have few sqlite database files. I want to know the database file version i.e if the database was created with sqlite2 or sqlite3 or any other main/sub version (not the sqlite library or driver or user_version or schema_version).


Solution 1:

You can write this command in any sqlite explorer which will give the sqlite version

select sqlite_version();

Solution 2:

You can get version number of a database file by the Magic Header String:

  • sqlite2 ==> first 48 bytes
  • sqlite3 ==> first 16 bytes

$ head -c 48 file2.db
** This file contains an SQLite 2.1 database **

$ head -c 16 file3.db
SQLite format 3

The easier way is using the file command:

$ file file2.db
file2.db: SQLite 2.x database

$ file file3.db
file3.db: SQLite 3.x database

Solution 3:

Get user_version

Run SQL: PRAGMA user_version;

Get schema_version:

Run SQL: PRAGMA schema_version;

When create database file (.db), user_version can be set by user.

Solution 4:

The correct answer from version 3 of sqlite program is:

sqlite3 --version

Solution 5:

You can extract the information from the header file. It will require you to open the database file 'by hand' but I don't know if there is an API function to get this information.