dbm.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: dbm.tcl,v 11.12 2000/08/25 14:21:50 sue Exp $
  7. #
  8. # Historic DBM interface test.
  9. # Use the first 1000 entries from the dictionary.
  10. # Insert each with self as key and data; retrieve each.
  11. # After all are entered, retrieve all; compare output to original.
  12. # Then reopen the file, re-retrieve everything.
  13. # Finally, delete everything.
  14. proc dbm { { nentries 1000 } } {
  15. source ./include.tcl
  16. puts "DBM interfaces test: $nentries"
  17. # Create the database and open the dictionary
  18. set testfile $testdir/dbmtest
  19. set t1 $testdir/t1
  20. set t2 $testdir/t2
  21. set t3 $testdir/t3
  22. cleanup $testdir NULL
  23. error_check_good dbminit [berkdb dbminit $testfile] 0
  24. set did [open $dict]
  25. set flags ""
  26. set txn ""
  27. set count 0
  28. set skippednullkey 0
  29. puts "tDBM.a: put/get loop"
  30. # Here is the loop where we put and get each key/data pair
  31. while { [gets $did str] != -1 && $count < $nentries } {
  32. # DBM can't handle zero-length keys
  33. if { [string length $str] == 0 } {
  34. set skippednullkey 1
  35. continue
  36. }
  37. set ret [berkdb store $str $str]
  38. error_check_good dbm_store $ret 0
  39. set d [berkdb fetch $str]
  40. error_check_good dbm_fetch $d $str
  41. incr count
  42. }
  43. close $did
  44. # Now we will get each key from the DB and compare the results
  45. # to the original.
  46. puts "tDBM.b: dump file"
  47. set oid [open $t1 w]
  48. for { set key [berkdb firstkey] } { $key != -1 } {
  49.  set key [berkdb nextkey $key] } {
  50. puts $oid $key
  51. set d [berkdb fetch $key]
  52. error_check_good dbm_refetch $d $key
  53. }
  54. # If we had to skip a zero-length key, juggle things to cover up
  55. # this fact in the dump.
  56. if { $skippednullkey == 1 } {
  57. puts $oid ""
  58. incr nentries 1
  59. }
  60. close $oid
  61. # Now compare the keys to see if they match the dictionary (or ints)
  62. set q q
  63. filehead $nentries $dict $t3
  64. filesort $t3 $t2
  65. filesort $t1 $t3
  66. error_check_good DBM:diff($t3,$t2) 
  67.     [filecmp $t3 $t2] 0
  68. puts "tDBM.c: close, open, and dump file"
  69. # Now, reopen the file and run the last test again.
  70. error_check_good dbminit2 [berkdb dbminit $testfile] 0
  71. set oid [open $t1 w]
  72. for { set key [berkdb firstkey] } { $key != -1 } {
  73.  set key [berkdb nextkey $key] } {
  74. puts $oid $key
  75. set d [berkdb fetch $key]
  76. error_check_good dbm_refetch $d $key
  77. }
  78. if { $skippednullkey == 1 } {
  79. puts $oid ""
  80. }
  81. close $oid
  82. # Now compare the keys to see if they match the dictionary (or ints)
  83. filesort $t1 $t3
  84. error_check_good DBM:diff($t2,$t3) 
  85.     [filecmp $t2 $t3] 0
  86. # Now, reopen the file and delete each entry
  87. puts "tDBM.d: sequential scan and delete"
  88. error_check_good dbminit3 [berkdb dbminit $testfile] 0
  89. set oid [open $t1 w]
  90. for { set key [berkdb firstkey] } { $key != -1 } {
  91.  set key [berkdb nextkey $key] } {
  92. puts $oid $key
  93. set ret [berkdb delete $key]
  94. error_check_good dbm_delete $ret 0
  95. }
  96. if { $skippednullkey == 1 } {
  97. puts $oid ""
  98. }
  99. close $oid
  100. # Now compare the keys to see if they match the dictionary (or ints)
  101. filesort $t1 $t3
  102. error_check_good DBM:diff($t2,$t3) 
  103.     [filecmp $t2 $t3] 0
  104. error_check_good "dbm_close" [berkdb dbmclose] 0
  105. }