1*4520Snw141292 2*4520Snw141292#pragma ident "%Z%%M% %I% %E% SMI" 3*4520Snw141292 4*4520Snw141292# 2001 November 22 5*4520Snw141292# 6*4520Snw141292# The author disclaims copyright to this source code. In place of 7*4520Snw141292# a legal notice, here is a blessing: 8*4520Snw141292# 9*4520Snw141292# May you do good and not evil. 10*4520Snw141292# May you find forgiveness for yourself and forgive others. 11*4520Snw141292# May you share freely, never taking more than you give. 12*4520Snw141292# 13*4520Snw141292#*********************************************************************** 14*4520Snw141292# This file implements regression tests for SQLite library. The 15*4520Snw141292# focus of this script is btree database backend 16*4520Snw141292# 17*4520Snw141292# In particular, this file tests a small part of the Delete logic 18*4520Snw141292# for the BTree backend. When a row is deleted from a table, the 19*4520Snw141292# cursor is suppose to be left pointing at either the previous or 20*4520Snw141292# next entry in that table. If the cursor is left pointing at the 21*4520Snw141292# next entry, then the next Next operation is ignored. So the 22*4520Snw141292# sequence of operations (Delete, Next) should always leave the 23*4520Snw141292# cursor pointing at the first entry past the one that was deleted. 24*4520Snw141292# This test is designed to verify that behavior. 25*4520Snw141292# 26*4520Snw141292# $Id: btree3.test,v 1.2 2002/12/04 13:40:27 drh Exp $ 27*4520Snw141292 28*4520Snw141292 29*4520Snw141292set testdir [file dirname $argv0] 30*4520Snw141292source $testdir/tester.tcl 31*4520Snw141292 32*4520Snw141292if {[info commands btree_open]!=""} { 33*4520Snw141292 34*4520Snw141292# Open a test database. 35*4520Snw141292# 36*4520Snw141292file delete -force test1.bt 37*4520Snw141292file delete -force test1.bt-journal 38*4520Snw141292set b1 [btree_open test1.bt] 39*4520Snw141292btree_begin_transaction $::b1 40*4520Snw141292 41*4520Snw141292# Insert a few one records 42*4520Snw141292# 43*4520Snw141292set data {abcdefghijklmnopqrstuvwxyz0123456789} 44*4520Snw141292append data $data 45*4520Snw141292append data $data 46*4520Snw141292append data $data 47*4520Snw141292append data $data 48*4520Snw141292for {set k 2} {$k<=10} {incr k} { 49*4520Snw141292 for {set j 1} {$j<=$k} {incr j} { 50*4520Snw141292 set jkey [format %02d $j] 51*4520Snw141292 btree_clear_table $::b1 2 52*4520Snw141292 set ::c1 [btree_cursor $::b1 2 1] 53*4520Snw141292 for {set i 1} {$i<=$k} {incr i} { 54*4520Snw141292 set key [format %02d $i] 55*4520Snw141292 do_test btree3-$k.$j.1.$i { 56*4520Snw141292 btree_insert $::c1 $::key $::data 57*4520Snw141292 } {} 58*4520Snw141292 # btree_tree_dump $::b1 2 59*4520Snw141292 } 60*4520Snw141292 do_test btree3-$k.$j.2 { 61*4520Snw141292 btree_move_to $::c1 $::jkey 62*4520Snw141292 btree_key $::c1 63*4520Snw141292 } $::jkey 64*4520Snw141292 do_test btree3-$k.$j.3 { 65*4520Snw141292 btree_delete $::c1 66*4520Snw141292 } {} 67*4520Snw141292 if {$j<$k} { 68*4520Snw141292 do_test btree3-$k.$j.4 { 69*4520Snw141292 btree_next $::c1 70*4520Snw141292 btree_key $::c1 71*4520Snw141292 } [format %02d [expr $j+1]] 72*4520Snw141292 } 73*4520Snw141292 if {$j>1} { 74*4520Snw141292 do_test btree3-$k.$j.5 { 75*4520Snw141292 btree_prev $::c1 76*4520Snw141292 btree_key $::c1 77*4520Snw141292 } [format %02d [expr $j-1]] 78*4520Snw141292 } 79*4520Snw141292 btree_close_cursor $::c1 80*4520Snw141292 } 81*4520Snw141292} 82*4520Snw141292 83*4520Snw141292btree_rollback $::b1 84*4520Snw141292btree_pager_ref_dump $::b1 85*4520Snw141292btree_close $::b1 86*4520Snw141292 87*4520Snw141292} ;# end if( not mem: and has pager_open command ); 88*4520Snw141292 89*4520Snw141292finish_test 90