sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
sqlite / test / tkt-f777251dc7a.test
| 1 | # 2009 October 16 |
| 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. |
| 12 | # |
| 13 | # This file implements tests to verify that ticket [f777251dc7a] has been |
| 14 | # fixed. |
| 15 | # |
| 16 | |
| 17 | set testdir [file dirname $argv0] |
| 18 | source $testdir/tester.tcl |
| 19 | |
| 20 | ifcapable !compound { |
| 21 | finish_test |
| 22 | return |
| 23 | } |
| 24 | |
| 25 | do_test tkt-f7772-1.1 { |
| 26 | execsql { |
| 27 | CREATE TEMP TABLE t1(x UNIQUE); |
| 28 | INSERT INTO t1 VALUES(1); |
| 29 | CREATE TABLE t2(x, y); |
| 30 | INSERT INTO t2 VALUES(1, 2); |
| 31 | CREATE TEMP TABLE t3(w, z); |
| 32 | } |
| 33 | } {} |
| 34 | |
| 35 | proc force_rollback {} { |
| 36 | catch {db eval {INSERT OR ROLLBACK INTO t1 VALUES(1)}} |
| 37 | } |
| 38 | db function force_rollback force_rollback |
| 39 | |
| 40 | do_test tkt-f7772-1.2 { |
| 41 | catchsql { |
| 42 | BEGIN IMMEDIATE; |
| 43 | CREATE TABLE xyzzy(abc); |
| 44 | SELECT x, force_rollback(), EXISTS(SELECT 1 FROM t3 WHERE w=x) FROM t2; |
| 45 | } |
| 46 | } {1 {abort due to ROLLBACK}} |
| 47 | do_test tkt-f7772-1.3 { |
| 48 | sqlite3_get_autocommit db |
| 49 | } {1} |
| 50 | |
| 51 | do_test tkt-f7772-2.1 { |
| 52 | execsql { |
| 53 | DROP TABLE IF EXISTS t1; |
| 54 | DROP TABLE IF EXISTS t2; |
| 55 | DROP TABLE IF EXISTS t3; |
| 56 | |
| 57 | CREATE TEMP TABLE t1(x UNIQUE); |
| 58 | INSERT INTO t1 VALUES(1); |
| 59 | CREATE TABLE t2(x, y); |
| 60 | INSERT INTO t2 VALUES(1, 2); |
| 61 | } |
| 62 | } {} |
| 63 | do_test tkt-f7772-2.2 { |
| 64 | execsql { |
| 65 | BEGIN IMMEDIATE; |
| 66 | CREATE TEMP TABLE t3(w, z); |
| 67 | } |
| 68 | catchsql { |
| 69 | SELECT x, force_rollback(), EXISTS(SELECT 1 FROM t3 WHERE w=x) FROM t2 |
| 70 | } |
| 71 | } {1 {abort due to ROLLBACK}} |
| 72 | do_test tkt-f7772-2.3 { |
| 73 | sqlite3_get_autocommit db |
| 74 | } {1} |
| 75 | |
| 76 | do_test tkt-f7772-3.1 { |
| 77 | execsql { |
| 78 | DROP TABLE IF EXISTS t1; |
| 79 | DROP TABLE IF EXISTS t2; |
| 80 | DROP TABLE IF EXISTS t3; |
| 81 | |
| 82 | CREATE TEMP TABLE t1(x); |
| 83 | CREATE TABLE t2(x); |
| 84 | CREATE TABLE t3(x); |
| 85 | |
| 86 | INSERT INTO t1 VALUES(1); |
| 87 | INSERT INTO t1 VALUES(2); |
| 88 | INSERT INTO t2 VALUES(1); |
| 89 | INSERT INTO t2 VALUES(2); |
| 90 | } |
| 91 | } {} |
| 92 | |
| 93 | proc ins {} { db eval {INSERT INTO t3 VALUES('hello')} } |
| 94 | db function ins ins |
| 95 | |
| 96 | do_test tkt-f7772-3.2 { |
| 97 | execsql { |
| 98 | SELECT ins() AS x FROM t2 UNION ALL SELECT ins() AS x FROM t1 |
| 99 | } |
| 100 | } {{} {} {} {}} |
| 101 | do_test tkt-f7772-3.3 { |
| 102 | execsql { SELECT * FROM t3 } |
| 103 | } {hello hello hello hello} |
| 104 | |
| 105 | finish_test |