1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2001
4
# Sleepycat Software. All rights reserved.
6
# $Id: test057.tcl,v 11.18 2001/01/25 18:23:12 bostic Exp $
9
# Check if we handle the case where we delete a key with the cursor on it
10
# and then add the same key. The cursor should not get the new item
11
# returned, but the item shouldn't disappear.
12
# Run test tests, one where the overwriting put is done with a put and
13
# one where it's done with a cursor put.
14
proc test057 { method args } {
18
set args [convert_args $method $args]
19
set omethod [convert_method $method]
21
append args " -create -truncate -mode 0644 -dup "
22
if { [is_record_based $method] == 1 || [is_rbtree $method] == 1 } {
23
puts "Test057: skipping for method $method"
26
puts "Test057: $method delete and replace in presence of cursor."
28
# Create the database and open the dictionary
29
set eindex [lsearch -exact $args "-env"]
31
# If we are using an env, then testfile should just be the db name.
32
# Otherwise it is the test directory and the name.
33
if { $eindex == -1 } {
34
set testfile $testdir/test057.db
37
set testfile test057.db
39
set env [lindex $args $eindex]
46
set db [eval {berkdb_open} $args {$omethod $testfile}]
47
error_check_good dbopen:dup [is_valid_db $db] TRUE
49
set curs [eval {$db cursor} $txn]
50
error_check_good curs_open:dup [is_substr $curs $db] 1
52
puts "\tTest057.a: Set cursor, delete cursor, put with key."
53
# Put three keys in the database
54
for { set key 1 } { $key <= 3 } {incr key} {
55
set r [eval {$db put} $txn $flags {$key datum$key}]
56
error_check_good put $r 0
59
# Retrieve keys sequentially so we can figure out their order
61
for {set d [$curs get -first] } {[llength $d] != 0 } {\
62
set d [$curs get -next] } {
63
set key_set($i) [lindex [lindex $d 0] 0]
67
# Now put in a bunch of duplicates for key 2
68
for { set d 1 } { $d <= 5 } {incr d} {
69
set r [eval {$db put} $txn $flags {$key_set(2) dup_$d}]
70
error_check_good dup:put $r 0
73
# Now put the cursor on key 1
75
# Now set the cursor on the first of the duplicate set.
76
set r [$curs get -set $key_set(1)]
77
error_check_bad cursor_get:DB_SET [llength $r] 0
78
set k [lindex [lindex $r 0] 0]
79
set d [lindex [lindex $r 0] 1]
80
error_check_good curs_get:DB_SET:key $k $key_set(1)
81
error_check_good curs_get:DB_SET:data $d datum$key_set(1)
85
error_check_good delete $r 0
87
# Now check the get current on the cursor.
88
error_check_good curs_get:del [$curs get -current] [list [list [] []]]
90
# Now do a put on the key
91
set r [eval {$db put} $txn $flags {$key_set(1) new_datum$key_set(1)}]
92
error_check_good put $r 0
95
set r [eval {$db get} $txn {$key_set(1)}]
96
error_check_good get [lindex [lindex $r 0] 1] new_datum$key_set(1)
99
error_check_good curs_get:deleted [$curs get -current] [list [list [] []]]
101
# Move cursor and see if we get the key.
102
set r [$curs get -first]
103
error_check_bad cursor_get:DB_FIRST [llength $r] 0
104
set k [lindex [lindex $r 0] 0]
105
set d [lindex [lindex $r 0] 1]
106
error_check_good curs_get:DB_FIRST:key $k $key_set(1)
107
error_check_good curs_get:DB_FIRST:data $d new_datum$key_set(1)
109
puts "\tTest057.b: Set two cursor on a key, delete one, overwrite other"
110
set curs2 [eval {$db cursor} $txn]
111
error_check_good curs2_open [is_substr $curs2 $db] 1
113
# Set both cursors on the 4rd key
114
set r [$curs get -set $key_set(3)]
115
error_check_bad cursor_get:DB_SET [llength $r] 0
116
set k [lindex [lindex $r 0] 0]
117
set d [lindex [lindex $r 0] 1]
118
error_check_good curs_get:DB_SET:key $k $key_set(3)
119
error_check_good curs_get:DB_SET:data $d datum$key_set(3)
121
set r [$curs2 get -set $key_set(3)]
122
error_check_bad cursor2_get:DB_SET [llength $r] 0
123
set k [lindex [lindex $r 0] 0]
124
set d [lindex [lindex $r 0] 1]
125
error_check_good curs2_get:DB_SET:key $k $key_set(3)
126
error_check_good curs2_get:DB_SET:data $d datum$key_set(3)
128
# Now delete through cursor 1
129
error_check_good curs1_del [$curs del] 0
131
# Verify gets on both 1 and 2
132
error_check_good curs_get:deleted [$curs get -current] \
134
error_check_good curs_get:deleted [$curs2 get -current] \
137
# Now do a replace through cursor 2
138
set pflags "-current"
139
if {[is_hash $method] == 1} {
140
error_check_good curs1_get_after_del [is_substr \
141
[$curs2 put $pflags new_datum$key_set(3)] "DB_NOTFOUND"] 1
144
error_check_good curs1_get:deleted \
145
[$curs get -current] \
147
error_check_good curs2_get:deleted \
148
[$curs get -current] \
151
# btree only, recno is skipped this test
152
set ret [$curs2 put $pflags new_datum$key_set(3)]
153
error_check_good curs_replace $ret 0
157
#error_check_good curs1_get:deleted [catch {$curs get -current} r] 1
158
#error_check_good curs1_get_after_del \
159
[is_substr $errorInfo "DB_KEYEMPTY"] 1
160
#error_check_good curs2_get:deleted [catch {$curs2 get -current} r] 1
161
#error_check_good curs2_get_after_del \
162
[is_substr $errorInfo "DB_KEYEMPTY"] 1
165
Set two cursors on a dup, delete one, overwrite other"
167
# Set both cursors on the 2nd duplicate of key 2
168
set r [$curs get -set $key_set(2)]
169
error_check_bad cursor_get:DB_SET [llength $r] 0
170
set k [lindex [lindex $r 0] 0]
171
set d [lindex [lindex $r 0] 1]
172
error_check_good curs_get:DB_SET:key $k $key_set(2)
173
error_check_good curs_get:DB_SET:data $d datum$key_set(2)
175
set r [$curs get -next]
176
error_check_bad cursor_get:DB_NEXT [llength $r] 0
177
set k [lindex [lindex $r 0] 0]
178
set d [lindex [lindex $r 0] 1]
179
error_check_good curs_get:DB_NEXT:key $k $key_set(2)
180
error_check_good curs_get:DB_NEXT:data $d dup_1
182
set r [$curs2 get -set $key_set(2)]
183
error_check_bad cursor2_get:DB_SET [llength $r] 0
184
set k [lindex [lindex $r 0] 0]
185
set d [lindex [lindex $r 0] 1]
186
error_check_good curs2_get:DB_SET:key $k $key_set(2)
187
error_check_good curs2_get:DB_SET:data $d datum$key_set(2)
189
set r [$curs2 get -next]
190
error_check_bad cursor2_get:DB_NEXT [llength $r] 0
191
set k [lindex [lindex $r 0] 0]
192
set d [lindex [lindex $r 0] 1]
193
error_check_good curs2_get:DB_NEXT:key $k $key_set(2)
194
error_check_good curs2_get:DB_NEXT:data $d dup_1
196
# Now delete through cursor 1
197
error_check_good curs1_del [$curs del] 0
199
# Verify gets on both 1 and 2
200
error_check_good curs_get:deleted [$curs get -current] \
202
error_check_good curs_get:deleted [$curs2 get -current] \
205
# Now do a replace through cursor 2 -- this will work on btree but
207
if {[is_hash $method] == 1} {
208
error_check_good hash_replace \
209
[is_substr [$curs2 put -current new_dup_1] "DB_NOTFOUND"] 1
211
error_check_good curs_replace [$curs2 put -current new_dup_1] 0
214
# Both gets should fail
215
#error_check_good curs1_get:deleted [catch {$curs get -current} r] 1
216
#error_check_good curs1_get_after_del \
217
[is_substr $errorInfo "DB_KEYEMPTY"] 1
218
#error_check_good curs2_get:deleted [catch {$curs2 get -current} r] 1
219
#error_check_good curs2_get_after_del \
220
[is_substr $errorInfo "DB_KEYEMPTY"] 1
222
error_check_good curs2_close [$curs2 close] 0
223
error_check_good curs_close [$curs close] 0
224
error_check_good db_close [$db close] 0