📄 io.test
字号:
} {0}do_test io-2.8.2 { execsql { SELECT * FROM abc }} {}do_test io-2.8.3 { execsql { ROLLBACK; SELECT * FROM abc; }} {1 2 3 4 5 6 7 8}# Test that the atomic write optimisation is not enabled if the sector# size is larger than the page-size.#do_test io-2.9.1 { sqlite3_simulate_device -char atomic -sectorsize 2048 execsql { BEGIN; INSERT INTO abc VALUES(9, 10); } file exists test.db-journal} {1}do_test io-2.9.2 { execsql { ROLLBACK; } db close file delete -force test.db test.db-journal sqlite3 db test.db -vfs devsym execsql { PRAGMA auto_vacuum = OFF; PRAGMA page_size = 2048; CREATE TABLE abc(a, b); } execsql { BEGIN; INSERT INTO abc VALUES(9, 10); } file exists test.db-journal} {0}do_test io-2.9.3 { execsql { COMMIT }} {}# Test a couple of the more specific IOCAP_ATOMIC flags # (i.e IOCAP_ATOMIC2K etc.).#do_test io-2.10.1 { sqlite3_simulate_device -char atomic1k execsql { BEGIN; INSERT INTO abc VALUES(11, 12); } file exists test.db-journal} {1}do_test io-2.10.2 { execsql { ROLLBACK } sqlite3_simulate_device -char atomic2k execsql { BEGIN; INSERT INTO abc VALUES(11, 12); } file exists test.db-journal} {0}do_test io-2.10.3 { execsql { ROLLBACK }} {}do_test io-2.11.0 { execsql { PRAGMA locking_mode = exclusive; PRAGMA locking_mode; }} {exclusive exclusive}do_test io-2.11.1 { execsql { INSERT INTO abc VALUES(11, 12); } file exists test.db-journal} {0}do_test io-2.11.2 { execsql { PRAGMA locking_mode = normal; INSERT INTO abc VALUES(13, 14); } file exists test.db-journal} {0}} ;# /* ifcapable atomicwrite */#----------------------------------------------------------------------# Test cases io-3.* test the IOCAP_SEQUENTIAL optimization.#sqlite3_simulate_device -char sequential -sectorsize 0ifcapable pager_pragmas { do_test io-3.1 { db close file delete -force test.db test.db-journal sqlite3 db test.db -vfs devsym db eval { PRAGMA auto_vacuum=OFF; } # File size might be 1 due to the hack to work around ticket #3260. # Search for #3260 in os_unix.c for additional information. expr {[file size test.db]>1} } {0} do_test io-3.2 { execsql { CREATE TABLE abc(a, b) } nSync execsql { PRAGMA temp_store = memory; PRAGMA cache_size = 10; BEGIN; INSERT INTO abc VALUES('hello', 'world'); INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; } # File has grown - showing there was a cache-spill - but there # have been no calls to fsync(): list [file size test.db] [nSync] } {31744 0} do_test io-3.3 { # The COMMIT requires a single fsync() - to the database file. execsql { COMMIT } list [file size test.db] [nSync] } {39936 1}}#----------------------------------------------------------------------# Test cases io-4.* test the IOCAP_SAFE_APPEND optimization.#sqlite3_simulate_device -char safe_append# With the SAFE_APPEND flag set, simple transactions require 3, rather# than 4, calls to fsync(). The fsync() calls are on:## 1) The directory in which the journal file is created, (unix only)# 2) The journal file (to sync the page data),# 3) The database file.## Normally, when the SAFE_APPEND flag is not set, there is another fsync()# on the journal file between steps (2) and (3) above.#if {$::tcl_platform(platform)=="unix"} { set expected_sync_count 3} else { set expected_sync_count 2}do_test io-4.1 { execsql { DELETE FROM abc } nSync execsql { INSERT INTO abc VALUES('a', 'b') } nSync} $expected_sync_count# With SAFE_APPEND set, the nRec field of the journal file header should# be set to 0xFFFFFFFF before the first journal sync. The nRec field# occupies bytes 8-11 of the journal file.#do_test io-4.2.1 { execsql { BEGIN } execsql { INSERT INTO abc VALUES('c', 'd') } file exists test.db-journal} {1}if {$::tcl_platform(platform)=="unix"} { do_test io-4.2.2 { hexio_read test.db-journal 8 4 } {FFFFFFFF}}do_test io-4.2.3 { execsql { COMMIT } nSync} $expected_sync_countsqlite3_simulate_device -char safe_append# With SAFE_APPEND set, there should only ever be one journal-header# written to the database, even though the sync-mode is "full".#do_test io-4.3.1 { execsql { INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; INSERT INTO abc SELECT * FROM abc; } expr {[file size test.db]/1024}} {43}ifcapable pager_pragmas { do_test io-4.3.2 { execsql { PRAGMA synchronous = full; PRAGMA cache_size = 10; PRAGMA synchronous; } } {2}}do_test io-4.3.3 { execsql { BEGIN; UPDATE abc SET a = 'x'; } file exists test.db-journal} {1}do_test io-4.3.4 { # The UPDATE statement in the statement above modifies 41 pages # (all pages in the database except page 1 and the root page of # abc). Because the cache_size is set to 10, this must have required # at least 4 cache-spills. If there were no journal headers written # to the journal file after the cache-spill, then the size of the # journal file is give by: # # <jrnl file size> = <jrnl header size> + nPage * (<page-size> + 8) # # If the journal file contains additional headers, this formula # will not predict the size of the journal file. # file size test.db-journal} [expr 512 + (1024+8)*41]#----------------------------------------------------------------------# Test cases io-5.* test that the default page size is selected and# used correctly.#set tn 0foreach {char sectorsize pgsize} { {} 512 1024 {} 1024 1024 {} 2048 2048 {} 8192 8192 {} 16384 8192 {atomic} 512 8192 {atomic512} 512 1024 {atomic2K} 512 2048 {atomic2K} 4096 4096 {atomic2K atomic} 512 8192 {atomic64K} 512 1024} { incr tn if {$pgsize>$::SQLITE_MAX_PAGE_SIZE} continue db close file delete -force test.db test.db-journal sqlite3_simulate_device -char $char -sectorsize $sectorsize sqlite3 db test.db -vfs devsym db eval { PRAGMA auto_vacuum=OFF; } ifcapable !atomicwrite { if {[regexp {^atomic} $char]} continue } do_test io-5.$tn { execsql { CREATE TABLE abc(a, b, c); } expr {[file size test.db]/2} } $pgsize}sqlite3_simulate_device -char {} -sectorsize 0finish_test
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -