1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2001
4
# Sleepycat Software. All rights reserved.
6
# $Id: test059.tcl,v 11.13 2001/01/25 18:23:12 bostic Exp $
9
# Make sure that we handle retrieves of zero-length data items correctly.
10
# The following ops, should allow a partial data retrieve of 0-length.
12
# db_cget FIRST, NEXT, LAST, PREV, CURRENT, SET, SET_RANGE
14
proc test059 { method args } {
17
set args [convert_args $method $args]
18
set omethod [convert_method $method]
20
puts "Test059: $method 0-length partial data retrieval"
22
# Create the database and open the dictionary
23
set eindex [lsearch -exact $args "-env"]
25
# If we are using an env, then testfile should just be the db name.
26
# Otherwise it is the test directory and the name.
27
if { $eindex == -1 } {
28
set testfile $testdir/test059.db
31
set testfile test059.db
33
set env [lindex $args $eindex]
42
if { [is_record_based $method] == 1 } {
43
append gflags " -recno"
46
puts "\tTest059.a: Populate a database"
47
set oflags "-create -truncate -mode 0644 $omethod $args $testfile"
48
set db [eval {berkdb_open} $oflags]
49
error_check_good db_create [is_substr $db db] 1
51
# Put ten keys in the database
52
for { set key 1 } { $key <= 10 } {incr key} {
53
set r [eval {$db put} $txn $pflags {$key datum$key}]
54
error_check_good put $r 0
57
# Retrieve keys sequentially so we can figure out their order
60
error_check_good db_curs [is_substr $curs $db] 1
62
for {set d [$curs get -first] } { [llength $d] != 0 } {
63
set d [$curs get -next] } {
64
set key_set($i) [lindex [lindex $d 0] 0]
68
puts "\tTest059.a: db get with 0 partial length retrieve"
70
# Now set the cursor on the middle one.
71
set ret [eval {$db get -partial {0 0}} $gflags {$key_set(5)}]
72
error_check_bad db_get_0 [llength $ret] 0
74
puts "\tTest059.a: db cget FIRST with 0 partial length retrieve"
75
set ret [$curs get -first -partial {0 0}]
76
set data [lindex [lindex $ret 0] 1]
77
set key [lindex [lindex $ret 0] 0]
78
error_check_good key_check_first $key $key_set(1)
79
error_check_good db_cget_first [string length $data] 0
81
puts "\tTest059.b: db cget NEXT with 0 partial length retrieve"
82
set ret [$curs get -next -partial {0 0}]
83
set data [lindex [lindex $ret 0] 1]
84
set key [lindex [lindex $ret 0] 0]
85
error_check_good key_check_next $key $key_set(2)
86
error_check_good db_cget_next [string length $data] 0
88
puts "\tTest059.c: db cget LAST with 0 partial length retrieve"
89
set ret [$curs get -last -partial {0 0}]
90
set data [lindex [lindex $ret 0] 1]
91
set key [lindex [lindex $ret 0] 0]
92
error_check_good key_check_last $key $key_set(10)
93
error_check_good db_cget_last [string length $data] 0
95
puts "\tTest059.d: db cget PREV with 0 partial length retrieve"
96
set ret [$curs get -prev -partial {0 0}]
97
set data [lindex [lindex $ret 0] 1]
98
set key [lindex [lindex $ret 0] 0]
99
error_check_good key_check_prev $key $key_set(9)
100
error_check_good db_cget_prev [string length $data] 0
102
puts "\tTest059.e: db cget CURRENT with 0 partial length retrieve"
103
set ret [$curs get -current -partial {0 0}]
104
set data [lindex [lindex $ret 0] 1]
105
set key [lindex [lindex $ret 0] 0]
106
error_check_good key_check_current $key $key_set(9)
107
error_check_good db_cget_current [string length $data] 0
109
puts "\tTest059.f: db cget SET with 0 partial length retrieve"
110
set ret [$curs get -set -partial {0 0} $key_set(7)]
111
set data [lindex [lindex $ret 0] 1]
112
set key [lindex [lindex $ret 0] 0]
113
error_check_good key_check_set $key $key_set(7)
114
error_check_good db_cget_set [string length $data] 0
116
if {[is_btree $method] == 1} {
118
db cget SET_RANGE with 0 partial length retrieve"
119
set ret [$curs get -set_range -partial {0 0} $key_set(5)]
120
set data [lindex [lindex $ret 0] 1]
121
set key [lindex [lindex $ret 0] 0]
122
error_check_good key_check_set $key $key_set(5)
123
error_check_good db_cget_set [string length $data] 0
126
error_check_good curs_close [$curs close] 0
127
error_check_good db_close [$db close] 0