test033.tcl
Upload User: tsgydb
Upload Date: 2007-04-14
Package Size: 10674k
Code Size: 3k
Category:

MySQL

Development Platform:

Visual C++

  1. # See the file LICENSE for redistribution information.
  2. #
  3. # Copyright (c) 1996, 1997, 1998, 1999, 2000
  4. # Sleepycat Software.  All rights reserved.
  5. #
  6. # $Id: test033.tcl,v 11.11 2000/10/25 15:45:20 sue Exp $
  7. #
  8. # DB Test 33 {access method}
  9. # Use the first 10,000 entries from the dictionary.
  10. # Insert each with self as key and data; add duplicate
  11. # records for each.
  12. # After all are entered, retrieve all; verify output by doing
  13. # DB_GET_BOTH on existing and non-existing keys.
  14. # This does not work for recno
  15. proc test033 { method {nentries 10000} {ndups 5} {tnum 33} args } {
  16. source ./include.tcl
  17. set args [convert_args $method $args]
  18. set omethod [convert_method $method]
  19. puts "Test0$tnum: $method ($args) $nentries small dup key/data pairs"
  20. if { [is_record_based $method] == 1 || 
  21.     [is_rbtree $method] == 1 } {
  22. puts "Test0$tnum skipping for method $omethod"
  23. return
  24. }
  25. # Create the database and open the dictionary
  26. set eindex [lsearch -exact $args "-env"]
  27. #
  28. # If we are using an env, then testfile should just be the db name.
  29. # Otherwise it is the test directory and the name.
  30. if { $eindex == -1 } {
  31. set testfile $testdir/test0$tnum.db
  32. set env NULL
  33. } else {
  34. set testfile test0$tnum.db
  35. incr eindex
  36. set env [lindex $args $eindex]
  37. }
  38. set t1 $testdir/t1
  39. set t2 $testdir/t2
  40. set t3 $testdir/t3
  41. cleanup $testdir $env
  42. set db [eval {berkdb_open -create -truncate -mode 0644 
  43. $omethod -dup} $args {$testfile}]
  44. error_check_good dbopen [is_valid_db $db] TRUE
  45. set did [open $dict]
  46. set pflags ""
  47. set gflags ""
  48. set txn ""
  49. set count 0
  50. puts "tTest0$tnum.a: Put/get loop."
  51. # Here is the loop where we put and get each key/data pair
  52. while { [gets $did str] != -1 && $count < $nentries } {
  53. for { set i 1 } { $i <= $ndups } { incr i } {
  54. set datastr $i:$str
  55. set ret [eval {$db put} 
  56.     $txn $pflags {$str [chop_data $method $datastr]}]
  57. error_check_good db_put $ret 0
  58. }
  59. # Now retrieve all the keys matching this key and dup
  60. for {set i 1} {$i <= $ndups } { incr i } {
  61. set datastr $i:$str
  62. set ret [eval {$db get} $txn {-get_both $str $datastr}]
  63. error_check_good "Test0$tnum:dup#" [lindex 
  64.     [lindex $ret 0] 1] [pad_data $method $datastr]
  65. }
  66. # Now retrieve non-existent dup (i is ndups + 1)
  67. set datastr $i:$str
  68. set ret [eval {$db get} $txn {-get_both $str $datastr}]
  69. error_check_good Test0$tnum:dupfailure [llength $ret] 0
  70. incr count
  71. }
  72. close $did
  73. set did [open $dict]
  74. set count 0
  75. puts "tTest0$tnum.b: Verifying DB_GET_BOTH after creation."
  76. while { [gets $did str] != -1 && $count < $nentries } {
  77. # Now retrieve all the keys matching this key and dup
  78. for {set i 1} {$i <= $ndups } { incr i } {
  79. set datastr $i:$str
  80. set ret [eval {$db get} $txn {-get_both $str $datastr}]
  81. error_check_good "Test0$tnum:dup#" 
  82.     [lindex [lindex $ret 0] 1] $datastr
  83. }
  84. # Now retrieve non-existent dup (i is ndups + 1)
  85. set datastr $i:$str
  86. set ret [eval {$db get} $txn {-get_both $str $datastr}]
  87. error_check_good Test0$tnum:dupfailure [llength $ret] 0
  88. incr count
  89. }
  90. close $did
  91. error_check_good db_close [$db close] 0
  92. }