Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/test/backup5.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / test / backup5.test` 171 lines ยท 3270 bytes Raw Blame History 1 # 2014 November 13 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 # 12 13 set testdir [file dirname $argv0] 14 source $testdir/tester.tcl 15 set testprefix backup5 16 17 forcedelete test2.db 18 19 do_execsql_test 1.0 { 20 CREATE TABLE t1(a, b); 21 CREATE TABLE t2(a, b); 22 INSERT INTO t2 VALUES(1, 1); 23 INSERT INTO t2 VALUES(2, 2); 24 INSERT INTO t2 VALUES(3, 3); 25 } 26 27 do_test 1.1 { 28 forcecopy test.db test.db2 29 db eval { 30 DROP TABLE t2; 31 INSERT INTO t1 VALUES(zeroblob(1000), zeroblob(1000)); 32 INSERT INTO t1 VALUES(randomblob(1000), randomblob(1000)); 33 } 34 } {} 35 36 do_test 1.2 { 37 sqlite3 db2 test.db2 38 set stmt [sqlite3_prepare_v2 db2 "SELECT * FROM t2" -1 dummy] 39 sqlite3_step $stmt 40 } {SQLITE_ROW} 41 42 do_test 1.3 { 43 list [catch { sqlite3_backup B db2 main db main } msg] $msg 44 } {1 {sqlite3_backup_init() failed}} 45 46 do_test 1.4 { 47 sqlite3_errmsg db2 48 } {destination database is in use} 49 50 do_test 1.5 { 51 sqlite3_reset $stmt 52 sqlite3_backup B db2 main db main 53 B step 200 54 B finish 55 } {SQLITE_OK} 56 57 do_test 1.6 { 58 list [sqlite3_step $stmt] [sqlite3_finalize $stmt] 59 } {SQLITE_ERROR SQLITE_ERROR} 60 61 do_test 1.7 { 62 sqlite3_errmsg db2 63 } {no such table: t2} 64 65 #------------------------------------------------------------------------- 66 reset_db 67 68 foreach n {test2.db test3.db test4.db test5.db test6.db test7.db test8.db} { 69 forcedelete $n 70 } 71 72 do_execsql_test 2.0 { 73 CREATE TABLE t1(a, b); 74 CREATE TABLE t2(a, b); 75 INSERT INTO t2 VALUES(1, 1); 76 INSERT INTO t2 VALUES(2, 2); 77 INSERT INTO t2 VALUES(3, 3); 78 CREATE INDEX i1 ON t1(a); 79 CREATE INDEX i2 ON t2(a); 80 ATTACH 'test2.db' AS aux2; 81 } 82 83 sqlite3 db2 test2.db 84 85 do_test 2.1 { 86 sqlite3_backup B db2 main db main 87 B step 1 88 89 execsql { 90 ATTACH 'test3.db' AS aux3; 91 ATTACH 'test4.db' AS aux4; 92 ATTACH 'test5.db' AS aux5; 93 ATTACH 'test6.db' AS aux6; 94 ATTACH 'test7.db' AS aux7; 95 ATTACH 'test8.db' AS aux8; 96 } 97 98 B step 200 99 B finish 100 } {SQLITE_OK} 101 102 db2 close 103 104 do_execsql_test 2.2 { 105 CREATE TABLE aux7.t3(a, b); 106 CREATE TABLE aux7.t4(a, b); 107 INSERT INTO t4 VALUES(1, 1); 108 INSERT INTO t4 VALUES(2, 2); 109 INSERT INTO t4 VALUES(3, 3); 110 CREATE INDEX aux7.i3 ON t3(a); 111 CREATE INDEX aux7.i4 ON t4(a); 112 } 113 114 sqlite3 db2 test2.db 115 116 do_test 2.3 { 117 sqlite3_backup B db2 main db aux7 118 B step 1 119 120 execsql { 121 DETACH aux4; 122 } 123 124 B step 200 125 B finish 126 } {SQLITE_OK} 127 128 do_test 2.4 { 129 sqlite3_backup B db2 main db aux7 130 B finish 131 } {SQLITE_OK} 132 db2 close 133 134 #------------------------------------------------------------------------- 135 reset_db 136 137 do_execsql_test 3.0 { 138 CREATE TABLE t1(x, y); 139 CREATE INDEX i1 ON t1(y, x); 140 INSERT INTO t1 VALUES(1, 2), (3, 4); 141 } 142 143 forcedelete test.db2 144 forcedelete test.db3 145 146 sqlite3 db2 test.db2 147 do_execsql_test -db db2 3.1 { 148 ATTACH 'test.db3' AS aux; 149 } 150 151 do_test 3.2 { 152 sqlite3_backup B db2 aux db main 153 execsql { DETACH aux } db2 154 } {} 155 156 do_test 3.3 { 157 B step 1 158 } {SQLITE_ERROR} 159 160 do_test 3.4 { 161 sqlite3_errmsg db2 162 } {unknown database aux} 163 164 do_test 3.5 { 165 B finish 166 } {SQLITE_ERROR} 167 168 169 170 171 finish_test