⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 btree6.test

📁 sqlite-3.4.1,嵌入式数据库.是一个功能强大的开源数据库,给学习和研发以及小型公司的发展带来了全所未有的好处.
💻 TEST
字号:
# 2004 May 10## The author disclaims copyright to this source code.  In place of# a legal notice, here is a blessing:##    May you do good and not evil.#    May you find forgiveness for yourself and forgive others.#    May you share freely, never taking more than you give.##***********************************************************************# This file implements regression tests for SQLite library.  The# focus of this script is btree database backend - specifically# the B+tree tables.  B+trees store all data on the leaves rather# that storing data with keys on interior nodes.## $Id: btree6.test,v 1.4 2004/05/20 22:16:31 drh Exp $set testdir [file dirname $argv0]source $testdir/tester.tcl# Insert many entries into the table that cursor $cur points to.# The table should be an INTKEY table.## Stagger the inserts.  After the inserts complete, go back and do# deletes.  Stagger the deletes too.  Repeat this several times.## Do N inserts into table $tab using random keys between 0 and 1000000#proc random_inserts {cur N} {  global inscnt  while {$N>0} {    set k [expr {int(rand()*1000000)}]    if {[btree_move_to $cur $k]==0} {      continue;  # entry already exists    }    incr inscnt    btree_insert $cur $k data-for-$k    incr N -1  }}set inscnt 0# Do N delete from the table that $cur points to.#proc random_deletes {cur N} {  while {$N>0} {    set k [expr {int(rand()*1000000)}]    btree_move_to $cur $k    btree_delete $cur    incr N -1  }}# Make sure the table that $cur points to has exactly N entries.  # Make sure the data for each entry agrees with its key.#proc check_table {cur N} {  btree_first $cur  set cnt 0  while {![btree_eof $cur]} {    if {[set data [btree_data $cur]] ne "data-for-[btree_key $cur]"} {      return "wrong data for entry $cnt"    }    set n [string length $data]    set fdata1 [btree_fetch_data $cur $n]    set fdata2 [btree_fetch_data $cur -1]    if {$fdata1 ne "" && $fdata1 ne $data} {      return "DataFetch returned the wrong value with amt=$n"    }    if {$fdata1 ne $fdata2} {      return "DataFetch returned the wrong value when amt=-1"    }    if {$n>10} {      set fdata3 [btree_fetch_data $cur 10]      if {$fdata3 ne [string range $data 0 9]} {        return "DataFetch returned the wrong value when amt=10"      }    }    incr cnt    btree_next $cur  }  if {$cnt!=$N} {    return "wrong number of entries.  Got $cnt.  Looking for $N"  }  return {}}# Initialize the database#file delete -force test1.btfile delete -force test1.bt-journalset b1 [btree_open test1.bt 2000 0]btree_begin_transaction $b1set tab [btree_create_table $b1 5]set cur [btree_cursor $b1 $tab 1]set btree_trace 0expr srand(1)# Do the tests.#set cnt 0for {set i 1} {$i<=40} {incr i} {  do_test btree6-1.$i.1 {    random_inserts $cur 200    incr cnt 200    check_table $cur $cnt  } {}  do_test btree6-1.$i.2 {    btree_integrity_check $b1 1 $tab  } {}  do_test btree6-1.$i.3 {    random_deletes $cur 90    incr cnt -90    check_table $cur $cnt  } {}  do_test btree6-1.$i.4 {    btree_integrity_check $b1 1 $tab  } {}}btree_close_cursor $curbtree_commit $b1btree_close $b1finish_test

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -