I am unable to find where Android stores the database version within the SQLite database file. Where exactly is the database version stored?
Asked
Active
Viewed 2.9k times
2 Answers
194
You can read the version using android.database.sqlite.SQLiteDatabase.getVersion()
.
Internally, this method executes the SQL statement "PRAGMA user_version
". I got that from the Android source code.
In the database file, the version is stored at byte offset 60 in the database header of the database file, in the field 'user cookie'.

elcuco
- 8,948
- 9
- 47
- 69

Thomas Mueller
- 48,905
- 14
- 116
- 132
-
that was useful, but my question is where does this version info get stored on the filesystem (or may be in database file)? – bhups Sep 15 '10 at 03:23
-
3And to read and modify it http://stackoverflow.com/questions/8030779/change-sqlite-database-version-number – Yaroslav Mytkalyk Jan 13 '14 at 15:14
-
how is the database version persisted into the database file? – xuehui Jul 18 '17 at 12:31
-
@xuehui see the answer: byte 60 in the database file. – Thomas Mueller Jul 18 '17 at 12:48
11
If someone is looking for the java code to read version from file:
private static int getDbVersionFromFile(File file) throws Exception
{
RandomAccessFile fp = new RandomAccessFile(file,"r");
fp.seek(60);
byte[] buff = new byte[4];
fp.read(buff, 0, 4);
return ByteBuffer.wrap(buff).getInt();
}

Rafal Malek
- 3,493
- 1
- 17
- 18