2 #pragma ident "%Z%%M% %I% %E% SMI"
6 # The author disclaims copyright to this source code. In place of
7 # a legal notice, here is a blessing:
9 # May you do good and not evil.
10 # May you find forgiveness for yourself and forgive others.
11 # May you share freely, never taking more than you give.
13 #***********************************************************************
14 # This file implements regression tests for SQLite library. The
15 # focus of this file is testing the 'progress callback'.
17 # $Id: progress.test,v 1.1 2003/10/18 09:37:27 danielk1977 Exp $
19 set testdir [file dirname $argv0]
20 source $testdir/tester.tcl
22 # Build some test data
27 INSERT INTO t1 VALUES(1);
28 INSERT INTO t1 VALUES(2);
29 INSERT INTO t1 VALUES(3);
30 INSERT INTO t1 VALUES(4);
31 INSERT INTO t1 VALUES(5);
32 INSERT INTO t1 VALUES(6);
33 INSERT INTO t1 VALUES(7);
34 INSERT INTO t1 VALUES(8);
35 INSERT INTO t1 VALUES(9);
36 INSERT INTO t1 VALUES(10);
41 # Test that the progress callback is invoked.
42 do_test progress-1.0 {
44 db progress 1 "[namespace code {incr counter}] ; expr 0"
51 # Test that the query is abandoned when the progress callback returns non-zero
54 db progress 1 "[namespace code {incr counter}] ; expr 1"
61 # Test that the query is rolled back when the progress callback returns
65 # This figures out how many opcodes it takes to copy 5 extra rows into t1.
66 db progress 1 "[namespace code {incr five_rows}] ; expr 0"
69 INSERT INTO t1 SELECT a+10 FROM t1 WHERE a < 6
73 DELETE FROM t1 WHERE a > 10
76 # Now set up the progress callback to abandon the query after the number of
77 # opcodes to copy 5 rows. That way, when we try to copy 6 rows, we know
78 # some data will have been inserted into the table by the time the progress
79 # callback abandons the query.
80 db progress $five_rows "expr 1"
82 INSERT INTO t1 SELECT a+10 FROM t1 WHERE a < 7
85 SELECT count(*) FROM t1
89 # Test that an active transaction remains active and not rolled back after the
90 # progress query abandons a query.
96 INSERT INTO t1 VALUES(11)
98 db progress 1 "expr 1"
100 INSERT INTO t1 VALUES(12)
105 SELECT count(*) FROM t1
109 # Check that a value of 0 for N means no progress callback
110 do_test progress1.4 {
112 db progress 0 "[namespace code {incr counter}] ; expr 0"