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

MySQL数据库

开发平台:

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: test021.tcl,v 11.10 2000/08/25 14:21:55 sue Exp $
  7. #
  8. # DB Test 21 {access method}
  9. # Use the first 10,000 entries from the dictionary.
  10. # Insert each with self, reversed as key and self as data.
  11. # After all are entered, retrieve each using a cursor SET_RANGE, and getting
  12. # about 20 keys sequentially after it (in some cases we'll run out towards
  13. # the end of the file).
  14. proc test021 { method {nentries 10000} args } {
  15. source ./include.tcl
  16. set args [convert_args $method $args]
  17. set omethod [convert_method $method]
  18. puts "Test021: $method ($args) $nentries equal key/data pairs"
  19. # Create the database and open the dictionary
  20. set eindex [lsearch -exact $args "-env"]
  21. #
  22. # If we are using an env, then testfile should just be the db name.
  23. # Otherwise it is the test directory and the name.
  24. if { $eindex == -1 } {
  25. set testfile $testdir/test021.db
  26. set env NULL
  27. } else {
  28. set testfile test021.db
  29. incr eindex
  30. set env [lindex $args $eindex]
  31. }
  32. set t1 $testdir/t1
  33. set t2 $testdir/t2
  34. set t3 $testdir/t3
  35. cleanup $testdir $env
  36. set db [eval {berkdb_open 
  37.      -create -truncate -mode 0644} $args {$omethod $testfile}]
  38. error_check_good dbopen [is_valid_db $db] TRUE
  39. set did [open $dict]
  40. set pflags ""
  41. set gflags ""
  42. set txn ""
  43. set count 0
  44. if { [is_record_based $method] == 1 } {
  45. set checkfunc test021_recno.check
  46. append gflags " -recno"
  47. } else {
  48. set checkfunc test021.check
  49. }
  50. puts "tTest021.a: put loop"
  51. # Here is the loop where we put each key/data pair
  52. while { [gets $did str] != -1 && $count < $nentries } {
  53. if { [is_record_based $method] == 1 } {
  54. global kvals
  55. set key [expr $count + 1]
  56. set kvals($key) [pad_data $method $str]
  57. } else {
  58. set key [reverse $str]
  59. }
  60. set r [eval {$db put} 
  61.     $txn $pflags {$key [chop_data $method $str]}]
  62. error_check_good db_put $r 0
  63. incr count
  64. }
  65. close $did
  66. # Now we will get each key from the DB and retrieve about 20
  67. # records after it.
  68. error_check_good db_close [$db close] 0
  69. puts "tTest021.b: test ranges"
  70. set db [eval {berkdb_open -rdonly} $args $omethod $testfile ]
  71. error_check_good dbopen [is_valid_db $db] TRUE
  72. # Open a cursor
  73. set dbc [eval {$db cursor} $txn]
  74. error_check_good db_cursor [is_substr $dbc $db] 1
  75. set did [open $dict]
  76. set i 0
  77. while { [gets $did str] != -1 && $i < $count } {
  78. if { [is_record_based $method] == 1 } {
  79. set key [expr $i + 1]
  80. } else {
  81. set key [reverse $str]
  82. }
  83. set r [$dbc get -set_range $key]
  84. error_check_bad dbc_get:$key [string length $r] 0
  85. set k [lindex [lindex $r 0] 0]
  86. set d [lindex [lindex $r 0] 1]
  87. $checkfunc $k $d
  88. for { set nrecs 0 } { $nrecs < 20 } { incr nrecs } {
  89. set r [$dbc get "-next"]
  90. # no error checking because we may run off the end
  91. # of the database
  92. if { [llength $r] == 0 } {
  93. continue;
  94. }
  95. set k [lindex [lindex $r 0] 0]
  96. set d [lindex [lindex $r 0] 1]
  97. $checkfunc $k $d
  98. }
  99. incr i
  100. }
  101. error_check_good db_close [$db close] 0
  102. close $did
  103. }
  104. # Check function for test021; keys and data are reversed
  105. proc test021.check { key data } {
  106. error_check_good "key/data mismatch for $key" $data [reverse $key]
  107. }
  108. proc test021_recno.check { key data } {
  109. global dict
  110. global kvals
  111. error_check_good key"$key"_exists [info exists kvals($key)] 1
  112. error_check_good "data mismatch: key $key" $data $kvals($key)
  113. }