<title>8+3 Filenames</title>
<tcl>hd_keywords {short filenames}</tcl>

<h1 align="center">SQLite And 8+3 Filenames</h1>

<p>
The default configuration of SQLite assumes the underlying filesystem
supports long filenames.
</p>

<p>
SQLite does not impose any naming requirements on database files.
SQLite will happily work with a database file that has any filename extension
or with no extension at all.
When auxiliary files are needed for a [rollback journal] or
a [write-ahead log] or for one of the other kinds of
[temporary disk files], then the name for the auxiliary file is normally
constructed by appending a suffix onto the end of the database file name.
For example, if the original database is call "<tt>app.db</tt>" then
the [rollback journal] will be called "<tt>app.db-journal</tt>"
and the [write-ahead log] will be called "<tt>app.db-wal</tt>".
This approach to auxiliary file naming works great on systems that
support long filenames.  But on systems that impose 8+3 filename
constraints, the auxiliary files do not fit the 8+3 format even though
the original database file does.
</p>


<h2>Changing Filesystems</h2>

<p>
The recommended fix for this problem is to select a different
filesystem.  These days, there is a huge selection of high-performance, 
reliable, patent-free filesystems that support long filenames.  
Where possible, it is recommended that embedded devices use one
of these other filesystems.  This will avoid compatibility issues
and the danger of
[database corruption caused by inconsistent use of 8+3 filenames].
</p>

<h2>Adjusting SQLite To Use 8+3 Filenames</h2>

<p>
Some devices are compelled to use an older filesystem with 8+3
filename restrictions for backwards compatibility, or due
to other non-technical factors.  In such situations, SQLite can be
coerced into using auxiliary files that fit the 8+3 pattern as follows:
</p>

<ol>
<li><p>Compile the SQLite library with the [SQLITE_ENABLE_8_3_NAMES]
       compile-time option.
       Support for 8+3 filenames is not included in SQLite by default
       because it does introduce some overhead.  The overhead is tiny,
       but even so, we do not want to burden the billions of SQLite
       applications that do not need 8+3 filename support.</p>

<li><p>Use [URI filenames] when [sqlite3_open | opening] or
       [ATTACH | ATTACH-ing] database files and include the
       "<tt>8_3_names=1</tt>" query parameter in the URI.</p>

<li><p>Make sure that database filenames follow the 8+3 filename
       format and that they do not have an empty name or extension.
       In other words, the database filename must contain between
       1 and 8 characters in the base name and between 1 and 3 characters
       in the extension.  Blank extensions are not allowed.</p>
</ol>

<p>
When the steps above are used, SQLite will shorten filename extensions
by only using the last 3 characters of
the extension.  Thus, for example, a file that would normally be called
"<tt>app.db-journal</tt>" is shortened to just "<tt>app.nal</tt>".
Similarly, "<tt>app.db-wal</tt>" will become "<tt>app.wal</tt>" and
"<tt>app.db-shm</tt>" becomes "<tt>app.shm</tt>".
</p>

<p>
Note that it is very important that the database filename have some kind
of extension.  If there is no extension, then SQLite creates auxiliary
filenames by appending to the base name of the file.  Thus, a database
named "<tt>db01</tt>" would have a [rollback journal] file named
"<tt>db01-journal</tt>".  And as this filename has no extension to shorten
to 3 characters, it will be used as-is, and will violate 8+3 naming rules.
</p>

<tcl>hd_fragment db83corrupt \
   {database corruption caused by inconsistent use of 8+3 filenames}
</tcl>
<h2>Database Corruption Warning</h2>

<p>
If a database file is accessed using 8+3 naming rather than the default
long filename, then it must be consistently accessed 
using 8+3 naming by every database
connection every time it is opened, or else there is a risk of database
corruption.
The auxiliary [rollback journal] and [write-ahead log] files are essential
to SQLite for being about to recover from a crash.  If an application is
using 8+3 names and crashes, then the information needed to safely recover
from the crash is stored in files with the "<tt>.nal</tt>" or
"<tt>.wal</tt>" extension.  If the next application to open the database
does not specify the "<tt>8_3_names=1</tt>" URI parameter, then SQLite
will use the long filenames to try to locate the rollback journal or
write-ahead log files.  It will not find them, since they were saved using
8+3 names by the application that crashed, and hence the database will not
be properly recovered and will likely go corrupt.
</p>

<p>
Using a database file with 8+3 filenames in some cases while in 
other cases using long filenames is equivalent to
[deleting a hot journal].
</p>
