16691 zfstest: rootpool tests do not make sense when rootfs is not zfs
[illumos-gate.git] / usr / src / lib / libsqlite / test / progress.test
blob150f75715d343ecdb76d005e0d5b94a4d32cee41
2 # 2001 September 15
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
22 execsql {
23   BEGIN;
24   CREATE TABLE t1(a);
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);
35   COMMIT;
39 # Test that the progress callback is invoked.
40 do_test progress-1.0 {
41   set counter 0
42   db progress 1 "[namespace code {incr counter}] ; expr 0"
43   execsql {
44     SELECT * FROM t1
45   }
46   expr $counter > 1
47 } 1
49 # Test that the query is abandoned when the progress callback returns non-zero
50 do_test progress1.1 {
51   set counter 0
52   db progress 1 "[namespace code {incr counter}] ; expr 1"
53   execsql {
54     SELECT * FROM t1
55   }
56   set counter
57 } 1
59 # Test that the query is rolled back when the progress callback returns
60 # non-zero.
61 do_test progress1.2 {
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"
65   set five_rows 0
66   execsql {
67     INSERT INTO t1 SELECT a+10 FROM t1 WHERE a < 6
68   }
69   db progress 0 ""
70   execsql {
71     DELETE FROM t1 WHERE a > 10
72   }
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"
79   execsql {
80     INSERT INTO t1 SELECT a+10 FROM t1 WHERE a < 7
81   }
82   execsql {
83     SELECT count(*) FROM t1
84   }
85 } 10
87 # Test that an active transaction remains active and not rolled back after the
88 # progress query abandons a query.
89 do_test progress1.3 {
91   db progress 0 ""
92   execsql BEGIN
93   execsql {
94     INSERT INTO t1 VALUES(11)
95   }
96   db progress 1 "expr 1"
97   execsql {
98     INSERT INTO t1 VALUES(12)
99   }
100   db progress 0 ""
101   execsql COMMIT
102   execsql {
103     SELECT count(*) FROM t1
104   }
105 } 11
107 # Check that a value of 0 for N means no progress callback
108 do_test progress1.4 {
109   set counter 0
110   db progress 0 "[namespace code {incr counter}] ; expr 0"
111   execsql {
112     SELECT * FROM t1;
113   }
114   set counter
115 } 0
117 db progress 0 ""
119 finish_test