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

require 'bdbxml'

query = [
   '/vendor', 
   '/vendor[@type="wholesale"]', 
   '/product/item[text()="Lemon Grass"]', 
   '/product/inventory[number(price)<=0.11]',
   '/product[number(inventory/price)<=0.11 and category/text()="vegetables"]',
]

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

env = BDB::Env.new(options['home'], BDB::INIT_LOMP)
con = env.open_xml(options['container'])
query.each do |q|
   puts "Exercising query '#{q}'"
   print "Return to continue : "
   STDIN.gets
   results = con.query(q)
   results.each {|r| puts r}
   puts "#{results.size} objects returned for expression '#{q}'"
   puts
end