SQLite User Forum

Database file format changes since 3.35.3?
Login

Database file format changes since 3.35.3?

(1.1) By Bradley Spatz (bspatz) on 2022-08-08 21:27:16 edited from 1.0 [link] [source]

As recommended, I'm upgrading to 3.39.2. In doing several old/new testing with the same inputs I notice the resulting new database file is the same size as the old, but the Windows FC command is showing some differences in what looks like the "header" and text-based schema description(s).

However, using sqldiff I can find no logical differences (i.e. sqldiff reports no changes) between the old and new database files.

I did a quick review of the release notes since 3.35.3 but didn't see anything that caught my eye indicating such changes; maybe I missed something.

But given the above, are database file differences to be expected between 3.36.0 and 3.39.2?

Just thought I'd check. Thanks!

(2) By anonymous on 2022-08-08 22:17:11 in reply to 1.1 [source]

The database file format does not change much, and even if it does, then the older files can still be opened in newer versions of SQLite, too.

However, the SQLite version number is stored in the database header at offset 96.

There may be other differences too but I do not know what they are.

(3) By Richard Hipp (drh) on 2022-08-08 22:57:49 in reply to 2 [link] [source]

the SQLite version number is stored in the database header

That sounds right. There is a big-endian 4-byte integer at offset 96. If you render that integer as text, it will come out as 3035003 for version 3.35.3 and 3039002 for version 3.39.2.

The value is the version number of the last version of SQLite that wrote to the database file. You might have multiple applications, each statically linked to a different version of SQLite, all taking turns writing to the same database file. The last writer wins. In other words, the value at offset 96 is the version number for the last application that actually changed the database.

(4) By Sunny Saini (SunnySaini_com) on 2022-08-09 12:52:35 in reply to 2 [link] [source]

SQLite database may not be backward compatible. For example database created in Samsung M30s phone (SQLite v3.22.0) may not be recognised in Lenovo K3 Note phone (SQLite v3.8.6).

(5) By Richard Hipp (drh) on 2022-08-09 13:15:13 in reply to 4 [link] [source]

That's not what "backwards compatible" means.

"Backwards compatible" means that any database created by v3.8.6 is readable and writable by v3.22.0. SQLite promises to be backwards compatible all the way back to v3.0.0. Any database file created by an earlier version of SQLite should be 100% readable and writable by later versions of SQLite.

However, SQLite does from time to time add new features. If you create a database in version 3.39.2 that makes use of RIGHT JOIN in a VIEW, for example, that database will not be usable in versions prior to 3.39.2, since prior versions did not know about RIGHT JOIN. But, as long as you do not make use of new features, database files created by version 3.39.2 should be readable and writable by SQLite version 3.0.0.

Summary:

  • Any SQLite database file created by an earlier version of SQLite (beginning with version 3.0.0) is 100% readable and writable by all later versions of SQLite.

  • Any SQLite database file created by a later version of SQLite is readable and writable by earlier versions of SQLite as long as the database file does not make use of features that were added after the release of the earlier version.

(6) By Sunny Saini (SunnySaini_com) on 2022-08-09 15:33:16 in reply to 5 [link] [source]

You are right, that is what I meant.