1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

The SQLITE_DIRECTONLY flag, when added to sqlite3_create_function() prevents

the function from being used inside a trigger or view.

FossilOrigin-Name: de767376987f7668b0770c4920f1532e341b5a27f797d69c0f5e92b87d036170
This commit is contained in:
drh
2019-08-17 00:53:29 +00:00
11 changed files with 129 additions and 54 deletions

View File

@@ -1419,7 +1419,45 @@ do_execsql_test func-32.150 {
SELECT test_frombind(x.a,y.b,x.c,:123,y.e,x.f,$xyz+y.f) FROM t1 x, t1 y;
} {8}
# 2019-08-15
# Direct-only functions.
#
proc testdirectonly {x} {return [expr {$x*2}]}
do_test func-33.1 {
db func testdirectonly -directonly testdirectonly
db eval {SELECT testdirectonly(15)}
} {30}
do_catchsql_test func-33.2 {
CREATE VIEW v33(y) AS SELECT testdirectonly(15);
SELECT * FROM v33;
} {1 {testdirectonly() prohibited in triggers and views}}
do_execsql_test func-33.3 {
SELECT * FROM (SELECT testdirectonly(15)) AS v33;
} {30}
do_execsql_test func-33.4 {
WITH c(x) AS (SELECT testdirectonly(15))
SELECT * FROM c;
} {30}
do_catchsql_test func-33.5 {
WITH c(x) AS (SELECT * FROM v33)
SELECT * FROM c;
} {1 {testdirectonly() prohibited in triggers and views}}
do_execsql_test func-33.10 {
CREATE TABLE t33a(a,b);
CREATE TABLE t33b(x,y);
CREATE TRIGGER r1 AFTER INSERT ON t33a BEGIN
INSERT INTO t33b(x,y) VALUES(testdirectonly(new.a),new.b);
END;
} {}
do_catchsql_test func-33.11 {
INSERT INTO t33a VALUES(1,2);
} {1 {testdirectonly() prohibited in triggers and views}}
do_execsql_test func-33.20 {
ALTER TABLE t33a RENAME COLUMN a TO aaa;
SELECT sql FROM sqlite_master WHERE name='r1';
} {{CREATE TRIGGER r1 AFTER INSERT ON t33a BEGIN
INSERT INTO t33b(x,y) VALUES(testdirectonly(new.aaa),new.b);
END}}
finish_test

View File

@@ -789,7 +789,7 @@ do_test 17.6.2 {
do_test 17.6.3 {
list [catch { db function xyz -n object ret } msg] $msg
} {1 {bad option "-n": must be -argcount, -deterministic or -returntype}}
} {1 {bad option "-n": must be -argcount, -deterministic, -directonly, or -returntype}}
# 2019-02-28: The "bind_fallback" command.
#