3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #*************************************************************************
12 # Testing of function factoring and the SQLITE_DETERMINISTIC flag.
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
17 # Verify that constant string expressions that get factored into initializing
18 # code are not reused between function parameters and other values in the
19 # VDBE program, as the function might have changed the encoding.
21 do_execsql_test func5-1.1 {
22 PRAGMA encoding=UTF16le;
23 CREATE TABLE t1(x,a,b,c);
24 INSERT INTO t1 VALUES(1,'ab','cd',1);
25 INSERT INTO t1 VALUES(2,'gh','ef',5);
26 INSERT INTO t1 VALUES(3,'pqr','fuzzy',99);
27 INSERT INTO t1 VALUES(4,'abcdefg','xy',22);
28 INSERT INTO t1 VALUES(5,'shoe','mayer',2953);
29 SELECT x FROM t1 WHERE c=instr('abcdefg',b) OR a='abcdefg' ORDER BY +x;
31 do_execsql_test func5-1.2 {
32 SELECT x FROM t1 WHERE a='abcdefg' OR c=instr('abcdefg',b) ORDER BY +x;
35 # Verify that SQLITE_DETERMINISTIC functions get factored out of the
36 # evaluation loop whereas non-deterministic functions do not. counter1()
37 # is marked as non-deterministic and so is not factored out of the loop,
38 # and it really is non-deterministic, returning a different result each
39 # time. But counter2() is marked as deterministic, so it does get factored
40 # out of the loop. counter2() has the same implementation as counter1(),
41 # returning a different result on each invocation, but because it is
42 # only invoked once outside of the loop, it appears to return the same
43 # result multiple times.
45 do_execsql_test func5-2.1 {
47 INSERT INTO t2 VALUES(1,2),(3,4),(5,6),(7,8);
48 SELECT x, y FROM t2 WHERE x+5=5+x ORDER BY +x;
50 sqlite3_create_function db
51 do_execsql_test func5-2.2 {
53 WHERE x+counter1('hello')=counter1('hello')+x
56 do_execsql_test func5-2.3 {
58 WHERE x+counter2('hello')=counter2('hello')+x