xref: /sqlite-3.40.0/ext/session/session6.test (revision cb6acda9)
1# 2011 July 11
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 sessions extension.
12# Specifically, it tests that sessions work when the database is modified
13# using incremental blob handles.
14#
15
16if {![info exists testdir]} {
17  set testdir [file join [file dirname [info script]] .. .. test]
18}
19source [file join [file dirname [info script]] session_common.tcl]
20source $testdir/tester.tcl
21ifcapable !session {finish_test; return}
22
23set testprefix session6
24
25proc do_then_apply_tcl {tcl {dbname main}} {
26  proc xConflict args { return "OMIT" }
27  set rc [catch {
28    sqlite3session S db $dbname
29    db eval "SELECT name FROM $dbname.sqlite_master WHERE type = 'table'" {
30      S attach $name
31    }
32    eval $tcl
33    sqlite3changeset_apply db2 [S changeset] xConflict
34  } msg]
35
36  catch { S delete }
37  if {$rc} {error $msg}
38}
39
40test_sqlite3_log x
41proc x {args} {puts $args}
42
43forcedelete test.db2
44sqlite3 db2 test.db2
45
46do_common_sql {
47  CREATE TABLE t1(a PRIMARY KEY, b);
48  CREATE TABLE t2(c PRIMARY KEY, d);
49}
50
51# Test a blob update.
52#
53do_test 1.1 {
54  do_then_apply_tcl {
55    db eval { INSERT INTO t1 VALUES(1, 'helloworld') }
56    db eval { INSERT INTO t2 VALUES(2, 'onetwothree') }
57  }
58  compare_db db db2
59} {}
60do_test 1.2 {
61  do_then_apply_tcl {
62    set fd [db incrblob t1 b 1]
63    puts -nonewline $fd 1234567890
64    close $fd
65  }
66  compare_db db db2
67} {}
68
69# Test an attached database.
70#
71do_test 2.1 {
72  forcedelete test.db3
73  file copy test.db2 test.db3
74  execsql { ATTACH 'test.db3' AS aux; }
75
76  do_then_apply_tcl {
77    set fd [db incrblob aux t2 d 1]
78    puts -nonewline $fd fourfivesix
79    close $fd
80  } aux
81
82  sqlite3 db3 test.db3
83  compare_db db2 db3
84} {}
85
86
87db3 close
88db2 close
89
90finish_test
91