File: b.rb

package info (click to toggle)
libdb2-ruby 0.5.4-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,352 kB
  • ctags: 2,743
  • sloc: ansic: 11,156; ruby: 6,199; cpp: 6,064; makefile: 86; sh: 31
file content (32 lines) | stat: -rwxr-xr-x 887 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/ruby -I../src
$LOAD_PATH.unshift "../src"
require 'bdbxml'

p BDB::XML::Name

env = BDB::Env.new("tmp", BDB::CREATE | BDB::INIT_TRANSACTION)
doc = env.open_xml("toto", "a")
doc.each {|x| p x }
index = doc.index
index.add("http://moulon.inra.fr/", "reference", 
	   "node-attribute-equality-string")
doc.index = index
bdb = env.open_db(BDB::Btree, "tutu", nil, "a")
2.times do |i|
   doc.push("<bk><ttl id='#{i}'>title nb #{i}</ttl></bk>")
   bdb[i] = "bdb#{i}"
end
env.begin(doc, bdb) do |txn, doc1, bdb1|
   2.times do |i|
      bdb1[i+2] = "bdb#{i+2}"
      doc1.push("<bk><ttl id='#{i+2}'>title nb #{i+2}</ttl></bk>")
   end
   puts "========================================="
   doc1.each {|x| p x }
   bdb1.each {|k,v| p "#{k} -- #{v}" }
   # implicit txn.abort
end
puts "========================================="
doc.each {|x| p x }
bdb.each {|k,v| p "#{k} -- #{v}" }