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 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this script is testing the sqlite3_set_authorizer() API
13 # and related functionality.
15 # $Id: auth2.test,v 1.3 2008/07/02 13:13:53 danielk1977 Exp $
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
21 # disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
22 # defined during compilation.
23 if {[catch {db auth {}} msg]} {
30 CREATE TABLE t1(a,b,c);
31 INSERT INTO t1 VALUES(1,2,3);
34 proc auth {code arg1 arg2 arg3 arg4 args} {
35 if {$code=="SQLITE_FUNCTION"} {
39 } elseif {$arg2=="min"} {
48 catchsql {SELECT max(a,b,c) FROM t1}
49 } {1 {not authorized to use function: max}}
55 catchsql {SELECT min(a,b,c) FROM t1}
62 catchsql {SELECT coalesce(min(a,b,c),999) FROM t1}
69 catchsql {SELECT coalesce(a,b,c) FROM t1}
75 # Make sure the authorizer is not called when parsing the schema
76 # and when computing the result set of a view.
83 append authargs [lrange $args 0 4]\n
90 CREATE TABLE t2(x,y,z);
93 } {SQLITE_INSERT sqlite_master {} main {}
94 SQLITE_CREATE_TABLE t2 {} main {}
95 SQLITE_UPDATE sqlite_master type main {}
96 SQLITE_UPDATE sqlite_master name main {}
97 SQLITE_UPDATE sqlite_master tbl_name main {}
98 SQLITE_UPDATE sqlite_master rootpage main {}
99 SQLITE_UPDATE sqlite_master sql main {}
100 SQLITE_READ sqlite_master ROWID main {}
101 SQLITE_READ sqlite_master name main {}
102 SQLITE_READ sqlite_master rootpage main {}
103 SQLITE_READ sqlite_master sql main {}
104 SQLITE_READ sqlite_master tbl_name main {}
105 SQLITE_READ sqlite_master type main {}
106 SQLITE_READ sqlite_master ROWID main {}
111 CREATE VIEW v2 AS SELECT x+y AS a, y+z AS b from t2;
114 } {SQLITE_INSERT sqlite_master {} main {}
115 SQLITE_CREATE_VIEW v2 {} main {}
116 SQLITE_UPDATE sqlite_master type main {}
117 SQLITE_UPDATE sqlite_master name main {}
118 SQLITE_UPDATE sqlite_master tbl_name main {}
119 SQLITE_UPDATE sqlite_master rootpage main {}
120 SQLITE_UPDATE sqlite_master sql main {}
121 SQLITE_READ sqlite_master ROWID main {}
122 SQLITE_READ sqlite_master name main {}
123 SQLITE_READ sqlite_master rootpage main {}
124 SQLITE_READ sqlite_master sql main {}
125 SQLITE_READ sqlite_master tbl_name main {}
126 SQLITE_READ sqlite_master type main {}
127 SQLITE_READ sqlite_master ROWID main {}
135 } {SQLITE_SELECT {} {} {} {}
136 SQLITE_READ t2 x main v2
137 SQLITE_READ t2 y main v2
138 SQLITE_READ t2 y main v2
139 SQLITE_READ t2 z main v2
140 SQLITE_READ v2 a main {}
141 SQLITE_READ v2 b main {}
142 SQLITE_SELECT {} {} {} v2
146 CREATE TABLE t3(p,q,r);
153 } {SQLITE_SELECT {} {} {} {}
154 SQLITE_READ t2 x main v2
155 SQLITE_READ t2 y main v2
156 SQLITE_READ t2 y main v2
157 SQLITE_READ t2 z main v2
158 SQLITE_READ v2 b main {}
159 SQLITE_READ v2 a main {}
160 SQLITE_SELECT {} {} {} v2
161 SQLITE_SELECT {} {} {} {}
162 SQLITE_READ t2 x main v2
163 SQLITE_READ t2 y main v2
164 SQLITE_READ t2 y main v2
165 SQLITE_READ t2 z main v2
166 SQLITE_READ v2 b main {}
167 SQLITE_READ v2 a main {}
168 SQLITE_SELECT {} {} {} v2