backup4.test 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # 2012 October 13
  2. #
  3. # The author disclaims copyright to this source code. In place of
  4. # a legal notice, here is a blessing:
  5. #
  6. # May you do good and not evil.
  7. # May you find forgiveness for yourself and forgive others.
  8. # May you share freely, never taking more than you give.
  9. #
  10. #***********************************************************************
  11. #
  12. # The tests in this file verify that if an empty database (zero bytes in
  13. # size) is used as the source of a backup operation, the final destination
  14. # database is one page in size.
  15. #
  16. # The destination must consist of at least one page as truncating a
  17. # database file to zero bytes is equivalent to resetting the database
  18. # schema cookie and change counter. Doing that could cause other clients
  19. # to become confused and continue using out-of-date cache data.
  20. #
  21. set testdir [file dirname $argv0]
  22. source $testdir/tester.tcl
  23. set testprefix backup4
  24. #-------------------------------------------------------------------------
  25. # At one point this test was failing because [db] was using an out of
  26. # date schema in test case 1.2.
  27. #
  28. do_execsql_test 1.0 {
  29. CREATE TABLE t1(x, y, UNIQUE(x, y));
  30. INSERT INTO t1 VALUES('one', 'two');
  31. SELECT * FROM t1 WHERE x='one';
  32. PRAGMA integrity_check;
  33. } {one two ok}
  34. do_test 1.1 {
  35. sqlite3 db1 :memory:
  36. db1 backup test.db
  37. sqlite3 db1 test.db
  38. db1 eval {
  39. CREATE TABLE t1(x, y);
  40. INSERT INTO t1 VALUES('one', 'two');
  41. }
  42. db1 close
  43. } {}
  44. do_execsql_test 1.2 {
  45. SELECT * FROM t1 WHERE x='one';
  46. PRAGMA integrity_check;
  47. } {one two ok}
  48. db close
  49. forcedelete test.db
  50. forcedelete test.db2
  51. sqlite3 db test.db
  52. #-------------------------------------------------------------------------
  53. # Test that if the source is zero bytes, the destination database
  54. # consists of a single page only.
  55. #
  56. do_execsql_test 2.1 {
  57. CREATE TABLE t1(a, b);
  58. CREATE INDEX i1 ON t1(a, b);
  59. }
  60. do_test 2.2 { file size test.db } [expr $AUTOVACUUM ? 4096 : 3072]
  61. do_test 2.3 {
  62. sqlite3 db1 test.db2
  63. db1 backup test.db
  64. db1 close
  65. file size test.db
  66. } {1024}
  67. do_test 2.4 { file size test.db2 } 0
  68. db close
  69. forcedelete test.db
  70. forcedelete test.db2
  71. sqlite3 db test.db
  72. #-------------------------------------------------------------------------
  73. # Test that if the destination has a page-size larger than the implicit
  74. # page-size of the source, the final destination database still consists
  75. # of a single page.
  76. #
  77. do_execsql_test 3.1 {
  78. PRAGMA page_size = 4096;
  79. CREATE TABLE t1(a, b);
  80. CREATE INDEX i1 ON t1(a, b);
  81. }
  82. do_test 3.2 { file size test.db } [expr $AUTOVACUUM ? 16384 : 12288]
  83. do_test 3.3 {
  84. sqlite3 db1 test.db2
  85. db1 backup test.db
  86. db1 close
  87. file size test.db
  88. } {1024}
  89. do_test 3.4 { file size test.db2 } 0
  90. finish_test