1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 1999,2008 Oracle.  All rights reserved.
4#
5# $Id: sdbscript.tcl,v 12.6 2008/01/08 20:58:53 bostic Exp $
6#
7# Usage: subdbscript testfile subdbnumber factor
8# testfile: name of DB itself
9# subdbnumber: n, subdb indicator, of form sub$n.db
10# factor: Delete over factor'th + n'th from my subdb.
11#
12# I.e. if factor is 10, and n is 0, remove entries, 0, 10, 20, ...
13# if factor is 10 and n is 1, remove entries 1, 11, 21, ...
14source ./include.tcl
15source $test_path/test.tcl
16
17set usage "subdbscript testfile subdbnumber factor"
18
19# Verify usage
20if { $argc != 3 } {
21	puts stderr "FAIL:[timestamp] Usage: $usage"
22	exit
23}
24
25# Initialize arguments
26set testfile [lindex $argv 0]
27set n [ lindex $argv 1 ]
28set factor [ lindex $argv 2 ]
29
30set db [berkdb_open -unknown $testfile sub$n.db]
31error_check_good db_open [is_valid_db $db] TRUE
32
33set dbc [$db cursor]
34error_check_good db_cursor [is_valid_cursor $dbc $db] TRUE
35set i 1
36for {set d [$dbc get -first]} {[llength $d] != 0} {set d [$dbc get -next]} {
37	set x [expr $i - $n]
38	if { $x >= 0 && [expr $x % $factor] == 0 } {
39		puts  "Deleting $d"
40		error_check_good dbc_del [$dbc del] 0
41	}
42	incr i
43}
44error_check_good db_close [$db close] 0
45
46exit
47