1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1999-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST DBcursor->c_get get test with SET_RANGE option.
10
proc test047 { method args } {
14
set args [convert_args $method $args]
16
if { [is_btree $method] != 1 } {
17
puts "Test$tstn skipping for method $method"
23
puts "\tTest$tstn: Test of SET_RANGE interface to DB->c_get ($method)."
30
puts "\tTest$tstn.a: Create $method database."
31
set eindex [lsearch -exact $args "-env"]
34
# If we are using an env, then testfile should just be the db name.
35
# Otherwise it is the test directory and the name.
36
if { $eindex == -1 } {
37
set testfile $testdir/test0$tstn.db
38
set testfile1 $testdir/test0$tstn.a.db
39
set testfile2 $testdir/test0$tstn.b.db
42
set testfile test0$tstn.db
43
set testfile1 test0$tstn.a.db
44
set testfile2 test0$tstn.b.db
46
set env [lindex $args $eindex]
47
set txnenv [is_txnenv $env]
49
append args " -auto_commit "
51
set testdir [get_home $env]
56
set oflags "-create -mode 0644 -dup $args $method"
57
set db [eval {berkdb_open} $oflags $testfile]
58
error_check_good dbopen [is_valid_db $db] TRUE
61
# Fill page w/ small key/data pairs
63
puts "\tTest$tstn.b: Fill page with $nkeys small key/data pairs."
64
for { set i 0 } { $i < $nkeys } { incr i } {
67
error_check_good txn [is_valid_txn $t $env] TRUE
70
set ret [eval {$db put} $txn {$key$i $data$i}]
71
error_check_good dbput $ret 0
73
error_check_good txn [$t commit] 0
79
error_check_good txn [is_valid_txn $t $env] TRUE
83
set dbc [eval {$db cursor} $txn]
84
error_check_good db_cursor [is_valid_cursor $dbc $db] TRUE
86
puts "\tTest$tstn.c: Get data with SET_RANGE, then delete by cursor."
88
set ret [$dbc get -set_range $key$i]
89
error_check_bad dbc_get:set_range [llength $ret] 0
92
# delete by cursor, make sure it is gone
93
error_check_good dbc_del [$dbc del] 0
95
set ret [$dbc get -set_range $key$i]
96
error_check_bad dbc_get(post-delete):set_range [llength $ret] 0
97
error_check_bad dbc_get(no-match):set_range $ret $curr
99
puts "\tTest$tstn.d: \
100
Use another cursor to fix item on page, delete by db."
101
set dbcurs2 [eval {$db cursor} $txn]
102
error_check_good db:cursor2 [is_valid_cursor $dbcurs2 $db] TRUE
104
set ret [$dbcurs2 get -set [lindex [lindex $ret 0] 0]]
105
error_check_bad dbc_get(2):set [llength $ret] 0
107
error_check_good db:del [eval {$db del} $txn \
108
{[lindex [lindex $ret 0] 0]}] 0
110
# make sure item is gone
111
set ret [$dbcurs2 get -set_range [lindex [lindex $curr 0] 0]]
112
error_check_bad dbc2_get:set_range [llength $ret] 0
113
error_check_bad dbc2_get:set_range $ret $curr
115
puts "\tTest$tstn.e: Close for second part of test, close db/cursors."
116
error_check_good dbc:close [$dbc close] 0
117
error_check_good dbc2:close [$dbcurs2 close] 0
118
if { $txnenv == 1 } {
119
error_check_good txn [$t commit] 0
121
error_check_good dbclose [$db close] 0
124
set db [eval {berkdb_open} $oflags $testfile1]
125
error_check_good dbopen2 [is_valid_db $db] TRUE
128
puts "\tTest$tstn.f: Fill page with $nkeys pairs, one set of dups."
129
for {set i 0} { $i < $nkeys } {incr i} {
131
if { $txnenv == 1 } {
133
error_check_good txn [is_valid_txn $t $env] TRUE
136
set ret [eval {$db put} $txn {$key$i $data$i}]
137
error_check_good dbput($i) $ret 0
138
if { $txnenv == 1 } {
139
error_check_good txn [$t commit] 0
144
for {set i 0} { $i < $nkeys } {incr i} {
145
# a dup set for same 1 key
146
if { $txnenv == 1 } {
148
error_check_good txn [is_valid_txn $t $env] TRUE
151
set ret [eval {$db put} $txn {$key$i DUP_$data$i}]
152
error_check_good dbput($i):dup $ret 0
153
if { $txnenv == 1 } {
154
error_check_good txn [$t commit] 0
158
puts "\tTest$tstn.g: \
159
Get dups key w/ SET_RANGE, pin onpage with another cursor."
161
if { $txnenv == 1 } {
163
error_check_good txn [is_valid_txn $t $env] TRUE
166
set dbc [eval {$db cursor} $txn]
167
error_check_good db_cursor [is_valid_cursor $dbc $db] TRUE
168
set ret [$dbc get -set_range $key$i]
169
error_check_bad dbc_get:set_range [llength $ret] 0
171
set dbc2 [eval {$db cursor} $txn]
172
error_check_good db_cursor [is_valid_cursor $dbc2 $db] TRUE
173
set ret2 [$dbc2 get -set_range $key$i]
174
error_check_bad dbc2_get:set_range [llength $ret] 0
176
error_check_good dbc_compare $ret $ret2
177
puts "\tTest$tstn.h: \
178
Delete duplicates' key, use SET_RANGE to get next dup."
180
error_check_good dbc2_del $ret 0
181
set ret [$dbc get -set_range $key$i]
182
error_check_bad dbc_get:set_range [llength $ret] 0
183
error_check_bad dbc_get:set_range $ret $ret2
185
error_check_good dbc_close [$dbc close] 0
186
error_check_good dbc2_close [$dbc2 close] 0
187
if { $txnenv == 1 } {
188
error_check_good txn [$t commit] 0
190
error_check_good db_close [$db close] 0
192
set db [eval {berkdb_open} $oflags $testfile2]
193
error_check_good dbopen [is_valid_db $db] TRUE
198
puts "\tTest$tstn.i: Fill page with $nkeys pairs and $ndups dups."
199
for {set i 0} { $i < $nkeys } { incr i} {
201
if { $txnenv == 1 } {
203
error_check_good txn [is_valid_txn $t $env] TRUE
206
set ret [eval {$db put} $txn {$key$i $data$i}]
207
error_check_good dbput $ret 0
209
# dups for single pair
211
for {set j 0} { $j < $ndups } { incr j } {
212
set ret [eval {$db put} $txn \
213
{$key$i DUP_$data$i:$j}]
214
error_check_good dbput:dup $ret 0
217
if { $txnenv == 1 } {
218
error_check_good txn [$t commit] 0
222
if { $txnenv == 1 } {
224
error_check_good txn [is_valid_txn $t $env] TRUE
227
set dbc [eval {$db cursor} $txn]
228
error_check_good db_cursor [is_valid_cursor $dbc $db] TRUE
229
set dbc2 [eval {$db cursor} $txn]
230
error_check_good db_cursor [is_valid_cursor $dbc2 $db] TRUE
231
puts "\tTest$tstn.j: \
232
Get key of first dup with SET_RANGE, fix with 2 curs."
233
set ret [$dbc get -set_range $key$i]
234
error_check_bad dbc_get:set_range [llength $ret] 0
236
set ret2 [$dbc2 get -set_range $key$i]
237
error_check_bad dbc2_get:set_range [llength $ret] 0
240
error_check_good dbc_compare $ret $ret2
242
puts "\tTest$tstn.k: Delete item by cursor, use SET_RANGE to verify."
244
error_check_good dbc2_del $ret 0
245
set ret [$dbc get -set_range $key$i]
246
error_check_bad dbc_get:set_range [llength $ret] 0
247
error_check_bad dbc_get:set_range $ret $curr
249
puts "\tTest$tstn.l: Cleanup."
250
error_check_good dbc_close [$dbc close] 0
251
error_check_good dbc2_close [$dbc2 close] 0
252
if { $txnenv == 1 } {
253
error_check_good txn [$t commit] 0
255
error_check_good db_close [$db close] 0
257
puts "\tTest$tstn complete."