4 # The author disclaims copyright to this source code. In place of
5 # a legal notice, here is a blessing:
7 # May you do good and not evil.
8 # May you find forgiveness for yourself and forgive others.
9 # May you share freely, never taking more than you give.
11 #***********************************************************************
12 # This file implements regression tests for SQLite library. The
13 # focus of this file is testing the 'progress callback'.
15 # $Id: progress.test,v 1.1 2003/10/18 09:37:27 danielk1977 Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 # Build some test data
25 INSERT INTO t1 VALUES(1);
26 INSERT INTO t1 VALUES(2);
27 INSERT INTO t1 VALUES(3);
28 INSERT INTO t1 VALUES(4);
29 INSERT INTO t1 VALUES(5);
30 INSERT INTO t1 VALUES(6);
31 INSERT INTO t1 VALUES(7);
32 INSERT INTO t1 VALUES(8);
33 INSERT INTO t1 VALUES(9);
34 INSERT INTO t1 VALUES(10);
39 # Test that the progress callback is invoked.
40 do_test progress-1.0 {
42 db progress 1 "[namespace code {incr counter}] ; expr 0"
49 # Test that the query is abandoned when the progress callback returns non-zero
52 db progress 1 "[namespace code {incr counter}] ; expr 1"
59 # Test that the query is rolled back when the progress callback returns
63 # This figures out how many opcodes it takes to copy 5 extra rows into t1.
64 db progress 1 "[namespace code {incr five_rows}] ; expr 0"
67 INSERT INTO t1 SELECT a+10 FROM t1 WHERE a < 6
71 DELETE FROM t1 WHERE a > 10
74 # Now set up the progress callback to abandon the query after the number of
75 # opcodes to copy 5 rows. That way, when we try to copy 6 rows, we know
76 # some data will have been inserted into the table by the time the progress
77 # callback abandons the query.
78 db progress $five_rows "expr 1"
80 INSERT INTO t1 SELECT a+10 FROM t1 WHERE a < 7
83 SELECT count(*) FROM t1
87 # Test that an active transaction remains active and not rolled back after the
88 # progress query abandons a query.
94 INSERT INTO t1 VALUES(11)
96 db progress 1 "expr 1"
98 INSERT INTO t1 VALUES(12)
103 SELECT count(*) FROM t1
107 # Check that a value of 0 for N means no progress callback
108 do_test progress1.4 {
110 db progress 0 "[namespace code {incr counter}] ; expr 0"