close Warning: Can't synchronize with repository "(default)" (/usr/local/svn/deb2-client does not appear to be a Subversion repository.). Look in the Trac log for more information.

Changes between Version 1 and Version 2 of DbxmlRubyInterface


Ignore:
Timestamp:
Jan 10, 2007, 1:15:53 PM (19 years ago)
Author:
Adam
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DbxmlRubyInterface

    v1 v2  
    11Full interface doc http://moulon.inra.fr/ruby/bdb.html
     2
     3#!/usr/bin/ruby
     4
     5# add debserver library path
     6$LOAD_PATH.unshift('/var/lib/deb-server/lib/')
     7
     8# include libraries
     9require 'bdbxml'
     10require 'slovnik/slovnik'
     11require 'servlets/slov'
     12
     13# set database path
     14db_path = '/var/lib/deb-server/db'
     15
     16# initiate DBXML environment
     17env = BDB::Env.new(db_path, BDB::CREATE | BDB::INIT_TRANSACTION, 0660, {'set_lk_max_lockers'=>2000, 'set_lk_max_locks'=>2000})
     18
     19# open database, we don't specify keypath because it's used mainly for queries
     20dict = Dictionary.new(db_path, 'demo.dbxml', '', env)
     21
     22# add some entries, first argument is the entry id, then data
     23dict.add('entry1', '<movies><movie name="Shrek" year="2001"/><movie name="Astérix et les Vikings" year="2006"/></movies>')
     24dict.add('entry2', '<tv><series name="The IT Crowd" year="2006"/><series name="Dead Like Me" year="2003"/></tv>')
     25
     26# display some of them
     27entry = dict.get('entry1')
     28puts entry.to_s
     29
     30# delete entry
     31dict.delete('entry1')
     32
     33# add some more
     34dict.add('entry3', '<books><book name="The Hogfather" year="1999"/><book name="Ночной доэор" year="1998"/></books>')
     35
     36# update entry
     37dict.update('entry2', '<tv><series name="The IT Crowd" year="2006"/><series name="Dead Like Me" year="2003"/><series name="Black Books" year="2000"/></tv>')
     38
     39# display all the entries
     40dict.container.each{|doc|
     41  puts doc
     42}