1
0
mirror of https://github.com/sqlite/sqlite.git synced 2026-10-23 21:49:02 +03:00
Files
sqlite/ext/session/sessionrebase2.test
2026-10-19 20:21:23 +00:00

109 lines
3.5 KiB
Plaintext

# 2026 July 6
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
if {![info exists testdir]} {
set testdir [file join [file dirname [info script]] .. .. test]
}
source [file join [file dirname [info script]] session_common.tcl]
source $testdir/tester.tcl
ifcapable !session {finish_test; return}
set testprefix sessionrebase2
#-------------------------------------------------------------------------
# Bug https://sqlite.org/bugs/forumpost/70e16d367d
#
set input "54280100000000000000000000000000000000000000000000000000000000000000000000000000000074310017000200000000000000070000000000000000000000000000000000000000000000000000000000000000000000000000000002c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c14141414141414102c141414141414141"
set rebaser "5401017431001200020000000000000007"
set I [db one {SELECT unhex($input)}]
set R [db one {SELECT unhex($rebaser)}]
do_test 1.0 {
sqlite3rebaser_create R
R configure $R
set I2 [R rebase $I]
R delete
} {}
#-------------------------------------------------------------------------
# Ensure that is an error to pass a patchset to sqlite3rebase_configure().
#
set input "0000ff0021"
set rebaser [string map {{ } {}} \
"5003030000 7400 0921 010000000d00490006"
]
set I [db one {SELECT unhex($input)}]
set R [db one {SELECT unhex($rebaser)}]
do_test 2.0 {
sqlite3rebaser_create R
list [catch { R configure $R } msg] $msg
} {1 SQLITE_ERROR}
do_test 2.1 {
list [catch { set I2 [R rebase $I] } msg] $msg
} {1 SQLITE_CORRUPT}
do_test 2.2 {
R delete
} {}
#-------------------------------------------------------------------------
#
reset_db
proc get_changeset {sql} {
execsql BEGIN
set cs [changeset_from_sql $sql]
execsql ROLLBACK
return $cs
}
proc xConflict {args} {
set res [lindex $::lConflict 0]
set ::lConflict [lrange $::lConflict 1 end]
return $res
}
proc rebased {blobs cs} {
sqlite3rebaser_create R
foreach b $blobs { R configure $b }
set out [R rebase $cs]
R delete
changeset_to_list $out
}
do_execsql_test 3.0 {
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
INSERT INTO t1 VALUES(1, 'x');
}
set c_peer1 [get_changeset {DELETE FROM t1 WHERE a=1}]
set c_peer2 [get_changeset {UPDATE t1 SET b='peer2' WHERE a=1}]
set c_local [changeset_from_sql {UPDATE t1 SET b='local' WHERE a=1}]
set ::lConflict REPLACE
set b1 [sqlite3changeset_apply_v2 db $c_peer1 xConflict]
set ::lConflict OMIT
set b2 [sqlite3changeset_apply_v2 db $c_peer2 xConflict]
do_test 3.1 { rebased [list $b1] $c_local } {}
do_test 3.2 { rebased [list $b2 $b1] $c_local } {}
do_test 3.3 { rebased [list $b1 $b2] $c_local } {}
finish_test