wasCSharpSQLite – Blame information for rev 7
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | # 2008 October 27 |
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 | # Test that the truncate optimization is disabled if the SQLITE_DELETE |
||
13 | # authorization callback returns SQLITE_IGNORE. |
||
14 | # |
||
15 | # $Id: auth3.test,v 1.2 2009/05/04 01:58:31 drh Exp $ |
||
16 | # |
||
17 | |||
18 | set testdir [file dirname $argv0] |
||
19 | source $testdir/tester.tcl |
||
20 | |||
21 | # disable this test if the SQLITE_OMIT_AUTHORIZATION macro is |
||
22 | # defined during compilation. |
||
23 | if {[catch {db auth {}} msg]} { |
||
24 | finish_test |
||
25 | return |
||
26 | } |
||
27 | |||
28 | # Disable the statement cache for these tests. |
||
29 | # |
||
30 | db cache size 0 |
||
31 | |||
32 | db authorizer ::auth |
||
33 | proc auth {code arg1 arg2 arg3 arg4} { |
||
34 | if {$code=="SQLITE_DELETE"} { |
||
35 | return $::authcode |
||
36 | } |
||
37 | return SQLITE_OK |
||
38 | } |
||
39 | |||
40 | #-------------------------------------------------------------------------- |
||
41 | # The following tests - auth3-1.* - test that return values of SQLITE_DENY, |
||
42 | # SQLITE_IGNORE, SQLITE_OK and <invalid> are correctly handled when returned |
||
43 | # by an SQLITE_DELETE authorization callback triggered by a |
||
44 | # "DELETE FROM <table-name>" statement. |
||
45 | # |
||
46 | do_test auth3-1.1 { |
||
47 | execsql { |
||
48 | CREATE TABLE t1(a,b,c); |
||
49 | INSERT INTO t1 VALUES(1, 2, 3); |
||
50 | INSERT INTO t1 VALUES(4, 5, 6); |
||
51 | } |
||
52 | } {} |
||
53 | do_test auth3.1.2 { |
||
54 | set ::authcode SQLITE_DENY |
||
55 | catchsql { DELETE FROM t1 } |
||
56 | } {1 {not authorized}} |
||
57 | do_test auth3.1.3 { |
||
58 | set ::authcode SQLITE_INVALID |
||
59 | catchsql { DELETE FROM t1 } |
||
60 | } {1 {authorizer malfunction}} |
||
61 | do_test auth3.1.4 { |
||
62 | execsql { SELECT * FROM t1 } |
||
63 | } {1 2 3 4 5 6} |
||
64 | do_test auth3-1.5 { |
||
65 | set ::authcode SQLITE_IGNORE |
||
66 | execsql { |
||
67 | DELETE FROM t1; |
||
68 | SELECT * FROM t1; |
||
69 | } |
||
70 | } {} |
||
71 | do_test auth3-1.6 { |
||
72 | set ::authcode SQLITE_OK |
||
73 | execsql { |
||
74 | INSERT INTO t1 VALUES(1, 2, 3); |
||
75 | INSERT INTO t1 VALUES(4, 5, 6); |
||
76 | DELETE FROM t1; |
||
77 | SELECT * FROM t1; |
||
78 | } |
||
79 | } {} |
||
80 | |||
81 | #-------------------------------------------------------------------------- |
||
82 | # These tests - auth3-2.* - test that returning SQLITE_IGNORE really does |
||
83 | # disable the truncate optimization. |
||
84 | # |
||
85 | do_test auth3-2.1 { |
||
86 | set ::authcode SQLITE_OK |
||
87 | execsql { |
||
88 | INSERT INTO t1 VALUES(1, 2, 3); |
||
89 | INSERT INTO t1 VALUES(4, 5, 6); |
||
90 | } |
||
91 | set sqlite_search_count 0 |
||
92 | execsql { |
||
93 | DELETE FROM t1; |
||
94 | } |
||
95 | set sqlite_search_count |
||
96 | } {0} |
||
97 | |||
98 | do_test auth3-2.2 { |
||
99 | set ::authcode SQLITE_IGNORE |
||
100 | execsql { |
||
101 | INSERT INTO t1 VALUES(1, 2, 3); |
||
102 | INSERT INTO t1 VALUES(4, 5, 6); |
||
103 | } |
||
104 | set sqlite_search_count 0 |
||
105 | execsql { |
||
106 | DELETE FROM t1; |
||
107 | } |
||
108 | set sqlite_search_count |
||
109 | } {1} |
||
110 | |||
111 | finish_test |