3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this file is the "memdb" VFS
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
20 ifcapable !deserialize {
25 # Create a MEMDB and populate it with some dummy data.
26 # Then extract the database into the $::db1 variable.
27 # Verify that the size of $::db1 is the same as the size of
32 unset -nocomplain pgsz
36 INSERT INTO t1 VALUES(1,2);
38 set ::pgsz [db one {PRAGMA page_size}]
39 set ::sz1 [expr {$::pgsz*[db one {PRAGMA page_count}]}]
40 set ::db1 [db serialize]
41 expr {[string length $::db1]==$::sz1}
43 set fd [open db1.db wb]
44 puts -nonewline $fd $db1
47 # Create a new MEMDB and initialize it to the content of $::db1
48 # Verify that the content is the same.
57 # What happens when we try to VACUUM a MEMDB database?
60 PRAGMA auto_vacuum = off;
64 CREATE TABLE t2(x, y);
65 WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100)
66 INSERT INTO t2(x, y) SELECT x, randomblob(1000) FROM c;
75 # Build a largish on-disk database and serialize it. Verify that the
76 # serialization works.
82 CREATE TABLE t3(x, y);
83 WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<400)
84 INSERT INTO t3(x, y) SELECT x, randomblob(1000) FROM c;
87 set fd [open test.db rb]
88 unset -nocomplain direct
92 string length [db serialize]
93 } [string length $direct]
95 db eval {ATTACH ':memory:' AS aux1}
96 db deserialize aux1 $::direct
98 SELECT x, y FROM main.t3 EXCEPT SELECT x, y FROM aux1.t3;
101 unset -nocomplain direct
103 # Do the same with a :memory: database.
107 do_execsql_test 300 {
108 CREATE TABLE t3(x, y);
109 WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<400)
110 INSERT INTO t3(x, y) SELECT x, randomblob(1000) FROM c;
114 db eval {ATTACH ':memory:' AS aux1}
115 db deserialize aux1 [db serialize main]
117 SELECT x, y FROM main.t3 EXCEPT SELECT x, y FROM aux1.t3;
121 # Deserialize an empty database
126 do_execsql_test 400 {
127 PRAGMA integrity_check;
129 do_execsql_test 410 {
130 CREATE TABLE t4(a,b);
131 INSERT INTO t4 VALUES('hello','world!');
132 PRAGMA integrity_check;
136 # Deserialize something that is not a database.
141 set rc [catch {db deserialize not-a-database} msg]
144 do_catchsql_test 510 {
145 PRAGMA integrity_check;
146 } {1 {file is not a database}}
148 # Abuse the serialize and deserialize commands. Make sure errors are caught.
151 set rc [catch {db deserialize} msg]
153 } {1 {wrong # args: should be "db deserialize ?DATABASE? VALUE"}}
155 set rc [catch {db deserialize a b c} msg]
157 } {1 {wrong # args: should be "db deserialize ?DATABASE? VALUE"}}
159 set rc [catch {db serialize a b} msg]
161 } {1 {wrong # args: should be "db serialize ?DATABASE?"}}