⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tkt2409.test

📁 sqlite-3.4.1,嵌入式数据库.是一个功能强大的开源数据库,给学习和研发以及小型公司的发展带来了全所未有的好处.
💻 TEST
字号:
# 2007 June 13## 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.## This file implements tests to verify that ticket #2409 has been# fixed. More specifically, they verify that if SQLite cannot# obtain an EXCLUSIVE lock while trying to spill the cache during# any statement other than a COMMIT, an I/O error is returned instead# of SQLITE_BUSY.## $Id: tkt2409.test,v 1.2 2007/06/15 12:41:02 drh Exp $# Test Outline:##   tkt-2409-1.*: Cause a cache-spill during an INSERT that is within#       a db transaction but does not start a statement transaction.#       Verify that the transaction is automatically rolled back#       and SQLITE_IOERR_BLOCKED is returned##   tkt-2409-2.*: Cause a cache-spill while updating the change-counter#       during a database COMMIT. Verify that the transaction is not#       rolled back and SQLITE_BUSY is returned.##   tkt-2409-3.*: Similar to 2409-1.*, but using many INSERT statements#       within a transaction instead of just one.##   tkt-2409-4.*: Similar to 2409-1.*, but rig it so that the#       INSERT statement starts a statement transaction. Verify that#       SQLOTE_BUSY is returned and the transaction is not rolled back.#set testdir [file dirname $argv0]source $testdir/tester.tclsqlite3_extended_result_codes $::DB 1# Aquire a read-lock on the database using handle [db2].#proc read_lock_db {} {  if {$::STMT eq ""} {    set ::STMT [sqlite3_prepare db2 {SELECT rowid FROM sqlite_master} -1 TAIL]    set rc [sqlite3_step $::STMT]    if {$rc eq "SQLITE_ERROR"} {      unread_lock_db      read_lock_db    }  }}# Release any read-lock obtained using [read_lock_db]#proc unread_lock_db {} {  if {$::STMT ne ""} {    sqlite3_finalize $::STMT    set ::STMT ""  }}# Open the db handle used by [read_lock_db].#sqlite3 db2 test.dbset ::STMT ""do_test tkt2409-1.1 {  execsql {    PRAGMA cache_size=10;    CREATE TABLE t1(x TEXT UNIQUE NOT NULL, y BLOB);  }  read_lock_db  set ::zShort [string repeat 0123456789 1]  set ::zLong  [string repeat 0123456789 1500]  catchsql {    BEGIN;    INSERT INTO t1 VALUES($::zShort, $::zLong);  }} {1 {disk I/O error}}do_test tkt2409-1.2 {  sqlite3_errcode $::DB} {SQLITE_IOERR+11}# Check the integrity of the cache.#integrity_check tkt2409-1.3# Check that the transaction was rolled back. Because the INSERT# statement in which the "I/O error" occured did not open a statement# transaction, SQLite had no choice but to roll back the transaction.#do_test tkt2409-1.4 {  unread_lock_db  catchsql { ROLLBACK }} {1 {cannot rollback - no transaction is active}}set ::zShort [string repeat 0123456789 1]set ::zLong  [string repeat 0123456789 1500]set ::rc 1for {set iCache 10} {$::rc} {incr iCache} {  execsql "PRAGMA cache_size = $iCache"  do_test tkt2409-2.1.$iCache {    read_lock_db    set ::rc [catch {      execsql {        BEGIN;        INSERT INTO t1 VALUES($::zShort, $::zLong);      }    } msg]    expr {($::rc == 1 && $msg eq "disk I/O error") || $::rc == 0}  } {1}}do_test tkt2409-2.2 {  catchsql {    ROLLBACK;    BEGIN;    INSERT INTO t1 VALUES($::zShort, $::zLong);    COMMIT;  }} {1 {database is locked}}do_test tkt2409-2.3 {  unread_lock_db  catchsql {    COMMIT;  }} {0 {}}do_test tkt2409-3.1 {  db close  set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db]  sqlite3_extended_result_codes $::DB 1  execsql {    PRAGMA cache_size=10;    DELETE FROM t1;  }  read_lock_db  set ::zShort [string repeat 0123456789 1]  set ::zLong  [string repeat 0123456789 1500]  catchsql {    BEGIN;    INSERT INTO t1 SELECT $::zShort, $::zLong;  }} {1 {database is locked}}do_test tkt2409-3.2 {  sqlite3_errcode $::DB} {SQLITE_BUSY}# Check the integrity of the cache.#integrity_check tkt2409-3.3# Check that the transaction was rolled back. Because the INSERT# statement in which the "I/O error" occured did not open a statement# transaction, SQLite had no choice but to roll back the transaction.#do_test tkt2409-3.4 {  unread_lock_db  catchsql { ROLLBACK }} {0 {}}do_test tkt2409-4.1 {  execsql {    PRAGMA cache_size=20;    DROP TABLE t1;    CREATE TABLE t1 (x TEXT UNIQUE NOT NULL);  }  unset -nocomplain t1  array unset t1  set t1(0) 1  set sql ""  for {set i 0} {$i<5000} {incr i} {    set r 0    while {[info exists t1($r)]} {      set r [expr {int(rand()*1000000000)}]    }    set t1($r) 1    append sql "INSERT INTO t1 VALUES('some-text-$r');"  }  read_lock_db  execsql BEGIN  catchsql $sql} {1 {disk I/O error}}do_test tkt2409-4.2 {  sqlite3_errcode $::DB} {SQLITE_IOERR+11}# Check the integrity of the cache.#integrity_check tkt2409-4.3do_test tkt2409-4.4 {  catchsql { ROLLBACK }} {1 {cannot rollback - no transaction is active}}unread_lock_dbdb2 closeunset -nocomplain t1finish_test

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -