File: build_db.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 (27 lines) | stat: -rwxr-xr-x 740 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
#!/usr/bin/ruby -I../.. -I../../../src

require 'bdbxml'

def value(document, xpath, context)
   result = document.query(xpath, context).to_a
   if result.size != 1
      raise "Expected 1 got #{result.size}"
   end
   result[0].to_s
end

options = {'home' => 'env', 'container' => 'name.xml'}

env = BDB::Env.new(options['home'], BDB::INIT_TRANSACTION)
context = BDB::XML::Context.new
context.returntype = BDB::XML::Context::Values
env.begin do |txn|
   con = txn.open_xml(options['container'])
   bdb = txn.open_db(BDB::Btree, 'bdb', nil, 'a')
   con.search("/vendor") do |doc|
      res = value(doc, "/vendor/salesrep/name/text()", context)
      bdb[res] = "This is the data stored in the database for #{res}"
   end
   txn.commit
end