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 / ext / session / sessionrebase2.test

108 lines · 3592 bytes Raw Blame History
1# 2026 July 6
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# This file implements regression tests for SQLite library.
12#
13
14if {![info exists testdir]} {
15 set testdir [file join [file dirname [info script]] .. .. test]
16}
17source [file join [file dirname [info script]] session_common.tcl]
18source $testdir/tester.tcl
19ifcapable !session {finish_test; return}
20
21set testprefix sessionrebase2
22
23
24#-------------------------------------------------------------------------
25# Bug https://sqlite.org/bugs/forumpost/70e16d367d
26#
27set input "54280100000000000000000000000000000000000000000000000000000000000000000000000000000074310017000200000000000000070000000000000000000000000000000000000000000000000000000000000000000000000000000002c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c141414141414141"
28
29set rebaser "5401017431001200020000000000000007"
30
31set I [db one {SELECT unhex($input)}]
32set R [db one {SELECT unhex($rebaser)}]
33do_test 1.0 {
34 sqlite3rebaser_create R
35 R configure $R
36 set I2 [R rebase $I]
37 R delete
38} {}
39
40#-------------------------------------------------------------------------
41# Ensure that is an error to pass a patchset to sqlite3rebase_configure().
42#
43set input "0000ff0021"
44set rebaser [string map {{ } {}} \
45 "5003030000 7400 0921 010000000d00490006"
46]
47
48set I [db one {SELECT unhex($input)}]
49set R [db one {SELECT unhex($rebaser)}]
50
51do_test 2.0 {
52 sqlite3rebaser_create R
53 list [catch { R configure $R } msg] $msg
54} {1 SQLITE_ERROR}
55
56do_test 2.1 {
57 list [catch { set I2 [R rebase $I] } msg] $msg
58} {1 SQLITE_CORRUPT}
59do_test 2.2 {
60 R delete
61} {}
62
63#-------------------------------------------------------------------------
64#
65reset_db
66
67proc get_changeset {sql} {
68 execsql BEGIN
69 set cs [changeset_from_sql $sql]
70 execsql ROLLBACK
71 return $cs
72}
73
74proc xConflict {args} {
75 set res [lindex $::lConflict 0]
76 set ::lConflict [lrange $::lConflict 1 end]
77 return $res
78}
79
80
81proc rebased {blobs cs} {
82 sqlite3rebaser_create R
83 foreach b $blobs { R configure $b }
84 set out [R rebase $cs]
85 R delete
86 changeset_to_list $out
87}
88
89do_execsql_test 3.0 {
90 CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
91 INSERT INTO t1 VALUES(1, 'x');
92}
93
94
95set c_peer1 [get_changeset {DELETE FROM t1 WHERE a=1}]
96set c_peer2 [get_changeset {UPDATE t1 SET b='peer2' WHERE a=1}]
97set c_local [changeset_from_sql {UPDATE t1 SET b='local' WHERE a=1}]
98
99set ::lConflict REPLACE
100set b1 [sqlite3changeset_apply_v2 db $c_peer1 xConflict]
101set ::lConflict OMIT
102set b2 [sqlite3changeset_apply_v2 db $c_peer2 xConflict]
103
104do_test 3.1 { rebased [list $b1] $c_local } {}
105do_test 3.2 { rebased [list $b2 $b1] $c_local } {}
106do_test 3.3 { rebased [list $b1 $b2] $c_local } {}
107
108finish_test