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

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: test050.tcl,v 11.15 2000/08/25 14:21:57 sue Exp $
  7. #
  8. # Test050: Overwrite test of small/big key/data with cursor checks for RECNO
  9. proc test050 { method args } {
  10. global alphabet
  11. global errorInfo
  12. global errorCode
  13. source ./include.tcl
  14. set tstn 050
  15. set args [convert_args $method $args]
  16. set omethod [convert_method $method]
  17. if { [is_rrecno $method] != 1 } {
  18. puts "Test$tstn skipping for method $method."
  19. return
  20. }
  21. puts "tTest$tstn:
  22.     Overwrite test with cursor and small/big key/data ($method)."
  23. set data "data"
  24. set txn ""
  25. set flags ""
  26. puts "tTest$tstn: Create $method database."
  27. set eindex [lsearch -exact $args "-env"]
  28. #
  29. # If we are using an env, then testfile should just be the db name.
  30. # Otherwise it is the test directory and the name.
  31. if { $eindex == -1 } {
  32. set testfile $testdir/test0$tstn.db
  33. set env NULL
  34. } else {
  35. set testfile test0$tstn.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 $args $omethod"
  42. set db [eval {berkdb_open_noerr} $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. # keep nkeys even
  48. set nkeys 20
  49. # Fill page w/ small key/data pairs
  50. #
  51. puts "tTest$tstn: Fill page with $nkeys small key/data pairs."
  52. for { set i 1 } { $i <= $nkeys } { incr i } {
  53. set ret [$db put $i [chop_data $method $data$i]]
  54. error_check_good dbput $ret 0
  55. }
  56. # get db order of keys
  57. for {set i 0; set ret [$dbc get -first]} { [llength $ret] != 0} { 
  58. set ret [$dbc get -next]} {
  59. set key_set($i) [lindex [lindex $ret 0] 0]
  60. set data_set($i) [lindex [lindex $ret 0] 1]
  61. incr i
  62. }
  63. # verify ordering: should be unnecessary, but hey, why take chances?
  64. # key_set is zero indexed but keys start at 1
  65. for {set i 0} { $i < $nkeys } {incr i} {
  66. error_check_good 
  67.     verify_order:$i $key_set($i) [pad_data $method [expr $i+1]]
  68. }
  69. puts "tTest$tstn.a: Inserts before/after by cursor."
  70. puts "ttTest$tstn.a.1:
  71.     Insert with uninitialized cursor (should fail)."
  72. error_check_good dbc_close [$dbc close] 0
  73. set dbc [$db cursor]
  74. error_check_good db_cursor [is_substr $dbc $db] 1
  75. catch {$dbc put -before DATA1} ret
  76. error_check_good dbc_put:before:uninit [is_substr $errorCode EINVAL] 1
  77. catch {$dbc put -after DATA2} ret
  78. error_check_good dbc_put:after:uninit [is_substr $errorCode EINVAL] 1
  79. puts "ttTest$tstn.a.2: Insert with deleted cursor (should succeed)."
  80. set ret [$dbc get -first]
  81. error_check_bad dbc_get:first [llength $ret] 0
  82. error_check_good dbc_del [$dbc del] 0
  83. set ret [$dbc put -current DATAOVER1]
  84. error_check_good dbc_put:current:deleted $ret 0
  85. puts "ttTest$tstn.a.3: Insert by cursor before cursor (DB_BEFORE)."
  86. set currecno [lindex [lindex [$dbc get -current] 0] 0]
  87. set ret [$dbc put -before DATAPUTBEFORE]
  88. error_check_good dbc_put:before $ret $currecno
  89. set old1 [$dbc get -next]
  90. error_check_bad dbc_get:next [llength $old1] 0
  91. error_check_good 
  92.     dbc_get:next(compare) [lindex [lindex $old1 0] 1] DATAOVER1
  93. puts "ttTest$tstn.a.4: Insert by cursor after cursor (DB_AFTER)."
  94. set ret [$dbc get -first]
  95. error_check_bad dbc_get:first [llength $ret] 0
  96. error_check_good dbc_get:first [lindex [lindex $ret 0] 1] DATAPUTBEFORE
  97. set currecno [lindex [lindex [$dbc get -current] 0] 0]
  98. set ret [$dbc put -after DATAPUTAFTER]
  99. error_check_good dbc_put:after $ret [expr $currecno + 1]
  100. set ret [$dbc get -prev]
  101. error_check_bad dbc_get:prev [llength $ret] 0
  102. error_check_good 
  103.     dbc_get:prev [lindex [lindex $ret 0] 1] DATAPUTBEFORE
  104. puts "ttTest$tstn.a.5: Verify that all keys have been renumbered."
  105. # should be $nkeys + 2 keys, starting at 1
  106. for {set i 1; set ret [$dbc get -first]} { 
  107. $i <= $nkeys && [llength $ret] != 0 } {
  108. incr i; set ret [$dbc get -next]} {
  109. error_check_good check_renumber $i [lindex [lindex $ret 0] 0]
  110. }
  111. # tested above
  112. puts "tTest$tstn.b: Overwrite tests (cursor and key)."
  113. # For the next part of the test, we need a db with no dups to test
  114. # overwrites
  115. #
  116. # we should have ($nkeys + 2) keys, ordered:
  117. # DATAPUTBEFORE, DATAPUTAFTER, DATAOVER1, data1, ..., data$nkeys
  118. #
  119. # Prepare cursor on item
  120. #
  121. set ret [$dbc get -first]
  122. error_check_bad dbc_get:first [llength $ret] 0
  123. # Prepare unique big/small values for an initial
  124. # and an overwrite set of data
  125. set databig DATA_BIG_[repeat alphabet 250]
  126. set datasmall DATA_SMALL
  127. # Now, we want to overwrite data:
  128. #  by key and by cursor
  129. #  1. small by small
  130. # 2. small by big
  131. # 3. big by small
  132. # 4. big by big
  133. #
  134. set i 0
  135. # Do all overwrites for key and cursor
  136. foreach type { by_key by_cursor } {
  137. incr i
  138. puts "tTest$tstn.b.$i: Overwrites $type."
  139. foreach pair { {small small} 
  140.     {small big} {big small} {big big} } {
  141. # put in initial type
  142. set data $data[lindex $pair 0]
  143. set ret [$dbc put -current $data]
  144. error_check_good dbc_put:curr:init:($pair) $ret 0
  145. # Now, try to overwrite: dups not supported in this db
  146. if { [string compare $type by_key] == 0 } {
  147. puts "ttTest$tstn.b.$i:
  148.     Overwrite:($pair):$type"
  149. set ret [$db put 
  150.     1 OVER$pair$data[lindex $pair 1]]
  151. error_check_good dbput:over:($pair) $ret 0
  152. } else {
  153. # This is a cursor overwrite
  154. puts "ttTest$tstn.b.$i:
  155.     Overwrite:($pair) by cursor."
  156. set ret [$dbc put 
  157.     -current OVER$pair$data[lindex $pair 1]]
  158. error_check_good dbcput:over:($pair) $ret 0
  159. }
  160. } ;# foreach pair
  161. } ;# foreach type key/cursor
  162. puts "tTest$tstn.c: Cleanup and close cursor."
  163. error_check_good dbc_close [$dbc close] 0
  164. error_check_good db_close [$db close] 0
  165. puts "tTest$tstn complete."
  166. }