1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

Update comments and documentation associated with new URI parsing code. Add test file e_uri.test, containing tests mapped to documentation regarding URI filenames.

FossilOrigin-Name: 92751788eae082e3104838cb6dd8b9793cb325d1
This commit is contained in:
dan
2011-05-06 18:34:54 +00:00
parent 4d7a4461e2
commit 286ab7c2b1
7 changed files with 560 additions and 41 deletions

View File

@@ -1791,9 +1791,28 @@ int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
}
/*
** This function is used to parse URIs passed by the user to API functions
** sqlite3_open() or sqlite3_open_v2(), and for database URIs specified as
** part of ATTACH statements.
** This function is used to parse both URIs and non-URI filenames passed by the
** user to API functions sqlite3_open() or sqlite3_open_v2(), and for database
** URIs specified as part of ATTACH statements.
**
** The first argument to this function is the name of the VFS to use (or
** a NULL to signify the default VFS) if the URI does not contain a "vfs=xxx"
** query parameter. The second argument contains the URI (or non-URI filename)
** itself. When this function is called the *pFlags variable should contain
** the default flags to open the database handle with. The value stored in
** *pFlags may be updated before returning if the URI filename contains
** "cache=xxx" or "mode=xxx" query parameters.
**
** If successful, SQLITE_OK is returned. In this case *ppVfs is set to point to
** the VFS that should be used to open the database file. *pzFile is set to
** point to a buffer containing the name of the file to open. It is the
** responsibility of the caller to eventually call sqlite3_free() to release
** this buffer.
**
** If an error occurs, then an SQLite error code is returned and *pzErrMsg
** may be set to point to a buffer containing an English language error
** message. It is the responsibility of the caller to eventually release
** this buffer by calling sqlite3_free().
*/
int sqlite3ParseUri(
const char *zDefaultVfs, /* VFS to use if no "vfs=xxx" query option */
@@ -1819,8 +1838,12 @@ int sqlite3ParseUri(
int iIn; /* Input character index */
int iOut = 0; /* Output character index */
int nByte = nUri+2; /* Bytes of space to allocate */
for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
/* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
** method that there may be extra parameters following the file-name. */
flags |= SQLITE_OPEN_URI;
for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
zFile = sqlite3_malloc(nByte);
if( !zFile ) return SQLITE_NOMEM;
@@ -1907,7 +1930,7 @@ int sqlite3ParseUri(
char *zVal = &zOpt[nOpt+1];
int nVal = sqlite3Strlen30(zVal);
if( nOpt==3 && sqlite3_strnicmp("vfs", zOpt, 3)==0 ){
if( nOpt==3 && memcmp("vfs", zOpt, 3)==0 ){
zVfs = zVal;
}else{
struct OpenMode {
@@ -1918,7 +1941,7 @@ int sqlite3ParseUri(
int mask;
int limit;
if( nOpt==5 && sqlite3_strnicmp("cache", zOpt, 5)==0 ){
if( nOpt==5 && memcmp("cache", zOpt, 5)==0 ){
static struct OpenMode aCacheMode[] = {
{ "shared", SQLITE_OPEN_SHAREDCACHE },
{ "private", SQLITE_OPEN_PRIVATECACHE },
@@ -1930,7 +1953,7 @@ int sqlite3ParseUri(
limit = mask;
zModeType = "cache";
}
if( nOpt==4 && sqlite3_strnicmp("mode", zOpt, 4)==0 ){
if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){
static struct OpenMode aOpenMode[] = {
{ "ro", SQLITE_OPEN_READONLY },
{ "rw", SQLITE_OPEN_READWRITE },
@@ -1949,7 +1972,7 @@ int sqlite3ParseUri(
int mode = 0;
for(i=0; aMode[i].z; i++){
const char *z = aMode[i].z;
if( nVal==strlen(z) && 0==sqlite3_strnicmp(zVal, z, nVal) ){
if( nVal==strlen(z) && 0==memcmp(zVal, z, nVal) ){
mode = aMode[i].mode;
break;
}