3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
15 set testprefix zipfile
20 if {[catch {load_static_extension db zipfile} error]} {
21 puts "Skipping zipfile tests, hit load error: $error"
27 CREATE VIRTUAL TABLE temp.zz USING zipfile('test.zip');
28 PRAGMA table_info(zz);
39 do_execsql_test 1.1.1 {
40 INSERT INTO zz(name, mode, mtime, sz, rawdata, method)
41 VALUES('f.txt', '-rw-r--r--', 1000000000, 5, 'abcde', 0);
43 do_execsql_test 1.1.2 {
44 INSERT INTO zz(name, mtime, sz, rawdata, method)
45 VALUES('g.txt', 1000000002, 5, '12345', 0);
49 SELECT name, mtime, data FROM zipfile('test.zip')
51 f.txt 1000000000 abcde
52 g.txt 1000000002 12345
56 INSERT INTO zz(name, mode, mtime, data) VALUES('h.txt',
57 '-rw-r--r--', 1000000004, 'aaaaaaaaaabbbbbbbbbb'
62 SELECT name, mtime, data, method FROM zipfile('test.zip');
64 f.txt 1000000000 abcde 0
65 g.txt 1000000002 12345 0
66 h.txt 1000000004 aaaaaaaaaabbbbbbbbbb 8
69 do_execsql_test 1.5.1 {
71 INSERT INTO zz(name, mode, mtime, data, method)
72 VALUES('i.txt', '-rw-r--r--', 1000000006, 'zxcvb', 0);
75 } {f.txt g.txt h.txt i.txt}
76 do_execsql_test 1.5.2 {
78 } {f.txt g.txt h.txt i.txt}
80 do_execsql_test 1.6.0 {
81 DELETE FROM zz WHERE name='g.txt';
85 #-------------------------------------------------------------------------
89 load_static_extension db zipfile
91 CREATE VIRTUAL TABLE zzz USING zipfile('test.zip');
92 INSERT INTO zzz(name, mode) VALUES('dirname', 'drwxr-xr-x');
93 SELECT name, mode, data FROM zzz;
96 INSERT INTO zzz(name, data) VALUES('dirname2', NULL);
97 INSERT INTO zzz(name, data) VALUES('dirname2/file1.txt', 'abcdefghijklmnop');
98 SELECT name, mode, data FROM zzz;
102 dirname2/file1.txt 33188 abcdefghijklmnop
105 do_catchsql_test 2.3 {
106 UPDATE zzz SET name = 'dirname3' WHERE name = 'dirname/';
107 } {1 {constraint failed}}
108 do_execsql_test 2.4 {
109 SELECT name, mode, data FROM zzz;
113 dirname2/file1.txt 33188 abcdefghijklmnop
116 # If on unix, check that the [unzip] utility can unpack our archive.
118 if {$::tcl_platform(platform)=="unix"} {
122 set rc [catch { exec unzip test.zip > /dev/null } msg]
125 do_test 2.5.2 { file isdir dirname } 1
126 do_test 2.5.3 { file isdir dirname2 } 1
127 do_test 2.5.4 { file isdir dirname2/file1.txt } 0
129 set fd [open dirname2/file1.txt]
136 #-------------------------------------------------------------------------
139 load_static_extension db zipfile
141 do_execsql_test 3.0 {
142 CREATE VIRTUAL TABLE temp.x1 USING zipfile('test.zip');
143 INSERT INTO x1(name, data) VALUES('dir1/', NULL);
144 INSERT INTO x1(name, data) VALUES('file1', '1234');
145 INSERT INTO x1(name, data) VALUES('dir1/file2', '5678');
152 do_catchsql_test 3.1.$tn.0 {
153 INSERT INTO x1(name, data) VALUES($fname, NULL);
154 } {1 {constraint failed}}
155 do_catchsql_test 3.1.$tn.1 {
156 INSERT INTO x1(name, data) VALUES($fname || '/', NULL);
157 } {1 {constraint failed}}
158 do_catchsql_test 3.1.$tn.2 {
159 INSERT INTO x1(name, data) VALUES($fname, 'abcd');
160 } {1 {constraint failed}}
163 do_catchsql_test 3.2 {
165 } {1 {no such column: rowid}}