interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / expridx2.test

86 lines · 2027 bytes Raw Blame History
1# 2026-04-23
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 omitting the update of an index when the new value is the
13# same as the old.
14#
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17set testprefix expridx2
18
19# This test requires wal mode, but the journaltest permutation installs
20# a custom VFS that does not support wal mode.
21if {[permutation]=="journaltest"} {
22 finish_test
23 return
24}
25
26do_execsql_test 1.0 {
27 PRAGMA journal_mode = wal;
28 CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT);
29 INSERT INTO t1 VALUES(1, '{a: 10, b: 20, c: 30}');
30 INSERT INTO t1 VALUES(2, '{a: 11, b: 21, c: 31}');
31 INSERT INTO t1 VALUES(3, '{a: 12, b: 22, c: 32}');
32 INSERT INTO t1 VALUES(4, '{a: 13, b: 23, c: 33}');
33
34 CREATE INDEX t1a ON t1( (b->>'a') );
35 CREATE INDEX t1b ON t1( (b->>'b') );
36 CREATE INDEX t1c ON t1( (b->>'c') );
37
38 CREATE TABLE t2(a INTEGER PRIMARY KEY, b, c);
39 CREATE INDEX t2b ON t2( b );
40 INSERT INTO t2 VALUES(1, 1, 1);
41 INSERT INTO t2 VALUES(2, 2, 2);
42 INSERT INTO t2 VALUES(3, 3, 3);
43 INSERT INTO t2 VALUES(4, 4, 4);
44} {wal}
45
46proc nWrite {sql} {
47 sqlite3_db_status db CACHE_WRITE 1
48 execsql $sql
49 lindex [sqlite3_db_status db CACHE_WRITE 0] 1
50}
51
52do_test 1.1 {
53 nWrite { UPDATE t1 SET b = json_set(b, '$.a', b->>'a' + 1) }
54} {2}
55
56do_test 1.2 {
57 nWrite {
58 UPDATE t1 SET b = json_set(
59 json_set(b, '$.a', b->>'a' + 1),
60 '$.b', b->>'b' + 1
61 );
62 }
63} {3}
64
65do_test 1.3 {
66 nWrite {
67 UPDATE t1 SET b = '{a:1, b:2, c:3}' WHERE rowid=1;
68 }
69} {4}
70
71integrity_check 1.4
72
73do_test 1.5 {
74 nWrite { UPDATE t2 SET b = b+1, c=c+1 }
75} {2}
76
77do_test 1.6 {
78 nWrite { UPDATE t2 SET b = b, c=c+1 }
79} {2}
80
81do_test 1.7 {
82 nWrite { UPDATE t2 SET c=c+1 }
83} {1}
84
85finish_test
86