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

📄 incrvacuum.test

📁 最新的sqlite3.6.2源代码
💻 TEST
📖 第 1 页 / 共 2 页
字号:
  # of tbl2 have to be moved to fill the gap.  #  do_test incrvacuum-6.${jj}.1 {    execsql {      DROP TABLE IF EXISTS tbl1;      DROP TABLE IF EXISTS tbl2;      PRAGMA incremental_vacuum;      CREATE TABLE tbl1(a, b);      CREATE TABLE tbl2(a, b);      BEGIN;    }    for {set ii 0} {$ii < 1000} {incr ii} {      db eval {INSERT INTO tbl1 VALUES($ii, $ii || $ii)}    }    execsql {      INSERT INTO tbl2 SELECT * FROM tbl1;      COMMIT;      DROP TABLE tbl1;    }    expr {[file size test.db] / 1024}  } {36}  # Run a linear scan query on tbl2. After reading ($jj*100) rows,   # run the incremental vacuum to shrink the database.  #  do_test incrvacuum-6.${jj}.2 {    set ::nRow 0    db eval {SELECT a FROM tbl2} {} {      if {$a == [expr $jj*100]} {        db eval {PRAGMA incremental_vacuum}      }      incr ::nRow    }    list [expr {[file size test.db] / 1024}] $nRow  } {19 1000}}#---------------------------------------------------------------------# This test - incrvacuum-7.* - is to check that the database can be# written in the middle of an incremental vacuum.#set ::iWrite 1while 1 {  do_test incrvacuum-7.${::iWrite}.1 {    execsql {      DROP TABLE IF EXISTS tbl1;      DROP TABLE IF EXISTS tbl2;      PRAGMA incremental_vacuum;      CREATE TABLE tbl1(a, b);      CREATE TABLE tbl2(a, b);      BEGIN;    }    for {set ii 0} {$ii < 1000} {incr ii} {      db eval {INSERT INTO tbl1 VALUES($ii, $ii || $ii)}    }    execsql {      INSERT INTO tbl2 SELECT * FROM tbl1;      COMMIT;      DROP TABLE tbl1;    }    expr {[file size test.db] / 1024}  } {36}  do_test incrvacuum-7.${::iWrite}.2 {    set ::nRow 0    db eval {PRAGMA incremental_vacuum} {      incr ::nRow      if {$::nRow == $::iWrite} {        db eval {          CREATE TABLE tbl1(a, b);          INSERT INTO tbl1 VALUES('hello', 'world');        }      }    }    list [expr {[file size test.db] / 1024}]  } {20}  do_test incrvacuum-7.${::iWrite}.3 {    execsql {      SELECT * FROM tbl1;    }  } {hello world}  if {$::nRow == $::iWrite} break  incr ::iWrite}#---------------------------------------------------------------------# This test - incrvacuum-8.* - is to check that nothing goes wrong# with an incremental-vacuum if it is the first statement executed# after an existing database is opened.## At one point, this would always return SQLITE_SCHEMA (which # causes an infinite loop in tclsqlite.c if using the Tcl interface).#do_test incrvacuum-8.1 {  db close  sqlite3 db test.db  execsql {    PRAGMA incremental_vacuum(50);  }} {}#---------------------------------------------------------------------# At one point this test case was causing an assert() to fail.#do_test incrvacuum-9.1 {  db close  file delete -force test.db test.db-journal  sqlite3 db test.db  execsql {    PRAGMA auto_vacuum = 'incremental';    CREATE TABLE t1(a, b, c);    CREATE TABLE t2(a, b, c);    INSERT INTO t2 VALUES(randstr(500,500),randstr(500,500),randstr(500,500));    INSERT INTO t1 VALUES(1, 2, 3);    INSERT INTO t1 SELECT a||a, b||b, c||c FROM t1;    INSERT INTO t1 SELECT a||a, b||b, c||c FROM t1;    INSERT INTO t1 SELECT a||a, b||b, c||c FROM t1;    INSERT INTO t1 SELECT a||a, b||b, c||c FROM t1;    INSERT INTO t1 SELECT a||a, b||b, c||c FROM t1;    INSERT INTO t1 SELECT a||a, b||b, c||c FROM t1;    INSERT INTO t1 SELECT a||a, b||b, c||c FROM t1;    INSERT INTO t1 SELECT a||a, b||b, c||c FROM t1;  }} {}do_test incrvacuum-9.2 {  execsql {    PRAGMA synchronous = 'OFF';    BEGIN;    UPDATE t1 SET a = a, b = b, c = c;    DROP TABLE t2;    PRAGMA incremental_vacuum(10);    ROLLBACK;  }} {}do_test incrvacuum-9.3 {  execsql {    PRAGMA cache_size = 10;    BEGIN;    UPDATE t1 SET a = a, b = b, c = c;    DROP TABLE t2;    PRAGMA incremental_vacuum(10);    ROLLBACK;  }} {}#---------------------------------------------------------------------# Test that the parameter to the incremental_vacuum pragma works. That# is, if the user executes "PRAGMA incremental_vacuum(N)", at most# N pages are vacuumed.#do_test incrvacuum-10.1 {  execsql {    DROP TABLE t1;    DROP TABLE t2;  }  expr [file size test.db] / 1024} {29}do_test incrvacuum-10.2 {  execsql {    PRAGMA incremental_vacuum(1);  }  expr [file size test.db] / 1024} {28}do_test incrvacuum-10.3 {  execsql {    PRAGMA incremental_vacuum(5);  }  expr [file size test.db] / 1024} {23}do_test incrvacuum-10.4 {  execsql {    PRAGMA incremental_vacuum('1');  }  expr [file size test.db] / 1024} {22}do_test incrvacuum-10.5 {  execsql {    PRAGMA incremental_vacuum("+3");  }  expr [file size test.db] / 1024} {19}do_test incrvacuum-10.6 {  execsql {    PRAGMA incremental_vacuum = 1;  }  expr [file size test.db] / 1024} {18}do_test incrvacuum-10.7 {  # Use a really big number as an argument to incremetal_vacuum. Should  # be interpreted as "free all possible space".  execsql {    PRAGMA incremental_vacuum(2147483649);  }  expr [file size test.db] / 1024} {1}do_test incrvacuum-10.8 {  execsql {    CREATE TABLE t1(x);    INSERT INTO t1 VALUES(hex(randomblob(1000)));    DROP TABLE t1;  }  # A negative number means free all possible space.  execsql {    PRAGMA incremental_vacuum=-1;  }  expr [file size test.db] / 1024} {1}#----------------------------------------------------------------# Test that if we set the auto_vacuum mode to 'incremental', then# create a database, thereafter that database defaults to incremental # vacuum mode.#db closefile delete -force test.db test.db-journalsqlite3 db test.dbifcapable default_autovacuum {  do_test incrvacuum-11.1-av-dflt-on {    execsql {      PRAGMA auto_vacuum;    }  } {1}} else {  do_test incrvacuum-11.1-av-dflt-off {    execsql {      PRAGMA auto_vacuum;    }  } {0}}do_test incrvacuum-11.2 {  execsql {    PRAGMA auto_vacuum = incremental;  }} {}do_test incrvacuum-11.3 {  execsql {    PRAGMA auto_vacuum;  }} {2}do_test incrvacuum-11.4 {  # The database has now been created.  expr {[file size test.db]>0}} {1}do_test incrvacuum-11.5 {  # Close and reopen the connection.  db close  sqlite3 db test.db  # Test we are still in incremental vacuum mode.  execsql { PRAGMA auto_vacuum; }} {2}do_test incrvacuum-11.6 {  execsql {    PRAGMA auto_vacuum = 'full';    PRAGMA auto_vacuum;  }} {1}do_test incrvacuum-11.7 {  # Close and reopen the connection.  db close  sqlite3 db test.db  # Test we are still in "full" auto-vacuum mode.  execsql { PRAGMA auto_vacuum; }} {1}#----------------------------------------------------------------------# Special case: What happens if the database is locked when a "PRAGMA# auto_vacuum = XXX" statement is executed.#db closefile delete -force test.db test.db-journalsqlite3 db test.dbdo_test incrvacuum-12.1 {  execsql {    PRAGMA auto_vacuum = 1;  }  expr {[file size test.db]>0}} {1}# Try to change the auto-vacuum from "full" to "incremental" while the# database is locked. Nothing should change.#do_test incrvacuum-12.2 {  sqlite3 db2 test.db  execsql { BEGIN EXCLUSIVE; } db2  catchsql { PRAGMA auto_vacuum = 2; }} {1 {database is locked}}do_test incrvacuum-12.3 {  execsql { ROLLBACK; } db2  execsql { PRAGMA auto_vacuum }} {1}do_test incrvacuum-12.3 {  execsql { SELECT * FROM sqlite_master }  execsql { PRAGMA auto_vacuum }} {1}#----------------------------------------------------------------------# Special case #2: What if one process prepares a "PRAGMA auto_vacuum = XXX"# statement when the database is empty, but doesn't execute it until# after some other process has created the database.#db2 closedb closefile delete -force test.db test.db-journalsqlite3 db test.db  ;  set ::DB [sqlite3_connection_pointer db]sqlite3 db2 test.dbdo_test incrvacuum-13.1 {  # File size is sometimes 1 instead of 0 due to the hack we put in  # to work around ticket #3260.  Search for comments on #3260 in  # os_unix.c.  expr {[file size test.db]>1}} {0}do_test incrvacuum-13.2 {  set ::STMT [sqlite3_prepare $::DB {PRAGMA auto_vacuum = 2} -1 DUMMY]  execsql {    PRAGMA auto_vacuum = none;    PRAGMA default_cache_size = 1024;    PRAGMA auto_vacuum;  } db2} {0}do_test incrvacuum-13.3 {  expr {[file size test.db]>0}} {1}do_test incrvacuum-13.4 {  set rc [sqlite3_step $::STMT]  list $rc [sqlite3_finalize $::STMT]} {SQLITE_DONE SQLITE_OK}do_test incrvacuum-13.5 {  execsql {    PRAGMA auto_vacuum;  }} {0}# Verify that the incremental_vacuum pragma fails gracefully if it# is used against an invalid database file.#do_test incrvacuum-14.1 {  set out [open invalid.db w]  puts $out "This is not an SQLite database file"  close $out  sqlite3 db3 invalid.db  catchsql {    PRAGMA incremental_vacuum(10);  } db3} {1 {file is encrypted or is not a database}}db2 closedb3 closefinish_test

⌨️ 快捷键说明

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