1*1da57d55SToomas Soome# 27c478bd9Sstevel@tonic-gate# 2004 Jan 14 37c478bd9Sstevel@tonic-gate# 47c478bd9Sstevel@tonic-gate# The author disclaims copyright to this source code. In place of 57c478bd9Sstevel@tonic-gate# a legal notice, here is a blessing: 67c478bd9Sstevel@tonic-gate# 77c478bd9Sstevel@tonic-gate# May you do good and not evil. 87c478bd9Sstevel@tonic-gate# May you find forgiveness for yourself and forgive others. 97c478bd9Sstevel@tonic-gate# May you share freely, never taking more than you give. 107c478bd9Sstevel@tonic-gate# 117c478bd9Sstevel@tonic-gate#*********************************************************************** 127c478bd9Sstevel@tonic-gate# This file implements regression tests for TCL interface to the 13*1da57d55SToomas Soome# SQLite library. 147c478bd9Sstevel@tonic-gate# 157c478bd9Sstevel@tonic-gate# The focus of the tests in this file is the following interface: 167c478bd9Sstevel@tonic-gate# 177c478bd9Sstevel@tonic-gate# sqlite_commit_hook 187c478bd9Sstevel@tonic-gate# 197c478bd9Sstevel@tonic-gate# $Id: hook.test,v 1.3 2004/01/15 02:44:03 drh Exp $ 207c478bd9Sstevel@tonic-gate 217c478bd9Sstevel@tonic-gateset testdir [file dirname $argv0] 227c478bd9Sstevel@tonic-gatesource $testdir/tester.tcl 237c478bd9Sstevel@tonic-gate 247c478bd9Sstevel@tonic-gatedo_test hook-1.2 { 257c478bd9Sstevel@tonic-gate db commit_hook 267c478bd9Sstevel@tonic-gate} {} 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gatedo_test hook-3.1 { 307c478bd9Sstevel@tonic-gate set commit_cnt 0 317c478bd9Sstevel@tonic-gate proc commit_hook {} { 327c478bd9Sstevel@tonic-gate incr ::commit_cnt 337c478bd9Sstevel@tonic-gate return 0 347c478bd9Sstevel@tonic-gate } 357c478bd9Sstevel@tonic-gate db commit_hook ::commit_hook 367c478bd9Sstevel@tonic-gate db commit_hook 377c478bd9Sstevel@tonic-gate} {::commit_hook} 387c478bd9Sstevel@tonic-gatedo_test hook-3.2 { 397c478bd9Sstevel@tonic-gate set commit_cnt 407c478bd9Sstevel@tonic-gate} {0} 417c478bd9Sstevel@tonic-gatedo_test hook-3.3 { 427c478bd9Sstevel@tonic-gate execsql { 437c478bd9Sstevel@tonic-gate CREATE TABLE t2(a,b); 447c478bd9Sstevel@tonic-gate } 457c478bd9Sstevel@tonic-gate set commit_cnt 467c478bd9Sstevel@tonic-gate} {1} 477c478bd9Sstevel@tonic-gatedo_test hook-3.4 { 487c478bd9Sstevel@tonic-gate execsql { 497c478bd9Sstevel@tonic-gate INSERT INTO t2 VALUES(1,2); 507c478bd9Sstevel@tonic-gate INSERT INTO t2 SELECT a+1, b+1 FROM t2; 517c478bd9Sstevel@tonic-gate INSERT INTO t2 SELECT a+2, b+2 FROM t2; 527c478bd9Sstevel@tonic-gate } 537c478bd9Sstevel@tonic-gate set commit_cnt 547c478bd9Sstevel@tonic-gate} {4} 557c478bd9Sstevel@tonic-gatedo_test hook-3.5 { 567c478bd9Sstevel@tonic-gate set commit_cnt {} 577c478bd9Sstevel@tonic-gate proc commit_hook {} { 587c478bd9Sstevel@tonic-gate set ::commit_cnt [execsql {SELECT * FROM t2}] 597c478bd9Sstevel@tonic-gate return 0 607c478bd9Sstevel@tonic-gate } 617c478bd9Sstevel@tonic-gate execsql { 627c478bd9Sstevel@tonic-gate INSERT INTO t2 VALUES(5,6); 637c478bd9Sstevel@tonic-gate } 647c478bd9Sstevel@tonic-gate set commit_cnt 657c478bd9Sstevel@tonic-gate} {1 2 2 3 3 4 4 5 5 6} 667c478bd9Sstevel@tonic-gatedo_test hook-3.6 { 677c478bd9Sstevel@tonic-gate set commit_cnt {} 687c478bd9Sstevel@tonic-gate proc commit_hook {} { 697c478bd9Sstevel@tonic-gate set ::commit_cnt [execsql {SELECT * FROM t2}] 707c478bd9Sstevel@tonic-gate return 1 717c478bd9Sstevel@tonic-gate } 727c478bd9Sstevel@tonic-gate catchsql { 737c478bd9Sstevel@tonic-gate INSERT INTO t2 VALUES(6,7); 747c478bd9Sstevel@tonic-gate } 757c478bd9Sstevel@tonic-gate} {1 {constraint failed}} 767c478bd9Sstevel@tonic-gatedo_test hook-3.7 { 777c478bd9Sstevel@tonic-gate set commit_cnt 787c478bd9Sstevel@tonic-gate} {1 2 2 3 3 4 4 5 5 6 6 7} 797c478bd9Sstevel@tonic-gatedo_test hook-3.8 { 807c478bd9Sstevel@tonic-gate execsql {SELECT * FROM t2} 817c478bd9Sstevel@tonic-gate} {1 2 2 3 3 4 4 5 5 6} 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gatefinish_test 85