Beruflich Dokumente
Kultur Dokumente
Each of these points will be described in more detail below, after first considering
more closely the meaning of "application file format". See also the short version of
this whitepaper.
"application formats". An EPUB file, in contrast, stores both text and images (as
contained XHTML and GIF/JPEG files) and so it is considered an "application format".
This article is about "application formats".
The boundary between a file format and an application format is fuzzy. This article
calls JPEG a file format, but for an image editor, JPEG might be considered the
application format. Much depends on context. For this article, let us say that a file
format stores a single object and an application format stores many different objects
and their relationships to one another.
1. Fully Custom Formats. Custom formats are specifically designed for a single
application. DOC, DWG, PDF, XLS, and PPT are examples of custom formats.
Custom formats are usually contained within a single file, for ease of transport.
They are also usually binary, though the DWG format is a notable exception.
Custom file formats require specialized application code to read and write and are
not normally accessible from commonly available tools such as unix command-
line programs and text editors. In other words, custom formats are usually
"opaque blobs". To access the content of a custom application file format, one
needs a tool specifically engineered to read and/or write that format.
https://sqlite.org/appfileformat.html 2/7
10/10/2017 SQLite As An Application File Format
disk file. And because it is compressed, the wrapped pile-of-files format tends to
be more compact.
As with custom file formats, and unlike pure pile-of-file formats, a wrapped pile-
of-files format is not as easy to edit, since usually the entire file must be
rewritten in order to change any component part.
If the content is compressed, then such an SQLite database is the same size (1%)
as an equivalent ZIP archive, and it has the advantage of being able to update
individual "files" without rewriting the entire document.
But an SQLite database is not limited to a simple key/value structure like a pile-of-
files database. An SQLite database can have dozens or hundreds or thousands of
different tables, with dozens or hundreds or thousands of fields per table, each with
different datatypes and constraints and particular meanings, all cross-referencing each
other, appropriately and automatically indexed for rapid retrieval, and all stored
efficiently and compactly in a single disk file. And all of this structure is succinctly
documented for humans by the SQL schema.
The power of an SQLite database could, in theory, be achieved using a custom file
format. But any custom file format that is as expressive as a relational database
would likely require an enormous design specification and many tens or hundreds of
thousands of lines of code to implement. And the end result would be an "opaque
blob" that is inaccessible without specialized tools.
SQLite is one of the most used software libraries in the world. There are literally
tens of billions of SQLite database files in use daily, on smartphones and gadgets
and in desktop applications. SQLite is carefully tested and proven reliable. It is
not a component that needs much tuning or debugging, allowing developers to
stay focused on application logic.
https://sqlite.org/appfileformat.html 3/7
10/10/2017 SQLite As An Application File Format
SQLite does not have any file naming requirements and so the application can
use any custom file suffix that it wants to help identify the file as "belonging" to
the application. SQLite database files contain a 4-byte Application ID in their
headers that can be set to an application-defined value and then used to identify
the "type" of the document for utility programs such as file(1), further enhancing
the document metaphor.
5. Cross-Platform. SQLite database files are portable between 32-bit and 64-bit
machines and between big-endian and little-endian architectures and between
any of the various flavors of Windows and Unix-like operating systems. The
application using an SQLite application file format can store binary numeric data
without having to worry about the byte-order of integers or floating point
numbers. Text content can be read or written as UTF-8, UTF-16LE, or UTF-16BE
and SQLite will automatically perform any necessary translations on-the-fly.
https://sqlite.org/appfileformat.html 4/7
10/10/2017 SQLite As An Application File Format
A pile-of-files format can be read incrementally just like SQLite. But many
developers are surprised to learn that SQLite can read and write smaller BLOBs
(less than about 100KB in size) from its database faster than those same blobs
can be read or written as separate files from the filesystem. (See 35% Faster
Than The Filesystem and Internal Versus External BLOBs for further information.)
There is overhead associated with operating a relational database engine,
however one should not assume that direct file I/O is faster than SQLite database
I/O, as often it is not.
https://sqlite.org/appfileformat.html 5/7
10/10/2017 SQLite As An Application File Format
12. Better Applications. If the application file format is an SQLite database, the
complete documentation for that file format consists of the database schema,
with perhaps a few extra words about what each table and column represents.
The description of a custom file format, on the other hand, typically runs on for
hundreds of pages. A pile-of-files format, while much simpler and easier to
describe than a fully custom format, still tends to be much larger and more
complex than an SQL schema dump, since the names and format for the
individual files must still be described.
This is not a trivial point. A clear, concise, and easy to understand file format is a
crucial part of any application design. Fred Brooks, in his all-time best-selling
computer science text, The Mythical Man-Month says:
Rob Pike, in his Rules of Programming expresses the same idea this way:
https://sqlite.org/appfileformat.html 6/7
10/10/2017 SQLite As An Application File Format
Linus Torvalds used different words to say much the same thing on the Git
mailing list on 2006-06-27:
The point is this: an SQL database schema almost always does a far better job of
defining and organizing the tables and data structures and their relationships.
And having clear, concise, and well-defined representation almost always results
in an application that performs better, has fewer problems, and is easier to
develop and maintain.
Conclusion
SQLite is not the perfect application file format for every situation. But in many cases,
SQLite is a far better choice than either a custom file format, a pile-of-files, or a
wrapped pile-of-files. SQLite is a high-level, stable, reliable, cross-platform, widely-
deployed, extensible, performant, accessible, concurrent file format. It deserves your
consideration as the standard file format on your next application design.
https://sqlite.org/appfileformat.html 7/7