1# 2021 June 22 2# 3# The author disclaims copyright to this source code. In place of 4# a legal notice, here is a blessing: 5# 6# May you do good and not evil. 7# May you find forgiveness for yourself and forgive others. 8# May you share freely, never taking more than you give. 9# 10#*********************************************************************** 11# 12# Tests for the sqlite3_changes() and sqlite3_total_changes() APIs. 13# 14 15set testdir [file dirname $argv0] 16source $testdir/tester.tcl 17set testprefix changes 18 19 20foreach {tn nRow wor} { 21 1 50 "" 22 2 50 "WITHOUT ROWID" 23 24 3 5000 "" 25 4 5000 "WITHOUT ROWID" 26 27 5 50000 "" 28 6 50000 "WITHOUT ROWID" 29} { 30 reset_db 31 set nBig [expr $nRow] 32 33 do_execsql_test 1.$tn.0 " 34 PRAGMA journal_mode = off; 35 CREATE TABLE t1(x INTEGER PRIMARY KEY) $wor; 36 " {off} 37 38 do_execsql_test 1.$tn.1 { 39 WITH s(i) AS ( 40 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i < $nBig 41 ) 42 INSERT INTO t1 SELECT i FROM s; 43 } 44 45 do_test 1.$tn.2 { 46 db changes 47 } [expr $nBig] 48 49 do_test 1.$tn.3 { 50 db total_changes 51 } [expr $nBig] 52 53 do_execsql_test 1.$tn.4 { 54 INSERT INTO t1 VALUES(-1) 55 } 56 57 do_test 1.$tn.5 { 58 db changes 59 } [expr 1] 60 61 do_test 1.$tn.6 { 62 db total_changes 63 } [expr {$nBig+1}] 64 65 do_execsql_test 1.$tn.7a { 66 SELECT count(*) FROM t1 67 } [expr {$nBig+1}] 68 69 do_execsql_test 1.$tn.7 { 70 DELETE FROM t1 71 } 72 73 do_test 1.$tn.8 { 74 db changes 75 } [expr {$nBig+1}] 76 77 do_test 1.$tn.9 { 78 db total_changes 79 } [expr {2*($nBig+1)}] 80} 81 82finish_test 83 84 85