2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A# The author disclaims copyright to this source code. In place of
2N/A# a legal notice, here is a blessing:
2N/A# May you do good and not evil.
2N/A# May you find forgiveness for yourself and forgive others.
2N/A# May you share freely, never taking more than you give.
2N/A#***********************************************************************
2N/A# This file implements regression tests for SQLite library. The
2N/A# focus of this script is testing the ATTACH and DETACH commands
2N/A# and related functionality.
2N/Aset testdir [file dirname $argv0]
2N/A# disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
2N/A# defined during compilation.
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
2N/A db authorizer ::auth
2N/A catchsql {CREATE TABLE t1(a,b,c)}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_TABLE"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {CREATE TABLE t1(a,b,c)}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
2N/A catchsql {CREATE TEMP TABLE t1(a,b,c)}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {CREATE TEMP TABLE t1(a,b,c)}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {CREATE TABLE t1(a,b,c)}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_TABLE"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A catchsql {CREATE TABLE t1(a,b,c)}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {CREATE TEMP TABLE t1(a,b,c)}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A catchsql {CREATE TEMP TABLE t1(a,b,c)}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_TABLE"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {CREATE TEMP TABLE t1(a,b,c)}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/Ado_test auth-1.19.1 {
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {CREATE TABLE t2(a,b,c)}
2N/Ado_test auth-1.19.2 {
2N/A execsql {SELECT name FROM sqlite_master}
2N/Ado_test auth-1.21.1 {
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_TABLE"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {DROP TABLE t2}
2N/A} {1 {not authorized}}
2N/Ado_test auth-1.21.2 {
2N/A execsql {SELECT name FROM sqlite_master}
2N/Ado_test auth-1.23.1 {
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_TABLE"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A catchsql {DROP TABLE t2}
2N/Ado_test auth-1.23.2 {
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_TEMP_TABLE"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {DROP TABLE t1}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_TEMP_TABLE"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A catchsql {DROP TABLE t1}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="t2"} {
2N/A catchsql {INSERT INTO t2 VALUES(1,2,3)}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT * FROM t2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="t2"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {INSERT INTO t2 VALUES(1,2,3)}
2N/A execsql {SELECT * FROM t2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="t1"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {INSERT INTO t2 VALUES(1,2,3)}
2N/A execsql {SELECT * FROM t2}
2N/Ado_test auth-1.35.1 {
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
2N/A catchsql {SELECT * FROM t2}
2N/A} {1 {access to
t2.b is prohibited}}
2N/Ado_test auth-1.35.2 {
2N/Aexecsql {DETACH DATABASE two}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {SELECT * FROM t2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {SELECT * FROM t2 WHERE b=2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="a"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {SELECT * FROM t2 WHERE b=2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {SELECT * FROM t2 WHERE b IS NULL}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
2N/A catchsql {SELECT a,c FROM t2 WHERE b IS NULL}
2N/A} {1 {access to
t2.b is prohibited}}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
2N/A catchsql {UPDATE t2 SET a=11}
2N/A execsql {SELECT * FROM t2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
2N/A catchsql {UPDATE t2 SET b=22, c=33}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT * FROM t2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {UPDATE t2 SET b=22, c=33}
2N/A execsql {SELECT * FROM t2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
2N/A catchsql {DELETE FROM t2 WHERE a=11}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT * FROM t2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {DELETE FROM t2 WHERE a=11}
2N/A execsql {SELECT * FROM t2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_SELECT"} {
2N/A catchsql {SELECT * FROM t2}
2N/A} {1 {not authorized}}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_SELECT"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {SELECT * FROM t2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_SELECT"} {
2N/A catchsql {SELECT * FROM t2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_COPY"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A} {1 {not authorized}}
2N/A execsql {SELECT * FROM t2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_COPY"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A execsql {SELECT * FROM t2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_COPY"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A execsql {SELECT * FROM t2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
2N/A catchsql {DROP TABLE t2}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
2N/A catchsql {DROP TABLE t2}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
2N/A catchsql {DROP TABLE t1}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
2N/A catchsql {DROP TABLE t1}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {DROP TABLE t2}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {DROP TABLE t2}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {DROP TABLE t1}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {DROP TABLE t1}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_VIEW"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_VIEW"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
2N/A catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
2N/A catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
2N/A CREATE VIEW v2 AS SELECT a+1,b+1 FROM t2;
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_VIEW"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {DROP VIEW v2}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {DROP VIEW v2}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_VIEW"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A catchsql {DROP VIEW v2}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_VIEW"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {DROP VIEW v2}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
2N/A CREATE TEMP VIEW v1 AS SELECT a+1,b+1 FROM t1;
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_TEMP_VIEW"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {DROP VIEW v1}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {DROP VIEW v1}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_TEMP_VIEW"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A catchsql {DROP VIEW v1}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_TEMP_VIEW"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {DROP VIEW v1}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_TRIGGER"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A CREATE TRIGGER r2 DELETE on t2 BEGIN
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
2N/A CREATE TRIGGER r2 DELETE on t2 BEGIN
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_TRIGGER"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A CREATE TRIGGER r2 DELETE on t2 BEGIN
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
2N/A return SQLITE_IGNORE
2N/A CREATE TRIGGER r2 DELETE on t2 BEGIN
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_TRIGGER"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A CREATE TABLE tx(id);
2N/A CREATE TRIGGER r2 AFTER INSERT ON t2 BEGIN
2N/Ado_test auth-1.136.1 {
2N/Ado_test auth-1.136.2 {
2N/A SELECT name FROM sqlite_master WHERE type='trigger'
2N/Ado_test auth-1.136.3 {
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A lappend ::authargs $code $arg1 $arg2 $arg3 $arg4
2N/A INSERT INTO t2 VALUES(1,2,3);
2N/A} {SQLITE_INSERT t2 {} main {} SQLITE_INSERT tx {} main r2 SQLITE_READ t2 ROWID main r2}
2N/Ado_test auth-1.136.4 {
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A CREATE TRIGGER r1 DELETE on t1 BEGIN
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
2N/A CREATE TRIGGER r1 DELETE on t1 BEGIN
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A CREATE TRIGGER r1 DELETE on t1 BEGIN
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
2N/A return SQLITE_IGNORE
2N/A CREATE TRIGGER r1 DELETE on t1 BEGIN
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A CREATE TRIGGER r1 DELETE on t1 BEGIN
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
2N/A catchsql {DROP TRIGGER r2}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_TRIGGER"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {DROP TRIGGER r2}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {DROP TRIGGER r2}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_TRIGGER"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A catchsql {DROP TRIGGER r2}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_TRIGGER"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {DROP TRIGGER r2}
2N/A DELETE FROM t2 WHERE a=1 AND b=2 AND c=3;
2N/A SELECT name FROM sqlite_master;
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
2N/A catchsql {DROP TRIGGER r1}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {DROP TRIGGER r1}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {DROP TRIGGER r1}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A catchsql {DROP TRIGGER r1}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {DROP TRIGGER r1}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_INDEX"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {CREATE INDEX i2 ON t2(a)}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
2N/A catchsql {CREATE INDEX i2 ON t2(a)}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_INDEX"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A catchsql {CREATE INDEX i2 ON t2(b)}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {CREATE INDEX i2 ON t2(b)}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_INDEX"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {CREATE INDEX i2 ON t2(a)}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {CREATE INDEX i1 ON t1(a)}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
2N/A catchsql {CREATE INDEX i1 ON t1(b)}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A catchsql {CREATE INDEX i1 ON t1(b)}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {CREATE INDEX i1 ON t1(c)}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {CREATE INDEX i1 ON t1(a)}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
2N/A catchsql {DROP INDEX i2}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_INDEX"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {DROP INDEX i2}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {DROP INDEX i2}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_INDEX"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A catchsql {DROP INDEX i2}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_INDEX"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {DROP INDEX i2}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
2N/A catchsql {DROP INDEX i1}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_TEMP_INDEX"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {DROP INDEX i1}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {DROP INDEX i1}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_TEMP_INDEX"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A catchsql {DROP INDEX i1}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DROP_TEMP_INDEX"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {DROP INDEX i1}
2N/A execsql {SELECT name FROM sqlite_temp_master}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_PRAGMA"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {PRAGMA full_column_names=on}
2N/A} {1 {not authorized}}
2N/A} {full_column_names on {} {}}
2N/A execsql2 {SELECT a FROM t2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_PRAGMA"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A catchsql {PRAGMA full_column_names=on}
2N/A} {full_column_names on {} {}}
2N/A execsql2 {SELECT a FROM t2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_PRAGMA"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {PRAGMA full_column_names=on}
2N/A execsql2 {SELECT a FROM t2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_PRAGMA"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {PRAGMA full_column_names=OFF}
2N/A} {full_column_names OFF {} {}}
2N/A execsql2 {SELECT a FROM t2}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_TRANSACTION"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A} {1 {not authorized}}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_TRANSACTION" && $arg1!="BEGIN"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A catchsql {BEGIN; INSERT INTO t2 VALUES(44,55,66); COMMIT}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT * FROM t2}
2N/A} {11 2 33 7 8 9 44 55 66}
2N/A} {1 {not authorized}}
2N/A} {ROLLBACK {} {} {}}
2N/A catchsql {END TRANSACTION}
2N/A} {1 {not authorized}}
2N/A execsql {SELECT * FROM t2}
2N/A# ticket #340 - authorization for ATTACH and DETACH.
2N/A db authorizer ::auth
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_ATTACH"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A ATTACH DATABASE ':memory:' AS test1
2N/A} {:memory: {} {} {}}
2N/A catchsql {DETACH DATABASE test1}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_ATTACH"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A ATTACH DATABASE ':memory:' AS test1;
2N/A} {1 {not authorized}}
2N/A lindex [execsql {PRAGMA database_list}] 7
2N/A catchsql {DETACH DATABASE test1}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_ATTACH"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A ATTACH DATABASE ':memory:' AS test1;
2N/A lindex [execsql {PRAGMA database_list}] 7
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DETACH"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A execsql {ATTACH DATABASE ':memory:' AS test1}
2N/A DETACH DATABASE test1;
2N/A lindex [execsql {PRAGMA database_list}] 7
2N/A execsql {ATTACH DATABASE ':memory:' AS test1}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DETACH"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A return SQLITE_IGNORE
2N/A DETACH DATABASE test1;
2N/A lindex [execsql {PRAGMA database_list}] 7
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_DETACH"} {
2N/A set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2N/A DETACH DATABASE test1;
2N/A} {1 {not authorized}}
2N/A lindex [execsql {PRAGMA database_list}] 7
2N/Aexecsql {DETACH DATABASE test1}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
2N/A db authorizer ::auth
2N/A execsql {CREATE TABLE t3(x INTEGER PRIMARY KEY, y, z)}
2N/A catchsql {SELECT * FROM t3}
2N/A} {1 {access to
t3.x is prohibited}}
2N/A catchsql {SELECT y,z FROM t3}
2N/A catchsql {SELECT ROWID,y,z FROM t3}
2N/A} {1 {access to
t3.x is prohibited}}
2N/A catchsql {SELECT OID,y,z FROM t3}
2N/A} {1 {access to
t3.x is prohibited}}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
2N/A return SQLITE_IGNORE
2N/A execsql {INSERT INTO t3 VALUES(44,55,66)}
2N/A catchsql {SELECT * FROM t3}
2N/A catchsql {SELECT rowid,y,z FROM t3}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="ROWID"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {SELECT * FROM t3}
2N/A catchsql {SELECT ROWID,y,z FROM t3}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {SELECT ROWID,b,c FROM t2}
2N/A} {0 {{} 2 33 {} 8 9}}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} {
2N/A catchsql {SELECT ROWID,b,c FROM t2}
2N/A} {1 {illegal return value (999) from the authorization function - should be SQLITE_OK, SQLITE_IGNORE, or SQLITE_DENY}}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_SELECT"} {
2N/A catchsql {SELECT ROWID,b,c FROM t2}
2N/A} {1 {illegal return value (1) from the authorization function - should be SQLITE_OK, SQLITE_IGNORE, or SQLITE_DENY}}
2N/Ado_test auth-2.11.1 {
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_READ" && $arg2=="a"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {SELECT * FROM t2, t3}
2N/A} {0 {{} 2 33 44 55 66 {} 8 9 44 55 66}}
2N/Ado_test auth-2.11.2 {
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_READ" && $arg2=="x"} {
2N/A return SQLITE_IGNORE
2N/A catchsql {SELECT * FROM t2, t3}
2N/A} {0 {11 2 33 {} 55 66 7 8 9 {} 55 66}}
2N/A# Make sure the OLD and NEW pseudo-tables of a trigger get authorized.
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A CREATE TABLE tx(a1,a2,b1,b2,c1,c2);
2N/A CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN
2N/A UPDATE t2 SET a=a+1;
2N/A} {11 12 2 2 33 33 7 8 8 8 9 9}
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="c"} {
2N/A return SQLITE_IGNORE
2N/A UPDATE t2 SET a=a+100;
2N/A} {12 112 2 2 {} {} 8 108 8 8 {} {}}
2N/A# Make sure the names of views and triggers are passed on on arg4.
2N/A proc auth {code arg1 arg2 arg3 arg4} {
2N/A lappend ::authargs $code $arg1 $arg2 $arg3 $arg4
2N/A UPDATE t2 SET a=a+1;
2N/A SQLITE_READ t2 a main {} \
2N/A SQLITE_UPDATE t2 a main {} \
2N/A SQLITE_INSERT tx {} main r1 \
2N/A SQLITE_READ t2 a main r1 \
2N/A SQLITE_READ t2 a main r1 \
2N/A SQLITE_READ t2 b main r1 \
2N/A SQLITE_READ t2 b main r1 \
2N/A SQLITE_READ t2 c main r1 \
2N/A SQLITE_READ t2 c main r1]
2N/A CREATE VIEW v1 AS SELECT a+b AS x FROM t2;
2N/A CREATE TABLE v1chng(x1,x2);
2N/A CREATE TRIGGER r2 INSTEAD OF UPDATE ON v1 BEGIN
2N/A UPDATE v1 SET x=1 WHERE x=117
2N/A SQLITE_UPDATE v1 x main {} \
2N/A SQLITE_READ v1 x main {} \
2N/A SQLITE_SELECT {} {} {} v1 \
2N/A SQLITE_READ t2 a main v1 \
2N/A SQLITE_READ t2 b main v1 \
2N/A SQLITE_INSERT v1chng {} main r2 \
2N/A SQLITE_READ v1 x main r2 \
2N/A SQLITE_READ v1 x main r2]
2N/A CREATE TRIGGER r3 INSTEAD OF DELETE ON v1 BEGIN
2N/A DELETE FROM v1 WHERE x=117
2N/A SQLITE_DELETE v1 {} main {} \
2N/A SQLITE_READ v1 x main {} \
2N/A SQLITE_SELECT {} {} {} v1 \
2N/A SQLITE_READ t2 a main v1 \
2N/A SQLITE_READ t2 b main v1 \
2N/A SQLITE_INSERT v1chng {} main r3 \
2N/A SQLITE_READ v1 x main r3]