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

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: test059.tcl,v 11.12 2000/08/25 14:21:57 sue Exp $
  7. #
  8. # Test059:
  9. # Make sure that we handle retrieves of zero-length data items correctly.
  10. # The following ops, should allow a partial data retrieve of 0-length.
  11. # db_get
  12. # db_cget FIRST, NEXT, LAST, PREV, CURRENT, SET, SET_RANGE
  13. #
  14. proc test059 { method args } {
  15. source ./include.tcl
  16. set args [convert_args $method $args]
  17. set omethod [convert_method $method]
  18. puts "Test059: $method 0-length partial data retrieval"
  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/test059.db
  26. set env NULL
  27. } else {
  28. set testfile test059.db
  29. incr eindex
  30. set env [lindex $args $eindex]
  31. }
  32. cleanup $testdir $env
  33. set pflags ""
  34. set gflags ""
  35. set txn ""
  36. set count 0
  37. if { [is_record_based $method] == 1 } {
  38. append gflags " -recno"
  39. }
  40. puts "tTest059.a: Populate a database"
  41. set oflags "-create -truncate -mode 0644 $omethod $args $testfile"
  42. set db [eval {berkdb_open} $oflags]
  43. error_check_good db_create [is_substr $db db] 1
  44. # Put ten keys in the database
  45. for { set key 1 } { $key <= 10 } {incr key} {
  46. set r [eval {$db put} $txn $pflags {$key datum$key}]
  47. error_check_good put $r 0
  48. }
  49. # Retrieve keys sequentially so we can figure out their order
  50. set i 1
  51. set curs [$db cursor]
  52. error_check_good db_curs [is_substr $curs $db] 1
  53. for {set d [$curs get -first] } { [llength $d] != 0 } {
  54.     set d [$curs get -next] } {
  55. set key_set($i) [lindex [lindex $d 0] 0]
  56. incr i
  57. }
  58. puts "tTest059.a: db get with 0 partial length retrieve"
  59. # Now set the cursor on the middle one.
  60. set ret [eval {$db get -partial {0 0}} $gflags {$key_set(5)}]
  61. error_check_bad db_get_0 [llength $ret] 0
  62. puts "tTest059.a: db cget FIRST with 0 partial length retrieve"
  63. set ret [$curs get -first -partial {0 0}]
  64. set data [lindex [lindex $ret 0] 1]
  65. set key [lindex [lindex $ret 0] 0]
  66. error_check_good key_check_first $key $key_set(1)
  67. error_check_good db_cget_first [string length $data] 0
  68. puts "tTest059.b: db cget NEXT with 0 partial length retrieve"
  69. set ret [$curs get -next -partial {0 0}]
  70. set data [lindex [lindex $ret 0] 1]
  71. set key [lindex [lindex $ret 0] 0]
  72. error_check_good key_check_next $key $key_set(2)
  73. error_check_good db_cget_next [string length $data] 0
  74. puts "tTest059.c: db cget LAST with 0 partial length retrieve"
  75. set ret [$curs get -last -partial {0 0}]
  76. set data [lindex [lindex $ret 0] 1]
  77. set key [lindex [lindex $ret 0] 0]
  78. error_check_good key_check_last $key $key_set(10)
  79. error_check_good db_cget_last [string length $data] 0
  80. puts "tTest059.d: db cget PREV with 0 partial length retrieve"
  81. set ret [$curs get -prev -partial {0 0}]
  82. set data [lindex [lindex $ret 0] 1]
  83. set key [lindex [lindex $ret 0] 0]
  84. error_check_good key_check_prev $key $key_set(9)
  85. error_check_good db_cget_prev [string length $data] 0
  86. puts "tTest059.e: db cget CURRENT with 0 partial length retrieve"
  87. set ret [$curs get -current -partial {0 0}]
  88. set data [lindex [lindex $ret 0] 1]
  89. set key [lindex [lindex $ret 0] 0]
  90. error_check_good key_check_current $key $key_set(9)
  91. error_check_good db_cget_current [string length $data] 0
  92. puts "tTest059.f: db cget SET with 0 partial length retrieve"
  93. set ret [$curs get -set -partial {0 0} $key_set(7)]
  94. set data [lindex [lindex $ret 0] 1]
  95. set key [lindex [lindex $ret 0] 0]
  96. error_check_good key_check_set $key $key_set(7)
  97. error_check_good db_cget_set [string length $data] 0
  98. if {[is_btree $method] == 1} {
  99. puts "tTest059.g:
  100.     db cget SET_RANGE with 0 partial length retrieve"
  101. set ret [$curs get -set_range -partial {0 0} $key_set(5)]
  102. set data [lindex [lindex $ret 0] 1]
  103. set key [lindex [lindex $ret 0] 0]
  104. error_check_good key_check_set $key $key_set(5)
  105. error_check_good db_cget_set [string length $data] 0
  106. }
  107. error_check_good curs_close [$curs close] 0
  108. error_check_good db_close [$db close] 0
  109. }