171998f03Sdan# 2018 September 2 271998f03Sdan# 371998f03Sdan# The author disclaims copyright to this source code. In place of 471998f03Sdan# a legal notice, here is a blessing: 571998f03Sdan# 671998f03Sdan# May you do good and not evil. 771998f03Sdan# May you find forgiveness for yourself and forgive others. 871998f03Sdan# May you share freely, never taking more than you give. 971998f03Sdan# 1071998f03Sdan#************************************************************************* 1171998f03Sdan# 1271998f03Sdan 1371998f03Sdanset testdir [file dirname $argv0] 1471998f03Sdan 1571998f03Sdansource $testdir/tester.tcl 1671998f03Sdan 1771998f03Sdan# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. 1871998f03Sdanifcapable !altertable { 1971998f03Sdan finish_test 2071998f03Sdan return 2171998f03Sdan} 2271998f03Sdanset testprefix alterauth 2371998f03Sdan 2471998f03Sdanset ::auth [list] 2571998f03Sdanproc xAuth {type args} { 2671998f03Sdan if {$type == "SQLITE_ALTER_TABLE"} { 27*85c6892aSdan lappend ::auth [concat $type [lrange $args 0 3]] 2871998f03Sdan } 2971998f03Sdan return SQLITE_OK 3071998f03Sdan} 3171998f03Sdandb auth xAuth 3271998f03Sdan 3371998f03Sdando_execsql_test 1.0 { CREATE TABLE t1(a, b, c); } 3471998f03Sdan 3571998f03Sdando_test 1.1 { 3671998f03Sdan set ::auth [list] 3771998f03Sdan execsql { ALTER TABLE t1 RENAME TO t2 } 3871998f03Sdan set ::auth 3971998f03Sdan} {{SQLITE_ALTER_TABLE main t1 {} {}}} 4071998f03Sdan 4171998f03Sdando_test 1.2 { 4271998f03Sdan set ::auth [list] 4371998f03Sdan execsql { ALTER TABLE t2 RENAME c TO ccc } 4471998f03Sdan set ::auth 4571998f03Sdan} {{SQLITE_ALTER_TABLE main t2 {} {}}} 4671998f03Sdan 4771998f03Sdando_test 1.3 { 4871998f03Sdan set ::auth [list] 4971998f03Sdan execsql { ALTER TABLE t2 ADD COLUMN d } 5071998f03Sdan set ::auth 5171998f03Sdan} {{SQLITE_ALTER_TABLE main t2 {} {}}} 5271998f03Sdan 5371998f03Sdanproc xAuth {type args} { 5471998f03Sdan if {$type == "SQLITE_ALTER_TABLE"} { 5571998f03Sdan return SQLITE_DENY 5671998f03Sdan } 5771998f03Sdan return SQLITE_OK 5871998f03Sdan} 5971998f03Sdan 6071998f03Sdando_test 2.1 { 6171998f03Sdan catchsql { ALTER TABLE t2 RENAME TO t3 } 6271998f03Sdan} {1 {not authorized}} 6371998f03Sdan 6471998f03Sdando_test 2.2 { 6571998f03Sdan catchsql { ALTER TABLE t2 RENAME d TO ddd } 6671998f03Sdan} {1 {not authorized}} 6771998f03Sdan 6871998f03Sdando_test 2.3 { 6971998f03Sdan catchsql { ALTER TABLE t2 ADD COLUMN e } 7071998f03Sdan} {1 {not authorized}} 7171998f03Sdan 7271998f03Sdanfinish_test 73