1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 1996-2009 Oracle. All rights reserved. 4# 5# $Id$ 6# 7# TEST test059 8# TEST Cursor ops work with a partial length of 0. 9# TEST Make sure that we handle retrieves of zero-length data items correctly. 10# TEST The following ops, should allow a partial data retrieve of 0-length. 11# TEST db_get 12# TEST db_cget FIRST, NEXT, LAST, PREV, CURRENT, SET, SET_RANGE 13proc test059 { method args } { 14 source ./include.tcl 15 16 set args [convert_args $method $args] 17 set omethod [convert_method $method] 18 19 puts "Test059: $method 0-length partial data retrieval" 20 21 # Create the database and open the dictionary 22 set txnenv 0 23 set eindex [lsearch -exact $args "-env"] 24 # 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 29 set env NULL 30 } else { 31 set testfile test059.db 32 incr eindex 33 set env [lindex $args $eindex] 34 set txnenv [is_txnenv $env] 35 if { $txnenv == 1 } { 36 append args " -auto_commit " 37 } 38 set testdir [get_home $env] 39 } 40 cleanup $testdir $env 41 42 set pflags "" 43 set gflags "" 44 set txn "" 45 set count 0 46 47 if { [is_record_based $method] == 1 } { 48 append gflags " -recno" 49 } 50 51 puts "\tTest059.a: Populate a database" 52 set oflags "-create -mode 0644 $omethod $args $testfile" 53 set db [eval {berkdb_open} $oflags] 54 error_check_good db_create [is_substr $db db] 1 55 56 # Put ten keys in the database 57 for { set key 1 } { $key <= 10 } {incr key} { 58 if { $txnenv == 1 } { 59 set t [$env txn] 60 error_check_good txn [is_valid_txn $t $env] TRUE 61 set txn "-txn $t" 62 } 63 set r [eval {$db put} $txn $pflags {$key datum$key}] 64 error_check_good put $r 0 65 if { $txnenv == 1 } { 66 error_check_good txn [$t commit] 0 67 } 68 } 69 70 # Retrieve keys sequentially so we can figure out their order 71 set i 1 72 if { $txnenv == 1 } { 73 set t [$env txn] 74 error_check_good txn [is_valid_txn $t $env] TRUE 75 set txn "-txn $t" 76 } 77 set curs [eval {$db cursor} $txn] 78 error_check_good db_curs [is_valid_cursor $curs $db] TRUE 79 80 for {set d [$curs get -first] } { [llength $d] != 0 } { 81 set d [$curs get -next] } { 82 set key_set($i) [lindex [lindex $d 0] 0] 83 incr i 84 } 85 86 puts "\tTest059.a: db get with 0 partial length retrieve" 87 88 # Now set the cursor on the middle one. 89 set ret [eval {$db get -partial {0 0}} $txn $gflags {$key_set(5)}] 90 error_check_bad db_get_0 [llength $ret] 0 91 92 puts "\tTest059.a: db cget FIRST with 0 partial length retrieve" 93 set ret [$curs get -first -partial {0 0}] 94 set data [lindex [lindex $ret 0] 1] 95 set key [lindex [lindex $ret 0] 0] 96 error_check_good key_check_first $key $key_set(1) 97 error_check_good db_cget_first [string length $data] 0 98 99 puts "\tTest059.b: db cget NEXT with 0 partial length retrieve" 100 set ret [$curs get -next -partial {0 0}] 101 set data [lindex [lindex $ret 0] 1] 102 set key [lindex [lindex $ret 0] 0] 103 error_check_good key_check_next $key $key_set(2) 104 error_check_good db_cget_next [string length $data] 0 105 106 puts "\tTest059.c: db cget LAST with 0 partial length retrieve" 107 set ret [$curs get -last -partial {0 0}] 108 set data [lindex [lindex $ret 0] 1] 109 set key [lindex [lindex $ret 0] 0] 110 error_check_good key_check_last $key $key_set(10) 111 error_check_good db_cget_last [string length $data] 0 112 113 puts "\tTest059.d: db cget PREV with 0 partial length retrieve" 114 set ret [$curs get -prev -partial {0 0}] 115 set data [lindex [lindex $ret 0] 1] 116 set key [lindex [lindex $ret 0] 0] 117 error_check_good key_check_prev $key $key_set(9) 118 error_check_good db_cget_prev [string length $data] 0 119 120 puts "\tTest059.e: db cget CURRENT with 0 partial length retrieve" 121 set ret [$curs get -current -partial {0 0}] 122 set data [lindex [lindex $ret 0] 1] 123 set key [lindex [lindex $ret 0] 0] 124 error_check_good key_check_current $key $key_set(9) 125 error_check_good db_cget_current [string length $data] 0 126 127 puts "\tTest059.f: db cget SET with 0 partial length retrieve" 128 set ret [$curs get -set -partial {0 0} $key_set(7)] 129 set data [lindex [lindex $ret 0] 1] 130 set key [lindex [lindex $ret 0] 0] 131 error_check_good key_check_set $key $key_set(7) 132 error_check_good db_cget_set [string length $data] 0 133 134 if {[is_btree $method] == 1} { 135 puts "\tTest059.g:\ 136 db cget SET_RANGE with 0 partial length retrieve" 137 set ret [$curs get -set_range -partial {0 0} $key_set(5)] 138 set data [lindex [lindex $ret 0] 1] 139 set key [lindex [lindex $ret 0] 0] 140 error_check_good key_check_set $key $key_set(5) 141 error_check_good db_cget_set [string length $data] 0 142 } 143 144 error_check_good curs_close [$curs close] 0 145 if { $txnenv == 1 } { 146 error_check_good txn [$t commit] 0 147 } 148 error_check_good db_close [$db close] 0 149} 150