Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add tests for snapshot_get(), _open() and _free(). |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | snapshot-get |
Files: | files | file ages | folders |
SHA1: |
502cc6f353358946080d9bcd335aed52 |
User & Date: | dan 2015-12-07 14:33:07.393 |
Context
2015-12-09
| ||
16:04 | Merge unrelated fixes from trunk. (check-in: 362615b4df user: drh tags: snapshot-get) | |
2015-12-07
| ||
14:33 | Add tests for snapshot_get(), _open() and _free(). (check-in: 502cc6f353 user: dan tags: snapshot-get) | |
2015-12-05
| ||
20:51 | Add untested implementations of experimental APIs sqlite3_snapshot_get(), _open() and _free(). (check-in: 0715eb00aa user: dan tags: snapshot-get) | |
Changes
Changes to src/wal.c.
︙ | ︙ | |||
2255 2256 2257 2258 2259 2260 2261 | ** to select one of the aReadMark[] entries that is closest to ** but not exceeding pWal->hdr.mxFrame and lock that entry. */ mxReadMark = 0; mxI = 0; mxFrame = pWal->hdr.mxFrame; #ifdef SQLITE_ENABLE_SNAPSHOT | > | > | 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 | ** to select one of the aReadMark[] entries that is closest to ** but not exceeding pWal->hdr.mxFrame and lock that entry. */ mxReadMark = 0; mxI = 0; mxFrame = pWal->hdr.mxFrame; #ifdef SQLITE_ENABLE_SNAPSHOT if( pWal->pSnapshot && pWal->pSnapshot->mxFrame<mxFrame ){ mxFrame = pWal->pSnapshot->mxFrame; } #endif for(i=1; i<WAL_NREADER; i++){ u32 thisMark = pInfo->aReadMark[i]; if( mxReadMark<=thisMark && thisMark<=mxFrame ){ assert( thisMark!=READMARK_NOT_USED ); mxReadMark = thisMark; mxI = i; |
︙ | ︙ |
Added test/snapshot.test.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | # 2015 December 7 # # 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. The # focus of this file is testing the SELECT statement. # # $Id: select1.test,v 1.70 2009/05/28 01:00:56 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl set testprefix snapshot #------------------------------------------------------------------------- # Check some error conditions in snapshot_get(). It is an error if: # # 1) snapshot_get() is called on a non-WAL database. # 2) there is no open read transaction on the database, or # 3) there is an open write transaction on the database. # do_execsql_test 1.0 { CREATE TABLE t1(a, b); INSERT INTO t1 VALUES(1, 2); INSERT INTO t1 VALUES(3, 4); } do_test 1.1.1 { execsql { BEGIN; SELECT * FROM t1; } list [catch { sqlite3_snapshot_get db main } msg] $msg } {1 SQLITE_ERROR} do_execsql_test 1.1.2 COMMIT do_test 1.2.1 { execsql { PRAGMA journal_mode = wal; INSERT INTO t1 VALUES(5, 6); } list [catch { sqlite3_snapshot_get db main } msg] $msg } {1 SQLITE_ERROR} do_test 1.3.1 { execsql { BEGIN; INSERT INTO t1 VALUES(7, 8); } list [catch { sqlite3_snapshot_get db main } msg] $msg } {1 SQLITE_ERROR} do_execsql_test 1.3.2 COMMIT #------------------------------------------------------------------------- # Check that a simple case works. Reuse the database created by the # block of tests above. # do_execsql_test 2.0 { BEGIN; SELECT * FROM t1; } {1 2 3 4 5 6 7 8} do_test 2.1 { set snapshot [sqlite3_snapshot_get db main] execsql { COMMIT; INSERT INTO t1 VALUES(9, 10); SELECT * FROM t1; } } {1 2 3 4 5 6 7 8 9 10} do_test 2.2 { execsql BEGIN sqlite3_snapshot_open db main $snapshot execsql { SELECT * FROM t1 } } {1 2 3 4 5 6 7 8} do_test 2.3 { sqlite3_snapshot_free $snapshot execsql COMMIT } {} #------------------------------------------------------------------------- # Check some errors in sqlite3_snapshot_open(). It is an error if: # # 1) the db is in auto-commit mode, # 2) the db has an open (read or write) transaction, # 3) the db is not a wal database, # # Reuse the database created by earlier tests. # do_execsql_test 3.0.0 { CREATE TABLE t2(x, y); INSERT INTO t2 VALUES('a', 'b'); INSERT INTO t2 VALUES('c', 'd'); BEGIN; SELECT * FROM t2; } {a b c d} do_test 3.0.1 { set snapshot [sqlite3_snapshot_get db main] execsql { COMMIT } execsql { INSERT INTO t2 VALUES('e', 'f'); } } {} do_test 3.1 { list [catch {sqlite3_snapshot_open db main $snapshot } msg] $msg } {1 SQLITE_ERROR} do_test 3.2.1 { execsql { BEGIN; SELECT * FROM t2; } } {a b c d e f} do_test 3.2.2 { list [catch {sqlite3_snapshot_open db main $snapshot } msg] $msg } {1 SQLITE_ERROR} do_test 3.2.3 { execsql { COMMIT; BEGIN; INSERT INTO t2 VALUES('g', 'h'); } list [catch {sqlite3_snapshot_open db main $snapshot } msg] $msg } {1 SQLITE_ERROR} do_execsql_test 3.2.4 COMMIT do_test 3.3.1 { execsql { PRAGMA journal_mode = DELETE } execsql { BEGIN } list [catch {sqlite3_snapshot_open db main $snapshot } msg] $msg } {1 SQLITE_ERROR} do_test 3.3.2 { sqlite3_snapshot_free $snapshot execsql COMMIT } {} #------------------------------------------------------------------------- # Check that SQLITE_BUSY_SNAPSHOT is returned if the specified snapshot # no longer exists because the wal file has been checkpointed. # # 1. Reading a snapshot from the middle of a wal file is not possible # after the wal file has been checkpointed. # # 2. That a snapshot from the end of a wal file can not be read once # the wal file has been wrapped. # do_execsql_test 4.1.0 { PRAGMA journal_mode = wal; CREATE TABLE t3(i, j); INSERT INTO t3 VALUES('o', 't'); INSERT INTO t3 VALUES('t', 'f'); BEGIN; SELECT * FROM t3; } {wal o t t f} do_test 4.1.1 { set snapshot [sqlite3_snapshot_get db main] execsql COMMIT } {} do_test 4.1.2 { execsql { INSERT INTO t3 VALUES('f', 's'); BEGIN; } sqlite3_snapshot_open db main $snapshot execsql { SELECT * FROM t3 } } {o t t f} do_test 4.1.3 { execsql { COMMIT; PRAGMA wal_checkpoint; BEGIN; } list [catch {sqlite3_snapshot_open db main $snapshot} msg] $msg } {1 SQLITE_BUSY_SNAPSHOT} do_test 4.1.4 { sqlite3_snapshot_free $snapshot execsql COMMIT } {} do_test 4.2.1 { execsql { INSERT INTO t3 VALUES('s', 'e'); INSERT INTO t3 VALUES('n', 't'); BEGIN; SELECT * FROM t3; } } {o t t f f s s e n t} do_test 4.2.2 { set snapshot [sqlite3_snapshot_get db main] execsql { COMMIT; PRAGMA wal_checkpoint; BEGIN; } sqlite3_snapshot_open db main $snapshot execsql { SELECT * FROM t3 } } {o t t f f s s e n t} do_test 4.2.3 { execsql { COMMIT; INSERT INTO t3 VALUES('e', 't'); BEGIN; } list [catch {sqlite3_snapshot_open db main $snapshot} msg] $msg } {1 SQLITE_BUSY_SNAPSHOT} do_test 4.2.4 { sqlite3_snapshot_free $snapshot } {} finish_test |