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