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

📄 malloc3.test

📁 sqlite嵌入式数据库源码
💻 TEST
📖 第 1 页 / 共 2 页
字号:
SQL {INSERT INTO abc VALUES(9, 'XXXXX', 11, 12);}TEST_AUTOCOMMIT 11 0SQL -norollback {UPDATE abc SET a = a + 1, c = c + 1;}TEST_AUTOCOMMIT 12 0SQL {DELETE FROM abc WHERE a = 10;}TEST_AUTOCOMMIT 13 0SQL {COMMIT;}TEST 14 {  do_test $testid.1 {    sqlite3_get_autocommit $::DB  } {1}  do_test $testid.2 {    execsql {SELECT a, b, c FROM abc}  } {1 2 3 4 5 6 7 8 9}}PREP [subst {  DROP TABLE abc;  CREATE TABLE abc(a, padding, b, c);  INSERT INTO abc VALUES(1, '$padding', 2, 3);  INSERT INTO abc VALUES(4, '$padding', 5, 6);  INSERT INTO abc VALUES(7, '$padding', 8, 9);  CREATE INDEX abc_i ON abc(a, padding, b, c);}]TEST 15 {  db eval {PRAGMA cache_size = 10}}SQL {BEGIN;}SQL -norllbck {INSERT INTO abc (oid, a, padding, b, c) SELECT NULL, * FROM abc}TEST 16 {  do_test $testid {    execsql {SELECT a, count(*) FROM abc GROUP BY a;}  } {1 2 4 2 7 2}}SQL -norllbck {INSERT INTO abc (oid, a, padding, b, c) SELECT NULL, * FROM abc}TEST 17 {  do_test $testid {    execsql {SELECT a, count(*) FROM abc GROUP BY a;}  } {1 4 4 4 7 4}}SQL -norllbck {INSERT INTO abc (oid, a, padding, b, c) SELECT NULL, * FROM abc}TEST 18 {  do_test $testid {    execsql {SELECT a, count(*) FROM abc GROUP BY a;}  } {1 8 4 8 7 8}}SQL -norllbck {INSERT INTO abc (oid, a, padding, b, c) SELECT NULL, * FROM abc}TEST 19 {  do_test $testid {    execsql {SELECT a, count(*) FROM abc GROUP BY a;}  } {1 16 4 16 7 16}}SQL {COMMIT;}TEST 21 {  do_test $testid {    execsql {SELECT a, count(*) FROM abc GROUP BY a;}  } {1 16 4 16 7 16}}SQL {BEGIN;}SQL {DELETE FROM abc WHERE oid %2}TEST 22 {  do_test $testid {    execsql {SELECT a, count(*) FROM abc GROUP BY a;}  } {1 8 4 8 7 8}}SQL {DELETE FROM abc}TEST 23 {  do_test $testid {    execsql {SELECT * FROM abc}  } {}}SQL {ROLLBACK;}TEST 24 {  do_test $testid {    execsql {SELECT a, count(*) FROM abc GROUP BY a;}  } {1 16 4 16 7 16}}# Test some schema modifications inside of a transaction. These should all# cause transaction rollback if they fail. Also query a view, to cover a bit# more code.#PREP {DROP VIEW abc_v;}TEST 25 {  do_test $testid {    execsql {      SELECT name, tbl_name FROM sqlite_master;    }  } {abc abc abc_i abc}}SQL {BEGIN;}SQL {CREATE TABLE def(d, e, f);}SQL {CREATE TABLE ghi(g, h, i);}TEST 26 {  do_test $testid {    execsql {      SELECT name, tbl_name FROM sqlite_master;    }  } {abc abc abc_i abc def def ghi ghi}}SQL {CREATE VIEW v1 AS SELECT * FROM def, ghi}SQL {CREATE UNIQUE INDEX ghi_i1 ON ghi(g);}TEST 27 {  do_test $testid {    execsql {      SELECT name, tbl_name FROM sqlite_master;    }  } {abc abc abc_i abc def def ghi ghi v1 v1 ghi_i1 ghi}}SQL {INSERT INTO def VALUES('a', 'b', 'c')}SQL {INSERT INTO def VALUES(1, 2, 3)}SQL -norollback {INSERT INTO ghi SELECT * FROM def}TEST 28 {  do_test $testid {    execsql {      SELECT * FROM def, ghi WHERE d = g;    }  } {a b c a b c 1 2 3 1 2 3}}SQL {COMMIT}TEST 29 {  do_test $testid {    execsql {      SELECT * FROM v1 WHERE d = g;    }  } {a b c a b c 1 2 3 1 2 3}}# Test a simple multi-file transaction #file delete -force test2.dbSQL {ATTACH 'test2.db' AS aux;}SQL {BEGIN}SQL {CREATE TABLE aux.tbl2(x, y, z)}SQL {INSERT INTO tbl2 VALUES(1, 2, 3)}SQL {INSERT INTO def VALUES(4, 5, 6)}TEST 30 {  do_test $testid {    execsql {      SELECT * FROM tbl2, def WHERE d = x;    }  } {1 2 3 1 2 3}}SQL {COMMIT}TEST 31 {  do_test $testid {    execsql {      SELECT * FROM tbl2, def WHERE d = x;    }  } {1 2 3 1 2 3}}# Test what happens when a malloc() fails while there are other active# statements. This changes the way sqlite3VdbeHalt() works.TEST 32 {  if {![info exists ::STMT32]} {    set sql "SELECT name FROM sqlite_master"    set ::STMT32 [sqlite3_prepare $::DB $sql -1 DUMMY]    do_test $testid {      sqlite3_step $::STMT32    } {SQLITE_ROW}  }}SQL BEGINTEST 33 {   do_test $testid {    execsql {SELECT * FROM ghi}  } {a b c 1 2 3}}SQL -norollback {   -- There is a unique index on ghi(g), so this statement may not cause  -- an automatic ROLLBACK. Hence the "-norollback" switch.  INSERT INTO ghi SELECT '2'||g, h, i FROM ghi;}TEST 34 {  if {[info exists ::STMT32]} {    do_test $testid {      sqlite3_finalize $::STMT32    } {SQLITE_OK}    unset ::STMT32  }}SQL COMMIT## End of test program declaration#--------------------------------------------------------------------------proc run_test {arglist {pcstart 0} {iFailStart 1}} {  if {[llength $arglist] %2} {    error "Uneven number of arguments to TEST"  }  for {set i 0} {$i < $pcstart} {incr i} {    set k2 [lindex $arglist [expr 2 * $i]]    set v2 [lindex $arglist [expr 2 * $i + 1]]    set ac [sqlite3_get_autocommit $::DB]        ;# Auto-Commit# puts "STARTUP"    switch -- $k2 {      -sql  {db eval [lindex $v2 1]}      -prep {db eval $v2}    }    set nac [sqlite3_get_autocommit $::DB]       ;# New Auto-Commit     if {$ac && !$nac} {set begin_pc $i}  }  db rollback_hook [list incr ::rollback_hook_count]  set iFail $iFailStart  set pc $pcstart  while {$pc*2 < [llength $arglist]} {    # Id of this iteration:    set iterid "(pc $pc).(iFail $iFail)"    set k [lindex $arglist [expr 2 * $pc]]    set v [lindex $arglist [expr 2 * $pc + 1]]    switch -- $k {      -test {         foreach {id script} $v {}        set testid "malloc3-(test $id).$iterid"        eval $script        incr pc      }      -sql {        set ::rollback_hook_count 0        set ac [sqlite3_get_autocommit $::DB]        ;# Auto-Commit        sqlite_malloc_fail $iFail# puts "SQL $iterid [lindex $v 1]"        set rc [catch {db eval [lindex $v 1]} msg]   ;# True error occurs# puts "rc = $rc msg = \"$msg\""        set nac [sqlite3_get_autocommit $::DB]       ;# New Auto-Commit         if {$rc != 0 && $nac && !$ac} {          # Before [db eval] the auto-commit flag was clear. Now it          # is set. Since an error occured we assume this was not a	  # commit - therefore a rollback occured. Check that the	  # rollback-hook was invoked.          do_test malloc3-rollback_hook.$iterid {            set ::rollback_hook_count          } {1}        }        if {$rc == 0} {            # Successful execution of sql. Our "mallocs-until-failure"             # count should be greater than 0. Otherwise a malloc() failed            # and the error was not reported.            if {[lindex [sqlite_malloc_stat] 2] <= 0} {              error "Unreported malloc() failure"            }            if {$ac && !$nac} {              # Before the [db eval] the auto-commit flag was set, now it              # is clear. We can deduce that a "BEGIN" statement has just              # been successfully executed.              set begin_pc $pc            }             incr pc            set iFail 1            sqlite_malloc_fail 0            integrity_check "malloc3-(integrity).$iterid"        } elseif {[regexp {.*out of memory} $msg]} {            # Out of memory error, as expected            integrity_check "malloc3-(integrity).$iterid"            incr iFail            if {$nac && !$ac} {              if {![lindex $v 0]} {                error "Statement \"[lindex $v 1]\" caused a rollback"              }# puts "Statement \"[lindex $v 1]\" caused a rollback"              for {set i $begin_pc} {$i < $pc} {incr i} {                set k2 [lindex $arglist [expr 2 * $i]]                set v2 [lindex $arglist [expr 2 * $i + 1]]                set catchupsql ""                switch -- $k2 {                  -sql  {set catchupsql [lindex $v2 1]}                  -prep {set catchupsql $v2}                }# puts "CATCHUP $iterid $i $catchupsql"                db eval $catchupsql              }            }        } else {            error $msg        }        while {[lindex $arglist [expr 2 * ($pc -1)]] == "-test"} {          incr pc -1        }      }      -prep {# puts "PREP $iterid $v"        db eval $v        incr pc      }      default { error "Unknown switch: $k" }    }# if {$iFail > ($iFailStart+1)} return  }}# Turn of the Tcl interface's prepared statement caching facility.db cache size 0run_test $::run_test_script 9 1# run_test [lrange $::run_test_script 0 3] 0 63sqlite_malloc_fail 0db closepp_check_for_leaksfinish_test

⌨️ 快捷键说明

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