xref: /onnv-gate/usr/src/lib/libsqlite/test/auth.test (revision 4520:7dbeadedd7fe)
1*4520Snw141292
2*4520Snw141292#pragma ident	"%Z%%M%	%I%	%E% SMI"
3*4520Snw141292
4*4520Snw141292# 2003 April 4
5*4520Snw141292#
6*4520Snw141292# The author disclaims copyright to this source code.  In place of
7*4520Snw141292# a legal notice, here is a blessing:
8*4520Snw141292#
9*4520Snw141292#    May you do good and not evil.
10*4520Snw141292#    May you find forgiveness for yourself and forgive others.
11*4520Snw141292#    May you share freely, never taking more than you give.
12*4520Snw141292#
13*4520Snw141292#***********************************************************************
14*4520Snw141292# This file implements regression tests for SQLite library.  The
15*4520Snw141292# focus of this script is testing the ATTACH and DETACH commands
16*4520Snw141292# and related functionality.
17*4520Snw141292#
18*4520Snw141292# $Id: auth.test,v 1.12 2003/12/07 00:24:35 drh Exp $
19*4520Snw141292#
20*4520Snw141292
21*4520Snw141292set testdir [file dirname $argv0]
22*4520Snw141292source $testdir/tester.tcl
23*4520Snw141292
24*4520Snw141292# disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
25*4520Snw141292# defined during compilation.
26*4520Snw141292
27*4520Snw141292do_test auth-1.1.1 {
28*4520Snw141292  db close
29*4520Snw141292  set ::DB [sqlite db test.db]
30*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
31*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
32*4520Snw141292      return SQLITE_DENY
33*4520Snw141292    }
34*4520Snw141292    return SQLITE_OK
35*4520Snw141292  }
36*4520Snw141292  db authorizer ::auth
37*4520Snw141292  catchsql {CREATE TABLE t1(a,b,c)}
38*4520Snw141292} {1 {not authorized}}
39*4520Snw141292do_test auth-1.1.2 {
40*4520Snw141292  db errorcode
41*4520Snw141292} {23}
42*4520Snw141292do_test auth-1.2 {
43*4520Snw141292  execsql {SELECT name FROM sqlite_master}
44*4520Snw141292} {}
45*4520Snw141292do_test auth-1.3.1 {
46*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
47*4520Snw141292    if {$code=="SQLITE_CREATE_TABLE"} {
48*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
49*4520Snw141292      return SQLITE_DENY
50*4520Snw141292    }
51*4520Snw141292    return SQLITE_OK
52*4520Snw141292  }
53*4520Snw141292  catchsql {CREATE TABLE t1(a,b,c)}
54*4520Snw141292} {1 {not authorized}}
55*4520Snw141292do_test auth-1.3.2 {
56*4520Snw141292  db errorcode
57*4520Snw141292} {23}
58*4520Snw141292do_test auth-1.3.3 {
59*4520Snw141292  set ::authargs
60*4520Snw141292} {t1 {} main {}}
61*4520Snw141292do_test auth-1.4 {
62*4520Snw141292  execsql {SELECT name FROM sqlite_master}
63*4520Snw141292} {}
64*4520Snw141292
65*4520Snw141292do_test auth-1.5 {
66*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
67*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
68*4520Snw141292      return SQLITE_DENY
69*4520Snw141292    }
70*4520Snw141292    return SQLITE_OK
71*4520Snw141292  }
72*4520Snw141292  catchsql {CREATE TEMP TABLE t1(a,b,c)}
73*4520Snw141292} {1 {not authorized}}
74*4520Snw141292do_test auth-1.6 {
75*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
76*4520Snw141292} {}
77*4520Snw141292do_test auth-1.7.1 {
78*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
79*4520Snw141292    if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
80*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
81*4520Snw141292      return SQLITE_DENY
82*4520Snw141292    }
83*4520Snw141292    return SQLITE_OK
84*4520Snw141292  }
85*4520Snw141292  catchsql {CREATE TEMP TABLE t1(a,b,c)}
86*4520Snw141292} {1 {not authorized}}
87*4520Snw141292do_test auth-1.7.2 {
88*4520Snw141292   set ::authargs
89*4520Snw141292} {t1 {} temp {}}
90*4520Snw141292do_test auth-1.8 {
91*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
92*4520Snw141292} {}
93*4520Snw141292
94*4520Snw141292do_test auth-1.9 {
95*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
96*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
97*4520Snw141292      return SQLITE_IGNORE
98*4520Snw141292    }
99*4520Snw141292    return SQLITE_OK
100*4520Snw141292  }
101*4520Snw141292  catchsql {CREATE TABLE t1(a,b,c)}
102*4520Snw141292} {0 {}}
103*4520Snw141292do_test auth-1.10 {
104*4520Snw141292  execsql {SELECT name FROM sqlite_master}
105*4520Snw141292} {}
106*4520Snw141292do_test auth-1.11 {
107*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
108*4520Snw141292    if {$code=="SQLITE_CREATE_TABLE"} {
109*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
110*4520Snw141292      return SQLITE_IGNORE
111*4520Snw141292    }
112*4520Snw141292    return SQLITE_OK
113*4520Snw141292  }
114*4520Snw141292  catchsql {CREATE TABLE t1(a,b,c)}
115*4520Snw141292} {0 {}}
116*4520Snw141292do_test auth-1.12 {
117*4520Snw141292  execsql {SELECT name FROM sqlite_master}
118*4520Snw141292} {}
119*4520Snw141292do_test auth-1.13 {
120*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
121*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
122*4520Snw141292      return SQLITE_IGNORE
123*4520Snw141292    }
124*4520Snw141292    return SQLITE_OK
125*4520Snw141292  }
126*4520Snw141292  catchsql {CREATE TEMP TABLE t1(a,b,c)}
127*4520Snw141292} {0 {}}
128*4520Snw141292do_test auth-1.14 {
129*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
130*4520Snw141292} {}
131*4520Snw141292do_test auth-1.15 {
132*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
133*4520Snw141292    if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
134*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
135*4520Snw141292      return SQLITE_IGNORE
136*4520Snw141292    }
137*4520Snw141292    return SQLITE_OK
138*4520Snw141292  }
139*4520Snw141292  catchsql {CREATE TEMP TABLE t1(a,b,c)}
140*4520Snw141292} {0 {}}
141*4520Snw141292do_test auth-1.16 {
142*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
143*4520Snw141292} {}
144*4520Snw141292
145*4520Snw141292do_test auth-1.17 {
146*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
147*4520Snw141292    if {$code=="SQLITE_CREATE_TABLE"} {
148*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
149*4520Snw141292      return SQLITE_DENY
150*4520Snw141292    }
151*4520Snw141292    return SQLITE_OK
152*4520Snw141292  }
153*4520Snw141292  catchsql {CREATE TEMP TABLE t1(a,b,c)}
154*4520Snw141292} {0 {}}
155*4520Snw141292do_test auth-1.18 {
156*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
157*4520Snw141292} {t1}
158*4520Snw141292do_test auth-1.19.1 {
159*4520Snw141292  set ::authargs {}
160*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
161*4520Snw141292    if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
162*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
163*4520Snw141292      return SQLITE_DENY
164*4520Snw141292    }
165*4520Snw141292    return SQLITE_OK
166*4520Snw141292  }
167*4520Snw141292  catchsql {CREATE TABLE t2(a,b,c)}
168*4520Snw141292} {0 {}}
169*4520Snw141292do_test auth-1.19.2 {
170*4520Snw141292  set ::authargs
171*4520Snw141292} {}
172*4520Snw141292do_test auth-1.20 {
173*4520Snw141292  execsql {SELECT name FROM sqlite_master}
174*4520Snw141292} {t2}
175*4520Snw141292
176*4520Snw141292do_test auth-1.21.1 {
177*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
178*4520Snw141292    if {$code=="SQLITE_DROP_TABLE"} {
179*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
180*4520Snw141292      return SQLITE_DENY
181*4520Snw141292    }
182*4520Snw141292    return SQLITE_OK
183*4520Snw141292  }
184*4520Snw141292  catchsql {DROP TABLE t2}
185*4520Snw141292} {1 {not authorized}}
186*4520Snw141292do_test auth-1.21.2 {
187*4520Snw141292  set ::authargs
188*4520Snw141292} {t2 {} main {}}
189*4520Snw141292do_test auth-1.22 {
190*4520Snw141292  execsql {SELECT name FROM sqlite_master}
191*4520Snw141292} {t2}
192*4520Snw141292do_test auth-1.23.1 {
193*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
194*4520Snw141292    if {$code=="SQLITE_DROP_TABLE"} {
195*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
196*4520Snw141292      return SQLITE_IGNORE
197*4520Snw141292    }
198*4520Snw141292    return SQLITE_OK
199*4520Snw141292  }
200*4520Snw141292  catchsql {DROP TABLE t2}
201*4520Snw141292} {0 {}}
202*4520Snw141292do_test auth-1.23.2 {
203*4520Snw141292  set ::authargs
204*4520Snw141292} {t2 {} main {}}
205*4520Snw141292do_test auth-1.24 {
206*4520Snw141292  execsql {SELECT name FROM sqlite_master}
207*4520Snw141292} {t2}
208*4520Snw141292
209*4520Snw141292do_test auth-1.25 {
210*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
211*4520Snw141292    if {$code=="SQLITE_DROP_TEMP_TABLE"} {
212*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
213*4520Snw141292      return SQLITE_DENY
214*4520Snw141292    }
215*4520Snw141292    return SQLITE_OK
216*4520Snw141292  }
217*4520Snw141292  catchsql {DROP TABLE t1}
218*4520Snw141292} {1 {not authorized}}
219*4520Snw141292do_test auth-1.26 {
220*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
221*4520Snw141292} {t1}
222*4520Snw141292do_test auth-1.27 {
223*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
224*4520Snw141292    if {$code=="SQLITE_DROP_TEMP_TABLE"} {
225*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
226*4520Snw141292      return SQLITE_IGNORE
227*4520Snw141292    }
228*4520Snw141292    return SQLITE_OK
229*4520Snw141292  }
230*4520Snw141292  catchsql {DROP TABLE t1}
231*4520Snw141292} {0 {}}
232*4520Snw141292do_test auth-1.28 {
233*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
234*4520Snw141292} {t1}
235*4520Snw141292
236*4520Snw141292do_test auth-1.29 {
237*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
238*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="t2"} {
239*4520Snw141292      return SQLITE_DENY
240*4520Snw141292    }
241*4520Snw141292    return SQLITE_OK
242*4520Snw141292  }
243*4520Snw141292  catchsql {INSERT INTO t2 VALUES(1,2,3)}
244*4520Snw141292} {1 {not authorized}}
245*4520Snw141292do_test auth-1.30 {
246*4520Snw141292  execsql {SELECT * FROM t2}
247*4520Snw141292} {}
248*4520Snw141292do_test auth-1.31 {
249*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
250*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="t2"} {
251*4520Snw141292      return SQLITE_IGNORE
252*4520Snw141292    }
253*4520Snw141292    return SQLITE_OK
254*4520Snw141292  }
255*4520Snw141292  catchsql {INSERT INTO t2 VALUES(1,2,3)}
256*4520Snw141292} {0 {}}
257*4520Snw141292do_test auth-1.32 {
258*4520Snw141292  execsql {SELECT * FROM t2}
259*4520Snw141292} {}
260*4520Snw141292do_test auth-1.33 {
261*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
262*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="t1"} {
263*4520Snw141292      return SQLITE_IGNORE
264*4520Snw141292    }
265*4520Snw141292    return SQLITE_OK
266*4520Snw141292  }
267*4520Snw141292  catchsql {INSERT INTO t2 VALUES(1,2,3)}
268*4520Snw141292} {0 {}}
269*4520Snw141292do_test auth-1.34 {
270*4520Snw141292  execsql {SELECT * FROM t2}
271*4520Snw141292} {1 2 3}
272*4520Snw141292
273*4520Snw141292do_test auth-1.35.1 {
274*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
275*4520Snw141292    if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
276*4520Snw141292      return SQLITE_DENY
277*4520Snw141292    }
278*4520Snw141292    return SQLITE_OK
279*4520Snw141292  }
280*4520Snw141292  catchsql {SELECT * FROM t2}
281*4520Snw141292} {1 {access to t2.b is prohibited}}
282*4520Snw141292do_test auth-1.35.2 {
283*4520Snw141292  execsql {ATTACH DATABASE 'test.db' AS two}
284*4520Snw141292  catchsql {SELECT * FROM two.t2}
285*4520Snw141292} {1 {access to two.t2.b is prohibited}}
286*4520Snw141292execsql {DETACH DATABASE two}
287*4520Snw141292do_test auth-1.36 {
288*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
289*4520Snw141292    if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
290*4520Snw141292      return SQLITE_IGNORE
291*4520Snw141292    }
292*4520Snw141292    return SQLITE_OK
293*4520Snw141292  }
294*4520Snw141292  catchsql {SELECT * FROM t2}
295*4520Snw141292} {0 {1 {} 3}}
296*4520Snw141292do_test auth-1.37 {
297*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
298*4520Snw141292    if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
299*4520Snw141292      return SQLITE_IGNORE
300*4520Snw141292    }
301*4520Snw141292    return SQLITE_OK
302*4520Snw141292  }
303*4520Snw141292  catchsql {SELECT * FROM t2 WHERE b=2}
304*4520Snw141292} {0 {}}
305*4520Snw141292do_test auth-1.38 {
306*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
307*4520Snw141292    if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="a"} {
308*4520Snw141292      return SQLITE_IGNORE
309*4520Snw141292    }
310*4520Snw141292    return SQLITE_OK
311*4520Snw141292  }
312*4520Snw141292  catchsql {SELECT * FROM t2 WHERE b=2}
313*4520Snw141292} {0 {{} 2 3}}
314*4520Snw141292do_test auth-1.39 {
315*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
316*4520Snw141292    if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
317*4520Snw141292      return SQLITE_IGNORE
318*4520Snw141292    }
319*4520Snw141292    return SQLITE_OK
320*4520Snw141292  }
321*4520Snw141292  catchsql {SELECT * FROM t2 WHERE b IS NULL}
322*4520Snw141292} {0 {1 {} 3}}
323*4520Snw141292do_test auth-1.40 {
324*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
325*4520Snw141292    if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
326*4520Snw141292      return SQLITE_DENY
327*4520Snw141292    }
328*4520Snw141292    return SQLITE_OK
329*4520Snw141292  }
330*4520Snw141292  catchsql {SELECT a,c FROM t2 WHERE b IS NULL}
331*4520Snw141292} {1 {access to t2.b is prohibited}}
332*4520Snw141292
333*4520Snw141292do_test auth-1.41 {
334*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
335*4520Snw141292    if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
336*4520Snw141292      return SQLITE_DENY
337*4520Snw141292    }
338*4520Snw141292    return SQLITE_OK
339*4520Snw141292  }
340*4520Snw141292  catchsql {UPDATE t2 SET a=11}
341*4520Snw141292} {0 {}}
342*4520Snw141292do_test auth-1.42 {
343*4520Snw141292  execsql {SELECT * FROM t2}
344*4520Snw141292} {11 2 3}
345*4520Snw141292do_test auth-1.43 {
346*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
347*4520Snw141292    if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
348*4520Snw141292      return SQLITE_DENY
349*4520Snw141292    }
350*4520Snw141292    return SQLITE_OK
351*4520Snw141292  }
352*4520Snw141292  catchsql {UPDATE t2 SET b=22, c=33}
353*4520Snw141292} {1 {not authorized}}
354*4520Snw141292do_test auth-1.44 {
355*4520Snw141292  execsql {SELECT * FROM t2}
356*4520Snw141292} {11 2 3}
357*4520Snw141292do_test auth-1.45 {
358*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
359*4520Snw141292    if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
360*4520Snw141292      return SQLITE_IGNORE
361*4520Snw141292    }
362*4520Snw141292    return SQLITE_OK
363*4520Snw141292  }
364*4520Snw141292  catchsql {UPDATE t2 SET b=22, c=33}
365*4520Snw141292} {0 {}}
366*4520Snw141292do_test auth-1.46 {
367*4520Snw141292  execsql {SELECT * FROM t2}
368*4520Snw141292} {11 2 33}
369*4520Snw141292
370*4520Snw141292do_test auth-1.47 {
371*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
372*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
373*4520Snw141292      return SQLITE_DENY
374*4520Snw141292    }
375*4520Snw141292    return SQLITE_OK
376*4520Snw141292  }
377*4520Snw141292  catchsql {DELETE FROM t2 WHERE a=11}
378*4520Snw141292} {1 {not authorized}}
379*4520Snw141292do_test auth-1.48 {
380*4520Snw141292  execsql {SELECT * FROM t2}
381*4520Snw141292} {11 2 33}
382*4520Snw141292do_test auth-1.49 {
383*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
384*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
385*4520Snw141292      return SQLITE_IGNORE
386*4520Snw141292    }
387*4520Snw141292    return SQLITE_OK
388*4520Snw141292  }
389*4520Snw141292  catchsql {DELETE FROM t2 WHERE a=11}
390*4520Snw141292} {0 {}}
391*4520Snw141292do_test auth-1.50 {
392*4520Snw141292  execsql {SELECT * FROM t2}
393*4520Snw141292} {11 2 33}
394*4520Snw141292
395*4520Snw141292do_test auth-1.51 {
396*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
397*4520Snw141292    if {$code=="SQLITE_SELECT"} {
398*4520Snw141292      return SQLITE_DENY
399*4520Snw141292    }
400*4520Snw141292    return SQLITE_OK
401*4520Snw141292  }
402*4520Snw141292  catchsql {SELECT * FROM t2}
403*4520Snw141292} {1 {not authorized}}
404*4520Snw141292do_test auth-1.52 {
405*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
406*4520Snw141292    if {$code=="SQLITE_SELECT"} {
407*4520Snw141292      return SQLITE_IGNORE
408*4520Snw141292    }
409*4520Snw141292    return SQLITE_OK
410*4520Snw141292  }
411*4520Snw141292  catchsql {SELECT * FROM t2}
412*4520Snw141292} {0 {}}
413*4520Snw141292do_test auth-1.53 {
414*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
415*4520Snw141292    if {$code=="SQLITE_SELECT"} {
416*4520Snw141292      return SQLITE_OK
417*4520Snw141292    }
418*4520Snw141292    return SQLITE_OK
419*4520Snw141292  }
420*4520Snw141292  catchsql {SELECT * FROM t2}
421*4520Snw141292} {0 {11 2 33}}
422*4520Snw141292
423*4520Snw141292set f [open data1.txt w]
424*4520Snw141292puts $f "7:8:9"
425*4520Snw141292close $f
426*4520Snw141292do_test auth-1.54 {
427*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
428*4520Snw141292    if {$code=="SQLITE_COPY"} {
429*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
430*4520Snw141292      return SQLITE_DENY
431*4520Snw141292    }
432*4520Snw141292    return SQLITE_OK
433*4520Snw141292  }
434*4520Snw141292  catchsql {COPY t2 FROM 'data1.txt' USING DELIMITERS ':'}
435*4520Snw141292} {1 {not authorized}}
436*4520Snw141292do_test auth-1.55 {
437*4520Snw141292  set ::authargs
438*4520Snw141292} {t2 data1.txt main {}}
439*4520Snw141292do_test auth-1.56 {
440*4520Snw141292  execsql {SELECT * FROM t2}
441*4520Snw141292} {11 2 33}
442*4520Snw141292do_test auth-1.57 {
443*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
444*4520Snw141292    if {$code=="SQLITE_COPY"} {
445*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
446*4520Snw141292      return SQLITE_IGNORE
447*4520Snw141292    }
448*4520Snw141292    return SQLITE_OK
449*4520Snw141292  }
450*4520Snw141292  catchsql {COPY t2 FROM 'data1.txt' USING DELIMITERS ':'}
451*4520Snw141292} {0 {}}
452*4520Snw141292do_test auth-1.58 {
453*4520Snw141292  set ::authargs
454*4520Snw141292} {t2 data1.txt main {}}
455*4520Snw141292do_test auth-1.59 {
456*4520Snw141292  execsql {SELECT * FROM t2}
457*4520Snw141292} {11 2 33}
458*4520Snw141292do_test auth-1.60 {
459*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
460*4520Snw141292    if {$code=="SQLITE_COPY"} {
461*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
462*4520Snw141292      return SQLITE_OK
463*4520Snw141292    }
464*4520Snw141292    return SQLITE_OK
465*4520Snw141292  }
466*4520Snw141292  catchsql {COPY t2 FROM 'data1.txt' USING DELIMITERS ':'}
467*4520Snw141292} {0 {}}
468*4520Snw141292do_test auth-1.61 {
469*4520Snw141292  set ::authargs
470*4520Snw141292} {t2 data1.txt main {}}
471*4520Snw141292do_test auth-1.62 {
472*4520Snw141292  execsql {SELECT * FROM t2}
473*4520Snw141292} {11 2 33 7 8 9}
474*4520Snw141292
475*4520Snw141292do_test auth-1.63 {
476*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
477*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
478*4520Snw141292       return SQLITE_DENY
479*4520Snw141292    }
480*4520Snw141292    return SQLITE_OK
481*4520Snw141292  }
482*4520Snw141292  catchsql {DROP TABLE t2}
483*4520Snw141292} {1 {not authorized}}
484*4520Snw141292do_test auth-1.64 {
485*4520Snw141292  execsql {SELECT name FROM sqlite_master}
486*4520Snw141292} {t2}
487*4520Snw141292do_test auth-1.65 {
488*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
489*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
490*4520Snw141292       return SQLITE_DENY
491*4520Snw141292    }
492*4520Snw141292    return SQLITE_OK
493*4520Snw141292  }
494*4520Snw141292  catchsql {DROP TABLE t2}
495*4520Snw141292} {1 {not authorized}}
496*4520Snw141292do_test auth-1.66 {
497*4520Snw141292  execsql {SELECT name FROM sqlite_master}
498*4520Snw141292} {t2}
499*4520Snw141292do_test auth-1.67 {
500*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
501*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
502*4520Snw141292       return SQLITE_DENY
503*4520Snw141292    }
504*4520Snw141292    return SQLITE_OK
505*4520Snw141292  }
506*4520Snw141292  catchsql {DROP TABLE t1}
507*4520Snw141292} {1 {not authorized}}
508*4520Snw141292do_test auth-1.68 {
509*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
510*4520Snw141292} {t1}
511*4520Snw141292do_test auth-1.69 {
512*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
513*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
514*4520Snw141292       return SQLITE_DENY
515*4520Snw141292    }
516*4520Snw141292    return SQLITE_OK
517*4520Snw141292  }
518*4520Snw141292  catchsql {DROP TABLE t1}
519*4520Snw141292} {1 {not authorized}}
520*4520Snw141292do_test auth-1.70 {
521*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
522*4520Snw141292} {t1}
523*4520Snw141292
524*4520Snw141292do_test auth-1.71 {
525*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
526*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
527*4520Snw141292       return SQLITE_IGNORE
528*4520Snw141292    }
529*4520Snw141292    return SQLITE_OK
530*4520Snw141292  }
531*4520Snw141292  catchsql {DROP TABLE t2}
532*4520Snw141292} {0 {}}
533*4520Snw141292do_test auth-1.72 {
534*4520Snw141292  execsql {SELECT name FROM sqlite_master}
535*4520Snw141292} {t2}
536*4520Snw141292do_test auth-1.73 {
537*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
538*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
539*4520Snw141292       return SQLITE_IGNORE
540*4520Snw141292    }
541*4520Snw141292    return SQLITE_OK
542*4520Snw141292  }
543*4520Snw141292  catchsql {DROP TABLE t2}
544*4520Snw141292} {0 {}}
545*4520Snw141292do_test auth-1.74 {
546*4520Snw141292  execsql {SELECT name FROM sqlite_master}
547*4520Snw141292} {t2}
548*4520Snw141292do_test auth-1.75 {
549*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
550*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
551*4520Snw141292       return SQLITE_IGNORE
552*4520Snw141292    }
553*4520Snw141292    return SQLITE_OK
554*4520Snw141292  }
555*4520Snw141292  catchsql {DROP TABLE t1}
556*4520Snw141292} {0 {}}
557*4520Snw141292do_test auth-1.76 {
558*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
559*4520Snw141292} {t1}
560*4520Snw141292do_test auth-1.77 {
561*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
562*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
563*4520Snw141292       return SQLITE_IGNORE
564*4520Snw141292    }
565*4520Snw141292    return SQLITE_OK
566*4520Snw141292  }
567*4520Snw141292  catchsql {DROP TABLE t1}
568*4520Snw141292} {0 {}}
569*4520Snw141292do_test auth-1.78 {
570*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
571*4520Snw141292} {t1}
572*4520Snw141292
573*4520Snw141292do_test auth-1.79 {
574*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
575*4520Snw141292    if {$code=="SQLITE_CREATE_VIEW"} {
576*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
577*4520Snw141292      return SQLITE_DENY
578*4520Snw141292    }
579*4520Snw141292    return SQLITE_OK
580*4520Snw141292  }
581*4520Snw141292  catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
582*4520Snw141292} {1 {not authorized}}
583*4520Snw141292do_test auth-1.80 {
584*4520Snw141292  set ::authargs
585*4520Snw141292} {v1 {} main {}}
586*4520Snw141292do_test auth-1.81 {
587*4520Snw141292  execsql {SELECT name FROM sqlite_master}
588*4520Snw141292} {t2}
589*4520Snw141292do_test auth-1.82 {
590*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
591*4520Snw141292    if {$code=="SQLITE_CREATE_VIEW"} {
592*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
593*4520Snw141292      return SQLITE_IGNORE
594*4520Snw141292    }
595*4520Snw141292    return SQLITE_OK
596*4520Snw141292  }
597*4520Snw141292  catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
598*4520Snw141292} {0 {}}
599*4520Snw141292do_test auth-1.83 {
600*4520Snw141292  set ::authargs
601*4520Snw141292} {v1 {} main {}}
602*4520Snw141292do_test auth-1.84 {
603*4520Snw141292  execsql {SELECT name FROM sqlite_master}
604*4520Snw141292} {t2}
605*4520Snw141292
606*4520Snw141292do_test auth-1.85 {
607*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
608*4520Snw141292    if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
609*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
610*4520Snw141292      return SQLITE_DENY
611*4520Snw141292    }
612*4520Snw141292    return SQLITE_OK
613*4520Snw141292  }
614*4520Snw141292  catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
615*4520Snw141292} {1 {not authorized}}
616*4520Snw141292do_test auth-1.86 {
617*4520Snw141292  set ::authargs
618*4520Snw141292} {v1 {} temp {}}
619*4520Snw141292do_test auth-1.87 {
620*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
621*4520Snw141292} {t1}
622*4520Snw141292do_test auth-1.88 {
623*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
624*4520Snw141292    if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
625*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
626*4520Snw141292      return SQLITE_IGNORE
627*4520Snw141292    }
628*4520Snw141292    return SQLITE_OK
629*4520Snw141292  }
630*4520Snw141292  catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
631*4520Snw141292} {0 {}}
632*4520Snw141292do_test auth-1.89 {
633*4520Snw141292  set ::authargs
634*4520Snw141292} {v1 {} temp {}}
635*4520Snw141292do_test auth-1.90 {
636*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
637*4520Snw141292} {t1}
638*4520Snw141292
639*4520Snw141292do_test auth-1.91 {
640*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
641*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
642*4520Snw141292      return SQLITE_DENY
643*4520Snw141292    }
644*4520Snw141292    return SQLITE_OK
645*4520Snw141292  }
646*4520Snw141292  catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
647*4520Snw141292} {1 {not authorized}}
648*4520Snw141292do_test auth-1.92 {
649*4520Snw141292  execsql {SELECT name FROM sqlite_master}
650*4520Snw141292} {t2}
651*4520Snw141292do_test auth-1.93 {
652*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
653*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
654*4520Snw141292      return SQLITE_IGNORE
655*4520Snw141292    }
656*4520Snw141292    return SQLITE_OK
657*4520Snw141292  }
658*4520Snw141292  catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
659*4520Snw141292} {0 {}}
660*4520Snw141292do_test auth-1.94 {
661*4520Snw141292  execsql {SELECT name FROM sqlite_master}
662*4520Snw141292} {t2}
663*4520Snw141292
664*4520Snw141292do_test auth-1.95 {
665*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
666*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
667*4520Snw141292      return SQLITE_DENY
668*4520Snw141292    }
669*4520Snw141292    return SQLITE_OK
670*4520Snw141292  }
671*4520Snw141292  catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
672*4520Snw141292} {1 {not authorized}}
673*4520Snw141292do_test auth-1.96 {
674*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
675*4520Snw141292} {t1}
676*4520Snw141292do_test auth-1.97 {
677*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
678*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
679*4520Snw141292      return SQLITE_IGNORE
680*4520Snw141292    }
681*4520Snw141292    return SQLITE_OK
682*4520Snw141292  }
683*4520Snw141292  catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
684*4520Snw141292} {0 {}}
685*4520Snw141292do_test auth-1.98 {
686*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
687*4520Snw141292} {t1}
688*4520Snw141292
689*4520Snw141292do_test auth-1.99 {
690*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
691*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
692*4520Snw141292      return SQLITE_DENY
693*4520Snw141292    }
694*4520Snw141292    return SQLITE_OK
695*4520Snw141292  }
696*4520Snw141292  catchsql {
697*4520Snw141292    CREATE VIEW v2 AS SELECT a+1,b+1 FROM t2;
698*4520Snw141292    DROP VIEW v2
699*4520Snw141292  }
700*4520Snw141292} {1 {not authorized}}
701*4520Snw141292do_test auth-1.100 {
702*4520Snw141292  execsql {SELECT name FROM sqlite_master}
703*4520Snw141292} {t2 v2}
704*4520Snw141292do_test auth-1.101 {
705*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
706*4520Snw141292    if {$code=="SQLITE_DROP_VIEW"} {
707*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
708*4520Snw141292      return SQLITE_DENY
709*4520Snw141292    }
710*4520Snw141292    return SQLITE_OK
711*4520Snw141292  }
712*4520Snw141292  catchsql {DROP VIEW v2}
713*4520Snw141292} {1 {not authorized}}
714*4520Snw141292do_test auth-1.102 {
715*4520Snw141292  set ::authargs
716*4520Snw141292} {v2 {} main {}}
717*4520Snw141292do_test auth-1.103 {
718*4520Snw141292  execsql {SELECT name FROM sqlite_master}
719*4520Snw141292} {t2 v2}
720*4520Snw141292do_test auth-1.104 {
721*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
722*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
723*4520Snw141292      return SQLITE_IGNORE
724*4520Snw141292    }
725*4520Snw141292    return SQLITE_OK
726*4520Snw141292  }
727*4520Snw141292  catchsql {DROP VIEW v2}
728*4520Snw141292} {0 {}}
729*4520Snw141292do_test auth-1.105 {
730*4520Snw141292  execsql {SELECT name FROM sqlite_master}
731*4520Snw141292} {t2 v2}
732*4520Snw141292do_test auth-1.106 {
733*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
734*4520Snw141292    if {$code=="SQLITE_DROP_VIEW"} {
735*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
736*4520Snw141292      return SQLITE_IGNORE
737*4520Snw141292    }
738*4520Snw141292    return SQLITE_OK
739*4520Snw141292  }
740*4520Snw141292  catchsql {DROP VIEW v2}
741*4520Snw141292} {0 {}}
742*4520Snw141292do_test auth-1.107 {
743*4520Snw141292  set ::authargs
744*4520Snw141292} {v2 {} main {}}
745*4520Snw141292do_test auth-1.108 {
746*4520Snw141292  execsql {SELECT name FROM sqlite_master}
747*4520Snw141292} {t2 v2}
748*4520Snw141292do_test auth-1.109 {
749*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
750*4520Snw141292    if {$code=="SQLITE_DROP_VIEW"} {
751*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
752*4520Snw141292      return SQLITE_OK
753*4520Snw141292    }
754*4520Snw141292    return SQLITE_OK
755*4520Snw141292  }
756*4520Snw141292  catchsql {DROP VIEW v2}
757*4520Snw141292} {0 {}}
758*4520Snw141292do_test auth-1.110 {
759*4520Snw141292  set ::authargs
760*4520Snw141292} {v2 {} main {}}
761*4520Snw141292do_test auth-1.111 {
762*4520Snw141292  execsql {SELECT name FROM sqlite_master}
763*4520Snw141292} {t2}
764*4520Snw141292
765*4520Snw141292
766*4520Snw141292do_test auth-1.112 {
767*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
768*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
769*4520Snw141292      return SQLITE_DENY
770*4520Snw141292    }
771*4520Snw141292    return SQLITE_OK
772*4520Snw141292  }
773*4520Snw141292  catchsql {
774*4520Snw141292    CREATE TEMP VIEW v1 AS SELECT a+1,b+1 FROM t1;
775*4520Snw141292    DROP VIEW v1
776*4520Snw141292  }
777*4520Snw141292} {1 {not authorized}}
778*4520Snw141292do_test auth-1.113 {
779*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
780*4520Snw141292} {t1 v1}
781*4520Snw141292do_test auth-1.114 {
782*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
783*4520Snw141292    if {$code=="SQLITE_DROP_TEMP_VIEW"} {
784*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
785*4520Snw141292      return SQLITE_DENY
786*4520Snw141292    }
787*4520Snw141292    return SQLITE_OK
788*4520Snw141292  }
789*4520Snw141292  catchsql {DROP VIEW v1}
790*4520Snw141292} {1 {not authorized}}
791*4520Snw141292do_test auth-1.115 {
792*4520Snw141292  set ::authargs
793*4520Snw141292} {v1 {} temp {}}
794*4520Snw141292do_test auth-1.116 {
795*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
796*4520Snw141292} {t1 v1}
797*4520Snw141292do_test auth-1.117 {
798*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
799*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
800*4520Snw141292      return SQLITE_IGNORE
801*4520Snw141292    }
802*4520Snw141292    return SQLITE_OK
803*4520Snw141292  }
804*4520Snw141292  catchsql {DROP VIEW v1}
805*4520Snw141292} {0 {}}
806*4520Snw141292do_test auth-1.118 {
807*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
808*4520Snw141292} {t1 v1}
809*4520Snw141292do_test auth-1.119 {
810*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
811*4520Snw141292    if {$code=="SQLITE_DROP_TEMP_VIEW"} {
812*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
813*4520Snw141292      return SQLITE_IGNORE
814*4520Snw141292    }
815*4520Snw141292    return SQLITE_OK
816*4520Snw141292  }
817*4520Snw141292  catchsql {DROP VIEW v1}
818*4520Snw141292} {0 {}}
819*4520Snw141292do_test auth-1.120 {
820*4520Snw141292  set ::authargs
821*4520Snw141292} {v1 {} temp {}}
822*4520Snw141292do_test auth-1.121 {
823*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
824*4520Snw141292} {t1 v1}
825*4520Snw141292do_test auth-1.122 {
826*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
827*4520Snw141292    if {$code=="SQLITE_DROP_TEMP_VIEW"} {
828*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
829*4520Snw141292      return SQLITE_OK
830*4520Snw141292    }
831*4520Snw141292    return SQLITE_OK
832*4520Snw141292  }
833*4520Snw141292  catchsql {DROP VIEW v1}
834*4520Snw141292} {0 {}}
835*4520Snw141292do_test auth-1.123 {
836*4520Snw141292  set ::authargs
837*4520Snw141292} {v1 {} temp {}}
838*4520Snw141292do_test auth-1.124 {
839*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
840*4520Snw141292} {t1}
841*4520Snw141292
842*4520Snw141292do_test auth-1.125 {
843*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
844*4520Snw141292    if {$code=="SQLITE_CREATE_TRIGGER"} {
845*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
846*4520Snw141292      return SQLITE_DENY
847*4520Snw141292    }
848*4520Snw141292    return SQLITE_OK
849*4520Snw141292  }
850*4520Snw141292  catchsql {
851*4520Snw141292    CREATE TRIGGER r2 DELETE on t2 BEGIN
852*4520Snw141292        SELECT NULL;
853*4520Snw141292    END;
854*4520Snw141292  }
855*4520Snw141292} {1 {not authorized}}
856*4520Snw141292do_test auth-1.126 {
857*4520Snw141292  set ::authargs
858*4520Snw141292} {r2 t2 main {}}
859*4520Snw141292do_test auth-1.127 {
860*4520Snw141292  execsql {SELECT name FROM sqlite_master}
861*4520Snw141292} {t2}
862*4520Snw141292do_test auth-1.128 {
863*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
864*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
865*4520Snw141292      return SQLITE_DENY
866*4520Snw141292    }
867*4520Snw141292    return SQLITE_OK
868*4520Snw141292  }
869*4520Snw141292  catchsql {
870*4520Snw141292    CREATE TRIGGER r2 DELETE on t2 BEGIN
871*4520Snw141292        SELECT NULL;
872*4520Snw141292    END;
873*4520Snw141292  }
874*4520Snw141292} {1 {not authorized}}
875*4520Snw141292do_test auth-1.129 {
876*4520Snw141292  execsql {SELECT name FROM sqlite_master}
877*4520Snw141292} {t2}
878*4520Snw141292do_test auth-1.130 {
879*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
880*4520Snw141292    if {$code=="SQLITE_CREATE_TRIGGER"} {
881*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
882*4520Snw141292      return SQLITE_IGNORE
883*4520Snw141292    }
884*4520Snw141292    return SQLITE_OK
885*4520Snw141292  }
886*4520Snw141292  catchsql {
887*4520Snw141292    CREATE TRIGGER r2 DELETE on t2 BEGIN
888*4520Snw141292        SELECT NULL;
889*4520Snw141292    END;
890*4520Snw141292  }
891*4520Snw141292} {0 {}}
892*4520Snw141292do_test auth-1.131 {
893*4520Snw141292  set ::authargs
894*4520Snw141292} {r2 t2 main {}}
895*4520Snw141292do_test auth-1.132 {
896*4520Snw141292  execsql {SELECT name FROM sqlite_master}
897*4520Snw141292} {t2}
898*4520Snw141292do_test auth-1.133 {
899*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
900*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
901*4520Snw141292      return SQLITE_IGNORE
902*4520Snw141292    }
903*4520Snw141292    return SQLITE_OK
904*4520Snw141292  }
905*4520Snw141292  catchsql {
906*4520Snw141292    CREATE TRIGGER r2 DELETE on t2 BEGIN
907*4520Snw141292        SELECT NULL;
908*4520Snw141292    END;
909*4520Snw141292  }
910*4520Snw141292} {0 {}}
911*4520Snw141292do_test auth-1.134 {
912*4520Snw141292  execsql {SELECT name FROM sqlite_master}
913*4520Snw141292} {t2}
914*4520Snw141292do_test auth-1.135 {
915*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
916*4520Snw141292    if {$code=="SQLITE_CREATE_TRIGGER"} {
917*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
918*4520Snw141292      return SQLITE_OK
919*4520Snw141292    }
920*4520Snw141292    return SQLITE_OK
921*4520Snw141292  }
922*4520Snw141292  catchsql {
923*4520Snw141292    CREATE TABLE tx(id);
924*4520Snw141292    CREATE TRIGGER r2 AFTER INSERT ON t2 BEGIN
925*4520Snw141292       INSERT INTO tx VALUES(NEW.rowid);
926*4520Snw141292    END;
927*4520Snw141292  }
928*4520Snw141292} {0 {}}
929*4520Snw141292do_test auth-1.136.1 {
930*4520Snw141292  set ::authargs
931*4520Snw141292} {r2 t2 main {}}
932*4520Snw141292do_test auth-1.136.2 {
933*4520Snw141292  execsql {
934*4520Snw141292    SELECT name FROM sqlite_master WHERE type='trigger'
935*4520Snw141292  }
936*4520Snw141292} {r2}
937*4520Snw141292do_test auth-1.136.3 {
938*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
939*4520Snw141292    lappend ::authargs $code $arg1 $arg2 $arg3 $arg4
940*4520Snw141292    return SQLITE_OK
941*4520Snw141292  }
942*4520Snw141292  set ::authargs {}
943*4520Snw141292  execsql {
944*4520Snw141292    INSERT INTO t2 VALUES(1,2,3);
945*4520Snw141292  }
946*4520Snw141292  set ::authargs
947*4520Snw141292} {SQLITE_INSERT t2 {} main {} SQLITE_INSERT tx {} main r2 SQLITE_READ t2 ROWID main r2}
948*4520Snw141292do_test auth-1.136.4 {
949*4520Snw141292  execsql {
950*4520Snw141292    SELECT * FROM tx;
951*4520Snw141292  }
952*4520Snw141292} {3}
953*4520Snw141292do_test auth-1.137 {
954*4520Snw141292  execsql {SELECT name FROM sqlite_master}
955*4520Snw141292} {t2 tx r2}
956*4520Snw141292do_test auth-1.138 {
957*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
958*4520Snw141292    if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
959*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
960*4520Snw141292      return SQLITE_DENY
961*4520Snw141292    }
962*4520Snw141292    return SQLITE_OK
963*4520Snw141292  }
964*4520Snw141292  catchsql {
965*4520Snw141292    CREATE TRIGGER r1 DELETE on t1 BEGIN
966*4520Snw141292        SELECT NULL;
967*4520Snw141292    END;
968*4520Snw141292  }
969*4520Snw141292} {1 {not authorized}}
970*4520Snw141292do_test auth-1.139 {
971*4520Snw141292  set ::authargs
972*4520Snw141292} {r1 t1 temp {}}
973*4520Snw141292do_test auth-1.140 {
974*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
975*4520Snw141292} {t1}
976*4520Snw141292do_test auth-1.141 {
977*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
978*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
979*4520Snw141292      return SQLITE_DENY
980*4520Snw141292    }
981*4520Snw141292    return SQLITE_OK
982*4520Snw141292  }
983*4520Snw141292  catchsql {
984*4520Snw141292    CREATE TRIGGER r1 DELETE on t1 BEGIN
985*4520Snw141292        SELECT NULL;
986*4520Snw141292    END;
987*4520Snw141292  }
988*4520Snw141292} {1 {not authorized}}
989*4520Snw141292do_test auth-1.142 {
990*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
991*4520Snw141292} {t1}
992*4520Snw141292do_test auth-1.143 {
993*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
994*4520Snw141292    if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
995*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
996*4520Snw141292      return SQLITE_IGNORE
997*4520Snw141292    }
998*4520Snw141292    return SQLITE_OK
999*4520Snw141292  }
1000*4520Snw141292  catchsql {
1001*4520Snw141292    CREATE TRIGGER r1 DELETE on t1 BEGIN
1002*4520Snw141292        SELECT NULL;
1003*4520Snw141292    END;
1004*4520Snw141292  }
1005*4520Snw141292} {0 {}}
1006*4520Snw141292do_test auth-1.144 {
1007*4520Snw141292  set ::authargs
1008*4520Snw141292} {r1 t1 temp {}}
1009*4520Snw141292do_test auth-1.145 {
1010*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
1011*4520Snw141292} {t1}
1012*4520Snw141292do_test auth-1.146 {
1013*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1014*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
1015*4520Snw141292      return SQLITE_IGNORE
1016*4520Snw141292    }
1017*4520Snw141292    return SQLITE_OK
1018*4520Snw141292  }
1019*4520Snw141292  catchsql {
1020*4520Snw141292    CREATE TRIGGER r1 DELETE on t1 BEGIN
1021*4520Snw141292        SELECT NULL;
1022*4520Snw141292    END;
1023*4520Snw141292  }
1024*4520Snw141292} {0 {}}
1025*4520Snw141292do_test auth-1.147 {
1026*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
1027*4520Snw141292} {t1}
1028*4520Snw141292do_test auth-1.148 {
1029*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1030*4520Snw141292    if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
1031*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1032*4520Snw141292      return SQLITE_OK
1033*4520Snw141292    }
1034*4520Snw141292    return SQLITE_OK
1035*4520Snw141292  }
1036*4520Snw141292  catchsql {
1037*4520Snw141292    CREATE TRIGGER r1 DELETE on t1 BEGIN
1038*4520Snw141292        SELECT NULL;
1039*4520Snw141292    END;
1040*4520Snw141292  }
1041*4520Snw141292} {0 {}}
1042*4520Snw141292do_test auth-1.149 {
1043*4520Snw141292  set ::authargs
1044*4520Snw141292} {r1 t1 temp {}}
1045*4520Snw141292do_test auth-1.150 {
1046*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
1047*4520Snw141292} {t1 r1}
1048*4520Snw141292
1049*4520Snw141292do_test auth-1.151 {
1050*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1051*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1052*4520Snw141292      return SQLITE_DENY
1053*4520Snw141292    }
1054*4520Snw141292    return SQLITE_OK
1055*4520Snw141292  }
1056*4520Snw141292  catchsql {DROP TRIGGER r2}
1057*4520Snw141292} {1 {not authorized}}
1058*4520Snw141292do_test auth-1.152 {
1059*4520Snw141292  execsql {SELECT name FROM sqlite_master}
1060*4520Snw141292} {t2 tx r2}
1061*4520Snw141292do_test auth-1.153 {
1062*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1063*4520Snw141292    if {$code=="SQLITE_DROP_TRIGGER"} {
1064*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1065*4520Snw141292      return SQLITE_DENY
1066*4520Snw141292    }
1067*4520Snw141292    return SQLITE_OK
1068*4520Snw141292  }
1069*4520Snw141292  catchsql {DROP TRIGGER r2}
1070*4520Snw141292} {1 {not authorized}}
1071*4520Snw141292do_test auth-1.154 {
1072*4520Snw141292  set ::authargs
1073*4520Snw141292} {r2 t2 main {}}
1074*4520Snw141292do_test auth-1.155 {
1075*4520Snw141292  execsql {SELECT name FROM sqlite_master}
1076*4520Snw141292} {t2 tx r2}
1077*4520Snw141292do_test auth-1.156 {
1078*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1079*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1080*4520Snw141292      return SQLITE_IGNORE
1081*4520Snw141292    }
1082*4520Snw141292    return SQLITE_OK
1083*4520Snw141292  }
1084*4520Snw141292  catchsql {DROP TRIGGER r2}
1085*4520Snw141292} {0 {}}
1086*4520Snw141292do_test auth-1.157 {
1087*4520Snw141292  execsql {SELECT name FROM sqlite_master}
1088*4520Snw141292} {t2 tx r2}
1089*4520Snw141292do_test auth-1.158 {
1090*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1091*4520Snw141292    if {$code=="SQLITE_DROP_TRIGGER"} {
1092*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1093*4520Snw141292      return SQLITE_IGNORE
1094*4520Snw141292    }
1095*4520Snw141292    return SQLITE_OK
1096*4520Snw141292  }
1097*4520Snw141292  catchsql {DROP TRIGGER r2}
1098*4520Snw141292} {0 {}}
1099*4520Snw141292do_test auth-1.159 {
1100*4520Snw141292  set ::authargs
1101*4520Snw141292} {r2 t2 main {}}
1102*4520Snw141292do_test auth-1.160 {
1103*4520Snw141292  execsql {SELECT name FROM sqlite_master}
1104*4520Snw141292} {t2 tx r2}
1105*4520Snw141292do_test auth-1.161 {
1106*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1107*4520Snw141292    if {$code=="SQLITE_DROP_TRIGGER"} {
1108*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1109*4520Snw141292      return SQLITE_OK
1110*4520Snw141292    }
1111*4520Snw141292    return SQLITE_OK
1112*4520Snw141292  }
1113*4520Snw141292  catchsql {DROP TRIGGER r2}
1114*4520Snw141292} {0 {}}
1115*4520Snw141292do_test auth-1.162 {
1116*4520Snw141292  set ::authargs
1117*4520Snw141292} {r2 t2 main {}}
1118*4520Snw141292do_test auth-1.163 {
1119*4520Snw141292  execsql {
1120*4520Snw141292    DROP TABLE tx;
1121*4520Snw141292    DELETE FROM t2 WHERE a=1 AND b=2 AND c=3;
1122*4520Snw141292    SELECT name FROM sqlite_master;
1123*4520Snw141292  }
1124*4520Snw141292} {t2}
1125*4520Snw141292
1126*4520Snw141292do_test auth-1.164 {
1127*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1128*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1129*4520Snw141292      return SQLITE_DENY
1130*4520Snw141292    }
1131*4520Snw141292    return SQLITE_OK
1132*4520Snw141292  }
1133*4520Snw141292  catchsql {DROP TRIGGER r1}
1134*4520Snw141292} {1 {not authorized}}
1135*4520Snw141292do_test auth-1.165 {
1136*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
1137*4520Snw141292} {t1 r1}
1138*4520Snw141292do_test auth-1.166 {
1139*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1140*4520Snw141292    if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
1141*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1142*4520Snw141292      return SQLITE_DENY
1143*4520Snw141292    }
1144*4520Snw141292    return SQLITE_OK
1145*4520Snw141292  }
1146*4520Snw141292  catchsql {DROP TRIGGER r1}
1147*4520Snw141292} {1 {not authorized}}
1148*4520Snw141292do_test auth-1.167 {
1149*4520Snw141292  set ::authargs
1150*4520Snw141292} {r1 t1 temp {}}
1151*4520Snw141292do_test auth-1.168 {
1152*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
1153*4520Snw141292} {t1 r1}
1154*4520Snw141292do_test auth-1.169 {
1155*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1156*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1157*4520Snw141292      return SQLITE_IGNORE
1158*4520Snw141292    }
1159*4520Snw141292    return SQLITE_OK
1160*4520Snw141292  }
1161*4520Snw141292  catchsql {DROP TRIGGER r1}
1162*4520Snw141292} {0 {}}
1163*4520Snw141292do_test auth-1.170 {
1164*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
1165*4520Snw141292} {t1 r1}
1166*4520Snw141292do_test auth-1.171 {
1167*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1168*4520Snw141292    if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
1169*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1170*4520Snw141292      return SQLITE_IGNORE
1171*4520Snw141292    }
1172*4520Snw141292    return SQLITE_OK
1173*4520Snw141292  }
1174*4520Snw141292  catchsql {DROP TRIGGER r1}
1175*4520Snw141292} {0 {}}
1176*4520Snw141292do_test auth-1.172 {
1177*4520Snw141292  set ::authargs
1178*4520Snw141292} {r1 t1 temp {}}
1179*4520Snw141292do_test auth-1.173 {
1180*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
1181*4520Snw141292} {t1 r1}
1182*4520Snw141292do_test auth-1.174 {
1183*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1184*4520Snw141292    if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
1185*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1186*4520Snw141292      return SQLITE_OK
1187*4520Snw141292    }
1188*4520Snw141292    return SQLITE_OK
1189*4520Snw141292  }
1190*4520Snw141292  catchsql {DROP TRIGGER r1}
1191*4520Snw141292} {0 {}}
1192*4520Snw141292do_test auth-1.175 {
1193*4520Snw141292  set ::authargs
1194*4520Snw141292} {r1 t1 temp {}}
1195*4520Snw141292do_test auth-1.176 {
1196*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
1197*4520Snw141292} {t1}
1198*4520Snw141292
1199*4520Snw141292do_test auth-1.177 {
1200*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1201*4520Snw141292    if {$code=="SQLITE_CREATE_INDEX"} {
1202*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1203*4520Snw141292      return SQLITE_DENY
1204*4520Snw141292    }
1205*4520Snw141292    return SQLITE_OK
1206*4520Snw141292  }
1207*4520Snw141292  catchsql {CREATE INDEX i2 ON t2(a)}
1208*4520Snw141292} {1 {not authorized}}
1209*4520Snw141292do_test auth-1.178 {
1210*4520Snw141292  set ::authargs
1211*4520Snw141292} {i2 t2 main {}}
1212*4520Snw141292do_test auth-1.179 {
1213*4520Snw141292  execsql {SELECT name FROM sqlite_master}
1214*4520Snw141292} {t2}
1215*4520Snw141292do_test auth-1.180 {
1216*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1217*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
1218*4520Snw141292      return SQLITE_DENY
1219*4520Snw141292    }
1220*4520Snw141292    return SQLITE_OK
1221*4520Snw141292  }
1222*4520Snw141292  catchsql {CREATE INDEX i2 ON t2(a)}
1223*4520Snw141292} {1 {not authorized}}
1224*4520Snw141292do_test auth-1.181 {
1225*4520Snw141292  execsql {SELECT name FROM sqlite_master}
1226*4520Snw141292} {t2}
1227*4520Snw141292do_test auth-1.182 {
1228*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1229*4520Snw141292    if {$code=="SQLITE_CREATE_INDEX"} {
1230*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1231*4520Snw141292      return SQLITE_IGNORE
1232*4520Snw141292    }
1233*4520Snw141292    return SQLITE_OK
1234*4520Snw141292  }
1235*4520Snw141292  catchsql {CREATE INDEX i2 ON t2(b)}
1236*4520Snw141292} {0 {}}
1237*4520Snw141292do_test auth-1.183 {
1238*4520Snw141292  set ::authargs
1239*4520Snw141292} {i2 t2 main {}}
1240*4520Snw141292do_test auth-1.184 {
1241*4520Snw141292  execsql {SELECT name FROM sqlite_master}
1242*4520Snw141292} {t2}
1243*4520Snw141292do_test auth-1.185 {
1244*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1245*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
1246*4520Snw141292      return SQLITE_IGNORE
1247*4520Snw141292    }
1248*4520Snw141292    return SQLITE_OK
1249*4520Snw141292  }
1250*4520Snw141292  catchsql {CREATE INDEX i2 ON t2(b)}
1251*4520Snw141292} {0 {}}
1252*4520Snw141292do_test auth-1.186 {
1253*4520Snw141292  execsql {SELECT name FROM sqlite_master}
1254*4520Snw141292} {t2}
1255*4520Snw141292do_test auth-1.187 {
1256*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1257*4520Snw141292    if {$code=="SQLITE_CREATE_INDEX"} {
1258*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1259*4520Snw141292      return SQLITE_OK
1260*4520Snw141292    }
1261*4520Snw141292    return SQLITE_OK
1262*4520Snw141292  }
1263*4520Snw141292  catchsql {CREATE INDEX i2 ON t2(a)}
1264*4520Snw141292} {0 {}}
1265*4520Snw141292do_test auth-1.188 {
1266*4520Snw141292  set ::authargs
1267*4520Snw141292} {i2 t2 main {}}
1268*4520Snw141292do_test auth-1.189 {
1269*4520Snw141292  execsql {SELECT name FROM sqlite_master}
1270*4520Snw141292} {t2 i2}
1271*4520Snw141292
1272*4520Snw141292do_test auth-1.190 {
1273*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1274*4520Snw141292    if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
1275*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1276*4520Snw141292      return SQLITE_DENY
1277*4520Snw141292    }
1278*4520Snw141292    return SQLITE_OK
1279*4520Snw141292  }
1280*4520Snw141292  catchsql {CREATE INDEX i1 ON t1(a)}
1281*4520Snw141292} {1 {not authorized}}
1282*4520Snw141292do_test auth-1.191 {
1283*4520Snw141292  set ::authargs
1284*4520Snw141292} {i1 t1 temp {}}
1285*4520Snw141292do_test auth-1.192 {
1286*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
1287*4520Snw141292} {t1}
1288*4520Snw141292do_test auth-1.193 {
1289*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1290*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
1291*4520Snw141292      return SQLITE_DENY
1292*4520Snw141292    }
1293*4520Snw141292    return SQLITE_OK
1294*4520Snw141292  }
1295*4520Snw141292  catchsql {CREATE INDEX i1 ON t1(b)}
1296*4520Snw141292} {1 {not authorized}}
1297*4520Snw141292do_test auth-1.194 {
1298*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
1299*4520Snw141292} {t1}
1300*4520Snw141292do_test auth-1.195 {
1301*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1302*4520Snw141292    if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
1303*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1304*4520Snw141292      return SQLITE_IGNORE
1305*4520Snw141292    }
1306*4520Snw141292    return SQLITE_OK
1307*4520Snw141292  }
1308*4520Snw141292  catchsql {CREATE INDEX i1 ON t1(b)}
1309*4520Snw141292} {0 {}}
1310*4520Snw141292do_test auth-1.196 {
1311*4520Snw141292  set ::authargs
1312*4520Snw141292} {i1 t1 temp {}}
1313*4520Snw141292do_test auth-1.197 {
1314*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
1315*4520Snw141292} {t1}
1316*4520Snw141292do_test auth-1.198 {
1317*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1318*4520Snw141292    if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
1319*4520Snw141292      return SQLITE_IGNORE
1320*4520Snw141292    }
1321*4520Snw141292    return SQLITE_OK
1322*4520Snw141292  }
1323*4520Snw141292  catchsql {CREATE INDEX i1 ON t1(c)}
1324*4520Snw141292} {0 {}}
1325*4520Snw141292do_test auth-1.199 {
1326*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
1327*4520Snw141292} {t1}
1328*4520Snw141292do_test auth-1.200 {
1329*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1330*4520Snw141292    if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
1331*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1332*4520Snw141292      return SQLITE_OK
1333*4520Snw141292    }
1334*4520Snw141292    return SQLITE_OK
1335*4520Snw141292  }
1336*4520Snw141292  catchsql {CREATE INDEX i1 ON t1(a)}
1337*4520Snw141292} {0 {}}
1338*4520Snw141292do_test auth-1.201 {
1339*4520Snw141292  set ::authargs
1340*4520Snw141292} {i1 t1 temp {}}
1341*4520Snw141292do_test auth-1.202 {
1342*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
1343*4520Snw141292} {t1 i1}
1344*4520Snw141292
1345*4520Snw141292do_test auth-1.203 {
1346*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1347*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1348*4520Snw141292      return SQLITE_DENY
1349*4520Snw141292    }
1350*4520Snw141292    return SQLITE_OK
1351*4520Snw141292  }
1352*4520Snw141292  catchsql {DROP INDEX i2}
1353*4520Snw141292} {1 {not authorized}}
1354*4520Snw141292do_test auth-1.204 {
1355*4520Snw141292  execsql {SELECT name FROM sqlite_master}
1356*4520Snw141292} {t2 i2}
1357*4520Snw141292do_test auth-1.205 {
1358*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1359*4520Snw141292    if {$code=="SQLITE_DROP_INDEX"} {
1360*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1361*4520Snw141292      return SQLITE_DENY
1362*4520Snw141292    }
1363*4520Snw141292    return SQLITE_OK
1364*4520Snw141292  }
1365*4520Snw141292  catchsql {DROP INDEX i2}
1366*4520Snw141292} {1 {not authorized}}
1367*4520Snw141292do_test auth-1.206 {
1368*4520Snw141292  set ::authargs
1369*4520Snw141292} {i2 t2 main {}}
1370*4520Snw141292do_test auth-1.207 {
1371*4520Snw141292  execsql {SELECT name FROM sqlite_master}
1372*4520Snw141292} {t2 i2}
1373*4520Snw141292do_test auth-1.208 {
1374*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1375*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1376*4520Snw141292      return SQLITE_IGNORE
1377*4520Snw141292    }
1378*4520Snw141292    return SQLITE_OK
1379*4520Snw141292  }
1380*4520Snw141292  catchsql {DROP INDEX i2}
1381*4520Snw141292} {0 {}}
1382*4520Snw141292do_test auth-1.209 {
1383*4520Snw141292  execsql {SELECT name FROM sqlite_master}
1384*4520Snw141292} {t2 i2}
1385*4520Snw141292do_test auth-1.210 {
1386*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1387*4520Snw141292    if {$code=="SQLITE_DROP_INDEX"} {
1388*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1389*4520Snw141292      return SQLITE_IGNORE
1390*4520Snw141292    }
1391*4520Snw141292    return SQLITE_OK
1392*4520Snw141292  }
1393*4520Snw141292  catchsql {DROP INDEX i2}
1394*4520Snw141292} {0 {}}
1395*4520Snw141292do_test auth-1.211 {
1396*4520Snw141292  set ::authargs
1397*4520Snw141292} {i2 t2 main {}}
1398*4520Snw141292do_test auth-1.212 {
1399*4520Snw141292  execsql {SELECT name FROM sqlite_master}
1400*4520Snw141292} {t2 i2}
1401*4520Snw141292do_test auth-1.213 {
1402*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1403*4520Snw141292    if {$code=="SQLITE_DROP_INDEX"} {
1404*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1405*4520Snw141292      return SQLITE_OK
1406*4520Snw141292    }
1407*4520Snw141292    return SQLITE_OK
1408*4520Snw141292  }
1409*4520Snw141292  catchsql {DROP INDEX i2}
1410*4520Snw141292} {0 {}}
1411*4520Snw141292do_test auth-1.214 {
1412*4520Snw141292  set ::authargs
1413*4520Snw141292} {i2 t2 main {}}
1414*4520Snw141292do_test auth-1.215 {
1415*4520Snw141292  execsql {SELECT name FROM sqlite_master}
1416*4520Snw141292} {t2}
1417*4520Snw141292
1418*4520Snw141292do_test auth-1.216 {
1419*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1420*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1421*4520Snw141292      return SQLITE_DENY
1422*4520Snw141292    }
1423*4520Snw141292    return SQLITE_OK
1424*4520Snw141292  }
1425*4520Snw141292  catchsql {DROP INDEX i1}
1426*4520Snw141292} {1 {not authorized}}
1427*4520Snw141292do_test auth-1.217 {
1428*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
1429*4520Snw141292} {t1 i1}
1430*4520Snw141292do_test auth-1.218 {
1431*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1432*4520Snw141292    if {$code=="SQLITE_DROP_TEMP_INDEX"} {
1433*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1434*4520Snw141292      return SQLITE_DENY
1435*4520Snw141292    }
1436*4520Snw141292    return SQLITE_OK
1437*4520Snw141292  }
1438*4520Snw141292  catchsql {DROP INDEX i1}
1439*4520Snw141292} {1 {not authorized}}
1440*4520Snw141292do_test auth-1.219 {
1441*4520Snw141292  set ::authargs
1442*4520Snw141292} {i1 t1 temp {}}
1443*4520Snw141292do_test auth-1.220 {
1444*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
1445*4520Snw141292} {t1 i1}
1446*4520Snw141292do_test auth-1.221 {
1447*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1448*4520Snw141292    if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1449*4520Snw141292      return SQLITE_IGNORE
1450*4520Snw141292    }
1451*4520Snw141292    return SQLITE_OK
1452*4520Snw141292  }
1453*4520Snw141292  catchsql {DROP INDEX i1}
1454*4520Snw141292} {0 {}}
1455*4520Snw141292do_test auth-1.222 {
1456*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
1457*4520Snw141292} {t1 i1}
1458*4520Snw141292do_test auth-1.223 {
1459*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1460*4520Snw141292    if {$code=="SQLITE_DROP_TEMP_INDEX"} {
1461*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1462*4520Snw141292      return SQLITE_IGNORE
1463*4520Snw141292    }
1464*4520Snw141292    return SQLITE_OK
1465*4520Snw141292  }
1466*4520Snw141292  catchsql {DROP INDEX i1}
1467*4520Snw141292} {0 {}}
1468*4520Snw141292do_test auth-1.224 {
1469*4520Snw141292  set ::authargs
1470*4520Snw141292} {i1 t1 temp {}}
1471*4520Snw141292do_test auth-1.225 {
1472*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
1473*4520Snw141292} {t1 i1}
1474*4520Snw141292do_test auth-1.226 {
1475*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1476*4520Snw141292    if {$code=="SQLITE_DROP_TEMP_INDEX"} {
1477*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1478*4520Snw141292      return SQLITE_OK
1479*4520Snw141292    }
1480*4520Snw141292    return SQLITE_OK
1481*4520Snw141292  }
1482*4520Snw141292  catchsql {DROP INDEX i1}
1483*4520Snw141292} {0 {}}
1484*4520Snw141292do_test auth-1.227 {
1485*4520Snw141292  set ::authargs
1486*4520Snw141292} {i1 t1 temp {}}
1487*4520Snw141292do_test auth-1.228 {
1488*4520Snw141292  execsql {SELECT name FROM sqlite_temp_master}
1489*4520Snw141292} {t1}
1490*4520Snw141292
1491*4520Snw141292do_test auth-1.229 {
1492*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1493*4520Snw141292    if {$code=="SQLITE_PRAGMA"} {
1494*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1495*4520Snw141292      return SQLITE_DENY
1496*4520Snw141292    }
1497*4520Snw141292    return SQLITE_OK
1498*4520Snw141292  }
1499*4520Snw141292  catchsql {PRAGMA full_column_names=on}
1500*4520Snw141292} {1 {not authorized}}
1501*4520Snw141292do_test auth-1.230 {
1502*4520Snw141292  set ::authargs
1503*4520Snw141292} {full_column_names on {} {}}
1504*4520Snw141292do_test auth-1.231 {
1505*4520Snw141292  execsql2 {SELECT a FROM t2}
1506*4520Snw141292} {a 11 a 7}
1507*4520Snw141292do_test auth-1.232 {
1508*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1509*4520Snw141292    if {$code=="SQLITE_PRAGMA"} {
1510*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1511*4520Snw141292      return SQLITE_IGNORE
1512*4520Snw141292    }
1513*4520Snw141292    return SQLITE_OK
1514*4520Snw141292  }
1515*4520Snw141292  catchsql {PRAGMA full_column_names=on}
1516*4520Snw141292} {0 {}}
1517*4520Snw141292do_test auth-1.233 {
1518*4520Snw141292  set ::authargs
1519*4520Snw141292} {full_column_names on {} {}}
1520*4520Snw141292do_test auth-1.234 {
1521*4520Snw141292  execsql2 {SELECT a FROM t2}
1522*4520Snw141292} {a 11 a 7}
1523*4520Snw141292do_test auth-1.235 {
1524*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1525*4520Snw141292    if {$code=="SQLITE_PRAGMA"} {
1526*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1527*4520Snw141292      return SQLITE_OK
1528*4520Snw141292    }
1529*4520Snw141292    return SQLITE_OK
1530*4520Snw141292  }
1531*4520Snw141292  catchsql {PRAGMA full_column_names=on}
1532*4520Snw141292} {0 {}}
1533*4520Snw141292do_test auth-1.236 {
1534*4520Snw141292  execsql2 {SELECT a FROM t2}
1535*4520Snw141292} {t2.a 11 t2.a 7}
1536*4520Snw141292do_test auth-1.237 {
1537*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1538*4520Snw141292    if {$code=="SQLITE_PRAGMA"} {
1539*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1540*4520Snw141292      return SQLITE_OK
1541*4520Snw141292    }
1542*4520Snw141292    return SQLITE_OK
1543*4520Snw141292  }
1544*4520Snw141292  catchsql {PRAGMA full_column_names=OFF}
1545*4520Snw141292} {0 {}}
1546*4520Snw141292do_test auth-1.238 {
1547*4520Snw141292  set ::authargs
1548*4520Snw141292} {full_column_names OFF {} {}}
1549*4520Snw141292do_test auth-1.239 {
1550*4520Snw141292  execsql2 {SELECT a FROM t2}
1551*4520Snw141292} {a 11 a 7}
1552*4520Snw141292
1553*4520Snw141292do_test auth-1.240 {
1554*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1555*4520Snw141292    if {$code=="SQLITE_TRANSACTION"} {
1556*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1557*4520Snw141292      return SQLITE_DENY
1558*4520Snw141292    }
1559*4520Snw141292    return SQLITE_OK
1560*4520Snw141292  }
1561*4520Snw141292  catchsql {BEGIN}
1562*4520Snw141292} {1 {not authorized}}
1563*4520Snw141292do_test auth-1.241 {
1564*4520Snw141292  set ::authargs
1565*4520Snw141292} {BEGIN {} {} {}}
1566*4520Snw141292do_test auth-1.242 {
1567*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1568*4520Snw141292    if {$code=="SQLITE_TRANSACTION" && $arg1!="BEGIN"} {
1569*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1570*4520Snw141292      return SQLITE_DENY
1571*4520Snw141292    }
1572*4520Snw141292    return SQLITE_OK
1573*4520Snw141292  }
1574*4520Snw141292  catchsql {BEGIN; INSERT INTO t2 VALUES(44,55,66); COMMIT}
1575*4520Snw141292} {1 {not authorized}}
1576*4520Snw141292do_test auth-1.243 {
1577*4520Snw141292  set ::authargs
1578*4520Snw141292} {COMMIT {} {} {}}
1579*4520Snw141292do_test auth-1.244 {
1580*4520Snw141292  execsql {SELECT * FROM t2}
1581*4520Snw141292} {11 2 33 7 8 9 44 55 66}
1582*4520Snw141292do_test auth-1.245 {
1583*4520Snw141292  catchsql {ROLLBACK}
1584*4520Snw141292} {1 {not authorized}}
1585*4520Snw141292do_test auth-1.246 {
1586*4520Snw141292  set ::authargs
1587*4520Snw141292} {ROLLBACK {} {} {}}
1588*4520Snw141292do_test auth-1.247 {
1589*4520Snw141292  catchsql {END TRANSACTION}
1590*4520Snw141292} {1 {not authorized}}
1591*4520Snw141292do_test auth-1.248 {
1592*4520Snw141292  set ::authargs
1593*4520Snw141292} {COMMIT {} {} {}}
1594*4520Snw141292do_test auth-1.249 {
1595*4520Snw141292  db authorizer {}
1596*4520Snw141292  catchsql {ROLLBACK}
1597*4520Snw141292} {0 {}}
1598*4520Snw141292do_test auth-1.250 {
1599*4520Snw141292  execsql {SELECT * FROM t2}
1600*4520Snw141292} {11 2 33 7 8 9}
1601*4520Snw141292
1602*4520Snw141292# ticket #340 - authorization for ATTACH and DETACH.
1603*4520Snw141292#
1604*4520Snw141292do_test auth-1.251 {
1605*4520Snw141292  db authorizer ::auth
1606*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1607*4520Snw141292    if {$code=="SQLITE_ATTACH"} {
1608*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1609*4520Snw141292    }
1610*4520Snw141292    return SQLITE_OK
1611*4520Snw141292  }
1612*4520Snw141292  catchsql {
1613*4520Snw141292    ATTACH DATABASE ':memory:' AS test1
1614*4520Snw141292  }
1615*4520Snw141292} {0 {}}
1616*4520Snw141292do_test auth-1.252 {
1617*4520Snw141292  set ::authargs
1618*4520Snw141292} {:memory: {} {} {}}
1619*4520Snw141292do_test auth-1.253 {
1620*4520Snw141292  catchsql {DETACH DATABASE test1}
1621*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1622*4520Snw141292    if {$code=="SQLITE_ATTACH"} {
1623*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1624*4520Snw141292      return SQLITE_DENY
1625*4520Snw141292    }
1626*4520Snw141292    return SQLITE_OK
1627*4520Snw141292  }
1628*4520Snw141292  catchsql {
1629*4520Snw141292    ATTACH DATABASE ':memory:' AS test1;
1630*4520Snw141292  }
1631*4520Snw141292} {1 {not authorized}}
1632*4520Snw141292do_test auth-1.254 {
1633*4520Snw141292  lindex [execsql {PRAGMA database_list}] 7
1634*4520Snw141292} {}
1635*4520Snw141292do_test auth-1.255 {
1636*4520Snw141292  catchsql {DETACH DATABASE test1}
1637*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1638*4520Snw141292    if {$code=="SQLITE_ATTACH"} {
1639*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1640*4520Snw141292      return SQLITE_IGNORE
1641*4520Snw141292    }
1642*4520Snw141292    return SQLITE_OK
1643*4520Snw141292  }
1644*4520Snw141292  catchsql {
1645*4520Snw141292    ATTACH DATABASE ':memory:' AS test1;
1646*4520Snw141292  }
1647*4520Snw141292} {0 {}}
1648*4520Snw141292do_test auth-1.256 {
1649*4520Snw141292  lindex [execsql {PRAGMA database_list}] 7
1650*4520Snw141292} {}
1651*4520Snw141292do_test auth-1.257 {
1652*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1653*4520Snw141292    if {$code=="SQLITE_DETACH"} {
1654*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1655*4520Snw141292      return SQLITE_OK
1656*4520Snw141292    }
1657*4520Snw141292    return SQLITE_OK
1658*4520Snw141292  }
1659*4520Snw141292  execsql {ATTACH DATABASE ':memory:' AS test1}
1660*4520Snw141292  catchsql {
1661*4520Snw141292    DETACH DATABASE test1;
1662*4520Snw141292  }
1663*4520Snw141292} {0 {}}
1664*4520Snw141292do_test auth-1.258 {
1665*4520Snw141292  lindex [execsql {PRAGMA database_list}] 7
1666*4520Snw141292} {}
1667*4520Snw141292do_test auth-1.259 {
1668*4520Snw141292  execsql {ATTACH DATABASE ':memory:' AS test1}
1669*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1670*4520Snw141292    if {$code=="SQLITE_DETACH"} {
1671*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1672*4520Snw141292      return SQLITE_IGNORE
1673*4520Snw141292    }
1674*4520Snw141292    return SQLITE_OK
1675*4520Snw141292  }
1676*4520Snw141292  catchsql {
1677*4520Snw141292    DETACH DATABASE test1;
1678*4520Snw141292  }
1679*4520Snw141292} {0 {}}
1680*4520Snw141292do_test auth-1.260 {
1681*4520Snw141292  lindex [execsql {PRAGMA database_list}] 7
1682*4520Snw141292} {test1}
1683*4520Snw141292do_test auth-1.261 {
1684*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1685*4520Snw141292    if {$code=="SQLITE_DETACH"} {
1686*4520Snw141292      set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1687*4520Snw141292      return SQLITE_DENY
1688*4520Snw141292    }
1689*4520Snw141292    return SQLITE_OK
1690*4520Snw141292  }
1691*4520Snw141292  catchsql {
1692*4520Snw141292    DETACH DATABASE test1;
1693*4520Snw141292  }
1694*4520Snw141292} {1 {not authorized}}
1695*4520Snw141292do_test auth-1.262 {
1696*4520Snw141292  lindex [execsql {PRAGMA database_list}] 7
1697*4520Snw141292} {test1}
1698*4520Snw141292db authorizer {}
1699*4520Snw141292execsql {DETACH DATABASE test1}
1700*4520Snw141292
1701*4520Snw141292
1702*4520Snw141292do_test auth-2.1 {
1703*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1704*4520Snw141292    if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
1705*4520Snw141292      return SQLITE_DENY
1706*4520Snw141292    }
1707*4520Snw141292    return SQLITE_OK
1708*4520Snw141292  }
1709*4520Snw141292  db authorizer ::auth
1710*4520Snw141292  execsql {CREATE TABLE t3(x INTEGER PRIMARY KEY, y, z)}
1711*4520Snw141292  catchsql {SELECT * FROM t3}
1712*4520Snw141292} {1 {access to t3.x is prohibited}}
1713*4520Snw141292do_test auth-2.1 {
1714*4520Snw141292  catchsql {SELECT y,z FROM t3}
1715*4520Snw141292} {0 {}}
1716*4520Snw141292do_test auth-2.2 {
1717*4520Snw141292  catchsql {SELECT ROWID,y,z FROM t3}
1718*4520Snw141292} {1 {access to t3.x is prohibited}}
1719*4520Snw141292do_test auth-2.3 {
1720*4520Snw141292  catchsql {SELECT OID,y,z FROM t3}
1721*4520Snw141292} {1 {access to t3.x is prohibited}}
1722*4520Snw141292do_test auth-2.4 {
1723*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1724*4520Snw141292    if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
1725*4520Snw141292      return SQLITE_IGNORE
1726*4520Snw141292    }
1727*4520Snw141292    return SQLITE_OK
1728*4520Snw141292  }
1729*4520Snw141292  execsql {INSERT INTO t3 VALUES(44,55,66)}
1730*4520Snw141292  catchsql {SELECT * FROM t3}
1731*4520Snw141292} {0 {{} 55 66}}
1732*4520Snw141292do_test auth-2.5 {
1733*4520Snw141292  catchsql {SELECT rowid,y,z FROM t3}
1734*4520Snw141292} {0 {{} 55 66}}
1735*4520Snw141292do_test auth-2.6 {
1736*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1737*4520Snw141292    if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="ROWID"} {
1738*4520Snw141292      return SQLITE_IGNORE
1739*4520Snw141292    }
1740*4520Snw141292    return SQLITE_OK
1741*4520Snw141292  }
1742*4520Snw141292  catchsql {SELECT * FROM t3}
1743*4520Snw141292} {0 {44 55 66}}
1744*4520Snw141292do_test auth-2.7 {
1745*4520Snw141292  catchsql {SELECT ROWID,y,z FROM t3}
1746*4520Snw141292} {0 {44 55 66}}
1747*4520Snw141292do_test auth-2.8 {
1748*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1749*4520Snw141292    if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} {
1750*4520Snw141292      return SQLITE_IGNORE
1751*4520Snw141292    }
1752*4520Snw141292    return SQLITE_OK
1753*4520Snw141292  }
1754*4520Snw141292  catchsql {SELECT ROWID,b,c FROM t2}
1755*4520Snw141292} {0 {{} 2 33 {} 8 9}}
1756*4520Snw141292do_test auth-2.9.1 {
1757*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1758*4520Snw141292    if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} {
1759*4520Snw141292      return bogus
1760*4520Snw141292    }
1761*4520Snw141292    return SQLITE_OK
1762*4520Snw141292  }
1763*4520Snw141292  catchsql {SELECT ROWID,b,c FROM t2}
1764*4520Snw141292} {1 {illegal return value (999) from the authorization function - should be SQLITE_OK, SQLITE_IGNORE, or SQLITE_DENY}}
1765*4520Snw141292do_test auth-2.9.2 {
1766*4520Snw141292  db errorcode
1767*4520Snw141292} {21}
1768*4520Snw141292do_test auth-2.10 {
1769*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1770*4520Snw141292    if {$code=="SQLITE_SELECT"} {
1771*4520Snw141292      return bogus
1772*4520Snw141292    }
1773*4520Snw141292    return SQLITE_OK
1774*4520Snw141292  }
1775*4520Snw141292  catchsql {SELECT ROWID,b,c FROM t2}
1776*4520Snw141292} {1 {illegal return value (1) from the authorization function - should be SQLITE_OK, SQLITE_IGNORE, or SQLITE_DENY}}
1777*4520Snw141292do_test auth-2.11.1 {
1778*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1779*4520Snw141292    if {$code=="SQLITE_READ" && $arg2=="a"} {
1780*4520Snw141292      return SQLITE_IGNORE
1781*4520Snw141292    }
1782*4520Snw141292    return SQLITE_OK
1783*4520Snw141292  }
1784*4520Snw141292  catchsql {SELECT * FROM t2, t3}
1785*4520Snw141292} {0 {{} 2 33 44 55 66 {} 8 9 44 55 66}}
1786*4520Snw141292do_test auth-2.11.2 {
1787*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1788*4520Snw141292    if {$code=="SQLITE_READ" && $arg2=="x"} {
1789*4520Snw141292      return SQLITE_IGNORE
1790*4520Snw141292    }
1791*4520Snw141292    return SQLITE_OK
1792*4520Snw141292  }
1793*4520Snw141292  catchsql {SELECT * FROM t2, t3}
1794*4520Snw141292} {0 {11 2 33 {} 55 66 7 8 9 {} 55 66}}
1795*4520Snw141292
1796*4520Snw141292# Make sure the OLD and NEW pseudo-tables of a trigger get authorized.
1797*4520Snw141292#
1798*4520Snw141292do_test auth-3.1 {
1799*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1800*4520Snw141292    return SQLITE_OK
1801*4520Snw141292  }
1802*4520Snw141292  execsql {
1803*4520Snw141292    CREATE TABLE tx(a1,a2,b1,b2,c1,c2);
1804*4520Snw141292    CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN
1805*4520Snw141292      INSERT INTO tx VALUES(OLD.a,NEW.a,OLD.b,NEW.b,OLD.c,NEW.c);
1806*4520Snw141292    END;
1807*4520Snw141292    UPDATE t2 SET a=a+1;
1808*4520Snw141292    SELECT * FROM tx;
1809*4520Snw141292  }
1810*4520Snw141292} {11 12 2 2 33 33 7 8 8 8 9 9}
1811*4520Snw141292do_test auth-3.2 {
1812*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1813*4520Snw141292    if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="c"} {
1814*4520Snw141292      return SQLITE_IGNORE
1815*4520Snw141292    }
1816*4520Snw141292    return SQLITE_OK
1817*4520Snw141292  }
1818*4520Snw141292  execsql {
1819*4520Snw141292    DELETE FROM tx;
1820*4520Snw141292    UPDATE t2 SET a=a+100;
1821*4520Snw141292    SELECT * FROM tx;
1822*4520Snw141292  }
1823*4520Snw141292} {12 112 2 2 {} {} 8 108 8 8 {} {}}
1824*4520Snw141292
1825*4520Snw141292# Make sure the names of views and triggers are passed on on arg4.
1826*4520Snw141292#
1827*4520Snw141292do_test auth-4.1 {
1828*4520Snw141292  proc auth {code arg1 arg2 arg3 arg4} {
1829*4520Snw141292    lappend ::authargs $code $arg1 $arg2 $arg3 $arg4
1830*4520Snw141292    return SQLITE_OK
1831*4520Snw141292  }
1832*4520Snw141292  set authargs {}
1833*4520Snw141292  execsql {
1834*4520Snw141292    UPDATE t2 SET a=a+1;
1835*4520Snw141292  }
1836*4520Snw141292  set authargs
1837*4520Snw141292} [list \
1838*4520Snw141292  SQLITE_READ   t2 a  main {} \
1839*4520Snw141292  SQLITE_UPDATE t2 a  main {} \
1840*4520Snw141292  SQLITE_INSERT tx {} main r1 \
1841*4520Snw141292  SQLITE_READ   t2 a  main r1 \
1842*4520Snw141292  SQLITE_READ   t2 a  main r1 \
1843*4520Snw141292  SQLITE_READ   t2 b  main r1 \
1844*4520Snw141292  SQLITE_READ   t2 b  main r1 \
1845*4520Snw141292  SQLITE_READ   t2 c  main r1 \
1846*4520Snw141292  SQLITE_READ   t2 c  main r1]
1847*4520Snw141292do_test auth-4.2 {
1848*4520Snw141292  execsql {
1849*4520Snw141292    CREATE VIEW v1 AS SELECT a+b AS x FROM t2;
1850*4520Snw141292    CREATE TABLE v1chng(x1,x2);
1851*4520Snw141292    CREATE TRIGGER r2 INSTEAD OF UPDATE ON v1 BEGIN
1852*4520Snw141292      INSERT INTO v1chng VALUES(OLD.x,NEW.x);
1853*4520Snw141292    END;
1854*4520Snw141292    SELECT * FROM v1;
1855*4520Snw141292  }
1856*4520Snw141292} {115 117}
1857*4520Snw141292do_test auth-4.3 {
1858*4520Snw141292  set authargs {}
1859*4520Snw141292  execsql {
1860*4520Snw141292    UPDATE v1 SET x=1 WHERE x=117
1861*4520Snw141292  }
1862*4520Snw141292  set authargs
1863*4520Snw141292} [list \
1864*4520Snw141292  SQLITE_UPDATE v1     x  main {} \
1865*4520Snw141292  SQLITE_READ   v1     x  main {} \
1866*4520Snw141292  SQLITE_SELECT {}     {} {}   v1 \
1867*4520Snw141292  SQLITE_READ   t2     a  main v1 \
1868*4520Snw141292  SQLITE_READ   t2     b  main v1 \
1869*4520Snw141292  SQLITE_INSERT v1chng {} main r2 \
1870*4520Snw141292  SQLITE_READ   v1     x  main r2 \
1871*4520Snw141292  SQLITE_READ   v1     x  main r2]
1872*4520Snw141292do_test auth-4.4 {
1873*4520Snw141292  execsql {
1874*4520Snw141292    CREATE TRIGGER r3 INSTEAD OF DELETE ON v1 BEGIN
1875*4520Snw141292      INSERT INTO v1chng VALUES(OLD.x,NULL);
1876*4520Snw141292    END;
1877*4520Snw141292    SELECT * FROM v1;
1878*4520Snw141292  }
1879*4520Snw141292} {115 117}
1880*4520Snw141292do_test auth-4.5 {
1881*4520Snw141292  set authargs {}
1882*4520Snw141292  execsql {
1883*4520Snw141292    DELETE FROM v1 WHERE x=117
1884*4520Snw141292  }
1885*4520Snw141292  set authargs
1886*4520Snw141292} [list \
1887*4520Snw141292  SQLITE_DELETE v1     {} main {} \
1888*4520Snw141292  SQLITE_READ   v1     x  main {} \
1889*4520Snw141292  SQLITE_SELECT {}     {} {}   v1 \
1890*4520Snw141292  SQLITE_READ   t2     a  main v1 \
1891*4520Snw141292  SQLITE_READ   t2     b  main v1 \
1892*4520Snw141292  SQLITE_INSERT v1chng {} main r3 \
1893*4520Snw141292  SQLITE_READ   v1     x  main r3]
1894*4520Snw141292
1895*4520Snw141292finish_test
1896