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.
- Timestamp:
-
Jan 10, 2007, 1:15:53 PM (19 years ago)
- Author:
-
Adam
- Comment:
-
--
Legend:
- Unmodified
- Added
- Removed
- Modified
-
v1
|
v2
|
|
1 | 1 | Full 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 |
| 9 | require 'bdbxml' |
| 10 | require 'slovnik/slovnik' |
| 11 | require 'servlets/slov' |
| 12 | |
| 13 | # set database path |
| 14 | db_path = '/var/lib/deb-server/db' |
| 15 | |
| 16 | # initiate DBXML environment |
| 17 | env = 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 |
| 20 | dict = Dictionary.new(db_path, 'demo.dbxml', '', env) |
| 21 | |
| 22 | # add some entries, first argument is the entry id, then data |
| 23 | dict.add('entry1', '<movies><movie name="Shrek" year="2001"/><movie name="Astérix et les Vikings" year="2006"/></movies>') |
| 24 | dict.add('entry2', '<tv><series name="The IT Crowd" year="2006"/><series name="Dead Like Me" year="2003"/></tv>') |
| 25 | |
| 26 | # display some of them |
| 27 | entry = dict.get('entry1') |
| 28 | puts entry.to_s |
| 29 | |
| 30 | # delete entry |
| 31 | dict.delete('entry1') |
| 32 | |
| 33 | # add some more |
| 34 | dict.add('entry3', '<books><book name="The Hogfather" year="1999"/><book name="Ночной доэор" year="1998"/></books>') |
| 35 | |
| 36 | # update entry |
| 37 | dict.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 |
| 40 | dict.container.each{|doc| |
| 41 | puts doc |
| 42 | } |