btree3.test 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # 2001 November 22
  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. # This file implements regression tests for SQLite library. The
  12. # focus of this script is btree database backend
  13. #
  14. # In particular, this file tests a small part of the Delete logic
  15. # for the BTree backend. When a row is deleted from a table, the
  16. # cursor is suppose to be left pointing at either the previous or
  17. # next entry in that table. If the cursor is left pointing at the
  18. # next entry, then the next Next operation is ignored. So the
  19. # sequence of operations (Delete, Next) should always leave the
  20. # cursor pointing at the first entry past the one that was deleted.
  21. # This test is designed to verify that behavior.
  22. #
  23. # $Id: btree3.test,v 1.1 2001/11/23 00:24:12 drh Exp $
  24. set testdir [file dirname $argv0]
  25. source $testdir/tester.tcl
  26. if {[info commands btree_open]!=""} {
  27. # Open a test database.
  28. #
  29. file delete -force test1.bt
  30. file delete -force test1.bt-journal
  31. set b1 [btree_open test1.bt]
  32. btree_begin_transaction $::b1
  33. # Insert a few one records
  34. #
  35. set data {abcdefghijklmnopqrstuvwxyz0123456789}
  36. append data $data
  37. append data $data
  38. append data $data
  39. append data $data
  40. for {set k 2} {$k<=10} {incr k} {
  41. for {set j 1} {$j<=$k} {incr j} {
  42. set jkey [format %02d $j]
  43. btree_clear_table $::b1 2
  44. set ::c1 [btree_cursor $::b1 2 1]
  45. for {set i 1} {$i<=$k+1} {incr i} {
  46. set key [format %02d $i]
  47. do_test btree3-$k.$j.1.$i {
  48. btree_insert $::c1 $::key $::data
  49. } {}
  50. # btree_tree_dump $::b1 2
  51. }
  52. do_test btree3-$k.$j.2 {
  53. btree_move_to $::c1 $::jkey
  54. btree_key $::c1
  55. } $::jkey
  56. do_test btree3-$k.$j.3 {
  57. btree_delete $::c1
  58. } {}
  59. do_test btree3-$k.$j.4 {
  60. btree_next $::c1
  61. btree_key $::c1
  62. } [format %02d [expr $j+1]]
  63. btree_close_cursor $::c1
  64. }
  65. }
  66. btree_rollback $::b1
  67. btree_pager_ref_dump $::b1
  68. btree_close $::b1
  69. } ;# end if( not mem: and has pager_open command );
  70. finish_test