drh | 398f872 | 2015-08-19 13:54:20 +0000 | [diff] [blame] | 1 | # 2015-08-19 |
| 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 | # This file implements tests for table-valued-functions implemented using |
| 13 | # eponymous virtual tables. |
| 14 | # |
| 15 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
| 18 | set testprefix tabfunc01 |
| 19 | |
| 20 | ifcapable !vtab { |
| 21 | finish_test |
| 22 | return |
| 23 | } |
| 24 | load_static_extension db series |
| 25 | |
| 26 | do_execsql_test tabfunc01-1.1 { |
| 27 | SELECT *, '|' FROM generate_series WHERE start=1 AND stop=9 AND step=2; |
| 28 | } {1 | 3 | 5 | 7 | 9 |} |
| 29 | do_execsql_test tabfunc01-1.2 { |
| 30 | SELECT *, '|' FROM generate_series LIMIT 5; |
| 31 | } {0 | 1 | 2 | 3 | 4 |} |
| 32 | do_catchsql_test tabfunc01-1.3 { |
| 33 | CREATE VIRTUAL TABLE t1 USING generate_series; |
drh | 8a48b9c | 2015-08-19 15:20:00 +0000 | [diff] [blame] | 34 | } {1 {no such module: generate_series}} |
drh | 01d230c | 2015-08-19 17:11:37 +0000 | [diff] [blame^] | 35 | do_execsql_test tabfunc01-1.4 { |
| 36 | SELECT * FROM generate_series(1,9,2); |
| 37 | } {1 3 5 7 9} |
| 38 | do_execsql_test tabfunc01-1.5 { |
| 39 | SELECT * FROM generate_series(1,9); |
| 40 | } {1 2 3 4 5 6 7 8 9} |
| 41 | do_execsql_test tabfunc01-1.6 { |
| 42 | SELECT * FROM generate_series(1,10) WHERE step=3; |
| 43 | } {1 4 7 10} |
| 44 | do_catchsql_test tabfunc01-1.7 { |
| 45 | SELECT * FROM generate_series(1,9,2,11); |
| 46 | } {1 {too many arguments on generate_series - max 3}} |
| 47 | |
| 48 | do_execsql_test tabfunc01-2.1 { |
| 49 | CREATE TABLE t1(x); |
| 50 | INSERT INTO t1(x) VALUES(2),(3); |
| 51 | SELECT *, '|' FROM t1, generate_series(1,x) ORDER BY 1, 2 |
| 52 | |
| 53 | } {2 1 | 2 2 | 3 1 | 3 2 | 3 3 |} |
drh | 398f872 | 2015-08-19 13:54:20 +0000 | [diff] [blame] | 54 | |
| 55 | finish_test |