dan | 4e9119d | 2014-01-13 15:12:23 +0000 | [diff] [blame] | 1 | # 2014 January 11 |
| 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 | # This file implements regression tests for SQLite library. The |
| 12 | # focus of this file is testing the WITH clause. |
| 13 | # |
| 14 | |
| 15 | set testdir [file dirname $argv0] |
| 16 | source $testdir/tester.tcl |
| 17 | source $testdir/malloc_common.tcl |
| 18 | set ::testprefix withM |
| 19 | |
dan | eede6a5 | 2014-01-15 19:42:23 +0000 | [diff] [blame] | 20 | ifcapable {!cte} { |
| 21 | finish_test |
| 22 | return |
| 23 | } |
| 24 | |
dan | 4e9119d | 2014-01-13 15:12:23 +0000 | [diff] [blame] | 25 | do_execsql_test 1.0 { |
| 26 | CREATE TABLE t1(x INTEGER, y INTEGER); |
| 27 | INSERT INTO t1 VALUES(123, 456); |
| 28 | } |
| 29 | |
dan | a9f5c13 | 2014-01-13 16:36:40 +0000 | [diff] [blame] | 30 | do_faultsim_test withM-1.1 -prep { |
dan | 4e9119d | 2014-01-13 15:12:23 +0000 | [diff] [blame] | 31 | sqlite3 db test.db |
| 32 | } -body { |
| 33 | execsql { |
| 34 | WITH tmp AS ( SELECT * FROM t1 ) |
| 35 | SELECT * FROM tmp; |
| 36 | } |
| 37 | } -test { |
| 38 | faultsim_test_result {0 {123 456}} |
| 39 | db close |
| 40 | } |
| 41 | |
dan | a9f5c13 | 2014-01-13 16:36:40 +0000 | [diff] [blame] | 42 | do_faultsim_test withM-1.2 -prep { |
| 43 | sqlite3 db test.db |
| 44 | } -body { |
| 45 | execsql { |
| 46 | WITH w1 AS ( SELECT * FROM t1 ), |
| 47 | w2 AS ( |
| 48 | WITH w3 AS ( SELECT * FROM w1 ) |
| 49 | SELECT * FROM w3 |
| 50 | ) |
| 51 | SELECT * FROM w2; |
| 52 | } |
| 53 | } -test { |
| 54 | faultsim_test_result {0 {123 456}} |
| 55 | db close |
| 56 | } |
| 57 | |
dan | 1fe3c4b | 2014-01-18 15:59:35 +0000 | [diff] [blame] | 58 | do_faultsim_test withM-1.3 -prep { |
| 59 | sqlite3 db test.db |
| 60 | } -body { |
| 61 | execsql { |
| 62 | WITH w1(a,b) AS ( |
| 63 | SELECT 1, 1 |
| 64 | UNION ALL |
| 65 | SELECT a+1, b + 2*a + 1 FROM w1 |
| 66 | ) |
| 67 | SELECT * FROM w1 LIMIT 5; |
| 68 | } |
| 69 | } -test { |
| 70 | faultsim_test_result {0 {1 1 2 4 3 9 4 16 5 25}} |
| 71 | db close |
| 72 | } |
| 73 | |
dan | 4e9119d | 2014-01-13 15:12:23 +0000 | [diff] [blame] | 74 | finish_test |