drh | aa940ea | 2004-01-15 02:44:03 +0000 | [diff] [blame] | 1 | # 2004 Jan 14 |
| 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 TCL interface to the |
| 12 | # SQLite library. |
| 13 | # |
| 14 | # The focus of the tests in this file is the following interface: |
| 15 | # |
| 16 | # sqlite_commit_hook |
| 17 | # |
danielk1977 | 1d850a7 | 2004-05-31 08:26:49 +0000 | [diff] [blame^] | 18 | # $Id: hook.test,v 1.4 2004/05/31 08:26:49 danielk1977 Exp $ |
drh | aa940ea | 2004-01-15 02:44:03 +0000 | [diff] [blame] | 19 | |
| 20 | set testdir [file dirname $argv0] |
| 21 | source $testdir/tester.tcl |
| 22 | |
| 23 | do_test hook-1.2 { |
| 24 | db commit_hook |
| 25 | } {} |
| 26 | |
| 27 | |
| 28 | do_test hook-3.1 { |
| 29 | set commit_cnt 0 |
| 30 | proc commit_hook {} { |
| 31 | incr ::commit_cnt |
| 32 | return 0 |
| 33 | } |
| 34 | db commit_hook ::commit_hook |
| 35 | db commit_hook |
| 36 | } {::commit_hook} |
| 37 | do_test hook-3.2 { |
| 38 | set commit_cnt |
| 39 | } {0} |
| 40 | do_test hook-3.3 { |
| 41 | execsql { |
| 42 | CREATE TABLE t2(a,b); |
| 43 | } |
| 44 | set commit_cnt |
| 45 | } {1} |
| 46 | do_test hook-3.4 { |
| 47 | execsql { |
| 48 | INSERT INTO t2 VALUES(1,2); |
| 49 | INSERT INTO t2 SELECT a+1, b+1 FROM t2; |
| 50 | INSERT INTO t2 SELECT a+2, b+2 FROM t2; |
| 51 | } |
| 52 | set commit_cnt |
| 53 | } {4} |
| 54 | do_test hook-3.5 { |
| 55 | set commit_cnt {} |
| 56 | proc commit_hook {} { |
| 57 | set ::commit_cnt [execsql {SELECT * FROM t2}] |
| 58 | return 0 |
| 59 | } |
| 60 | execsql { |
| 61 | INSERT INTO t2 VALUES(5,6); |
| 62 | } |
| 63 | set commit_cnt |
| 64 | } {1 2 2 3 3 4 4 5 5 6} |
| 65 | do_test hook-3.6 { |
| 66 | set commit_cnt {} |
| 67 | proc commit_hook {} { |
danielk1977 | 1d850a7 | 2004-05-31 08:26:49 +0000 | [diff] [blame^] | 68 | set ::commit_cnt [execsql {SELECT * FROM t2}] |
drh | aa940ea | 2004-01-15 02:44:03 +0000 | [diff] [blame] | 69 | return 1 |
| 70 | } |
| 71 | catchsql { |
| 72 | INSERT INTO t2 VALUES(6,7); |
| 73 | } |
| 74 | } {1 {constraint failed}} |
| 75 | do_test hook-3.7 { |
danielk1977 | 1d850a7 | 2004-05-31 08:26:49 +0000 | [diff] [blame^] | 76 | set ::commit_cnt |
drh | aa940ea | 2004-01-15 02:44:03 +0000 | [diff] [blame] | 77 | } {1 2 2 3 3 4 4 5 5 6 6 7} |
| 78 | do_test hook-3.8 { |
| 79 | execsql {SELECT * FROM t2} |
| 80 | } {1 2 2 3 3 4 4 5 5 6} |
| 81 | |
| 82 | |
| 83 | finish_test |