1# 2019 November 18 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# This file implements regression tests for SQLite library. The 12# focus of this file is testing that SQLite can follow symbolic links. 13# 14 15set testdir [file dirname $argv0] 16source $testdir/tester.tcl 17set testprefix symlink2 18 19# This only runs on Windows. 20if {$::tcl_platform(platform)!="windows"} { 21 finish_test 22 return 23} 24 25proc createWin32Symlink { link target } { 26 exec -- $::env(ComSpec) /c mklink \ 27 [file nativename $link] [file nativename $target] 28 return "" 29} 30 31proc deleteWin32Symlink { link } { 32 exec -- $::env(ComSpec) /c del [file nativename $link] 33 return "" 34} 35 36proc canCreateWin32Symlink {} { 37 set link [file join $::testdir lnk[pid].sym] 38 if {[file exists $link]} { return 0 } 39 set target [info nameofexecutable] 40 if {[catch {createWin32Symlink $link $target}] == 0} { 41 deleteWin32Symlink $link 42 return 1 43 } 44 return 0 45} 46 47# Creating symlinks may require administrator privileges on Windows. 48if {![canCreateWin32Symlink]} { 49 finish_test 50 return 51} 52 53# Ensure that test.db has been created. 54# 55do_execsql_test 1.0 { 56 CREATE TABLE t1(x, y); 57 INSERT INTO t1 VALUES(1,9999); 58} 59 60do_test 2.0 { 61 createWin32Symlink link.db test.db 62} {} 63 64do_test 2.1 { 65 file exists test.db 66} {1} 67 68do_test 2.2 { 69 file exists link.db 70} {1} 71 72do_test 3.1 { 73 execsql { SELECT x, y FROM t1; } db 74} {1 9999} 75 76do_test 3.2 { 77 sqlite3 db2 link.db 78 execsql { SELECT x, y FROM t1; } db2 79} {1 9999} 80 81do_test 3.3 { 82 sqlite3 db3 test.db -nofollow true 83 execsql { SELECT x, y FROM t1; } db3 84} {1 9999} 85 86do_test 3.4 { 87 db3 close 88} {} 89 90do_test 3.5 { 91 list [catch { 92 sqlite3 db4 link.db -nofollow true 93 execsql { SELECT x, y FROM t1; } db4 94 } res] $res 95} {1 {unable to open database file}} 96 97catch {db4 close} 98 99do_test 4.0 { 100 db2 close 101 deleteWin32Symlink link.db 102} {} 103 104do_test 4.1 { 105 file exists test.db 106} {1} 107 108do_test 4.2 { 109 file exists link.db 110} {0} 111 112do_test 5.1 { 113 execsql { SELECT x, y FROM t1; } db 114} {1 9999} 115 116finish_test 117