| 1 |
<!DOCTYPE html> |
| 2 |
<html><head> |
| 3 |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 4 |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> |
| 5 |
<link href="sqlite.css" rel="stylesheet"> |
| 6 |
<title>Benefits of SQLite As A File Format</title> |
| 7 |
<!-- path= --> |
| 8 |
</head> |
| 9 |
<body> |
| 10 |
<div class=nosearch> |
| 11 |
<a href="index.html"> |
| 12 |
<img class="logo" src="images/sqlite370_banner.svg" alt="SQLite" border="0"> |
| 13 |
</a> |
| 14 |
<div><!-- IE hack to prevent disappearing logo --></div> |
| 15 |
<div class="tagline desktoponly"> |
| 16 |
Small. Fast. Reliable.<br>Choose any three. |
| 17 |
</div> |
| 18 |
<div class="menu mainmenu"> |
| 19 |
<ul> |
| 20 |
<li><a href="index.html">Home</a> |
| 21 |
<li class='mobileonly'><a href="javascript:void(0)" onclick='toggle_div("submenu")'>Menu</a> |
| 22 |
<li class='wideonly'><a href='about.html'>About</a> |
| 23 |
<li class='desktoponly'><a href="docs.html">Documentation</a> |
| 24 |
<li class='desktoponly'><a href="download.html">Download</a> |
| 25 |
<li class='wideonly'><a href='copyright.html'>License</a> |
| 26 |
<li class='desktoponly'><a href="support.html">Support</a> |
| 27 |
<li class='desktoponly'><a href="prosupport.html">Purchase</a> |
| 28 |
<li class='search' id='search_menubutton'> |
| 29 |
<a href="javascript:void(0)" onclick='toggle_search()'>Search</a> |
| 30 |
</ul> |
| 31 |
</div> |
| 32 |
<div class="menu submenu" id="submenu"> |
| 33 |
<ul> |
| 34 |
<li><a href='about.html'>About</a> |
| 35 |
<li><a href='docs.html'>Documentation</a> |
| 36 |
<li><a href='download.html'>Download</a> |
| 37 |
<li><a href='support.html'>Support</a> |
| 38 |
<li><a href='prosupport.html'>Purchase</a> |
| 39 |
</ul> |
| 40 |
</div> |
| 41 |
<div class="searchmenu" id="searchmenu"> |
| 42 |
<form method="GET" action="search"> |
| 43 |
<select name="s" id="searchtype"> |
| 44 |
<option value="d">Search Documentation</option> |
| 45 |
<option value="c">Search Changelog</option> |
| 46 |
</select> |
| 47 |
<input type="text" name="q" id="searchbox" value=""> |
| 48 |
<input type="submit" value="Go"> |
| 49 |
</form> |
| 50 |
</div> |
| 51 |
</div> |
| 52 |
<script> |
| 53 |
function toggle_div(nm) { |
| 54 |
var w = document.getElementById(nm); |
| 55 |
if( w.style.display=="block" ){ |
| 56 |
w.style.display = "none"; |
| 57 |
}else{ |
| 58 |
w.style.display = "block"; |
| 59 |
} |
| 60 |
} |
| 61 |
function toggle_search() { |
| 62 |
var w = document.getElementById("searchmenu"); |
| 63 |
if( w.style.display=="block" ){ |
| 64 |
w.style.display = "none"; |
| 65 |
} else { |
| 66 |
w.style.display = "block"; |
| 67 |
setTimeout(function(){ |
| 68 |
document.getElementById("searchbox").focus() |
| 69 |
}, 30); |
| 70 |
} |
| 71 |
} |
| 72 |
function div_off(nm){document.getElementById(nm).style.display="none";} |
| 73 |
window.onbeforeunload = function(e){div_off("submenu");} |
| 74 |
/* Disable the Search feature if we are not operating from CGI, since */ |
| 75 |
/* Search is accomplished using CGI and will not work without it. */ |
| 76 |
if( !location.origin || !location.origin.match || !location.origin.match(/http/) ){ |
| 77 |
document.getElementById("search_menubutton").style.display = "none"; |
| 78 |
} |
| 79 |
/* Used by the Hide/Show button beside syntax diagrams, to toggle the */ |
| 80 |
function hideorshow(btn,obj){ |
| 81 |
var x = document.getElementById(obj); |
| 82 |
var b = document.getElementById(btn); |
| 83 |
if( x.style.display!='none' ){ |
| 84 |
x.style.display = 'none'; |
| 85 |
b.innerHTML='show'; |
| 86 |
}else{ |
| 87 |
x.style.display = ''; |
| 88 |
b.innerHTML='hide'; |
| 89 |
} |
| 90 |
return false; |
| 91 |
} |
| 92 |
var antiRobot = 0; |
| 93 |
function antiRobotGo(){ |
| 94 |
if( antiRobot!=3 ) return; |
| 95 |
antiRobot = 7; |
| 96 |
var j = document.getElementById("mtimelink"); |
| 97 |
if(j && j.hasAttribute("data-href")) j.href=j.getAttribute("data-href"); |
| 98 |
} |
| 99 |
function antiRobotDefense(){ |
| 100 |
document.body.onmousedown=function(){ |
| 101 |
antiRobot |= 2; |
| 102 |
antiRobotGo(); |
| 103 |
document.body.onmousedown=null; |
| 104 |
} |
| 105 |
document.body.onmousemove=function(){ |
| 106 |
antiRobot |= 2; |
| 107 |
antiRobotGo(); |
| 108 |
document.body.onmousemove=null; |
| 109 |
} |
| 110 |
setTimeout(function(){ |
| 111 |
antiRobot |= 1; |
| 112 |
antiRobotGo(); |
| 113 |
}, 100) |
| 114 |
antiRobotGo(); |
| 115 |
} |
| 116 |
antiRobotDefense(); |
| 117 |
</script> |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
<h1 align="center"> |
| 122 |
SQLite As An Application File Format |
| 123 |
</h1> |
| 124 |
|
| 125 |
<p><i>(Note: The current page is a brief summary of why SQLite makes |
| 126 |
a good application file format. The topic is considered at greater |
| 127 |
detail in a <a href="appfileformat.html">separate technical note</a>.)</i></p> |
| 128 |
|
| 129 |
<p> |
| 130 |
SQLite has been used with great success as the on-disk file format |
| 131 |
for desktop applications such as version control systems, |
| 132 |
financial analysis tools, media cataloging and editing suites, CAD |
| 133 |
packages, record keeping programs, and so forth. The traditional |
| 134 |
File/Open operation calls sqlite3_open() to attach to the database |
| 135 |
file. Updates happen automatically as application content is revised |
| 136 |
so the File/Save menu option becomes superfluous. The File/Save_As |
| 137 |
menu option can be implemented using the <a href="backup.html">backup API</a>. |
| 138 |
</p> |
| 139 |
|
| 140 |
<p> |
| 141 |
There are many advantages to using SQLite as an application file format, |
| 142 |
including: |
| 143 |
</p> |
| 144 |
|
| 145 |
<ol type="1"> |
| 146 |
<li><b>Better performance</b> |
| 147 |
<ul> |
| 148 |
<li> Reading and writing from an SQLite database |
| 149 |
is often faster than reading and writing individual files from disk. |
| 150 |
See <a href="fasterthanfs.html">35% Faster Than The Filesystem</a> |
| 151 |
and <a href="intern-v-extern-blob.html">Internal Versus External BLOBs</a>. |
| 152 |
<li> The application only has to load the data it needs, rather |
| 153 |
than reading the entire file and holding a complete parse |
| 154 |
in memory. |
| 155 |
<li> Small edits only overwrite the parts of the file that change, |
| 156 |
reducing write time and wear on SSD drives. |
| 157 |
</ul> |
| 158 |
<li><b>Reduced application cost and complexity</b> |
| 159 |
<ul> |
| 160 |
<li> No application file I/O code to write and debug. |
| 161 |
<li> Content can be accessed and updated using concise SQL queries instead |
| 162 |
of lengthy and error-prone procedural routines. |
| 163 |
<li> The file format can be extended in future releases simply |
| 164 |
by adding new tables and/or columns, preserving backwards compatibility. |
| 165 |
<li> Applications can leverage the |
| 166 |
<a href="fts3.html">full-text search</a> and <a href="rtree.html">RTREE</a> indexes and use triggers to implement |
| 167 |
an <a href="undoredo.html">automated undo/redo stack</a>. |
| 168 |
<li> Performance problems can often be resolved, even late in the |
| 169 |
development cycle, using <a href="lang_createindex.html">CREATE INDEX</a>, avoiding costly |
| 170 |
redesign, rewrite, and retest efforts. |
| 171 |
</ul> |
| 172 |
<li><b>Portability</b> |
| 173 |
<ul> |
| 174 |
<li> The application file is portable across all operating systems, |
| 175 |
32-bit and 64-bit and big- and little-endian architectures. |
| 176 |
<li> A federation of programs, perhaps all written in different programming |
| 177 |
languages, can access the same application file with no |
| 178 |
compatibility concerns. |
| 179 |
<li> Multiple processes can attach to the same application |
| 180 |
file and can read and write without interfering with each another. |
| 181 |
<li> Diverse content which might otherwise be stored as a "pile-of-files" |
| 182 |
is encapsulated into a single disk file for simpler transport |
| 183 |
via scp/ftp, USB stick, and/or email attachment. |
| 184 |
</ul> |
| 185 |
<li><b>Reliability</b> |
| 186 |
<ul> |
| 187 |
<li> Content can be updated continuously and atomically so |
| 188 |
that little or no work is lost in a power failure or crash. |
| 189 |
<li> Bugs are far less likely in SQLite than in custom-written file I/O code. |
| 190 |
<li> SQL queries are many times smaller than the equivalent procedural |
| 191 |
code, and since the number of bugs per line of code is roughly |
| 192 |
constant, this means fewer bugs overall. |
| 193 |
</ul> |
| 194 |
<li><b>Accessibility</b> |
| 195 |
<ul> |
| 196 |
<li> SQLite database content can be viewed using a wide variety of |
| 197 |
third-party tools. |
| 198 |
<li> Content stored in an SQLite database is more likely to be |
| 199 |
recoverable decades in the future, long after all traces of |
| 200 |
the original application have been lost. Data lives longer than code. |
| 201 |
<li> SQLite database files are <a href="locrsf.html">recommended by the US Library of Congress</a> |
| 202 |
as a storage format for long-term preservation of digital content. |
| 203 |
</ul> |
| 204 |
</ol> |
| 205 |
|
| 206 |
<p> |
| 207 |
SQLite allows database files to have any desired filename extension, so |
| 208 |
an application can choose a custom filename extension for its own use, if |
| 209 |
desired. The <a href="pragma.html#pragma_application_id">application_id pragma</a> can be used to set an "Application ID" |
| 210 |
integer in the database file so that tools like |
| 211 |
<a href="http://www.darwinsys.com/file/">file(1)</a> can determine that the file |
| 212 |
is associated with your application and is not just a generic |
| 213 |
SQL database.</p> |
| 214 |
<p align="center"><small><i>This page was last updated on 2025-05-31 13:08:22Z </small></i></p> |
| 215 |
|