1# 2011 April 22 2# 3# The author disclaims copyright to this source code. In place of 4# a legal notice, here is a blessing: 5# 6# May you do good and not evil. 7# May you find forgiveness for yourself and forgive others. 8# May you share freely, never taking more than you give. 9# 10#*********************************************************************** 11# 12 13set testdir [file dirname $argv0] 14source $testdir/tester.tcl 15 16set testprefix uri 17db close 18sqlite3_shutdown 19sqlite3_config_uri 1 20 21#------------------------------------------------------------------------- 22# Test that file names are correctly extracted from URIs. 23# 24foreach {tn uri file} { 25 1 test.db test.db 26 2 file:test.db test.db 27 3 file://an-authorityPWD/test.db test.db 28 4 file:PWD/test.db test.db 29 5 file:test.db?mork=1 test.db 30 6 file:test.db?mork=1&tonglor=2 test.db 31 7 file:test.db?mork=1#boris test.db 32 8 file:test.db#boris test.db 33 9 test.db#boris test.db#boris 34 10 test.db?mork=1#boris test.db?mork=1#boris 35 11 file:test%2Edb test.db 36 12 file file 37 13 http:test.db http:test.db 38 14 file://xyzPWD/test.db%3Fhello test.db?hello 39 15 file:test.db%00extra test.db 40 16 file:test%00.db%00extra test 41} { 42 set uri [string map [list PWD [pwd]] $uri] 43 set file [string map [list PWD [pwd]] $file] 44 45 forcedelete $file 46 do_test 1.$tn.1 { file exists $file } 0 47 set DB [sqlite3_open $uri] 48 do_test 1.$tn.2 { file exists $file } 1 49 sqlite3_close $DB 50 forcedelete $file 51 52 do_test 1.$tn.3 { file exists $file } 0 53 sqlite3 db xxx.db 54 execsql { ATTACH $uri AS aux } 55 do_test 1.$tn.4 { file exists $file } 1 56 db close 57} 58 59 60#------------------------------------------------------------------------- 61# Test that URI query parameters are passed through to the VFS layer 62# correctly. 63# 64testvfs tvfs -default 1 65tvfs filter xOpen 66tvfs script open_method 67proc open_method {method file arglist} { 68 set ::arglist $arglist 69} 70foreach {tn uri kvlist} { 71 1 file:test.db?hello=world {hello world} 72 2 file:test.db?hello&world {hello {} world {}} 73 3 file:test.db?hello=1&world=2&vfs=tvfs {hello 1 world 2 vfs tvfs} 74 4 file:test.db?hello=1&world=2&vfs=unix {} 75 5 file:test.db?%68%65%6C%6C%6F=%77%6F%72%6C%64 {hello world} 76 6 file:test%00.db?hello%00extra=world%00ex {hello world} 77 7 file:test%00.db?hello%00=world%00 {hello world} 78 8 file:test%00.db?=world&xyz=abc {xyz abc} 79 9 file:test.db?%00hello=world&xyz=abc {xyz abc} 80 10 file:test.db?hello=%00world&xyz= {hello {} xyz {}} 81 11 file:test.db?=#ravada {} 82 12 file:test.db?&&&&&&&&hello=world&&&&&&& {hello world} 83 13 test.db?&&&&&&&&hello=world&&&&&&& {} 84 14 http:test.db?hello&world {} 85} { 86 set ::arglist "" 87 set DB [sqlite3_open $uri] 88 do_test 2.$tn.1 { set ::arglist } $kvlist 89 sqlite3_close $DB 90 91 sqlite3 db xxx.db 92 set ::arglist "" 93 execsql { ATTACH $uri AS aux } 94 do_test 2.$tn.2 { set ::arglist } $kvlist 95 db close 96} 97tvfs delete 98 99#------------------------------------------------------------------------- 100# Test that specifying a non-existent VFS raises an error. 101# 102do_test 3.1 { 103 list [catch { sqlite3 db "file:test.db?vfs=nosuchvfs" } msg] $msg 104} {1 {no such vfs: nosuchvfs}} 105 106#------------------------------------------------------------------------- 107# Test the "readonly" URI option. 108# 109do_test 4.0 { 110 sqlite3 db test.db 111 db eval {CREATE TABLE t1(a, b)} 112 db close 113} {} 114foreach {tn uri ro} { 115 1 "file:test.db" 0 116 2 "file:test.db?readonly=0" 0 117 3 "file:test.db?readonly=1&readwrite=0&create=0" 1 118} { 119 set RES(0) {0 {}} 120 set RES(1) {1 {attempt to write a readonly database}} 121 122 do_test 4.$tn { 123 sqlite3 db $uri 124 catchsql { INSERT INTO t1 VALUES(1, 2) } 125 } $RES($ro) 126 db close 127} 128 129finish_test 130 131