Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Update comments and documentation associated with new URI parsing code. Add test file e_uri.test, containing tests mapped to documentation regarding URI filenames. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | uri |
Files: | files | file ages | folders |
SHA1: |
92751788eae082e3104838cb6dd8b979 |
User & Date: | dan 2011-05-06 18:34:54.463 |
Context
2011-05-06
| ||
18:53 | Remove some unnecessary modifications from the uri branch. Add a test to show that ATTACH only interprets its argument as a URI if the connection was opened with SQLITE_OPEN_URI (or URI interpretation is globally enabled). (Closed-Leaf check-in: aa90b94325 user: dan tags: uri) | |
18:34 | Update comments and documentation associated with new URI parsing code. Add test file e_uri.test, containing tests mapped to documentation regarding URI filenames. (check-in: 92751788ea user: dan tags: uri) | |
2011-05-05
| ||
18:53 | Have the xFullpath method in os_win.c discard the initial "/" if a filename begins with "/X:", where X is any alphabetic character. Also fix some test issues in uri.test. (check-in: fe57a8f621 user: dan tags: uri) | |
Changes
Changes to src/main.c.
︙ | ︙ | |||
1787 1788 1789 1790 1791 1792 1793 | } db->aLimit[limitId] = newLimit; } return oldLimit; /* IMP: R-53341-35419 */ } /* | | | | > > > > > > > > > > > > > > > > > > > | 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 | } db->aLimit[limitId] = newLimit; } return oldLimit; /* IMP: R-53341-35419 */ } /* ** 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 */ const char *zUri, /* Nul-terminated URI to parse */ int *pFlags, /* IN/OUT: SQLITE_OPEN_XXX flags */ sqlite3_vfs **ppVfs, /* OUT: VFS to use */ char **pzFile, /* OUT: Filename component of URI */ |
︙ | ︙ | |||
1815 1816 1817 1818 1819 1820 1821 | && nUri>=5 && memcmp(zUri, "file:", 5)==0 ){ char *zOpt; int eState; /* Parser state when parsing URI */ int iIn; /* Input character index */ int iOut = 0; /* Output character index */ int nByte = nUri+2; /* Bytes of space to allocate */ | | > > > > | 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 | && nUri>=5 && memcmp(zUri, "file:", 5)==0 ){ char *zOpt; int eState; /* Parser state when parsing URI */ int iIn; /* Input character index */ int iOut = 0; /* Output character index */ int nByte = nUri+2; /* Bytes of space to allocate */ /* 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; /* Discard the scheme and authority segments of the URI. */ if( zUri[5]=='/' && zUri[6]=='/' ){ iIn = 7; while( zUri[iIn] && zUri[iIn]!='/' ) iIn++; |
︙ | ︙ | |||
1903 1904 1905 1906 1907 1908 1909 | ** method. */ zOpt = &zFile[sqlite3Strlen30(zFile)+1]; while( zOpt[0] ){ int nOpt = sqlite3Strlen30(zOpt); char *zVal = &zOpt[nOpt+1]; int nVal = sqlite3Strlen30(zVal); | | | | | | 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 | ** method. */ zOpt = &zFile[sqlite3Strlen30(zFile)+1]; while( zOpt[0] ){ int nOpt = sqlite3Strlen30(zOpt); char *zVal = &zOpt[nOpt+1]; int nVal = sqlite3Strlen30(zVal); if( nOpt==3 && memcmp("vfs", zOpt, 3)==0 ){ zVfs = zVal; }else{ struct OpenMode { const char *z; int mode; } *aMode = 0; char *zModeType; int mask; int limit; if( nOpt==5 && memcmp("cache", zOpt, 5)==0 ){ static struct OpenMode aCacheMode[] = { { "shared", SQLITE_OPEN_SHAREDCACHE }, { "private", SQLITE_OPEN_PRIVATECACHE }, { 0, 0 } }; mask = SQLITE_OPEN_SHAREDCACHE|SQLITE_OPEN_PRIVATECACHE; aMode = aCacheMode; limit = mask; zModeType = "cache"; } if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){ static struct OpenMode aOpenMode[] = { { "ro", SQLITE_OPEN_READONLY }, { "rw", SQLITE_OPEN_READWRITE }, { "rwc", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE }, { 0, 0 } }; mask = SQLITE_OPEN_READONLY|SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE; aMode = aOpenMode; limit = mask & flags; zModeType = "access"; } if( aMode ){ int i; int mode = 0; for(i=0; aMode[i].z; i++){ const char *z = aMode[i].z; if( nVal==strlen(z) && 0==memcmp(zVal, z, nVal) ){ mode = aMode[i].mode; break; } } if( mode==0 ){ *pzErrMsg = sqlite3_mprintf("no such %s mode: %s", zModeType, zVal); rc = SQLITE_ERROR; |
︙ | ︙ |
Changes to src/sqlite.h.in.
︙ | ︙ | |||
2426 2427 2428 2429 2430 2431 2432 | ** "localhost". ^If the authority is not an empty string or "localhost", an ** error is returned to the caller. ^The 'fragment' component of a URI, if ** present, is always ignored. ** ** ^SQLite uses the 'path' component of the URI as the path to the database file ** to open. ^If the path begins with a '/' character, then it is interpreted as ** an absolute path. ^If it does not begin with a '/', it is interpreted as a | | < | < | > > | | | | | | | | | | | | | 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 | ** "localhost". ^If the authority is not an empty string or "localhost", an ** error is returned to the caller. ^The 'fragment' component of a URI, if ** present, is always ignored. ** ** ^SQLite uses the 'path' component of the URI as the path to the database file ** to open. ^If the path begins with a '/' character, then it is interpreted as ** an absolute path. ^If it does not begin with a '/', it is interpreted as a ** relative path. ^On windows, the first component of an absolute path ** is a drive specification (e.g. "C:"). ** ** The query component of a URI may contain parameters that are interpreted ** either by SQLite itself, or by a [sqlite3_vfs | custom VFS implementation]. ** SQLite interprets the following three query parameters: ** ** <ul> ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of ** a VFS object that provides the operating system interface that should ** be used to access the database file on disk. ^If this option is set to ** an empty string the default VFS object is used. ^Specifying an unknown ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is ** present, then the VFS specified by the option takes precedence over ** the value passed as the fourth parameter to sqlite3_open_v2(). ** ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or ** "rwc". Attempting to set it to any other value is an error)^. ** ^If "ro" is specified, then the database is opened for read-only ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the ** third argument to sqlite3_prepare_v2(). ^If the mode option is set to ** "rw", then the database is opened for read-write (but not create) ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had ** been set. ^Value "rwc" is equivalent to setting both ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is ** used, it is an error to specify a value for the mode parameter that is ** less restrictive than that specified by the flags passed as the third ** parameter. ** ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or ** "private". ^Setting it to "shared" is equivalent to setting the ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in |
︙ | ︙ | |||
2483 2484 2485 2486 2487 2488 2489 | ** file://localhost/home/fred/data.db <br> <td> ** Open the database file "/home/fred/data.db". ** <tr><td> file://darkstar/home/fred/data.db <td> ** An error. "darkstar" is not a recognized authority. ** <tr><td style="white-space:nowrap"> ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db ** <td> Windows only: Open the file "data.db" on fred's desktop on drive | < < | | | 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 | ** file://localhost/home/fred/data.db <br> <td> ** Open the database file "/home/fred/data.db". ** <tr><td> file://darkstar/home/fred/data.db <td> ** An error. "darkstar" is not a recognized authority. ** <tr><td style="white-space:nowrap"> ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db ** <td> Windows only: Open the file "data.db" on fred's desktop on drive ** C:. Note that the %20 escaping in this example is not strictly ** necessary - space characters can be used literally ** in URI filenames. ** <tr><td> file:data.db?mode=ro&cache=private <td> ** Open file "data.db" in the current directory for read-only access. ** Regardless of whether or not shared-cache mode is enabled by ** default, use a private cache. ** <tr><td> file:/home/fred/data.db?vfs=unix-nolock <td> ** Open file "/home/fred/data.db". Use the special VFS "unix-nolock". |
︙ | ︙ |
Changes to src/test1.c.
︙ | ︙ | |||
3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 | zFilename = objc>1 ? Tcl_GetString(objv[1]) : 0; rc = sqlite3_open(zFilename, &db); if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR; Tcl_AppendResult(interp, zBuf, 0); return TCL_OK; } /* ** Usage: sqlite3_open16 filename options */ static int test_open16( void * clientData, Tcl_Interp *interp, | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 | zFilename = objc>1 ? Tcl_GetString(objv[1]) : 0; rc = sqlite3_open(zFilename, &db); if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR; Tcl_AppendResult(interp, zBuf, 0); return TCL_OK; } /* ** Usage: sqlite3_open_v2 FILENAME FLAGS VFS */ static int test_open_v2( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ const char *zFilename; const char *zVfs; int flags = 0; sqlite3 *db; int rc; char zBuf[100]; int nFlag; Tcl_Obj **apFlag; int i; if( objc!=4 ){ Tcl_WrongNumArgs(interp, 1, objv, "FILENAME FLAGS VFS"); return TCL_ERROR; } zFilename = Tcl_GetString(objv[1]); zVfs = Tcl_GetString(objv[3]); if( zVfs[0]==0x00 ) zVfs = 0; rc = Tcl_ListObjGetElements(interp, objv[2], &nFlag, &apFlag); if( rc!=TCL_OK ) return rc; for(i=0; i<nFlag; i++){ int iFlag; struct OpenFlag { const char *zFlag; int flag; } aFlag[] = { { "SQLITE_OPEN_READONLY", SQLITE_OPEN_READONLY }, { "SQLITE_OPEN_READWRITE", SQLITE_OPEN_READWRITE }, { "SQLITE_OPEN_CREATE", SQLITE_OPEN_CREATE }, { "SQLITE_OPEN_DELETEONCLOSE", SQLITE_OPEN_DELETEONCLOSE }, { "SQLITE_OPEN_EXCLUSIVE", SQLITE_OPEN_EXCLUSIVE }, { "SQLITE_OPEN_AUTOPROXY", SQLITE_OPEN_AUTOPROXY }, { "SQLITE_OPEN_MAIN_DB", SQLITE_OPEN_MAIN_DB }, { "SQLITE_OPEN_TEMP_DB", SQLITE_OPEN_TEMP_DB }, { "SQLITE_OPEN_TRANSIENT_DB", SQLITE_OPEN_TRANSIENT_DB }, { "SQLITE_OPEN_MAIN_JOURNAL", SQLITE_OPEN_MAIN_JOURNAL }, { "SQLITE_OPEN_TEMP_JOURNAL", SQLITE_OPEN_TEMP_JOURNAL }, { "SQLITE_OPEN_SUBJOURNAL", SQLITE_OPEN_SUBJOURNAL }, { "SQLITE_OPEN_MASTER_JOURNAL", SQLITE_OPEN_MASTER_JOURNAL }, { "SQLITE_OPEN_NOMUTEX", SQLITE_OPEN_NOMUTEX }, { "SQLITE_OPEN_FULLMUTEX", SQLITE_OPEN_FULLMUTEX }, { "SQLITE_OPEN_SHAREDCACHE", SQLITE_OPEN_SHAREDCACHE }, { "SQLITE_OPEN_PRIVATECACHE", SQLITE_OPEN_PRIVATECACHE }, { "SQLITE_OPEN_WAL", SQLITE_OPEN_WAL }, { "SQLITE_OPEN_URI", SQLITE_OPEN_URI }, { 0, 0 } }; rc = Tcl_GetIndexFromObjStruct(interp, apFlag[i], aFlag, sizeof(aFlag[0]), "flag", 0, &iFlag ); if( rc!=TCL_OK ) return rc; flags |= aFlag[iFlag].flag; } rc = sqlite3_open_v2(zFilename, &db, flags, zVfs); if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR; Tcl_AppendResult(interp, zBuf, 0); return TCL_OK; } /* ** Usage: sqlite3_open16 filename options */ static int test_open16( void * clientData, Tcl_Interp *interp, |
︙ | ︙ | |||
5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 | { "sqlite3_sleep", test_sleep, 0}, { "sqlite3_errcode", test_errcode ,0 }, { "sqlite3_extended_errcode", test_ex_errcode ,0 }, { "sqlite3_errmsg", test_errmsg ,0 }, { "sqlite3_errmsg16", test_errmsg16 ,0 }, { "sqlite3_open", test_open ,0 }, { "sqlite3_open16", test_open16 ,0 }, { "sqlite3_complete16", test_complete16 ,0 }, { "sqlite3_prepare", test_prepare ,0 }, { "sqlite3_prepare16", test_prepare16 ,0 }, { "sqlite3_prepare_v2", test_prepare_v2 ,0 }, { "sqlite3_prepare_tkt3134", test_prepare_tkt3134, 0}, { "sqlite3_prepare16_v2", test_prepare16_v2 ,0 }, | > | 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 | { "sqlite3_sleep", test_sleep, 0}, { "sqlite3_errcode", test_errcode ,0 }, { "sqlite3_extended_errcode", test_ex_errcode ,0 }, { "sqlite3_errmsg", test_errmsg ,0 }, { "sqlite3_errmsg16", test_errmsg16 ,0 }, { "sqlite3_open", test_open ,0 }, { "sqlite3_open16", test_open16 ,0 }, { "sqlite3_open_v2", test_open_v2 ,0 }, { "sqlite3_complete16", test_complete16 ,0 }, { "sqlite3_prepare", test_prepare ,0 }, { "sqlite3_prepare16", test_prepare16 ,0 }, { "sqlite3_prepare_v2", test_prepare_v2 ,0 }, { "sqlite3_prepare_tkt3134", test_prepare_tkt3134, 0}, { "sqlite3_prepare16_v2", test_prepare16_v2 ,0 }, |
︙ | ︙ |
Added test/e_uri.test.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | # 2011 May 06 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # set testdir [file dirname $argv0] source $testdir/tester.tcl set testprefix e_uri db close proc parse_uri {uri} { testvfs tvfs2 testvfs tvfs tvfs filter xOpen tvfs script parse_uri_open_cb set ::uri_open [list] set DB [sqlite3_open_v2 $uri { SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE SQLITE_OPEN_WAL } tvfs] sqlite3_close $DB tvfs delete tvfs2 delete set ::uri_open } proc parse_uri_open_cb {method file arglist} { set ::uri_open [list $file $arglist] } proc open_uri_error {uri} { set flags {SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE SQLITE_OPEN_WAL} set DB [sqlite3_open_v2 $uri $flags ""] set e [sqlite3_errmsg $DB] sqlite3_close $DB set e } # EVIDENCE-OF: R-35840-33204 If URI filename interpretation is enabled, # and the filename argument begins with "file:", then the filename is # interpreted as a URI. # # EVIDENCE-OF: R-00067-59538 URI filename interpretation is enabled if # the SQLITE_OPEN_URI flag is is set in the fourth argument to # sqlite3_open_v2(), or if it has been enabled globally using the # SQLITE_CONFIG_URI option with the sqlite3_config() method. # if {$tcl_platform(platform) == "unix"} { set flags [list SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE] # Tests with SQLITE_CONFIG_URI configured to false. URI intepretation is # only enabled if the SQLITE_OPEN_URI flag is specified. sqlite3_shutdown sqlite3_config_uri 0 do_test 1.1 { forcedelete file:test.db test.db set DB [sqlite3_open_v2 file:test.db [concat $flags SQLITE_OPEN_URI] ""] list [file exists file:test.db] [file exists test.db] } {0 1} sqlite3_close $DB do_test 1.2 { forcedelete file:test.db test.db set DB [sqlite3_open_v2 file:test.db [concat $flags] ""] list [file exists file:test.db] [file exists test.db] } {1 0} sqlite3_close $DB # Tests with SQLITE_CONFIG_URI configured to true. URI intepretation is # enabled with or without SQLITE_OPEN_URI. sqlite3_shutdown sqlite3_config_uri 1 do_test 1.3 { forcedelete file:test.db test.db set DB [sqlite3_open_v2 file:test.db [concat $flags SQLITE_OPEN_URI] ""] list [file exists file:test.db] [file exists test.db] } {0 1} sqlite3_close $DB do_test 1.4 { forcedelete file:test.db test.db set DB [sqlite3_open_v2 file:test.db [concat $flags] ""] list [file exists file:test.db] [file exists test.db] } {0 1} sqlite3_close $DB } # EVIDENCE-OF: R-17482-00398 If the authority is not an empty string or # "localhost", an error is returned to the caller. # if {$tcl_platform(platform) == "unix"} { set flags [list SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE SQLITE_OPEN_URI] foreach {tn uri error} " 1 {file://localhost[pwd]/test.db} {not an error} 2 {file://[pwd]/test.db} {not an error} 3 {file://x[pwd]/test.db} {invalid uri authority: x} 4 {file://invalid[pwd]/test.db} {invalid uri authority: invalid} " { do_test 2.$tn { set DB [sqlite3_open_v2 $uri $flags ""] set e [sqlite3_errmsg $DB] sqlite3_close $DB set e } $error } } # EVIDENCE-OF: R-43804-65312 The 'fragment' component of a URI, if # present, is always ignored. # # It is difficult to test that something is ignore correctly. So these tests # just show that adding a fragment does not interfere with the pathname or # parameters passed through to the VFS xOpen() methods. # if {$tcl_platform(platform) == "unix"} { foreach {tn uri parse} " 1 {file:test.db#abc} {[pwd]/test.db {}} 2 {file:test.db?a=b#abc} {[pwd]/test.db {a b}} 3 {file:test.db?a=b#?c=d} {[pwd]/test.db {a b}} " { do_test 3.$tn { parse_uri $uri } $parse } } # EVIDENCE-OF: R-00273-20588 SQLite uses the 'path' component of the URI # as the path to the database file to open. # # EVIDENCE-OF: R-28659-11035 If the path begins with a '/' character, # then it is interpreted as an absolute path. # # EVIDENCE-OF: R-39349-47203 If it does not begin with a '/', it is # interpreted as a relative path. # if {$tcl_platform(platform) == "unix"} { foreach {tn uri parse} " 1 {file:test.db} {[pwd]/test.db {}} 2 {file:/test.db} {/test.db {}} 3 {file:///test.db} {/test.db {}} 4 {file://localhost/test.db} {/test.db {}} 5 {file:/a/b/c/test.db} {/a/b/c/test.db {}} " { do_test 4.$tn { parse_uri $uri } $parse } } # EVIDENCE-OF: R-01612-30877 The "vfs" parameter may be used to specify # the name of a VFS object that provides the operating system interface # that should be used to access the database file on disk. # # The above is tested by cases 1.* below. # # EVIDENCE-OF: R-52293-58497 If this option is set to an empty string # the default VFS object is used. # # The above is tested by cases 2.* below. # # EVIDENCE-OF: R-31855-18665 If sqlite3_open_v2() is used and the vfs # option is present, then the VFS specified by the option takes # precedence over the value passed as the fourth parameter to # sqlite3_open_v2(). # # The above is tested by cases 3.* below. # proc vfs_open_cb {name args} { set ::vfs $name } foreach {name default} {vfs1 0 vfs2 0 vfs3 1} { testvfs $name -default $default $name filter xOpen $name script [list vfs_open_cb $name] } foreach {tn uri defvfs vfs} { 1.1 "file:test.db?vfs=vfs1" "" vfs1 1.2 "file:test.db?vfs=vfs2" "" vfs2 2.1 "file:test.db" vfs1 vfs1 2.2 "file:test.db?vfs=" vfs1 vfs3 3.1 "file:test.db?vfs=vfs1" vfs2 vfs1 3.2 "file:test.db?vfs=vfs2" vfs1 vfs2 3.3 "file:test.db?xvfs=vfs1" vfs2 vfs2 3.4 "file:test.db?xvfs=vfs2" vfs1 vfs1 } { do_test 5.$tn { set flags [list SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE SQLITE_OPEN_URI] sqlite3_close [ sqlite3_open_v2 $uri $flags $defvfs ] set ::vfs } $vfs } vfs1 delete vfs2 delete vfs3 delete # EVIDENCE-OF: R-48365-36308 Specifying an unknown VFS is an error. # set flags [list SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE SQLITE_OPEN_URI] do_test 6.1 { set DB [sqlite3_open_v2 file:test.db?vfs=nosuchvfs $flags ""] set errmsg [sqlite3_errmsg $DB] sqlite3_close $DB set errmsg } {no such vfs: nosuchvfs} # EVIDENCE-OF: R-60479-64270 The mode parameter may be set to either # "ro", "rw" or "rwc". Attempting to set it to any other value is an # error # sqlite3 db test.db db close foreach {tn uri error} " 1 {file:test.db?mode=ro} {not an error} 2 {file:test.db?mode=rw} {not an error} 3 {file:test.db?mode=rwc} {not an error} 4 {file:test.db?mode=Ro} {no such access mode: Ro} 5 {file:test.db?mode=Rw} {no such access mode: Rw} 6 {file:test.db?mode=Rwc} {no such access mode: Rwc} " { do_test 7.$tn { open_uri_error $uri } $error } # EVIDENCE-OF: R-09651-31805 If "ro" is specified, then the database is # opened for read-only access, just as if the SQLITE_OPEN_READONLY flag # had been set in the third argument to sqlite3_prepare_v2(). # # EVIDENCE-OF: R-40137-26050 If the mode option is set to "rw", then the # database is opened for read-write (but not create) access, as if # SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had been set. # # EVIDENCE-OF: R-26845-32976 Value "rwc" is equivalent to setting both # SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. # sqlite3_shutdown sqlite3_config_uri 1 foreach {tn uri read write create} { 1 {file:test.db?mode=ro} 1 0 0 2 {file:test.db?mode=rw} 1 1 0 3 {file:test.db?mode=rwc} 1 1 1 } { set RES(c,0) {1 {unable to open database file}} set RES(c,1) {0 {}} set RES(w,0) {1 {attempt to write a readonly database}} set RES(w,1) {0 {}} set RES(r,0) {1 {this never happens}} set RES(r,1) {0 {a b}} # Test CREATE access: forcedelete test.db do_test 8.$tn.c { list [catch { sqlite3 db $uri } msg] $msg } $RES(c,$create) catch { db close } sqlite3 db test.db db eval { CREATE TABLE t1(a, b) ; INSERT INTO t1 VALUES('a', 'b') ;} db close # Test READ access: do_test 8.$tn.r { sqlite3 db $uri catchsql { SELECT * FROM t1 } } $RES(r,$read) # Test WRITE access: do_test 8.$tn.w { sqlite3 db $uri catchsql { INSERT INTO t1 VALUES(1, 2) } } $RES(w,$write) catch {db close} } # EVIDENCE-OF: R-56032-32287 If sqlite3_open_v2() is used, it is an # error to specify a value for the mode parameter that is less # restrictive than that specified by the flags passed as the third # parameter. # forcedelete test.db sqlite3 db test.db db close foreach {tn uri flags error} { 1 {file:test.db?mode=ro} ro {not an error} 2 {file:test.db?mode=ro} rw {not an error} 3 {file:test.db?mode=ro} rwc {not an error} 4 {file:test.db?mode=rw} ro {access permission denied} 5 {file:test.db?mode=rw} rw {not an error} 6 {file:test.db?mode=rw} rwc {not an error} 7 {file:test.db?mode=rwc} ro {access permission denied} 8 {file:test.db?mode=rwc} rw {access permission denied} 9 {file:test.db?mode=rwc} rwc {not an error} } { set f(ro) [list SQLITE_OPEN_READONLY SQLITE_OPEN_URI] set f(rw) [list SQLITE_OPEN_READWRITE SQLITE_OPEN_URI] set f(rwc) [list SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE SQLITE_OPEN_URI] set DB [sqlite3_open_v2 $uri $f($flags) ""] set e [sqlite3_errmsg $DB] sqlite3_close $DB do_test 9.$tn { set e } $error } # EVIDENCE-OF: R-23182-54295 The cache parameter may be set to either # "shared" or "private". sqlite3 db test.db db close foreach {tn uri error} " 1 {file:test.db?cache=private} {not an error} 2 {file:test.db?cache=shared} {not an error} 3 {file:test.db?cache=yes} {no such cache mode: yes} 4 {file:test.db?cache=} {no such cache mode: } " { do_test 10.$tn { open_uri_error $uri } $error } # EVIDENCE-OF: R-23027-03515 Setting it to "shared" is equivalent to # setting the SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed # to sqlite3_open_v2(). # # EVIDENCE-OF: R-49793-28525 Setting the cache parameter to "private" is # equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. # # EVIDENCE-OF: R-19510-48080 If sqlite3_open_v2() is used and the # "cache" parameter is present in a URI filename, its value overrides # any behaviour requested by setting SQLITE_OPEN_PRIVATECACHE or # SQLITE_OPEN_SHAREDCACHE flag. # set orig [sqlite3_enable_shared_cache] foreach {tn uri flags shared_default isshared} { 1.1 "file:test.db" "" 0 0 1.2 "file:test.db" "" 1 1 1.3 "file:test.db" private 0 0 1.4 "file:test.db" private 1 0 1.5 "file:test.db" shared 0 1 1.6 "file:test.db" shared 1 1 2.1 "file:test.db?cache=private" "" 0 0 2.2 "file:test.db?cache=private" "" 1 0 2.3 "file:test.db?cache=private" private 0 0 2.4 "file:test.db?cache=private" private 1 0 2.5 "file:test.db?cache=private" shared 0 0 2.6 "file:test.db?cache=private" shared 1 0 3.1 "file:test.db?cache=shared" "" 0 1 3.2 "file:test.db?cache=shared" "" 1 1 3.3 "file:test.db?cache=shared" private 0 1 3.4 "file:test.db?cache=shared" private 1 1 3.5 "file:test.db?cache=shared" shared 0 1 3.6 "file:test.db?cache=shared" shared 1 1 } { forcedelete test.db sqlite3_enable_shared_cache 1 sqlite3 db test.db sqlite3_enable_shared_cache 0 db eval { CREATE TABLE t1(x); INSERT INTO t1 VALUES('ok'); } unset -nocomplain f set f() {SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE SQLITE_OPEN_URI} set f(shared) [concat $f() SQLITE_OPEN_SHAREDCACHE] set f(private) [concat $f() SQLITE_OPEN_PRIVATECACHE] sqlite3_enable_shared_cache $shared_default set DB [sqlite3_open_v2 $uri $f($flags) ""] set STMT [sqlite3_prepare $DB "SELECT * FROM t1" -1 dummy] db eval { BEGIN; INSERT INTO t1 VALUES('ko'); } sqlite3_step $STMT sqlite3_finalize $STMT set RES(0) {not an error} set RES(1) {database table is locked: t1} do_test 11.$tn { sqlite3_errmsg $DB } $RES($isshared) sqlite3_close $DB db close } sqlite3_enable_shared_cache $orig # EVIDENCE-OF: R-63472-46769 Specifying an unknown parameter in the # query component of a URI is not an error. # do_test 12.1 { parse_uri file://localhost/test.db?an=unknown¶meter=is&ok= } {/test.db {an unknown parameter is ok {}}} do_test 12.2 { parse_uri file://localhost/test.db?an&unknown¶meter&is&ok } {/test.db {an {} unknown {} parameter {} is {} ok {}}} # EVIDENCE-OF: R-27458-04043 URI hexadecimal escape sequences (%HH) are # supported within the path and query components of a URI. # # EVIDENCE-OF: R-52765-50368 Before the path or query components of a # URI filename are interpreted, they are encoded using UTF-8 and all # hexadecimal escape sequences replaced by a single byte containing the # corresponding octet. # # The second of the two statements above is tested by creating a # multi-byte utf-8 character using a sequence of %HH escapes. # foreach {tn uri parse} " 1 {file:/test.%64%62} {/test.db {}} 2 {file:/test.db?%68%65%6c%6c%6f=%77%6f%72%6c%64} {/test.db {hello world}} 3 {file:/%C3%BF.db} {/\xFF.db {}} " { do_test 13.$tn { parse_uri $uri } $parse } finish_test |
Changes to test/uri.test.
︙ | ︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 29 | # Test organization: # # 1.*: That file names are correctly extracted from URIs. # 2.*: That URI options (query parameters) are correctly extracted from URIs. # 3.*: That specifying an unknown VFS causes an error. # 4.*: Tests for specifying other options (other than "vfs"). # 5.*: Test using a different VFS with an attached database. # set testprefix uri db close sqlite3_shutdown sqlite3_config_uri 1 | > | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | # Test organization: # # 1.*: That file names are correctly extracted from URIs. # 2.*: That URI options (query parameters) are correctly extracted from URIs. # 3.*: That specifying an unknown VFS causes an error. # 4.*: Tests for specifying other options (other than "vfs"). # 5.*: Test using a different VFS with an attached database. # 6.*: Test that authorities other than "" and localhost cause errors. # set testprefix uri db close sqlite3_shutdown sqlite3_config_uri 1 |
︙ | ︙ | |||
124 125 126 127 128 129 130 | do_test 3.1 { list [catch { sqlite3 db "file:test.db?vfs=nosuchvfs" } msg] $msg } {1 {no such vfs: nosuchvfs}} #------------------------------------------------------------------------- # Test some of the other options (other than "vfs"). # | < < | 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | do_test 3.1 { list [catch { sqlite3 db "file:test.db?vfs=nosuchvfs" } msg] $msg } {1 {no such vfs: nosuchvfs}} #------------------------------------------------------------------------- # Test some of the other options (other than "vfs"). # foreach {tn mode create_ok write_ok readonly_ok} { 1 ro 0 0 1 2 rw 0 1 0 3 rwc 1 1 0 } { catch { db close } forcedelete test.db |
︙ | ︙ |