1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2002
4
# Sleepycat Software. All rights reserved.
10
# TEST Test of DB->get and DBC->c_get with set_recno and get_recno.
12
# TEST Populate a small btree -recnum database.
13
# TEST After all are entered, retrieve each using -recno with DB->get.
14
# TEST Open a cursor and do the same for DBC->c_get with set_recno.
15
# TEST Verify that set_recno sets the record number position properly.
16
# TEST Verify that get_recno returns the correct record numbers.
17
proc test099 { method {nentries 10000} args } {
20
set args [convert_args $method $args]
21
set omethod [convert_method $method]
23
puts "Test099: Test of set_recno and get_recno in DBC->c_get."
24
if { [is_rbtree $method] != 1 } {
25
puts "Test099: skipping for method $method."
30
set eindex [lsearch -exact $args "-env"]
32
# If we are using an env, then testfile should just be the db name.
33
# Otherwise it is the test directory and the name.
34
if { $eindex == -1 } {
35
set testfile $testdir/test099.db
38
set testfile test099.db
40
set env [lindex $args $eindex]
41
set txnenv [is_txnenv $env]
43
append args " -auto_commit "
45
# If we are using txns and running with the
46
# default, set the default down a bit.
48
if { $nentries == 10000 } {
52
set testdir [get_home $env]
57
# Create the database and open the dictionary
58
set db [eval {berkdb_open \
59
-create -mode 0644} $args {$omethod $testfile}]
60
error_check_good dbopen [is_valid_db $db] TRUE
69
append gflags " -recno"
71
puts "\tTest099.a: put loop"
72
# Here is the loop where we put each key/data pair
73
while { [gets $did str] != -1 && $count < $nentries } {
75
# set key [expr $count]
76
# set kvals($key) [pad_data $method $str]
80
error_check_good txn [is_valid_txn $t $env] TRUE
83
set r [eval {$db put} \
84
$txn $pflags {$key [chop_data $method $str]}]
85
error_check_good db_put $r 0
87
error_check_good txn [$t commit] 0
93
puts "\tTest099.b: dump file"
96
error_check_good txn [is_valid_txn $t $env] TRUE
99
dump_file $db $txn $t1 test099.check
100
if { $txnenv == 1 } {
101
error_check_good txn [$t commit] 0
103
error_check_good db_close [$db close] 0
105
puts "\tTest099.c: Test set_recno then get_recno"
106
set db [eval {berkdb_open -rdonly} $args $omethod $testfile ]
107
error_check_good dbopen [is_valid_db $db] TRUE
110
if { $txnenv == 1 } {
112
error_check_good txn [is_valid_txn $t $env] TRUE
115
set dbc [eval {$db cursor} $txn]
116
error_check_good db_cursor [is_substr $dbc $db] 1
121
# Create key(recno) array to use for later comparison
122
while { [gets $did str] != -1 } {
123
set kvals($recno) $str
128
set ret [$dbc get -first]
129
error_check_bad dbc_get_first [llength $ret] 0
131
# First walk forward through the database ....
132
while { $recno < $count } {
133
# Test set_recno: verify it sets the record number properly.
134
set current [$dbc get -current]
135
set r [$dbc get -set_recno $recno]
136
error_check_good set_recno $current $r
137
# Test set_recno: verify that we find the expected key
138
# at the current record number position.
139
set k [lindex [lindex $r 0] 0]
140
error_check_good set_recno $kvals($recno) $k
142
# Test get_recno: verify that the return from
143
# get_recno matches the record number just set.
144
set g [$dbc get -get_recno]
145
error_check_good get_recno $recno $g
146
set ret [$dbc get -next]
150
# ... and then backward.
151
set recno [expr $count - 1]
152
while { $recno > 0 } {
153
# Test set_recno: verify that we find the expected key
154
# at the current record number position.
155
set r [$dbc get -set_recno $recno]
156
set k [lindex [lindex $r 0] 0]
157
error_check_good set_recno $kvals($recno) $k
159
# Test get_recno: verify that the return from
160
# get_recno matches the record number just set.
161
set g [$dbc get -get_recno]
162
error_check_good get_recno $recno $g
163
set recno [expr $recno - 1]
166
error_check_good cursor_close [$dbc close] 0
167
if { $txnenv == 1 } {
168
error_check_good txn [$t commit] 0
170
error_check_good db_close [$db close] 0
174
# Check function for dumped file; data should be fixed are identical
175
proc test099.check { key data } {
176
error_check_good "data mismatch for key $key" $key $data