summaryrefslogtreecommitdiffstats
path: root/test/alterauth2.test
blob: 6f9242d364ea249c156862d0ef873c94e2d53d92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# 2018 October 6
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#*************************************************************************
#

set testdir [file dirname $argv0]

source $testdir/tester.tcl

# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
ifcapable !altertable {
  finish_test
  return
}
set testprefix alterauth2

set ::auth [list]
proc xAuth {type args} {
  lappend ::auth [concat $type [lrange $args 0 3]]
  if {$type=="SQLITE_READ" && [lindex $args 0] == "t2"} breakpoint
  return SQLITE_OK
}
db auth xAuth

proc do_auth_test {tn sql authcode} {
  set script "
    set ::auth \[list\]
    execsql {$sql}
    lsort -unique \[set ::auth\]
  "

  set normal [list {*}$authcode]
  uplevel [list do_test $tn $script $normal]
}

do_execsql_test 1.0 { 
  CREATE TABLE t1(a, b, c); 
  CREATE VIEW v1 AS SELECT * FROM t1;
  CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
    DELETE FROM t1 WHERE a<new.a;
  END;

  CREATE TEMP TRIGGER tr2 AFTER UPDATE OF a, b ON t1 BEGIN
    UPDATE t1 SET a=a+1 WHERE new.b<b;
  END;
}

do_auth_test 1.1 {
  ALTER TABLE t1 RENAME TO t2;
} {
    {SQLITE_ALTER_TABLE main t1 {} {}} 
    {SQLITE_FUNCTION {} like {} {}} 
  {SQLITE_FUNCTION {} sqlite_rename_table {} {}} 
  {SQLITE_FUNCTION {} sqlite_rename_test {} {}} 
    {SQLITE_FUNCTION {} substr {} {}} 
    {SQLITE_READ sqlite_master name main {}} 
    {SQLITE_READ sqlite_master sql main {}} 
    {SQLITE_READ sqlite_master tbl_name main {}} 
    {SQLITE_READ sqlite_master type main {}} 
  {SQLITE_READ sqlite_temp_master name temp {}} 
  {SQLITE_READ sqlite_temp_master sql temp {}} 
  {SQLITE_READ sqlite_temp_master tbl_name temp {}} 
  {SQLITE_READ sqlite_temp_master type temp {}} 
  {SQLITE_SELECT {} {} {} {}} 
    {SQLITE_UPDATE sqlite_master name main {}} 
    {SQLITE_UPDATE sqlite_master sql main {}} 
    {SQLITE_UPDATE sqlite_master tbl_name main {}} 
  {SQLITE_UPDATE sqlite_temp_master sql temp {}} 
  {SQLITE_UPDATE sqlite_temp_master tbl_name temp {}}
}

do_auth_test 1.2 {
  ALTER TABLE t2 RENAME a TO aaa;
} {
  {SQLITE_ALTER_TABLE main t2 {} {}} 
  {SQLITE_FUNCTION {} like {} {}} 
  {SQLITE_FUNCTION {} sqlite_rename_column {} {}} 
  {SQLITE_FUNCTION {} sqlite_rename_quotefix {} {}} 
  {SQLITE_FUNCTION {} sqlite_rename_test {} {}} 
  {SQLITE_READ sqlite_master name main {}} 
  {SQLITE_READ sqlite_master sql main {}} 
  {SQLITE_READ sqlite_master tbl_name main {}} 
  {SQLITE_READ sqlite_master type main {}} 
  {SQLITE_READ sqlite_temp_master name temp {}} 
  {SQLITE_READ sqlite_temp_master sql temp {}} 
  {SQLITE_READ sqlite_temp_master type temp {}} 
  {SQLITE_SELECT {} {} {} {}} 
  {SQLITE_UPDATE sqlite_master sql main {}} 
  {SQLITE_UPDATE sqlite_temp_master sql temp {}}
}

do_auth_test 1.3 {
  ALTER TABLE t2 DROP COLUMN c;
} {
  {SQLITE_ALTER_TABLE main t2 c {}} 
  {SQLITE_FUNCTION {} like {} {}} 
  {SQLITE_FUNCTION {} sqlite_drop_column {} {}}
  {SQLITE_FUNCTION {} sqlite_rename_quotefix {} {}} 
  {SQLITE_FUNCTION {} sqlite_rename_test {} {}} 
  {SQLITE_READ sqlite_master name main {}} 
  {SQLITE_READ sqlite_master sql main {}} 
  {SQLITE_READ sqlite_master tbl_name main {}} 
  {SQLITE_READ sqlite_master type main {}} 
  {SQLITE_READ sqlite_temp_master name temp {}} 
  {SQLITE_READ sqlite_temp_master sql temp {}} 
  {SQLITE_READ sqlite_temp_master type temp {}} 
  {SQLITE_SELECT {} {} {} {}} 
  {SQLITE_UPDATE sqlite_master sql main {}}
  {SQLITE_UPDATE sqlite_temp_master sql temp {}}
}

finish_test