Beginning with [version 3.7.7], the SQLite database file argument to the [sqlite3_open()], [sqlite3_open16()], and [sqlite3_open_v2()] interfaces and to the [ATTACH] 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 [VFS] can be specified using "vfs=" query parameter. Or the database can be opened read-only by using "mode=ro" as a query parameter.
In order to maintain full backwards compatibility for legacy applications, the URI filename capability is disabled by default. ^(In order for URI filenames to work, one or more of the following must be true:
The SQLite library is compiled with the [SQLITE_USE_URI] compile-time option.
The [sqlite3_config]([SQLITE_CONFIG_URI], 1); configuration option is set at application start-time.
The [SQLITE_OPEN_URI] bit is OR-ed in with the set bits passed in as the 3rd parameter to the [sqlite3_open_v2()] interface.
^If URI filenames are recognized when the database connection is originally opened, then URI filenames will also be recognized on [ATTACH] statemenets. ^Similarly, if URI filenames are not recognized when the database connection is first opened, they will not be recognized by [ATTACH].
Since SQLite always interprets any filename that does not begin with "file:" is interpreted as an ordinary filename regardless of the URI setting, and because it is very unusual to have an actual file that beings with "file:", for most applications it is safe to enable URI processing even if URI filenames are not currently being used.
According to [http://tools.ietf.org/html/rfc3986 | RFC 3986], 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.
SQLite uses the "file:" URI syntax to identify database files. SQLite strives to interpret file: URIs in exactly the same way as popular web-browsers such as [http://www.mozilla.com/en-US/firefox/new/ | Firefox], [http://www.google.com/chrome/ | Chrome], [http://www.apple.com/safari/ | Safari], [http://windows.microsoft.com/en-US/internet-explorer/products/ie/home | Internet Explorer], and [http://www.opera.com/ | Opera], and command-line programs such as [http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/start.mspx | Windows "start"] and the [http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/open.1.html | "open"] command on Mac OS-X. A succinct summary of the URI parsing rules follows:
^Zero or more escape sequences of the form "%HH" (where H represents any hexadecimal digit) can occur in the path, query string, or fragment.
^A filename that is not a well-formed URI is interpreted as an ordinary filename.
^URIs are processed as UTF8 text. ^The filename argument sqlite3_open16() is converted from UTF16 native byte order into UTF8 prior to processing.
^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 a temporary files is opened as a new database that will be automatically deleted when the database connection closes.)^ ^If the authority section is present, then the path is alway 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 "/X:/" where X is any single ASCII alphabetic character ("a" through "z" or "A" through "Z") then the "X:" is understood to be the drive letter of the the volume containing the file, not the toplevel directory.)^
An ordinary filename can usually be converted into an equivalent URI by the step 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.
^A URI filename can optionally be followed by a query string. ^The query string consists of text following the first "?" character but exluding the optional fragment that begins with with "#". ^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 "&" character. ^The key comes first and is separated from the value by a single "=" character. ^Both key and value may contain %HH escape sequences.
^The text of query parameters is appended to the filename argument to the xOpen method of the [VFS]. ^Any %HH escape sequences in the query parameters are resolved prior to being appended ot 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 query parameters 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.
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 [VFS] even if they are previously read and interpreted by the SQLite core.
The following query parameters are recognized by SQLite as of version 3.7.7. Other query parameters might be added to this set in future releases.
^This query parameter cases the database connection to be opened using the [VFS] called NAME. ^The open attempt fails if NAME is not the name of a [VFS] that is built into SQLite or that has been previously registered using [sqlite3_vfs_register()].
^These query parameters determine if the new database is opened read-only, read-write, or read-write and created if it does not exist, respectively.
^These query parameters determine if the new database is opened using [shared cache mode] or with a private cache, respectively.