rbumisc.test 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. # 2014 August 30
  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. source [file join [file dirname [info script]] rbu_common.tcl]
  13. if_no_rbu_support { finish_test ; return }
  14. set ::testprefix rbumisc
  15. proc populate_rbu_db {} {
  16. forcedelete rbu.db
  17. sqlite3 rbu rbu.db
  18. rbu eval {
  19. CREATE TABLE data_x1(a, b, c, rbu_control);
  20. INSERT INTO data_x1 VALUES(1, 1, 1, 0);
  21. INSERT INTO data_x1 VALUES(2, 2, 2, 0);
  22. CREATE TABLE dat(a, b, c, rbu_control);
  23. CREATE TABLE "data x1"(a, b, c, rbu_control);
  24. CREATE TABLE datax1(a, b, c, rbu_control);
  25. CREATE TABLE data_(a, b, c, rbu_control);
  26. INSERT INTO "data x1" VALUES(3, 3, 3, 0);
  27. INSERT INTO datax1 VALUES(3, 3, 3, 0);
  28. INSERT INTO data_ VALUES(3, 3, 3, 0);
  29. INSERT INTO dat VALUES(3, 3, 3, 0);
  30. }
  31. rbu close
  32. }
  33. #-------------------------------------------------------------------------
  34. # Ensure that RBU is not confused by oddly named tables in an RBU
  35. # database.
  36. #
  37. do_execsql_test 1.0 {
  38. CREATE TABLE x1(a, b, c INTEGER PRIMARY KEY);
  39. }
  40. do_test 1.1 {
  41. populate_rbu_db
  42. } {}
  43. do_test 1.2 {
  44. step_rbu test.db rbu.db
  45. db eval { SELECT * FROM x1 }
  46. } {1 1 1 2 2 2}
  47. do_test 1.3 {
  48. db eval { DELETE FROM x1 }
  49. sqlite3 rbu rbu.db
  50. rbu eval { DELETE FROM rbu_state }
  51. rbu close
  52. step_rbu test.db rbu.db
  53. db eval { SELECT * FROM x1 }
  54. } {1 1 1 2 2 2}
  55. do_test 1.4 {
  56. db eval { DELETE FROM x1 }
  57. populate_rbu_db
  58. sqlite3rbu rbu test.db rbu.db
  59. rbu step
  60. rbu step
  61. rbu close
  62. forcecopy test.db-oal test.db-wal
  63. sqlite3rbu rbu test.db rbu.db
  64. rbu step
  65. list [catch { rbu close } msg] $msg
  66. } {1 {SQLITE_ERROR - cannot update wal mode database}}
  67. #-------------------------------------------------------------------------
  68. # Test the effect of a wal file appearing after the target database has
  69. # been opened, but before it has been locked.
  70. #
  71. catch { db close }
  72. testvfs tvfs -default 1
  73. for {set N 1} {$N < 10} {incr N} {
  74. reset_db
  75. populate_rbu_db
  76. do_execsql_test 2.$N.0 {
  77. CREATE TABLE x1(a, b, c INTEGER PRIMARY KEY);
  78. }
  79. set nAccessCnt 0
  80. do_test 2.$N.1 {
  81. sqlite3rbu rbu test.db rbu.db
  82. rbu step
  83. rbu step
  84. rbu close
  85. } {SQLITE_OK}
  86. tvfs script xAccess
  87. tvfs filter xAccess
  88. set nAccessCnt 0
  89. proc xAccess {method file args} {
  90. global nAccessCnt
  91. if {[file tail $file]=="test.db-wal"} {
  92. incr nAccessCnt -1
  93. if {$nAccessCnt==0} {
  94. set fd [open test.db-wal w]
  95. puts -nonewline $fd [string repeat 0 2000]
  96. close $fd
  97. }
  98. }
  99. return SQLITE_OK
  100. }
  101. foreach r {
  102. {1 {SQLITE_ERROR - cannot update wal mode database}}
  103. {0 SQLITE_OK}
  104. {1 {SQLITE_CANTOPEN - unable to open database file}}
  105. } {
  106. set RES($r) 1
  107. }
  108. do_test 2.$N.2 {
  109. set ::nAccessCnt $N
  110. set res [list [catch {
  111. sqlite3rbu rbu test.db rbu.db
  112. rbu step
  113. rbu close
  114. } msg ] $msg]
  115. set RES($res)
  116. } {1}
  117. catch {rbu close}
  118. }
  119. catch {db close}
  120. catch {tvfs delete}
  121. #-------------------------------------------------------------------------
  122. testvfs tvfs -default 1
  123. reset_db
  124. populate_rbu_db
  125. do_execsql_test 3.0 {
  126. CREATE TABLE x1(a, b, c INTEGER PRIMARY KEY);
  127. }
  128. tvfs script xFileControl
  129. tvfs filter xFileControl
  130. proc xFileControl {method file verb args} {
  131. if {$verb=="ZIPVFS" && [info exists ::zipvfs_filecontrol]} {
  132. return $::zipvfs_filecontrol
  133. }
  134. return "SQLITE_NOTFOUND"
  135. }
  136. breakpoint
  137. foreach {tn ret err} {
  138. 1 SQLITE_OK 0
  139. 2 SQLITE_ERROR 1
  140. 3 SQLITE_NOTFOUND 0
  141. 4 SQLITE_OMIT 1
  142. } {
  143. set ::zipvfs_filecontrol $ret
  144. do_test 3.$tn.1 {
  145. catch {
  146. sqlite3rbu rbu test.db rbu.db
  147. rbu step
  148. rbu close
  149. }
  150. } $err
  151. }
  152. catch {db close}
  153. catch {tvfs delete}
  154. #-------------------------------------------------------------------------
  155. finish_test