1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Uniform Resource Identifiers</title>
<style type="text/css">
body {
margin: auto;
font-family: Verdana, sans-serif;
padding: 8px 1%;
}
a { color: #044a64 }
a:visited { color: #734559 }
.logo { position:absolute; margin:3px; }
.tagline {
float:right;
text-align:right;
font-style:italic;
width:300px;
margin:12px;
margin-top:58px;
}
.menubar {
clear: both;
border-radius: 8px;
background: #044a64;
padding: 0px;
margin: 0px;
cell-spacing: 0px;
}
.toolbar {
text-align: center;
line-height: 1.6em;
margin: 0;
padding: 0px 8px;
}
.toolbar a { color: white; text-decoration: none; padding: 6px 12px; }
.toolbar a:visited { color: white; }
.toolbar a:hover { color: #044a64; background: white; }
.content { margin: 5%; }
.content dt { font-weight:bold; }
.content dd { margin-bottom: 25px; margin-left:20%; }
.content ul { padding:0px; padding-left: 15px; margin:0px; }
/* Things for "fancyformat" documents start here. */
.fancy img+p {font-style:italic}
.fancy .codeblock i { color: darkblue; }
.fancy h1,.fancy h2,.fancy h3,.fancy h4 {font-weight:normal;color:#044a64}
.fancy h2 { margin-left: 10px }
.fancy h3 { margin-left: 20px }
.fancy h4 { margin-left: 30px }
.fancy th {white-space:nowrap;text-align:left;border-bottom:solid 1px #444}
.fancy th, .fancy td {padding: 0.2em 1ex; vertical-align:top}
.fancy #toc a { color: darkblue ; text-decoration: none }
.fancy .todo { color: #AA3333 ; font-style : italic }
.fancy .todo:before { content: 'TODO:' }
.fancy p.todo { border: solid #AA3333 1px; padding: 1ex }
.fancy img { display:block; }
.fancy :link:hover, .fancy :visited:hover { background: wheat }
.fancy p,.fancy ul,.fancy ol { margin: 1em 5ex }
.fancy li p { margin: 1em 0 }
/* End of "fancyformat" specific rules. */
</style>
</head>
<body>
<div><!-- container div to satisfy validator -->
<a href="index.html">
<img class="logo" src="images/sqlite370_banner.gif" alt="SQLite Logo"
border="0"></a>
<div><!-- IE hack to prevent disappearing logo--></div>
<div class="tagline">Small. Fast. Reliable.<br>Choose any three.</div>
<table width=100% class="menubar"><tr>
<td width=100%>
<div class="toolbar">
<a href="about.html">About</a>
<a href="sitemap.html">Sitemap</a>
<a href="docs.html">Documentation</a>
<a href="download.html">Download</a>
<a href="copyright.html">License</a>
<a href="news.html">News</a>
<a href="support.html">Support</a>
</div>
<script>
gMsg = "Search SQLite Docs..."
function entersearch() {
var q = document.getElementById("q");
if( q.value == gMsg ) { q.value = "" }
q.style.color = "black"
q.style.fontStyle = "normal"
}
function leavesearch() {
var q = document.getElementById("q");
if( q.value == "" ) {
q.value = gMsg
q.style.color = "#044a64"
q.style.fontStyle = "italic"
}
}
function hideorshow(btn,obj){
var x = document.getElementById(obj);
var b = document.getElementById(btn);
if( x.style.display!='none' ){
x.style.display = 'none';
b.innerHTML='show';
}else{
x.style.display = '';
b.innerHTML='hide';
}
return false;
}
</script>
<td>
<div style="padding:0 1em 0px 0;white-space:nowrap">
<form name=f method="GET" action="http://www.sqlite.org/search">
<input id=q name=q type=text
onfocus="entersearch()" onblur="leavesearch()" style="width:24ex;padding:1px 1ex; border:solid white 1px; font-size:0.9em ; font-style:italic;color:#044a64;" value="Search SQLite Docs...">
<input type=submit value="Go" style="border:solid white 1px;background-color:#044a64;color:white;font-size:0.9em;padding:0 1ex">
</form>
</div>
</table>
<div class=startsearch></div>
<h1>1.0 URI Filenames In SQLite</h1>
<p>
Beginning with <a href="releaselog/3_7_7.html">version 3.7.7</a>, the SQLite database file argument to the
<a href="c3ref/open.html">sqlite3_open()</a>, <a href="c3ref/open.html">sqlite3_open16()</a>, and <a href="c3ref/open.html">sqlite3_open_v2()</a> interfaces
and to the <a href="lang_attach.html">ATTACH</a> command can be specified
either as an ordinary filename or as a Uniform Resource Identifier or URI.
The advantage of using a URI filename is that query parameters on the URI can
be used to control details of the newly created database connection.
For example, an alternative <a href="vfs.html">VFS</a> can be specified using a
"vfs=" query parameter.
Or the database can be opened read-only by using "mode=ro" as a query
parameter.
</p>
<h1>2.0 Backwards Compatibility</h1>
<p>
In order to maintain full backwards compatibility for legacy applications,
the URI filename capability is disabled by default.
URI filenames can be enabled or disabled using the <a href="compile.html#use_uri">SQLITE_USE_URI=1</a>
or <a href="compile.html#use_uri">SQLITE_USE_URI=0</a> compile-time options.
The compile-time setting for URI filenames can be changed
at start-time using the <a href="c3ref/config.html">sqlite3_config</a>(<a href="c3ref/c_config_covering_index_scan.html#sqliteconfiguri">SQLITE_CONFIG_URI</a>,1)
or <a href="c3ref/config.html">sqlite3_config</a>(<a href="c3ref/c_config_covering_index_scan.html#sqliteconfiguri">SQLITE_CONFIG_URI</a>,0) configuration calls.
Regardless of the compile-time or start-time settings, URI filenames
can be enabled for individual database connections by including the
<a href="c3ref/c_open_autoproxy.html">SQLITE_OPEN_URI</a> bit in the set of bits passed as the F parameter
to <a href="c3ref/open.html">sqlite3_open_v2(N,P,F,V)</a>.
</p>
<p>
If URI filenames are recognized when the database connection is originally
opened, then URI filenames will also be recognized on <a href="lang_attach.html">ATTACH</a> statements.
Similarly, if URI filenames are not recognized when the database connection
is first opened, they will not be recognized by <a href="lang_attach.html">ATTACH</a>.
</p>
<p>
Since SQLite always interprets any filename that does not begin
with "<tt>file:</tt>"
as an ordinary filename regardless of the URI setting, and because it is
very unusual to have an actual file begin with "<tt>file:</tt>",
it is safe for most applications to enable URI processing even if URI
filenames are not currently being used.
</p>
<h1>3.0 URI Format</h1>
<p>
According to <a href="http://tools.ietf.org/html/rfc3986">RFC 3986</a>, a URI consists
of a scheme, an authority, a path, a query string, and a fragment. The
scheme is always required. One of either the authority or the path is also
always required. The query string and fragment are optional.
</p>
<p>
SQLite uses the "<tt>file:</tt>" URI syntax to identify database files.
SQLite strives to interpret file: URIs in exactly the same way as
popular web-browsers such as
<a href="http://www.mozilla.com/en-US/firefox/new/">Firefox</a>,
<a href="http://www.google.com/chrome/">Chrome</a>,
<a href="http://www.apple.com/safari/">Safari</a>,
<a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home">Internet Explorer</a>, and
<a href="http://www.opera.com/">Opera</a>,
and command-line programs such as
<a href="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/start.mspx">Windows "start"</a> and the Mac OS-X
<a href="http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/open.1.html">"open"</a> command.
A succinct summary of the URI parsing rules follows:
</p>
<ul>
<li> The scheme of the URI must be "<tt>file:</tt>". Any other scheme
results in the input being treated as an ordinary filename.
<li> The authority may be omitted, may be blank, or may be
"<tt>localhost</tt>". Any other authority results in an error.
Exception: If SQLite is compiled with <a href="compile.html#allow_uri_authority">SQLITE_ALLOW_URI_AUTHORITY</a>
then any authority value other than "localhost" is passed through to the
underlying operating system as a UNC filename.
<li> The path is optional if the authority is present. If the authority
is omitted then the path is required.
<li> The query string is optional. If the query string is present, then
all query parameters are passed through into the xOpen method of
the underlying <a href="vfs.html">VFS</a>.
<li> The fragment is optional. If present, it is ignored.
</ul>
<p>Zero or more escape sequences of the form "<b>%<i>HH</i></b>"
(where <b><i>H</i></b> represents any hexadecimal digit) can occur
in the path, query string, or fragment.</p>
<p>A filename that is not a well-formed URI is interpreted as an
ordinary filename.</p>
<p>URIs are processed as UTF8 text.
The filename argument sqlite3_open16() is converted from UTF16
native byte order into UTF8 prior to processing.
<h2>3.1 The URI Path</h2>
<p>The path component of the URI specifies the disk file that is the
SQLite database to be opened. If the path component is omitted, then
the database is stored in a temporary file that will be automatically
deleted when the database connection closes. If the authority section
is present, then the path is always an absolute pathname. If the
authority section is omitted, then the path is an absolute pathname if it
begins with the "/" character (ASCII code 0x2f) and is a relative
pathname otherwise. On windows, if the absolute path begins with
"<b>/<i>X</i>:/</b>" where <b><i>X</i></b> is any single ASCII alphabetic
character ("a" through "z" or "A" through "Z") then the "<b><i>X:</i></b>"
is understood to be the drive letter of the volume containing the file,
not the toplevel directory.
<p>An ordinary filename can usually be converted into an equivalent URI
by the steps shown below. The one exception is that a relative windows
pathname with a drive letter cannot be converted directly into a URI; it must
be changed into an absolute pathname first.</p>
<ol>
<li>Convert all "<tt>?</tt>" characters into "<tt>%3f</tt>".
<li>Convert all "<tt>#</tt>" characters into "<tt>%23</tt>".
<li>On windows only, convert all "<tt>\</tt>" characters into "<tt>/</tt>".
<li>Convert all sequences of two or more "<tt>/</tt>" characters into a
single "<tt>/</tt>" character.
<li>On windows only, if the filename begins with a drive letter, prepend
a single "<tt>/</tt>" character.
<li>Prepend the "<tt>file:</tt>" scheme.
</ol>
<h2>3.2 Query String</h2>
<p>A URI filename can optionally be followed by a query string.
The query string consists of text following the first "<tt>?</tt>"
character but excluding the optional fragment that begins with
"<tt>#</tt>". The query string is divided into key/value pairs.
We usually refer to these key/value pairs as "query parameters".
Key/value pairs are separated by a single "<tt>&</tt>" character.
The key comes first and is separated from the value by a single
"<tt>=</tt>" character.
Both key and value may contain <b>%HH</b> escape sequences.</p>
<p>
The text of query parameters is appended to the filename argument of
the xOpen method of the <a href="vfs.html">VFS</a>.
Any %HH escape sequences in the query parameters are resolved prior to
being appended to the xOpen filename.
A single zero-byte separates the xOpen filename argument from the key of
the first query parameters, each key and value, and each subsequent key
from the prior value.
The list of query parameters appended to the xOpen filename
is terminated by a single zero-length key.
Note that the value of a query parameter can be an empty string.
</p>
<a name="coreqp"></a>
<h2>3.3 Recognized Query Parameters</h2>
<p>
Some query parameters are interpreted by the SQLite core and used to
modify the characteristics of the new connection. All query parameters
are always passed through into the xOpen method of the <a href="vfs.html">VFS</a> even if
they are previously read and interpreted by the SQLite core.
</p>
<p>
The following query parameters are recognized by SQLite as of version 3.8.0.
Other query parameters might be added to this set in future releases.
</p>
<dl>
<a name="urivfs"></a>
<dt><b>vfs=</b><i>NAME</i></dt>
<dd><p>The vfs query parameter causes the database connection to be opened
using the <a href="vfs.html">VFS</a> called <i>NAME</i>.
The open attempt fails if <i>NAME</i> is not the name of a <a href="vfs.html">VFS</a> that
is built into SQLite or that has been previously registered using
<a href="c3ref/vfs_find.html">sqlite3_vfs_register()</a>.</dd>
<a name="urimode"></a>
<dt><b>mode=ro<br>mode=rw<br>mode=rwc<br>mode=memory</b></dt>
<dd><p>The mode query parameter determines if the new database is opened
read-only, read-write, read-write and created if it does not exist, or
that the database is a pure in-memory database that never interacts with
disk, respectively.
</dd>
<a name="uricache"></a>
<dt><b>cache=shared<br>cache=private</b></dt>
<dd><p>The cache query parameter determines if the new database is opened
using <a href="sharedcache.html">shared cache mode</a> or with a private cache.
</dd>
<a name="uripsow"></a>
<dt><b>psow=0<br>psow=1</b></dt>
<dd><p>The psow query parameter overrides the <a href="psow.html">powersafe overwrite</a>
property of the database file being opened. The psow query parameter
works with the default windows and unix <a href="vfs.html">VFSes</a> but might be a no-op for
other proprietary or non-standard VFSes.
</dd>
<a name="urinolock"></a>
<dt><b>nolock=1</b></dt>
<dd><p>The nolock query parameter is a boolean that disables all calls
to the xLock, xUnlock, and xCheckReservedLock methods of the VFS when true.
The nolock query parameter might be used, for example, when trying to
access a file on a filesystem that does not support file locking.
Caution: If two or more <a href="c3ref/sqlite3.html">database connections</a> try to interact with
the same SQLite database and one or more of those connections has
enabled "nolock", then database corruption can result. The "nolock"
query parameter should only be used if the application can guarantee
that writes to the database are serialized.
</dd>
<a name="uriimmutable"></a>
<dt><b>immutable=1</b></dt>
<dd><p>The immutable query parameter is a boolean that signals to
SQLite that the underlying database file is held on read-only media
and cannot be modified, even by another process with elevated
privileges. SQLite always opens immutable database files
read-only and it skips all file locking and change detection
on immutable database files. If these query parameter (or
the <a href="c3ref/c_iocap_atomic.html">SQLITE_IOCAP_IMMUTABLE</a> bit in xDeviceCharacteristics)
asserts that a database file is immutable and that file
changes anyhow, then SQLite might return incorrect query
results and/or <a href="rescode.html#corrupt">SQLITE_CORRUPT</a> errors.
</dd>
</dl>
<h1>4.0 See Also</h1>
<ul>
<li> <a href="c3ref/open.html#urifilenamesinsqlite3open">URI filenames in sqlite3_open()</a>
<li> <a href="c3ref/open.html#urifilenameexamples">URI filename examples</a>
</ul>
|