2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A# 2001 September 15
2N/A#
2N/A# The author disclaims copyright to this source code. In place of
2N/A# a legal notice, here is a blessing:
2N/A#
2N/A# May you do good and not evil.
2N/A# May you find forgiveness for yourself and forgive others.
2N/A# May you share freely, never taking more than you give.
2N/A#
2N/A#***********************************************************************
2N/A# This file implements regression tests for SQLite library. The
2N/A# focus of this file is testing the 'progress callback'.
2N/A#
2N/A# $Id: progress.test,v 1.1 2003/10/18 09:37:27 danielk1977 Exp $
2N/A
2N/Aset testdir [file dirname $argv0]
2N/Asource $testdir/tester.tcl
2N/A
2N/A# Build some test data
2N/A#
2N/Aexecsql {
2N/A BEGIN;
2N/A CREATE TABLE t1(a);
2N/A INSERT INTO t1 VALUES(1);
2N/A INSERT INTO t1 VALUES(2);
2N/A INSERT INTO t1 VALUES(3);
2N/A INSERT INTO t1 VALUES(4);
2N/A INSERT INTO t1 VALUES(5);
2N/A INSERT INTO t1 VALUES(6);
2N/A INSERT INTO t1 VALUES(7);
2N/A INSERT INTO t1 VALUES(8);
2N/A INSERT INTO t1 VALUES(9);
2N/A INSERT INTO t1 VALUES(10);
2N/A COMMIT;
2N/A}
2N/A
2N/A
2N/A# Test that the progress callback is invoked.
2N/Ado_test progress-1.0 {
2N/A set counter 0
2N/A db progress 1 "[namespace code {incr counter}] ; expr 0"
2N/A execsql {
2N/A SELECT * FROM t1
2N/A }
2N/A expr $counter > 1
2N/A} 1
2N/A
2N/A# Test that the query is abandoned when the progress callback returns non-zero
2N/Ado_test progress1.1 {
2N/A set counter 0
2N/A db progress 1 "[namespace code {incr counter}] ; expr 1"
2N/A execsql {
2N/A SELECT * FROM t1
2N/A }
2N/A set counter
2N/A} 1
2N/A
2N/A# Test that the query is rolled back when the progress callback returns
2N/A# non-zero.
2N/Ado_test progress1.2 {
2N/A
2N/A # This figures out how many opcodes it takes to copy 5 extra rows into t1.
2N/A db progress 1 "[namespace code {incr five_rows}] ; expr 0"
2N/A set five_rows 0
2N/A execsql {
2N/A INSERT INTO t1 SELECT a+10 FROM t1 WHERE a < 6
2N/A }
2N/A db progress 0 ""
2N/A execsql {
2N/A DELETE FROM t1 WHERE a > 10
2N/A }
2N/A
2N/A # Now set up the progress callback to abandon the query after the number of
2N/A # opcodes to copy 5 rows. That way, when we try to copy 6 rows, we know
2N/A # some data will have been inserted into the table by the time the progress
2N/A # callback abandons the query.
2N/A db progress $five_rows "expr 1"
2N/A execsql {
2N/A INSERT INTO t1 SELECT a+10 FROM t1 WHERE a < 7
2N/A }
2N/A execsql {
2N/A SELECT count(*) FROM t1
2N/A }
2N/A} 10
2N/A
2N/A# Test that an active transaction remains active and not rolled back after the
2N/A# progress query abandons a query.
2N/Ado_test progress1.3 {
2N/A
2N/A db progress 0 ""
2N/A execsql BEGIN
2N/A execsql {
2N/A INSERT INTO t1 VALUES(11)
2N/A }
2N/A db progress 1 "expr 1"
2N/A execsql {
2N/A INSERT INTO t1 VALUES(12)
2N/A }
2N/A db progress 0 ""
2N/A execsql COMMIT
2N/A execsql {
2N/A SELECT count(*) FROM t1
2N/A }
2N/A} 11
2N/A
2N/A# Check that a value of 0 for N means no progress callback
2N/Ado_test progress1.4 {
2N/A set counter 0
2N/A db progress 0 "[namespace code {incr counter}] ; expr 0"
2N/A execsql {
2N/A SELECT * FROM t1;
2N/A }
2N/A set counter
2N/A} 0
2N/A
2N/Adb progress 0 ""
2N/A
2N/Afinish_test