| 1 |
# 2018 September 2 |
| 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 |
|
| 13 |
set testdir [file dirname $argv0] |
| 14 |
|
| 15 |
source $testdir/tester.tcl |
| 16 |
|
| 17 |
# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. |
| 18 |
ifcapable !altertable { |
| 19 |
finish_test |
| 20 |
return |
| 21 |
} |
| 22 |
set testprefix alterauth |
| 23 |
|
| 24 |
set ::auth [list] |
| 25 |
proc xAuth {type args} { |
| 26 |
if {$type == "SQLITE_ALTER_TABLE"} { |
| 27 |
lappend ::auth [concat $type [lrange $args 0 3]] |
| 28 |
} |
| 29 |
return SQLITE_OK |
| 30 |
} |
| 31 |
db auth xAuth |
| 32 |
|
| 33 |
do_execsql_test 1.0 { CREATE TABLE t1(a, b, c); } |
| 34 |
|
| 35 |
do_test 1.1 { |
| 36 |
set ::auth [list] |
| 37 |
execsql { ALTER TABLE t1 RENAME TO t2 } |
| 38 |
set ::auth |
| 39 |
} {{SQLITE_ALTER_TABLE main t1 {} {}}} |
| 40 |
|
| 41 |
do_test 1.2 { |
| 42 |
set ::auth [list] |
| 43 |
execsql { ALTER TABLE t2 RENAME c TO ccc } |
| 44 |
set ::auth |
| 45 |
} {{SQLITE_ALTER_TABLE main t2 {} {}}} |
| 46 |
|
| 47 |
do_test 1.3 { |
| 48 |
set ::auth [list] |
| 49 |
execsql { ALTER TABLE t2 ADD COLUMN d } |
| 50 |
set ::auth |
| 51 |
} {{SQLITE_ALTER_TABLE main t2 {} {}}} |
| 52 |
|
| 53 |
proc xAuth {type args} { |
| 54 |
if {$type == "SQLITE_ALTER_TABLE"} { |
| 55 |
return SQLITE_DENY |
| 56 |
} |
| 57 |
return SQLITE_OK |
| 58 |
} |
| 59 |
|
| 60 |
do_test 2.1 { |
| 61 |
catchsql { ALTER TABLE t2 RENAME TO t3 } |
| 62 |
} {1 {not authorized}} |
| 63 |
|
| 64 |
do_test 2.2 { |
| 65 |
catchsql { ALTER TABLE t2 RENAME d TO ddd } |
| 66 |
} {1 {not authorized}} |
| 67 |
|
| 68 |
do_test 2.3 { |
| 69 |
catchsql { ALTER TABLE t2 ADD COLUMN e } |
| 70 |
} {1 {not authorized}} |
| 71 |
|
| 72 |
finish_test |