3 DB_File.xs -- Perl 5 interface to Berkeley DB
5 written by Paul Marquess (pmarquess@bfsec.bt.co.uk)
6 last modified 19th November 1998
9 All comments/suggestions/problems are welcome
11 Copyright (c) 1995, 1996, 1997, 1998 Paul Marquess. All rights reserved.
12 This program is free software; you can redistribute it and/or
13 modify it under the same terms as Perl itself.
17 0.2 - No longer bombs out if dbopen returns an error.
18 0.3 - Added some support for multiple btree compares
19 1.0 - Complete support for multiple callbacks added.
20 Fixed a problem with pushing a value onto an empty list.
21 1.01 - Fixed a SunOS core dump problem.
22 The return value from TIEHASH wasn't set to NULL when
23 dbopen returned an error.
24 1.02 - Use ALIAS to define TIEARRAY.
25 Removed some redundant commented code.
26 Merged OS2 code into the main distribution.
27 Allow negative subscripts with RECNO interface.
28 Changed the default flags to O_CREAT|O_RDWR
30 1.04 - fixed a couple of bugs in hash_cb. Patches supplied by
31 Dave Hammen, hammen@gothamcity.jsc.nasa.gov
32 1.05 - Added logic to allow prefix & hash types to be specified via
34 1.06 - Minor namespace cleanup: Localized PrintBtree.
35 1.07 - Fixed bug with RECNO, where bval wasn't defaulting to "\n".
36 1.08 - No change to DB_File.xs
37 1.09 - Default mode for dbopen changed to 0666
38 1.10 - Fixed fd method so that it still returns -1 for
39 in-memory files when db 1.86 is used.
40 1.11 - No change to DB_File.xs
41 1.12 - No change to DB_File.xs
42 1.13 - Tidied up a few casts.
43 1.14 - Made it illegal to tie an associative array to a RECNO
44 database and an ordinary array to a HASH or BTREE database.
45 1.50 - Make work with both DB 1.x or DB 2.x
46 1.51 - Fixed a bug in mapping 1.x O_RDONLY flag to 2.x DB_RDONLY equivalent
47 1.52 - Patch from Gisle Aas <gisle@aas.no> to suppress "use of
48 undefined value" warning with db_get and db_seq.
49 1.53 - Added DB_RENUMBER to flags for recno.
50 1.54 - Fixed bug in the fd method
51 1.55 - Fix for AIX from Jarkko Hietaniemi
52 1.56 - No change to DB_File.xs
53 1.57 - added the #undef op to allow building with Threads support.
54 1.58 - Fixed a problem with the use of sv_setpvn. When the
55 size is specified as 0, it does a strlen on the data.
56 This was ok for DB 1.x, but isn't for DB 2.x.
57 1.59 - No change to DB_File.xs
58 1.60 - Some code tidy up
59 1.61 - added flagSet macro for DB 2.5.x
60 fixed typo in O_RDONLY test.
70 /* Being the Berkeley DB we prefer the <sys/cdefs.h> (which will be
71 * shortly #included by the <db.h>) __attribute__ to the possibly
72 * already defined __attribute__, for example by GNUC or by Perl. */
76 /* If Perl has been compiled with Threads support,the symbol op will
77 be defined here. This clashes with a field name in db.h, so get rid of it.
90 #ifdef DB_VERSION_MAJOR
92 /* map version 2 features & constants onto their version 1 equivalent */
97 #define DB_Prefix_t size_t
102 #define DB_Hash_t u_int32_t
104 /* DBTYPE stays the same */
105 /* HASHINFO, RECNOINFO and BTREEINFO map to DB_INFO */
106 typedef DB_INFO INFO ;
108 /* version 2 has db_recno_t in place of recno_t */
109 typedef db_recno_t recno_t;
112 #define R_CURSOR DB_SET_RANGE
113 #define R_FIRST DB_FIRST
114 #define R_IAFTER DB_AFTER
115 #define R_IBEFORE DB_BEFORE
116 #define R_LAST DB_LAST
117 #define R_NEXT DB_NEXT
118 #define R_NOOVERWRITE DB_NOOVERWRITE
119 #define R_PREV DB_PREV
120 #define R_SETCURSOR 0
121 #define R_RECNOSYNC 0
122 #define R_FIXEDLEN DB_FIXEDLEN
125 #define db_HA_hash h_hash
126 #define db_HA_ffactor h_ffactor
127 #define db_HA_nelem h_nelem
128 #define db_HA_bsize db_pagesize
129 #define db_HA_cachesize db_cachesize
130 #define db_HA_lorder db_lorder
132 #define db_BT_compare bt_compare
133 #define db_BT_prefix bt_prefix
134 #define db_BT_flags flags
135 #define db_BT_psize db_pagesize
136 #define db_BT_cachesize db_cachesize
137 #define db_BT_lorder db_lorder
138 #define db_BT_maxkeypage
139 #define db_BT_minkeypage
142 #define db_RE_reclen re_len
143 #define db_RE_flags flags
144 #define db_RE_bval re_pad
145 #define db_RE_bfname re_source
146 #define db_RE_psize db_pagesize
147 #define db_RE_cachesize db_cachesize
148 #define db_RE_lorder db_lorder
152 #define do_SEQ(db, key, value, flag) (db->cursor->c_get)(db->cursor, &key, &value, flag)
155 #define DBT_flags(x) x.flags = 0
156 #define DB_flags(x, v) x |= v
158 #if DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR < 5
159 #define flagSet(flags, bitmask) ((flags) & (bitmask))
161 #define flagSet(flags, bitmask) (((flags) & DB_OPFLAGS_MASK) == (bitmask))
164 #else /* db version 1.x */
177 #define DB_Prefix_t mDB_Prefix_t
184 #define DB_Hash_t mDB_Hash_t
187 #define db_HA_hash hash.hash
188 #define db_HA_ffactor hash.ffactor
189 #define db_HA_nelem hash.nelem
190 #define db_HA_bsize hash.bsize
191 #define db_HA_cachesize hash.cachesize
192 #define db_HA_lorder hash.lorder
194 #define db_BT_compare btree.compare
195 #define db_BT_prefix btree.prefix
196 #define db_BT_flags btree.flags
197 #define db_BT_psize btree.psize
198 #define db_BT_cachesize btree.cachesize
199 #define db_BT_lorder btree.lorder
200 #define db_BT_maxkeypage btree.maxkeypage
201 #define db_BT_minkeypage btree.minkeypage
203 #define db_RE_reclen recno.reclen
204 #define db_RE_flags recno.flags
205 #define db_RE_bval recno.bval
206 #define db_RE_bfname recno.bfname
207 #define db_RE_psize recno.psize
208 #define db_RE_cachesize recno.cachesize
209 #define db_RE_lorder recno.lorder
213 #define do_SEQ(db, key, value, flag) (db->dbp->seq)(db->dbp, &key, &value, flag)
215 #define DB_flags(x, v)
216 #define flagSet(flags, bitmask) ((flags) & (bitmask))
218 #endif /* db version 1 */
222 #define db_DELETE(db, key, flags) ((db->dbp)->del)(db->dbp, TXN &key, flags)
223 #define db_STORE(db, key, value, flags) ((db->dbp)->put)(db->dbp, TXN &key, &value, flags)
224 #define db_FETCH(db, key, flags) ((db->dbp)->get)(db->dbp, TXN &key, &value, flags)
226 #define db_sync(db, flags) ((db->dbp)->sync)(db->dbp, flags)
227 #define db_get(db, key, value, flags) ((db->dbp)->get)(db->dbp, TXN &key, &value, flags)
229 #ifdef DB_VERSION_MAJOR
230 #define db_DESTROY(db) ((db->dbp)->close)(db->dbp, 0)
231 #define db_close(db) ((db->dbp)->close)(db->dbp, 0)
232 #define db_del(db, key, flags) (flagSet(flags, R_CURSOR) \
233 ? ((db->cursor)->c_del)(db->cursor, 0) \
234 : ((db->dbp)->del)(db->dbp, NULL, &key, flags) )
238 #define db_DESTROY(db) ((db->dbp)->close)(db->dbp)
239 #define db_close(db) ((db->dbp)->close)(db->dbp)
240 #define db_del(db, key, flags) ((db->dbp)->del)(db->dbp, &key, flags)
241 #define db_put(db, key, value, flags) ((db->dbp)->put)(db->dbp, &key, &value, flags)
246 #define db_seq(db, key, value, flags) do_SEQ(db, key, value, flags)
256 #ifdef DB_VERSION_MAJOR
261 typedef DB_File_type * DB_File ;
264 #define my_sv_setpvn(sv, d, s) sv_setpvn(sv, (s ? d : (void*)""), s)
266 #define OutputValue(arg, name) \
267 { if (RETVAL == 0) { \
268 my_sv_setpvn(arg, name.data, name.size) ; \
272 #define OutputKey(arg, name) \
275 if (db->type != DB_RECNO) { \
276 my_sv_setpvn(arg, name.data, name.size); \
279 sv_setiv(arg, (I32)*(I32*)name.data - 1); \
284 /* Internal Global Data */
285 static recno_t Value ;
286 static recno_t zero = 0 ;
287 static DB_File CurrentDB ;
288 static DBTKEY empty ;
290 #ifdef DB_VERSION_MAJOR
293 db_put(db, key, value, flags)
302 if (flagSet(flags, R_CURSOR)) {
303 status = ((db->cursor)->c_del)(db->cursor, 0);
307 #if DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR < 5
310 flags &= ~DB_OPFLAGS_MASK ;
315 return ((db->dbp)->put)(db->dbp, NULL, &key, &value, flags) ;
319 #endif /* DB_VERSION_MAJOR */
324 SV * ver_sv = perl_get_sv("DB_File::db_version", TRUE) ;
325 #ifdef DB_VERSION_MAJOR
326 int Major, Minor, Patch ;
328 (void)db_version(&Major, &Minor, &Patch) ;
330 /* check that libdb is recent enough */
331 if (Major == 2 && Minor == 0 && Patch < 5)
332 croak("DB_File needs Berkeley DB 2.0.5 or greater, you have %d.%d.%d\n",
333 Major, Minor, Patch) ;
336 sv_setpvf(ver_sv, "%d.%d", Major, Minor) ;
340 sprintf(buffer, "%d.%d", Major, Minor) ;
341 sv_setpv(ver_sv, buffer) ;
346 sv_setiv(ver_sv, 1) ;
353 btree_compare(key1, key2)
358 void * data1, * data2 ;
365 /* As newSVpv will assume that the data pointer is a null terminated C
366 string if the size parameter is 0, make sure that data points to an
367 empty string if the length is 0
379 PUSHs(sv_2mortal(newSVpv(data1,key1->size)));
380 PUSHs(sv_2mortal(newSVpv(data2,key2->size)));
383 count = perl_call_sv(CurrentDB->compare, G_SCALAR);
388 croak ("DB_File btree_compare: expected 1 return value from compare sub, got %d\n", count) ;
400 btree_prefix(key1, key2)
405 void * data1, * data2 ;
412 /* As newSVpv will assume that the data pointer is a null terminated C
413 string if the size parameter is 0, make sure that data points to an
414 empty string if the length is 0
426 PUSHs(sv_2mortal(newSVpv(data1,key1->size)));
427 PUSHs(sv_2mortal(newSVpv(data2,key2->size)));
430 count = perl_call_sv(CurrentDB->prefix, G_SCALAR);
435 croak ("DB_File btree_prefix: expected 1 return value from prefix sub, got %d\n", count) ;
458 /* DGH - Next two lines added to fix corrupted stack problem */
464 XPUSHs(sv_2mortal(newSVpv((char*)data,size)));
467 count = perl_call_sv(CurrentDB->hash, G_SCALAR);
472 croak ("DB_File hash_cb: expected 1 return value from hash sub, got %d\n", count) ;
490 printf ("HASH Info\n") ;
491 printf (" hash = %s\n",
492 (hash->db_HA_hash != NULL ? "redefined" : "default")) ;
493 printf (" bsize = %d\n", hash->db_HA_bsize) ;
494 printf (" ffactor = %d\n", hash->db_HA_ffactor) ;
495 printf (" nelem = %d\n", hash->db_HA_nelem) ;
496 printf (" cachesize = %d\n", hash->db_HA_cachesize) ;
497 printf (" lorder = %d\n", hash->db_HA_lorder) ;
505 printf ("RECNO Info\n") ;
506 printf (" flags = %d\n", recno->db_RE_flags) ;
507 printf (" cachesize = %d\n", recno->db_RE_cachesize) ;
508 printf (" psize = %d\n", recno->db_RE_psize) ;
509 printf (" lorder = %d\n", recno->db_RE_lorder) ;
510 printf (" reclen = %ul\n", (unsigned long)recno->db_RE_reclen) ;
511 printf (" bval = %d 0x%x\n", recno->db_RE_bval, recno->db_RE_bval) ;
512 printf (" bfname = %d [%s]\n", recno->db_RE_bfname, recno->db_RE_bfname) ;
519 printf ("BTREE Info\n") ;
520 printf (" compare = %s\n",
521 (btree->db_BT_compare ? "redefined" : "default")) ;
522 printf (" prefix = %s\n",
523 (btree->db_BT_prefix ? "redefined" : "default")) ;
524 printf (" flags = %d\n", btree->db_BT_flags) ;
525 printf (" cachesize = %d\n", btree->db_BT_cachesize) ;
526 printf (" psize = %d\n", btree->db_BT_psize) ;
527 #ifndef DB_VERSION_MAJOR
528 printf (" maxkeypage = %d\n", btree->db_BT_maxkeypage) ;
529 printf (" minkeypage = %d\n", btree->db_BT_minkeypage) ;
531 printf (" lorder = %d\n", btree->db_BT_lorder) ;
536 #define PrintRecno(recno)
537 #define PrintHash(hash)
538 #define PrintBtree(btree)
553 RETVAL = do_SEQ(db, key, value, R_LAST) ;
555 RETVAL = *(I32 *)key.data ;
556 else /* No key means empty file */
559 return ((I32)RETVAL) ;
563 GetRecnoKey(db, value)
568 /* Get the length of the array */
569 I32 length = GetArrayLength(db) ;
571 /* check for attempt to write before start of array */
572 if (length + value + 1 <= 0)
573 croak("Modification of non-creatable array value attempted, subscript %ld", (long)value) ;
575 value = length + value + 1 ;
584 ParseOpenInfo(isHASH, name, flags, mode, sv)
593 DB_File RETVAL = (DB_File)safemalloc(sizeof(DB_File_type)) ;
594 void * openinfo = NULL ;
595 INFO * info = &RETVAL->info ;
598 /* printf("In ParseOpenInfo name=[%s] flags=[%d] mode = [%d]\n", name, flags, mode) ; */
599 Zero(RETVAL, 1, DB_File_type) ;
601 /* Default to HASH */
602 RETVAL->hash = RETVAL->compare = RETVAL->prefix = NULL ;
603 RETVAL->type = DB_HASH ;
605 /* DGH - Next line added to avoid SEGV on existing hash DB */
608 /* fd for 1.86 hash in memory files doesn't return -1 like 1.85 */
609 RETVAL->in_memory = (name == NULL) ;
614 croak ("type parameter is not a reference") ;
616 svp = hv_fetch( (HV*)SvRV(sv), "GOT", 3, FALSE) ;
617 if (svp && SvOK(*svp))
618 action = (HV*) SvRV(*svp) ;
620 croak("internal error") ;
622 if (sv_isa(sv, "DB_File::HASHINFO"))
626 croak("DB_File can only tie an associative array to a DB_HASH database") ;
628 RETVAL->type = DB_HASH ;
629 openinfo = (void*)info ;
631 svp = hv_fetch(action, "hash", 4, FALSE);
633 if (svp && SvOK(*svp))
635 info->db_HA_hash = hash_cb ;
636 RETVAL->hash = newSVsv(*svp) ;
639 info->db_HA_hash = NULL ;
641 svp = hv_fetch(action, "ffactor", 7, FALSE);
642 info->db_HA_ffactor = svp ? SvIV(*svp) : 0;
644 svp = hv_fetch(action, "nelem", 5, FALSE);
645 info->db_HA_nelem = svp ? SvIV(*svp) : 0;
647 svp = hv_fetch(action, "bsize", 5, FALSE);
648 info->db_HA_bsize = svp ? SvIV(*svp) : 0;
650 svp = hv_fetch(action, "cachesize", 9, FALSE);
651 info->db_HA_cachesize = svp ? SvIV(*svp) : 0;
653 svp = hv_fetch(action, "lorder", 6, FALSE);
654 info->db_HA_lorder = svp ? SvIV(*svp) : 0;
658 else if (sv_isa(sv, "DB_File::BTREEINFO"))
661 croak("DB_File can only tie an associative array to a DB_BTREE database");
663 RETVAL->type = DB_BTREE ;
664 openinfo = (void*)info ;
666 svp = hv_fetch(action, "compare", 7, FALSE);
667 if (svp && SvOK(*svp))
669 info->db_BT_compare = btree_compare ;
670 RETVAL->compare = newSVsv(*svp) ;
673 info->db_BT_compare = NULL ;
675 svp = hv_fetch(action, "prefix", 6, FALSE);
676 if (svp && SvOK(*svp))
678 info->db_BT_prefix = btree_prefix ;
679 RETVAL->prefix = newSVsv(*svp) ;
682 info->db_BT_prefix = NULL ;
684 svp = hv_fetch(action, "flags", 5, FALSE);
685 info->db_BT_flags = svp ? SvIV(*svp) : 0;
687 svp = hv_fetch(action, "cachesize", 9, FALSE);
688 info->db_BT_cachesize = svp ? SvIV(*svp) : 0;
690 #ifndef DB_VERSION_MAJOR
691 svp = hv_fetch(action, "minkeypage", 10, FALSE);
692 info->btree.minkeypage = svp ? SvIV(*svp) : 0;
694 svp = hv_fetch(action, "maxkeypage", 10, FALSE);
695 info->btree.maxkeypage = svp ? SvIV(*svp) : 0;
698 svp = hv_fetch(action, "psize", 5, FALSE);
699 info->db_BT_psize = svp ? SvIV(*svp) : 0;
701 svp = hv_fetch(action, "lorder", 6, FALSE);
702 info->db_BT_lorder = svp ? SvIV(*svp) : 0;
707 else if (sv_isa(sv, "DB_File::RECNOINFO"))
710 croak("DB_File can only tie an array to a DB_RECNO database");
712 RETVAL->type = DB_RECNO ;
713 openinfo = (void *)info ;
715 info->db_RE_flags = 0 ;
717 svp = hv_fetch(action, "flags", 5, FALSE);
718 info->db_RE_flags = (u_long) (svp ? SvIV(*svp) : 0);
720 svp = hv_fetch(action, "reclen", 6, FALSE);
721 info->db_RE_reclen = (size_t) (svp ? SvIV(*svp) : 0);
723 svp = hv_fetch(action, "cachesize", 9, FALSE);
724 info->db_RE_cachesize = (u_int) (svp ? SvIV(*svp) : 0);
726 svp = hv_fetch(action, "psize", 5, FALSE);
727 info->db_RE_psize = (u_int) (svp ? SvIV(*svp) : 0);
729 svp = hv_fetch(action, "lorder", 6, FALSE);
730 info->db_RE_lorder = (int) (svp ? SvIV(*svp) : 0);
732 #ifdef DB_VERSION_MAJOR
733 info->re_source = name ;
736 svp = hv_fetch(action, "bfname", 6, FALSE);
737 if (svp && SvOK(*svp)) {
738 char * ptr = SvPV(*svp,n_a) ;
739 #ifdef DB_VERSION_MAJOR
740 name = (char*) n_a ? ptr : NULL ;
742 info->db_RE_bfname = (char*) (n_a ? ptr : NULL) ;
746 #ifdef DB_VERSION_MAJOR
749 info->db_RE_bfname = NULL ;
752 svp = hv_fetch(action, "bval", 4, FALSE);
753 #ifdef DB_VERSION_MAJOR
754 if (svp && SvOK(*svp))
758 value = (int)*SvPV(*svp, n_a) ;
762 if (info->flags & DB_FIXEDLEN) {
763 info->re_pad = value ;
764 info->flags |= DB_PAD ;
767 info->re_delim = value ;
768 info->flags |= DB_DELIMITER ;
773 if (svp && SvOK(*svp))
776 info->db_RE_bval = (u_char)*SvPV(*svp, n_a) ;
778 info->db_RE_bval = (u_char)(unsigned long) SvIV(*svp) ;
779 DB_flags(info->flags, DB_DELIMITER) ;
784 if (info->db_RE_flags & R_FIXEDLEN)
785 info->db_RE_bval = (u_char) ' ' ;
787 info->db_RE_bval = (u_char) '\n' ;
788 DB_flags(info->flags, DB_DELIMITER) ;
793 info->flags |= DB_RENUMBER ;
799 croak("type is not of type DB_File::HASHINFO, DB_File::BTREEINFO or DB_File::RECNOINFO");
803 /* OS2 Specific Code */
810 #ifdef DB_VERSION_MAJOR
816 /* Map 1.x flags to 2.x flags */
817 if ((flags & O_CREAT) == O_CREAT)
821 if ((flags & O_NONBLOCK) == O_NONBLOCK)
826 if (flags == O_RDONLY)
828 if ((flags & O_RDONLY) == O_RDONLY)
833 if ((flags & O_TRUNC) == O_TRUNC)
834 Flags |= DB_TRUNCATE ;
837 status = db_open(name, RETVAL->type, Flags, mode, NULL, openinfo, &RETVAL->dbp) ;
839 status = (RETVAL->dbp->cursor)(RETVAL->dbp, NULL, &RETVAL->cursor) ;
846 RETVAL->dbp = dbopen(name, flags, mode, RETVAL->type, openinfo) ;
857 croak("DB_File::%s not implemented on this architecture", s);
871 if (strEQ(name, "BTREEMAGIC"))
877 if (strEQ(name, "BTREEVERSION"))
887 if (strEQ(name, "DB_LOCK"))
893 if (strEQ(name, "DB_SHMEM"))
899 if (strEQ(name, "DB_TXN"))
913 if (strEQ(name, "HASHMAGIC"))
919 if (strEQ(name, "HASHVERSION"))
935 if (strEQ(name, "MAX_PAGE_NUMBER"))
936 #ifdef MAX_PAGE_NUMBER
937 return (U32)MAX_PAGE_NUMBER;
941 if (strEQ(name, "MAX_PAGE_OFFSET"))
942 #ifdef MAX_PAGE_OFFSET
943 return MAX_PAGE_OFFSET;
947 if (strEQ(name, "MAX_REC_NUMBER"))
948 #ifdef MAX_REC_NUMBER
949 return (U32)MAX_REC_NUMBER;
963 if (strEQ(name, "RET_ERROR"))
969 if (strEQ(name, "RET_SPECIAL"))
975 if (strEQ(name, "RET_SUCCESS"))
981 if (strEQ(name, "R_CURSOR"))
987 if (strEQ(name, "R_DUP"))
993 if (strEQ(name, "R_FIRST"))
999 if (strEQ(name, "R_FIXEDLEN"))
1005 if (strEQ(name, "R_IAFTER"))
1011 if (strEQ(name, "R_IBEFORE"))
1017 if (strEQ(name, "R_LAST"))
1023 if (strEQ(name, "R_NEXT"))
1029 if (strEQ(name, "R_NOKEY"))
1035 if (strEQ(name, "R_NOOVERWRITE"))
1036 #ifdef R_NOOVERWRITE
1037 return R_NOOVERWRITE;
1041 if (strEQ(name, "R_PREV"))
1047 if (strEQ(name, "R_RECNOSYNC"))
1053 if (strEQ(name, "R_SETCURSOR"))
1059 if (strEQ(name, "R_SNAPSHOT"))
1093 MODULE = DB_File PACKAGE = DB_File PREFIX = db_
1099 empty.data = &zero ;
1100 empty.size = sizeof(recno_t) ;
1111 db_DoTie_(isHASH, dbtype, name=undef, flags=O_CREAT|O_RDWR, mode=0666, type=DB_HASH)
1118 char * name = (char *) NULL ;
1119 SV * sv = (SV *) NULL ;
1122 if (items >= 3 && SvOK(ST(2)))
1123 name = (char*) SvPV(ST(2), n_a) ;
1128 RETVAL = ParseOpenInfo(isHASH, name, flags, mode, sv) ;
1129 if (RETVAL->dbp == NULL)
1142 SvREFCNT_dec(db->hash) ;
1144 SvREFCNT_dec(db->compare) ;
1146 SvREFCNT_dec(db->prefix) ;
1148 #ifdef DB_VERSION_MAJOR
1155 db_DELETE(db, key, flags=0)
1173 RETVAL = (((db->dbp)->get)(db->dbp, TXN &key, &value, 0) == 0) ;
1179 db_FETCH(db, key, flags=0)
1189 /* RETVAL = ((db->dbp)->get)(db->dbp, TXN &key, &value, flags) ; */
1190 RETVAL = db_get(db, key, value, flags) ;
1191 ST(0) = sv_newmortal();
1192 OutputValue(ST(0), value)
1196 db_STORE(db, key, value, flags=0)
1217 RETVAL = do_SEQ(db, key, value, R_FIRST) ;
1218 ST(0) = sv_newmortal();
1219 OutputKey(ST(0), key) ;
1233 RETVAL = do_SEQ(db, key, value, R_NEXT) ;
1234 ST(0) = sv_newmortal();
1235 OutputKey(ST(0), key) ;
1239 # These would be nice for RECNO
1258 #ifdef DB_VERSION_MAJOR
1259 /* get the first value */
1260 RETVAL = do_SEQ(db, key, value, DB_FIRST) ;
1265 for (i = items-1 ; i > 0 ; --i)
1267 value.data = SvPV(ST(i), n_a) ;
1271 key.size = sizeof(int) ;
1272 #ifdef DB_VERSION_MAJOR
1273 RETVAL = (db->cursor->c_put)(db->cursor, &key, &value, DB_BEFORE) ;
1275 RETVAL = (Db->put)(Db, &key, &value, R_IBEFORE) ;
1298 /* First get the final value */
1299 RETVAL = do_SEQ(db, key, value, R_LAST) ;
1300 ST(0) = sv_newmortal();
1304 /* the call to del will trash value, so take a copy now */
1305 OutputValue(ST(0), value) ;
1306 RETVAL = db_del(db, key, R_CURSOR) ;
1308 sv_setsv(ST(0), &PL_sv_undef);
1325 /* get the first value */
1326 RETVAL = do_SEQ(db, key, value, R_FIRST) ;
1327 ST(0) = sv_newmortal();
1331 /* the call to del will trash value, so take a copy now */
1332 OutputValue(ST(0), value) ;
1333 RETVAL = db_del(db, key, R_CURSOR) ;
1335 sv_setsv (ST(0), &PL_sv_undef) ;
1347 DBTKEY * keyptr = &key ;
1356 /* Set the Cursor to the Last element */
1357 RETVAL = do_SEQ(db, key, value, R_LAST) ;
1362 #ifdef DB_VERSION_MAJOR
1363 for (i = 1 ; i < items ; ++i)
1366 ++ (* (int*)key.data) ;
1367 value.data = SvPV(ST(i), n_a) ;
1369 RETVAL = (Db->put)(Db, NULL, &key, &value, 0) ;
1374 for (i = items - 1 ; i > 0 ; --i)
1376 value.data = SvPV(ST(i), n_a) ;
1378 RETVAL = (Db->put)(Db, keyptr, &value, R_IAFTER) ;
1392 ALIAS: FETCHSIZE = 1
1395 RETVAL = GetArrayLength(db) ;
1401 # Now provide an interface to the rest of the DB functionality
1405 db_del(db, key, flags=0)
1411 RETVAL = db_del(db, key, flags) ;
1412 #ifdef DB_VERSION_MAJOR
1415 else if (RETVAL == DB_NOTFOUND)
1423 db_get(db, key, value, flags=0)
1431 RETVAL = db_get(db, key, value, flags) ;
1432 #ifdef DB_VERSION_MAJOR
1435 else if (RETVAL == DB_NOTFOUND)
1443 db_put(db, key, value, flags=0)
1450 RETVAL = db_put(db, key, value, flags) ;
1451 #ifdef DB_VERSION_MAJOR
1454 else if (RETVAL == DB_KEYEXIST)
1459 key if (flagSet(flags, R_IAFTER) || flagSet(flags, R_IBEFORE)) OutputKey(ST(1), key);
1467 #ifdef DB_VERSION_MAJOR
1469 status = (db->in_memory
1471 : ((db->dbp)->fd)(db->dbp, &RETVAL) ) ;
1475 RETVAL = (db->in_memory
1477 : ((db->dbp)->fd)(db->dbp) ) ;
1483 db_sync(db, flags=0)
1488 RETVAL = db_sync(db, flags) ;
1489 #ifdef DB_VERSION_MAJOR
1498 db_seq(db, key, value, flags)
1506 RETVAL = db_seq(db, key, value, flags);
1507 #ifdef DB_VERSION_MAJOR
1510 else if (RETVAL == DB_NOTFOUND)