14 plan(skip_all => "this needs BerkeleyDB 4.6.x or better" )
15 if $BerkeleyDB::db_version < 4.6;
23 # db->associate -- secondary keys returning DB_DBT_MULTIPLE
30 $_[0] = ["a","b", "c"];
35 my ($Dfile1, $Dfile2);
36 my $lex = new LexFile $Dfile1, $Dfile2 ;
39 my ($k, $v, $pk) = ('','','');
41 # create primary database
42 ok my $primary = new BerkeleyDB::Hash -Filename => $Dfile1,
45 # create secondary database
46 ok my $secondary = new BerkeleyDB::Hash -Filename => $Dfile2,
49 # associate primary with secondary
50 ok $primary->associate($secondary, \&sec_key) == 0 ;
52 # add data to the primary
53 ok $primary->db_put("foo", "bar") == 0;
55 # check the records in the secondary (there should be three "a", "b", "c")
56 is countRecords($secondary), 3 ;
58 ok $secondary->db_get("a", $v) == 0;
61 ok $secondary->db_get("b", $v) == 0;
64 ok $secondary->db_get("c", $v) == 0;
69 # db->associate -- secondary keys returning DB_DBT_MULTIPLE, but with
82 my ($Dfile1, $Dfile2);
83 my $lex = new LexFile $Dfile1, $Dfile2 ;
86 my ($k, $v, $pk) = ('','','');
88 # create primary database
89 ok my $primary = new BerkeleyDB::Hash -Filename => $Dfile1,
92 # create secondary database
93 ok my $secondary = new BerkeleyDB::Hash -Filename => $Dfile2,
96 # associate primary with secondary
97 ok $primary->associate($secondary, \&sec_key1) == 0 ;
99 # add data to the primary
100 ok $primary->db_put("foo", "bar") == 0;
102 # check the records in the secondary (there should be three "a", "b", "c")
103 is countRecords($secondary), 1 ;
105 ok $secondary->db_get("a", $v) == 0;
111 # db->associate -- multiple secondary keys
115 #print "in sec_key\n";
119 $_[0] = [ split ',', $pdata ] ;
123 my ($Dfile1, $Dfile2);
124 my $lex = new LexFile $Dfile1, $Dfile2 ;
127 my ($k, $v, $pk) = ('','','');
129 # create primary database
130 ok my $primary = new BerkeleyDB::Hash -Filename => $Dfile1,
131 -Flags => DB_CREATE ;
133 # create secondary database
134 ok my $secondary = new BerkeleyDB::Hash -Filename => $Dfile2,
135 -Flags => DB_CREATE ;
137 # associate primary with secondary
138 ok $primary->associate($secondary, \&sec_key_mult) == 0;
140 # add data to the primary
146 "bar" => "hello,goodbye",
150 while (($k, $v) = each %data) {
151 my $r = $primary->db_put($k, $v) ;
156 # check the records in the secondary
157 is countRecords($secondary), 5 ;
159 ok $secondary->db_get("house", $v) == 0;
162 ok $secondary->db_get("sea", $v) == 0;
165 ok $secondary->db_get("flag", $v) == 0;
168 ok $secondary->db_get("hello", $v) == 0;
169 ok $v eq "hello,goodbye";
171 ok $secondary->db_get("goodbye", $v) == 0;
172 ok $v eq "hello,goodbye";
174 # pget to primary database is illegal
175 ok $primary->db_pget('red', $pk, $v) != 0 ;
177 # pget to secondary database is ok
178 ok $secondary->db_pget('house', $pk, $v) == 0 ;
182 # pget to secondary database is ok
183 ok $secondary->db_pget('hello', $pk, $v) == 0 ;
185 ok $v eq 'hello,goodbye';
187 # pget to DB_GET_BOTH from secondary database
190 ok $secondary->db_pget($k, $pk, $v, DB_GET_BOTH) == 0 ;
194 ok my $p_cursor = $primary->db_cursor();
195 ok my $s_cursor = $secondary->db_cursor();
199 ok $p_cursor->c_get($k, $v, DB_SET) == 0;
203 # c_get from secondary
205 ok $s_cursor->c_get($k, $v, DB_SET) == 0;
209 # c_pget from primary database should fail
211 ok $p_cursor->c_pget($k, $pk, $v, DB_FIRST) != 0;
213 # c_pget from secondary database
215 ok $s_cursor->c_pget($k, $pk, $v, DB_SET) == 0;
220 # c_pget with DB_GET_BOTH from secondary database
223 ok $s_cursor->c_pget($k, $pk, $v, DB_GET_BOTH) == 0;
227 # check put to secondary is illegal
228 ok $secondary->db_put("tom", "dick") != 0;
229 is countRecords($secondary), 5 ;
231 # delete from primary
232 ok $primary->db_del("green") == 0 ;
233 is countRecords($primary), 4 ;
235 # check has been deleted in secondary
236 ok $secondary->db_get("house", $v) != 0;
237 is countRecords($secondary), 4 ;
239 # delete from secondary
240 ok $secondary->db_del('flag') == 0 ;
241 is countRecords($secondary), 3 ;
244 # check deleted from primary
245 ok $primary->db_get("red", $v) != 0;
246 is countRecords($primary), 3 ;