… | |
… | |
108 | no warnings; |
108 | no warnings; |
109 | use strict 'vars'; |
109 | use strict 'vars'; |
110 | |
110 | |
111 | use base 'Exporter'; |
111 | use base 'Exporter'; |
112 | |
112 | |
|
|
113 | our $VERSION; |
|
|
114 | |
113 | BEGIN { |
115 | BEGIN { |
114 | our $VERSION = '1.6'; |
116 | $VERSION = '1.8'; |
115 | |
117 | |
116 | our @BDB_REQ = qw( |
118 | our @BDB_REQ = qw( |
117 | db_env_open db_env_close db_env_txn_checkpoint db_env_lock_detect |
119 | db_env_open db_env_close db_env_txn_checkpoint db_env_lock_detect |
118 | db_env_memp_sync db_env_memp_trickle db_env_dbrename db_env_dbremove |
120 | db_env_memp_sync db_env_memp_trickle db_env_dbrename db_env_dbremove |
119 | db_open db_close db_compact db_sync db_upgrade |
121 | db_open db_close db_compact db_sync db_upgrade |
120 | db_put db_get db_pget db_del db_key_range |
122 | db_put db_exists db_get db_pget db_del db_key_range |
121 | db_txn_commit db_txn_abort db_txn_finish |
123 | db_txn_commit db_txn_abort db_txn_finish |
122 | db_c_close db_c_count db_c_put db_c_get db_c_pget db_c_del |
124 | db_c_close db_c_count db_c_put db_c_get db_c_pget db_c_del |
123 | db_sequence_open db_sequence_close |
125 | db_sequence_open db_sequence_close |
124 | db_sequence_get db_sequence_remove |
126 | db_sequence_get db_sequence_remove |
125 | ); |
127 | ); |
… | |
… | |
160 | In the following, C<$int> signifies an integer return value, |
162 | In the following, C<$int> signifies an integer return value, |
161 | C<bdb_filename> is a "filename" (octets on unix, madness on windows), |
163 | C<bdb_filename> is a "filename" (octets on unix, madness on windows), |
162 | C<U32> is an unsigned 32 bit integer, C<int> is some integer, C<NV> is a |
164 | C<U32> is an unsigned 32 bit integer, C<int> is some integer, C<NV> is a |
163 | floating point value. |
165 | floating point value. |
164 | |
166 | |
165 | The C<SV *> types are generic perl scalars (for input and output of data |
167 | Most C<SV *> types are generic perl scalars (for input and output of data |
166 | values), and the C<SV *callback> is the optional callback function to call |
168 | values). |
167 | when the request is completed. |
|
|
168 | |
169 | |
169 | The various C<DB_ENV> etc. arguments are handles return by |
170 | The various C<DB_ENV> etc. arguments are handles return by |
170 | C<db_env_create>, C<db_create>, C<txn_begin> and so on. If they have an |
171 | C<db_env_create>, C<db_create>, C<txn_begin> and so on. If they have an |
171 | appended C<_ornull> this means they are optional and you can pass C<undef> |
172 | appended C<_ornull> this means they are optional and you can pass C<undef> |
172 | for them, resulting a NULL pointer on the C level. |
173 | for them, resulting a NULL pointer on the C level. |
|
|
174 | |
|
|
175 | The C<SV *callback> is the optional callback function to call when the |
|
|
176 | request is completed. This last callback argument is special: the callback |
|
|
177 | is simply the last argument passed. If there are "optional" arguments |
|
|
178 | before the callback they can be left out. The callback itself can be left |
|
|
179 | out or specified as C<undef>, in which case the function will be executed |
|
|
180 | synchronously. |
|
|
181 | |
|
|
182 | For example, C<db_env_txn_checkpoint> usually is called with all integer |
|
|
183 | arguments zero. These can be left out, so all of these specify a call |
|
|
184 | to C<< DB_ENV->txn_checkpoint >>, to be executed asynchronously with a |
|
|
185 | callback to be called: |
|
|
186 | |
|
|
187 | db_env_txn_checkpoint $db_env, 0, 0, 0, sub { }; |
|
|
188 | db_env_txn_checkpoint $db_env, 0, 0, sub { }; |
|
|
189 | db_env_txn_checkpoint $db_env, sub { }; |
|
|
190 | |
|
|
191 | While these all specify a call to C<< DB_ENV->txn_checkpoint >> to be |
|
|
192 | executed synchronously: |
|
|
193 | |
|
|
194 | db_env_txn_checkpoint $db_env, 0, 0, 0, undef; |
|
|
195 | db_env_txn_checkpoint $db_env, 0, 0, 0; |
|
|
196 | db_env_txn_checkpoint $db_env, 0; |
173 | |
197 | |
174 | =head3 BDB functions |
198 | =head3 BDB functions |
175 | |
199 | |
176 | Functions in the BDB namespace, exported by default: |
200 | Functions in the BDB namespace, exported by default: |
177 | |
201 | |
… | |
… | |
202 | flags: FREELIST_ONLY FREE_SPACE |
226 | flags: FREELIST_ONLY FREE_SPACE |
203 | db_sync (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) |
227 | db_sync (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) |
204 | db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = &PL_sv_undef) |
228 | db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = &PL_sv_undef) |
205 | db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
229 | db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
206 | flags: APPEND NODUPDATA NOOVERWRITE |
230 | flags: APPEND NODUPDATA NOOVERWRITE |
|
|
231 | db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) (v4.6) |
207 | db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
232 | db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
208 | flags: CONSUME CONSUME_WAIT GET_BOTH SET_RECNO MULTIPLE READ_COMMITTED READ_UNCOMMITTED RMW |
233 | flags: CONSUME CONSUME_WAIT GET_BOTH SET_RECNO MULTIPLE READ_COMMITTED READ_UNCOMMITTED RMW |
209 | db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
234 | db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
210 | flags: CONSUME CONSUME_WAIT GET_BOTH SET_RECNO MULTIPLE READ_COMMITTED READ_UNCOMMITTED RMW |
235 | flags: CONSUME CONSUME_WAIT GET_BOTH SET_RECNO MULTIPLE READ_COMMITTED READ_UNCOMMITTED RMW |
211 | db_del (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = &PL_sv_undef) |
236 | db_del (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = &PL_sv_undef) |
… | |
… | |
279 | $int = $env->set_tmp_dir (const char *dir) |
304 | $int = $env->set_tmp_dir (const char *dir) |
280 | $int = $env->set_lg_dir (const char *dir) |
305 | $int = $env->set_lg_dir (const char *dir) |
281 | $int = $env->set_shm_key (long shm_key) |
306 | $int = $env->set_shm_key (long shm_key) |
282 | $int = $env->set_cachesize (U32 gbytes, U32 bytes, int ncache = 0) |
307 | $int = $env->set_cachesize (U32 gbytes, U32 bytes, int ncache = 0) |
283 | $int = $env->set_flags (U32 flags, int onoff = 1) |
308 | $int = $env->set_flags (U32 flags, int onoff = 1) |
284 | $int = $env->log_set_config (U32 flags, int onoff = 1) [v4.7] |
309 | $int = $env->log_set_config (U32 flags, int onoff = 1) (v4.7) |
285 | $int = $env->set_intermediate_dir_mode (const char *modestring) [v4.7] |
310 | $int = $env->set_intermediate_dir_mode (const char *modestring) (v4.7) |
286 | $env->set_errfile (FILE *errfile = 0) |
311 | $env->set_errfile (FILE *errfile = 0) |
287 | $env->set_msgfile (FILE *msgfile = 0) |
312 | $env->set_msgfile (FILE *msgfile = 0) |
288 | $int = $env->set_verbose (U32 which, int onoff = 1) |
313 | $int = $env->set_verbose (U32 which, int onoff = 1) |
289 | $int = $env->set_encrypt (const char *password, U32 flags = 0) |
314 | $int = $env->set_encrypt (const char *password, U32 flags = 0) |
290 | $int = $env->set_timeout (NV timeout_seconds, U32 flags = SET_TXN_TIMEOUT) |
315 | $int = $env->set_timeout (NV timeout_seconds, U32 flags = SET_TXN_TIMEOUT) |
… | |
… | |
302 | $int = $env->mutex_set_max (U32 max) |
327 | $int = $env->mutex_set_max (U32 max) |
303 | $int = $env->mutex_set_align (U32 align) |
328 | $int = $env->mutex_set_align (U32 align) |
304 | |
329 | |
305 | $txn = $env->txn_begin (DB_TXN_ornull *parent = 0, U32 flags = 0) |
330 | $txn = $env->txn_begin (DB_TXN_ornull *parent = 0, U32 flags = 0) |
306 | flags: READ_COMMITTED READ_UNCOMMITTED TXN_NOSYNC TXN_NOWAIT TXN_SNAPSHOT TXN_SYNC TXN_WAIT TXN_WRITE_NOSYNC |
331 | flags: READ_COMMITTED READ_UNCOMMITTED TXN_NOSYNC TXN_NOWAIT TXN_SNAPSHOT TXN_SYNC TXN_WAIT TXN_WRITE_NOSYNC |
|
|
332 | $txn = $env->cdsgroup_begin; (v4.5) |
307 | |
333 | |
308 | =head4 Example: |
334 | =head4 Example: |
309 | |
335 | |
310 | use AnyEvent; |
336 | use AnyEvent; |
311 | use BDB; |
337 | use BDB; |
… | |
… | |
403 | DESTROY (DBC_ornull *dbc) |
429 | DESTROY (DBC_ornull *dbc) |
404 | CODE: |
430 | CODE: |
405 | if (dbc) |
431 | if (dbc) |
406 | dbc->c_close (dbc); |
432 | dbc->c_close (dbc); |
407 | |
433 | |
408 | $int = $cursor->set_priority ($priority = PRIORITY_*) |
434 | $int = $cursor->set_priority ($priority = PRIORITY_*) (v4.6) |
409 | |
435 | |
410 | =head4 Example: |
436 | =head4 Example: |
411 | |
437 | |
412 | my $c = $db->cursor; |
438 | my $c = $db->cursor; |
413 | |
439 | |
… | |
… | |
546 | |
572 | |
547 | BerkeleyDB comes in various versions, many of them have minor |
573 | BerkeleyDB comes in various versions, many of them have minor |
548 | incompatibilities. This means that traditional "at least version x.x" |
574 | incompatibilities. This means that traditional "at least version x.x" |
549 | checks are often not sufficient. |
575 | checks are often not sufficient. |
550 | |
576 | |
551 | Example: set the log_autoremove option in a way compatible with <v.47 and |
577 | Example: set the log_autoremove option in a way compatible with <v4.7 and |
552 | v4.7. Note the use of & on the constants to avoid triggering a compiletime |
578 | v4.7. Note the use of & on the constants to avoid triggering a compiletime |
553 | bug when the symbol isn't available. |
579 | bug when the symbol isn't available. |
554 | |
580 | |
555 | $DB_ENV->set_flags (&BDB::LOG_AUTOREMOVE ) if BDB::VERSION v0, v4.7; |
581 | $DB_ENV->set_flags (&BDB::LOG_AUTOREMOVE ) if BDB::VERSION v0, v4.7; |
556 | $DB_ENV->log_set_config (&BDB::LOG_AUTO_REMOVE) if BDB::VERSION v4.7; |
582 | $DB_ENV->log_set_config (&BDB::LOG_AUTO_REMOVE) if BDB::VERSION v4.7; |
… | |
… | |
589 | =back |
615 | =back |
590 | |
616 | |
591 | =cut |
617 | =cut |
592 | |
618 | |
593 | sub VERSION { |
619 | sub VERSION { |
|
|
620 | # I was dumb enough to override the VERSION method here, so let's try |
|
|
621 | # to fix it up. |
|
|
622 | |
|
|
623 | if ($_[0] eq __PACKAGE__) { |
|
|
624 | $VERSION |
|
|
625 | } else { |
594 | if (@_ > 0) { |
626 | if (@_ > 0) { |
595 | return undef if VERSION_v lt $_[0]; |
627 | return undef if VERSION_v lt $_[0]; |
596 | if (@_ > 1) { |
628 | if (@_ > 1) { |
597 | return undef if VERSION_v ge $_[1]; |
629 | return undef if VERSION_v ge $_[1]; |
|
|
630 | } |
598 | } |
631 | } |
|
|
632 | |
|
|
633 | VERSION_v |
599 | } |
634 | } |
600 | |
|
|
601 | VERSION_v |
|
|
602 | } |
635 | } |
603 | |
636 | |
604 | =head3 CONTROLLING THE NUMBER OF THREADS |
637 | =head3 CONTROLLING THE NUMBER OF THREADS |
605 | |
638 | |
606 | =over 4 |
639 | =over 4 |