test047.tcl
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:5k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. # See the file LICENSE for redistribution information.
  2. #
  3. # Copyright (c) 1999, 2000
  4. # Sleepycat Software.  All rights reserved.
  5. #
  6. # $Id: test047.tcl,v 11.10 2000/08/25 14:21:56 sue Exp $
  7. #
  8. # DB Test 47: test of the SET_RANGE interface to DB->c_get.
  9. proc test047 { method args } {
  10. source ./include.tcl
  11. set tstn 047
  12. if { [is_btree $method] != 1 } {
  13. puts "Test$tstn skipping for method $method"
  14. return
  15. }
  16. set method "-btree"
  17. puts "tTest$tstn: Test of SET_RANGE interface to DB->c_get ($method)."
  18. set key "key"
  19. set data "data"
  20. set txn ""
  21. set flags ""
  22. puts "tTest$tstn.a: Create $method database."
  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/test0$tstn.db
  29. set testfile1 $testdir/test0$tstn.a.db
  30. set testfile2 $testdir/test0$tstn.b.db
  31. set env NULL
  32. } else {
  33. set testfile test0$tstn.db
  34. set testfile1 test0$tstn.a.db
  35. set testfile2 test0$tstn.b.db
  36. incr eindex
  37. set env [lindex $args $eindex]
  38. }
  39. set t1 $testdir/t1
  40. cleanup $testdir $env
  41. set oflags "-create -truncate -mode 0644 -dup $args $method"
  42. set db [eval {berkdb_open} $oflags $testfile]
  43. error_check_good dbopen [is_valid_db $db] TRUE
  44. # open curs to db
  45. set dbc [$db cursor]
  46. error_check_good db_cursor [is_substr $dbc $db] 1
  47. set nkeys 20
  48. # Fill page w/ small key/data pairs
  49. #
  50. puts "tTest$tstn.b: Fill page with $nkeys small key/data pairs."
  51. for { set i 0 } { $i < $nkeys } { incr i } {
  52. set ret [$db put $key$i $data$i]
  53. error_check_good dbput $ret 0
  54. }
  55. puts "tTest$tstn.c: Get data with SET_RANGE, then delete by cursor."
  56. set i 0
  57. set ret [$dbc get -set_range $key$i]
  58. error_check_bad dbc_get:set_range [llength $ret] 0
  59. set curr $ret
  60. # delete by cursor, make sure it is gone
  61. error_check_good dbc_del [$dbc del] 0
  62. set ret [$dbc get -set_range $key$i]
  63. error_check_bad dbc_get(post-delete):set_range [llength $ret] 0
  64. error_check_bad dbc_get(no-match):set_range $ret $curr
  65. puts "tTest$tstn.d: 
  66.     Use another cursor to fix item on page, delete by db."
  67. set dbcurs2 [$db cursor]
  68. error_check_good db:cursor2 [is_substr $dbcurs2 $db] 1
  69. set ret [$dbcurs2 get -set [lindex [lindex $ret 0] 0]]
  70. error_check_bad dbc_get(2):set [llength $ret] 0
  71. set curr $ret
  72. error_check_good db:del [$db del [lindex [lindex $ret 0] 0]] 0
  73. # make sure item is gone
  74. set ret [$dbcurs2 get -set_range [lindex [lindex $curr 0] 0]]
  75. error_check_bad dbc2_get:set_range [llength $ret] 0
  76. error_check_bad dbc2_get:set_range $ret $curr
  77. puts "tTest$tstn.e: Close for second part of test, close db/cursors."
  78. error_check_good dbc:close [$dbc close] 0
  79. error_check_good dbc2:close [$dbcurs2 close] 0
  80. error_check_good dbclose [$db close] 0
  81. # open db
  82. set db [eval {berkdb_open} $oflags $testfile1]
  83. error_check_good dbopen2 [is_valid_db $db] TRUE
  84. set nkeys 10
  85. puts "tTest$tstn.f: Fill page with $nkeys pairs, one set of dups."
  86. for {set i 0} { $i < $nkeys } {incr i} {
  87. # a pair
  88. set ret [$db put $key$i $data$i]
  89. error_check_good dbput($i) $ret 0
  90. }
  91. set j 0
  92. for {set i 0} { $i < $nkeys } {incr i} {
  93. # a dup set for same  1 key
  94. set ret [$db put $key$i DUP_$data$i]
  95. error_check_good dbput($i):dup $ret 0
  96. }
  97. puts "tTest$tstn.g: 
  98.     Get dups key w/ SET_RANGE, pin onpage with another cursor."
  99. set i 0
  100. set dbc [$db cursor]
  101. error_check_good db_cursor [is_substr $dbc $db] 1
  102. set ret [$dbc get -set_range $key$i]
  103. error_check_bad dbc_get:set_range [llength $ret] 0
  104. set dbc2 [$db cursor]
  105. error_check_good db_cursor2 [is_substr $dbc2 $db] 1
  106. set ret2 [$dbc2 get -set_range $key$i]
  107. error_check_bad dbc2_get:set_range [llength $ret] 0
  108. error_check_good dbc_compare $ret $ret2
  109. puts "tTest$tstn.h: 
  110.     Delete duplicates' key, use SET_RANGE to get next dup."
  111. set ret [$dbc2 del]
  112. error_check_good dbc2_del $ret 0
  113. set ret [$dbc get -set_range $key$i]
  114. error_check_bad dbc_get:set_range [llength $ret] 0
  115. error_check_bad dbc_get:set_range $ret $ret2
  116. error_check_good dbc_close [$dbc close] 0
  117. error_check_good dbc2_close [$dbc2 close] 0
  118. error_check_good db_close [$db close] 0
  119. set db [eval {berkdb_open} $oflags $testfile2]
  120. error_check_good dbopen [is_valid_db $db] TRUE
  121. set dbc [$db cursor]
  122. error_check_good db_cursor [is_substr $dbc $db] 1
  123. set dbc2 [$db cursor]
  124. error_check_good db_cursor2 [is_substr $dbc2 $db] 1
  125. set nkeys 10
  126. set ndups 1000
  127. puts "tTest$tstn.i: Fill page with $nkeys pairs and $ndups dups."
  128. for {set i 0} { $i < $nkeys } { incr i} {
  129. # a pair
  130. set ret [$db put $key$i $data$i]
  131. error_check_good dbput $ret 0
  132. # dups for single pair
  133. if { $i == 0} {
  134. for {set j 0} { $j < $ndups } { incr j } {
  135. set ret [$db put $key$i DUP_$data$i:$j]
  136. error_check_good dbput:dup $ret 0
  137. }
  138. }
  139. }
  140. set i 0
  141. puts "tTest$tstn.j: 
  142.     Get key of first dup with SET_RANGE, fix with 2 curs."
  143. set ret [$dbc get -set_range $key$i]
  144. error_check_bad dbc_get:set_range [llength $ret] 0
  145. set ret2 [$dbc2 get -set_range $key$i]
  146. error_check_bad dbc2_get:set_range [llength $ret] 0
  147. set curr $ret2
  148. error_check_good dbc_compare $ret $ret2
  149. puts "tTest$tstn.k: Delete item by cursor, use SET_RANGE to verify."
  150. set ret [$dbc2 del]
  151. error_check_good dbc2_del $ret 0
  152. set ret [$dbc get -set_range $key$i]
  153. error_check_bad dbc_get:set_range [llength $ret] 0
  154. error_check_bad dbc_get:set_range $ret $curr
  155. puts "tTest$tstn.l: Cleanup."
  156. error_check_good dbc_close [$dbc close] 0
  157. error_check_good dbc2_close [$dbc2 close] 0
  158. error_check_good db_close [$db close] 0
  159. puts "tTest$tstn complete."
  160. }