… | |
… | |
22 | db_put $db, undef, "key", "data", 0, sub { |
22 | db_put $db, undef, "key", "data", 0, sub { |
23 | db_del $db, undef, "key"; |
23 | db_del $db, undef, "key"; |
24 | }; |
24 | }; |
25 | db_sync $db; |
25 | db_sync $db; |
26 | |
26 | |
|
|
27 | # when you also use Coro, management is easy: |
|
|
28 | use Coro::BDB; |
|
|
29 | |
27 | # automatic result processing with AnyEvent: |
30 | # automatic result processing with AnyEvent: |
28 | our $FH; open $FH, "<&=" . BDB::poll_fileno; |
31 | our $FH; open $FH, "<&=" . BDB::poll_fileno; |
29 | our $WATCHER = AnyEvent->io (fh => $FH, poll => 'r', cb => \&BDB::poll_cb); |
32 | our $WATCHER = AnyEvent->io (fh => $FH, poll => 'r', cb => \&BDB::poll_cb); |
30 | |
33 | |
31 | # automatic result processing with EV: |
34 | # automatic result processing with EV: |
… | |
… | |
84 | Request has reached the end of its lifetime and holds no resources |
87 | Request has reached the end of its lifetime and holds no resources |
85 | anymore (except possibly for the Perl object, but its connection to |
88 | anymore (except possibly for the Perl object, but its connection to |
86 | the actual aio request is severed and calling its methods will |
89 | the actual aio request is severed and calling its methods will |
87 | either do nothing or result in a runtime error). |
90 | either do nothing or result in a runtime error). |
88 | |
91 | |
|
|
92 | FILENAMES/DATABASE NAMES |
|
|
93 | The BDB expects "binary" filenames (octet strings) for pathnames on |
|
|
94 | POSIX systems, and "unicode" filenames (strings with characters |
|
|
95 | potentially >255) on Win32 (expecting a Unicode win32 build - win32 is a |
|
|
96 | total mess). |
|
|
97 | |
89 | BERKELEYDB FUNCTIONS |
98 | BERKELEYDB FUNCTIONS |
90 | All of these are functions. The create functions simply return a new |
99 | All of these are functions. The create functions simply return a new |
91 | object and never block. All the remaining functions all take an optional |
100 | object and never block. All the remaining functions take an optional |
92 | callback as last argument. If it is missing, then the function will be |
101 | callback as last argument. If it is missing, then the function will be |
93 | executed synchronously. In both cases, $! will reflect the return value |
102 | executed synchronously. In both cases, $! will reflect the return value |
94 | of the function. |
103 | of the function. |
95 | |
104 | |
96 | BDB functions that cannot block (mostly functions that manipulate |
105 | BDB functions that cannot block (mostly functions that manipulate |
97 | settings) are method calls on the relevant objects, so the rule of thumb |
106 | settings) are method calls on the relevant objects, so the rule of thumb |
98 | is: if its a method, its not blocking, if its a function, it takes a |
107 | is: if it's a method, it's not blocking, if it's a function, it takes a |
99 | callback as last argument. |
108 | callback as last argument. |
100 | |
109 | |
101 | In the following, $int signifies an integer return value, "octetstring" |
110 | In the following, $int signifies an integer return value, "octetstring" |
102 | is a "binary string" (i.e. a perl string with no character indices |
111 | is a "binary string" (i.e. a perl string with no character indices |
103 | >255), "U32" is an unsigned 32 bit integer, "int" is some integer, "NV" |
112 | >255), "U32" is an unsigned 32 bit integer, "int" is some integer, "NV" |
… | |
… | |
329 | DESTROY (DBC_ornull *dbc) |
338 | DESTROY (DBC_ornull *dbc) |
330 | CODE: |
339 | CODE: |
331 | if (dbc) |
340 | if (dbc) |
332 | dbc->c_close (dbc); |
341 | dbc->c_close (dbc); |
333 | |
342 | |
|
|
343 | $int = $cursor->set_priority ($priority = PRIORITY_*) |
|
|
344 | |
334 | Example: |
345 | Example: |
335 | my $c = $db->cursor; |
346 | my $c = $db->cursor; |
336 | |
347 | |
337 | for (;;) { |
348 | for (;;) { |
338 | db_c_get $c, my $key, my $data, BDB::NEXT; |
349 | db_c_get $c, my $key, my $data, BDB::NEXT; |
… | |
… | |
356 | flags: SEQ_DEC SEQ_INC SEQ_WRAP |
367 | flags: SEQ_DEC SEQ_INC SEQ_WRAP |
357 | $int = $seq->set_range (db_seq_t min, db_seq_t max) |
368 | $int = $seq->set_range (db_seq_t min, db_seq_t max) |
358 | |
369 | |
359 | Example: |
370 | Example: |
360 | my $seq = $db->sequence; |
371 | my $seq = $db->sequence; |
361 | |
372 | |
362 | db_sequence_open $seq, undef, "seq", BDB::CREATE; |
373 | db_sequence_open $seq, undef, "seq", BDB::CREATE; |
363 | db_sequence_get $seq, undef, 1, my $value; |
374 | db_sequence_get $seq, undef, 1, my $value; |
364 | |
375 | |
365 | SUPPORT FUNCTIONS |
376 | SUPPORT FUNCTIONS |
366 | EVENT PROCESSING AND EVENT LOOP INTEGRATION |
377 | EVENT PROCESSING AND EVENT LOOP INTEGRATION |
367 | $msg = BDB::strerror [$errno] |
378 | $msg = BDB::strerror [$errno] |
368 | Returns the string corresponding to the given errno value. If no |
379 | Returns the string corresponding to the given errno value. If no |
369 | argument is given, use $!. |
380 | argument is given, use $!. |
|
|
381 | |
|
|
382 | Note that the BDB module also patches the $! variable directly, so |
|
|
383 | you should be able to get a bdb error string by simply stringifying |
|
|
384 | $!. |
370 | |
385 | |
371 | $fileno = BDB::poll_fileno |
386 | $fileno = BDB::poll_fileno |
372 | Return the *request result pipe file descriptor*. This filehandle |
387 | Return the *request result pipe file descriptor*. This filehandle |
373 | must be polled for reading by some mechanism outside this module |
388 | must be polled for reading by some mechanism outside this module |
374 | (e.g. Event or select, see below or the SYNOPSIS). If the pipe |
389 | (e.g. Event or select, see below or the SYNOPSIS). If the pipe |