… | |
… | |
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 | WIN32 FILENAMES/DATABASE NAME MESS |
|
|
93 | Perl on Win32 supports only ASCII filenames (the reason is that it |
|
|
94 | abuses an internal flag to store wether a filename is Unicode or ANSI, |
|
|
95 | but that flag is used for somethign else in the perl core, so there is |
|
|
96 | no way to detect wether a filename is ANSI or Unicode-encoded). The BDB |
|
|
97 | module tries to work around this issue by assuming that the filename is |
|
|
98 | an ANSI filename and BDB was built for unicode support. |
|
|
99 | |
89 | BERKELEYDB FUNCTIONS |
100 | BERKELEYDB FUNCTIONS |
90 | All of these are functions. The create functions simply return a new |
101 | 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 |
102 | 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 |
103 | callback as last argument. If it is missing, then the function will be |
93 | executed synchronously. In both cases, $! will reflect the return value |
104 | executed synchronously. In both cases, $! will reflect the return value |
94 | of the function. |
105 | of the function. |
95 | |
106 | |
96 | BDB functions that cannot block (mostly functions that manipulate |
107 | BDB functions that cannot block (mostly functions that manipulate |
97 | settings) are method calls on the relevant objects, so the rule of thumb |
108 | 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 |
109 | is: if it's a method, it's not blocking, if it's a function, it takes a |
99 | callback as last argument. |
110 | callback as last argument. |
100 | |
111 | |
101 | In the following, $int signifies an integer return value, "octetstring" |
112 | In the following, $int signifies an integer return value, "octetstring" |
102 | is a "binary string" (i.e. a perl string with no character indices |
113 | 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" |
114 | >255), "U32" is an unsigned 32 bit integer, "int" is some integer, "NV" |
… | |
… | |
329 | DESTROY (DBC_ornull *dbc) |
340 | DESTROY (DBC_ornull *dbc) |
330 | CODE: |
341 | CODE: |
331 | if (dbc) |
342 | if (dbc) |
332 | dbc->c_close (dbc); |
343 | dbc->c_close (dbc); |
333 | |
344 | |
|
|
345 | $int = $cursor->set_priority ($priority = PRIORITY_*) |
|
|
346 | |
334 | Example: |
347 | Example: |
335 | my $c = $db->cursor; |
348 | my $c = $db->cursor; |
336 | |
349 | |
337 | for (;;) { |
350 | for (;;) { |
338 | db_c_get $c, my $key, my $data, BDB::NEXT; |
351 | db_c_get $c, my $key, my $data, BDB::NEXT; |
… | |
… | |
356 | flags: SEQ_DEC SEQ_INC SEQ_WRAP |
369 | flags: SEQ_DEC SEQ_INC SEQ_WRAP |
357 | $int = $seq->set_range (db_seq_t min, db_seq_t max) |
370 | $int = $seq->set_range (db_seq_t min, db_seq_t max) |
358 | |
371 | |
359 | Example: |
372 | Example: |
360 | my $seq = $db->sequence; |
373 | my $seq = $db->sequence; |
361 | |
374 | |
362 | db_sequence_open $seq, undef, "seq", BDB::CREATE; |
375 | db_sequence_open $seq, undef, "seq", BDB::CREATE; |
363 | db_sequence_get $seq, undef, 1, my $value; |
376 | db_sequence_get $seq, undef, 1, my $value; |
364 | |
377 | |
365 | SUPPORT FUNCTIONS |
378 | SUPPORT FUNCTIONS |
366 | EVENT PROCESSING AND EVENT LOOP INTEGRATION |
379 | EVENT PROCESSING AND EVENT LOOP INTEGRATION |
367 | $msg = BDB::strerror [$errno] |
380 | $msg = BDB::strerror [$errno] |
368 | Returns the string corresponding to the given errno value. If no |
381 | Returns the string corresponding to the given errno value. If no |
369 | argument is given, use $!. |
382 | argument is given, use $!. |
|
|
383 | |
|
|
384 | Note that the BDB module also patches the $! variable directly, so |
|
|
385 | you should be able to get a bdb error string by simply stringifying |
|
|
386 | $!. |
370 | |
387 | |
371 | $fileno = BDB::poll_fileno |
388 | $fileno = BDB::poll_fileno |
372 | Return the *request result pipe file descriptor*. This filehandle |
389 | Return the *request result pipe file descriptor*. This filehandle |
373 | must be polled for reading by some mechanism outside this module |
390 | 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 |
391 | (e.g. Event or select, see below or the SYNOPSIS). If the pipe |