SQLite

Check-in [de05eb75]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Another attempt at generalizing the URI parsing so that it works with a wider variety of file URIs and yet remains backwards compatible.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | uri-enhancement
Files: files | file ages | folders
SHA1: de05eb75ecfd208846d583c82ec05c5c5ef7e8ce
User & Date: drh 2013-07-24 14:54:35
Context
2013-08-07
18:07
Merge in the latest changes from trunk. (Closed-Leaf check-in: c78b0d30 user: drh tags: uri-enhancement)
2013-07-24
14:54
Another attempt at generalizing the URI parsing so that it works with a wider variety of file URIs and yet remains backwards compatible. (check-in: de05eb75 user: drh tags: uri-enhancement)
2013-07-20
00:34
Add 'queryplantest' target to the MSVC makefile. (check-in: ad0551e0 user: mistachkin tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/main.c.

2173
2174
2175
2176
2177
2178
2179
2180












2181
2182
2183
2184
2185
2186




2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
    ** 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++;

      if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
        *pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s", 




            iIn-7, &zUri[7]);
        rc = SQLITE_ERROR;
        goto parse_uri_out;
      }
    }else{
      iIn = 5;
    }

    /* Copy the filename and any query parameters into the zFile buffer. 
    ** Decode %HH escape codes along the way. 
    **
    ** Within this loop, variable eState may be set to 0, 1 or 2, depending
    ** on the parsing context. As follows:







|
>
>
>
>
>
>
>
>
>
>
>
>
|

<
|
<
<
>
>
>
>
|
<
<
<
|
|







2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194

2195


2196
2197
2198
2199
2200



2201
2202
2203
2204
2205
2206
2207
2208
2209
    ** 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;

    /* Mappings:
    ** URI                            FILENAME
    ** ---------------------------    ----------------------
    ** file:abc/xyz                   abc/xyz
    ** file:/abc/xyz                  /abc/xyz
    ** file://abc/xyz                 //abc/xyz
    ** file:///abc/xyz                /abc/xyz
    ** file:////abc/xyz               //abc/xyz
    ** file://///abc/xyz              //abc/xyz
    ** file://localhost/xyz           /xyz
    ** file:///c:/abc/xyz             /c:/abc/xyz    (winOpen() removes leading /)
    */
    iIn = 5;
    if( strncmp(zUri+5, "///", 3)==0 ){
      iIn = 7;

      /* The following condition causes URIs with five leading / characters


      ** like file://///host/path to be converted into UNCs like //host/path.
      ** The correct URI for that UNC has only two or four leading / characters
      ** file://host/path or file:////host/path.  But 5 leading slashes is a 
      ** common error, we are told, so we handle it as a special case. */
      if( strncmp(zUri+7, "///", 3)==0 ){ iIn++; }



    }else if( strncmp(zUri+5, "//localhost/", 12)==0 ){
      iIn = 16;
    }

    /* Copy the filename and any query parameters into the zFile buffer. 
    ** Decode %HH escape codes along the way. 
    **
    ** Within this loop, variable eState may be set to 0, 1 or 2, depending
    ** on the parsing context. As follows:

Changes to test/e_uri.test.

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# "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[test_pwd /]test.db}   {not an error}
    2  {file://[test_pwd /]test.db}            {not an error}
    3  {file://x[test_pwd /]test.db}           {invalid uri authority: x}
    4  {file://invalid[test_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







<
<







129
130
131
132
133
134
135


136
137
138
139
140
141
142
# "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[test_pwd /]test.db}   {not an error}
    2  {file://[test_pwd /]test.db}            {not an error}


  " {
    do_test 2.$tn {
      set DB [sqlite3_open_v2 $uri $flags ""]
      set e [sqlite3_errmsg $DB]
      sqlite3_close $DB
      set e
    } $error

Changes to test/uri.test.

277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# Check that only "" and "localhost" are acceptable as authorities.
#
catch {db close}
foreach {tn uri res} {
  1     "file://localhost/PWD/test.db"   {not an error}
  2     "file:///PWD/test.db"            {not an error}
  3     "file:/PWD/test.db"              {not an error}
  4     "file://l%6Fcalhost/PWD/test.db" {invalid uri authority: l%6Fcalhost}
  5     "file://lbcalhost/PWD/test.db"   {invalid uri authority: lbcalhost}
  6     "file://x/PWD/test.db"           {invalid uri authority: x}
} {

  if {$tcl_platform(platform)=="windows"} {
    set uri  [string map [list PWD [string range [get_pwd] 3 end]] $uri]
  } else {
    set uri  [string map [list PWD [string range [get_pwd] 1 end]] $uri]
  }







<
<
<







277
278
279
280
281
282
283



284
285
286
287
288
289
290
# Check that only "" and "localhost" are acceptable as authorities.
#
catch {db close}
foreach {tn uri res} {
  1     "file://localhost/PWD/test.db"   {not an error}
  2     "file:///PWD/test.db"            {not an error}
  3     "file:/PWD/test.db"              {not an error}



} {

  if {$tcl_platform(platform)=="windows"} {
    set uri  [string map [list PWD [string range [get_pwd] 3 end]] $uri]
  } else {
    set uri  [string map [list PWD [string range [get_pwd] 1 end]] $uri]
  }