OLD | NEW |
(Empty) | |
| 1 # 2013-11-21 |
| 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 # Testing of function factoring and the SQLITE_DETERMINISTIC flag. |
| 13 # |
| 14 set testdir [file dirname $argv0] |
| 15 source $testdir/tester.tcl |
| 16 |
| 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. |
| 20 # |
| 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; |
| 30 } {2 4} |
| 31 do_execsql_test func5-1.2 { |
| 32 SELECT x FROM t1 WHERE a='abcdefg' OR c=instr('abcdefg',b) ORDER BY +x; |
| 33 } {2 4} |
| 34 |
| 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. |
| 44 # |
| 45 do_execsql_test func5-2.1 { |
| 46 CREATE TABLE t2(x,y); |
| 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; |
| 49 } {1 2 3 4 5 6 7 8} |
| 50 sqlite3_create_function db |
| 51 do_execsql_test func5-2.2 { |
| 52 SELECT x, y FROM t2 |
| 53 WHERE x+counter1('hello')=counter1('hello')+x |
| 54 ORDER BY +x; |
| 55 } {} |
| 56 do_execsql_test func5-2.3 { |
| 57 SELECT x, y FROM t2 |
| 58 WHERE x+counter2('hello')=counter2('hello')+x |
| 59 ORDER BY +x; |
| 60 } {1 2 3 4 5 6 7 8} |
| 61 |
| 62 |
| 63 finish_test |
OLD | NEW |