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# To test that the change-counters do not suffer from 32-bit signed integer 20# rollover, add the following line to the array of test cases below. The 21# test will take will over an hour to run. 22# 23# 7 (1<<31)+10 "" 24# 25 26foreach {tn nRow wor} { 27 1 50 "" 28 2 50 "WITHOUT ROWID" 29 30 3 5000 "" 31 4 5000 "WITHOUT ROWID" 32 33 5 50000 "" 34 6 50000 "WITHOUT ROWID" 35} { 36 reset_db 37 set nBig [expr $nRow] 38 39 do_execsql_test 1.$tn.0 " 40 PRAGMA journal_mode = off; 41 CREATE TABLE t1(x INTEGER PRIMARY KEY) $wor; 42 " {off} 43 44 do_execsql_test 1.$tn.1 { 45 WITH s(i) AS ( 46 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i < $nBig 47 ) 48 INSERT INTO t1 SELECT i FROM s; 49 } 50 51 do_test 1.$tn.2 { 52 db changes 53 } [expr $nBig] 54 55 do_test 1.$tn.3 { 56 db total_changes 57 } [expr $nBig] 58 59 do_execsql_test 1.$tn.4 { 60 INSERT INTO t1 VALUES(-1) 61 } 62 63 do_test 1.$tn.5 { 64 db changes 65 } [expr 1] 66 67 do_test 1.$tn.6 { 68 db total_changes 69 } [expr {$nBig+1}] 70 71 do_execsql_test 1.$tn.7a { 72 SELECT count(*) FROM t1 73 } [expr {$nBig+1}] 74 75 do_execsql_test 1.$tn.7 { 76 DELETE FROM t1 77 } 78 79 do_test 1.$tn.8 { 80 db changes 81 } [expr {$nBig+1}] 82 83 do_test 1.$tn.9 { 84 db total_changes 85 } [expr {2*($nBig+1)}] 86} 87 88finish_test 89 90 91