blob: 083d80df2e117accc8fa7d517f199394bb19e1e3 [file] [log] [blame]
dan226744d2017-08-05 16:15:33 +00001# 2017-07-15
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. The
12# focus of this file is error handling in the swarmvtab extension.
13#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17set testprefix swarmvtabfault
18
19ifcapable !vtab {
20 finish_test
21 return
22}
23
24proc fetch_db {file} {
25 forcedelete $file
26 sqlite3 dbX $file
mistachkin02957742017-10-23 20:17:19 +000027 set rc [catch {
28 dbX eval { CREATE TABLE t1(a INTEGER PRIMARY KEY, b) }
29 } res]
dan226744d2017-08-05 16:15:33 +000030 dbX close
mistachkin02957742017-10-23 20:17:19 +000031 if {$rc!=0} {error $res}
dan226744d2017-08-05 16:15:33 +000032}
33
34forcedelete test.db1
mistachkin15dd7802017-10-23 17:36:52 +000035forcedelete test.db2
36
dan226744d2017-08-05 16:15:33 +000037do_execsql_test 1.0 {
38 ATTACH 'test.db1' AS aux;
39 CREATE TABLE aux.t1(a INTEGER PRIMARY KEY, b);
40 INSERT INTO aux.t1 VALUES(1, NULL);
41 INSERT INTO aux.t1 VALUES(2, NULL);
42 INSERT INTO aux.t1 VALUES(9, NULL);
43 DETACH aux;
44} {}
45
46faultsim_save_and_close
47do_faultsim_test 1.1 -faults oom* -prep {
48 faultsim_restore_and_reopen
49 db func fetch_db fetch_db
50 load_static_extension db unionvtab
51 db eval {
52 CREATE VIRTUAL TABLE temp.xyz USING swarmvtab(
53 'VALUES
54 ("test.db1", "t1", 1, 10),
55 ("test.db2", "t1", 11, 20)
56 ', 'fetch_db'
57 );
58 }
59} -body {
60 execsql { SELECT a FROM xyz }
61} -test {
62 faultsim_test_result {0 {1 2 9}} {1 {sql error: out of memory}}
63}
64
65finish_test
66