File: transaction.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 (29 lines) | stat: -rw-r--r-- 871 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
#!/usr/bin/ruby -I../../src -I..
$LOAD_PATH.unshift "../../src", ".."
require 'bdbxml'
require 'find'

Find::find('tmp') do |f|
   File::unlink(f) if FileTest::file? f
end

env = BDB::Env.new("tmp", BDB::CREATE | BDB::INIT_TRANSACTION)
doc = env.open_xml("toto", "a")
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.search("//ttl[@id < 12]", BDB::XML::Context::Values) {|x| p x}
   bdb1.each {|k,v| p "#{k} -- #{v}" }
end
puts "========================================="
doc.search("//ttl[@id < 12]") {|x| p x }
bdb.each {|k,v| p "#{k} -- #{v}" }