xref: /freebsd/lib/libc/db/man/dbopen.3 (revision 1fae73b137bfc5a237d7258e3c667ba87a36b7ff)
158f0484fSRodney W. Grimes.\" Copyright (c) 1990, 1993
258f0484fSRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
358f0484fSRodney W. Grimes.\"
458f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
558f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions
658f0484fSRodney W. Grimes.\" are met:
758f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
858f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
958f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
1058f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
1158f0484fSRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
1258f0484fSRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software
1358f0484fSRodney W. Grimes.\"    must display the following acknowledgement:
1458f0484fSRodney W. Grimes.\"	This product includes software developed by the University of
1558f0484fSRodney W. Grimes.\"	California, Berkeley and its contributors.
1658f0484fSRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors
1758f0484fSRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
1858f0484fSRodney W. Grimes.\"    without specific prior written permission.
1958f0484fSRodney W. Grimes.\"
2058f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2158f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2258f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2358f0484fSRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2458f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2558f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2658f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2758f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2858f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2958f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3058f0484fSRodney W. Grimes.\" SUCH DAMAGE.
3158f0484fSRodney W. Grimes.\"
3258f0484fSRodney W. Grimes.\"	@(#)dbopen.3	8.5 (Berkeley) 1/2/94
337f3dea24SPeter Wemm.\" $FreeBSD$
3458f0484fSRodney W. Grimes.\"
35d74f3e32SRuslan Ermilov.Dd January 2, 1994
36d74f3e32SRuslan Ermilov.Dt DBOPEN 3
37d74f3e32SRuslan Ermilov.Os
38d74f3e32SRuslan Ermilov.Sh NAME
39d74f3e32SRuslan Ermilov.Nm dbopen
40d74f3e32SRuslan Ermilov.Nd "database access methods"
41d74f3e32SRuslan Ermilov.Sh SYNOPSIS
4232eef9aeSRuslan Ermilov.In sys/types.h
4332eef9aeSRuslan Ermilov.In db.h
449e542d7dSMark Murray.In fcntl.h
459e542d7dSMark Murray.In limits.h
46d74f3e32SRuslan Ermilov.Ft DB *
47d74f3e32SRuslan Ermilov.Fn dbopen "const char *file" "int flags" "int mode" "DBTYPE type" "const void *openinfo"
48d74f3e32SRuslan Ermilov.Sh DESCRIPTION
491fae73b1SRuslan ErmilovThe
501fae73b1SRuslan Ermilov.Fn dbopen
511fae73b1SRuslan Ermilovfunction
5258f0484fSRodney W. Grimesis the library interface to database files.
5358f0484fSRodney W. GrimesThe supported file formats are btree, hashed and UNIX file oriented.
5458f0484fSRodney W. GrimesThe btree format is a representation of a sorted, balanced tree structure.
5558f0484fSRodney W. GrimesThe hashed format is an extensible, dynamic hashing scheme.
5658f0484fSRodney W. GrimesThe flat-file format is a byte stream file with fixed or variable length
5758f0484fSRodney W. Grimesrecords.
5858f0484fSRodney W. GrimesThe formats and file format specific information are described in detail
5958f0484fSRodney W. Grimesin their respective manual pages
60d74f3e32SRuslan Ermilov.Xr btree 3 ,
61d74f3e32SRuslan Ermilov.Xr hash 3
6258f0484fSRodney W. Grimesand
63d74f3e32SRuslan Ermilov.Xr recno 3 .
64d74f3e32SRuslan Ermilov.Pp
651fae73b1SRuslan ErmilovThe
661fae73b1SRuslan Ermilov.Fn dbopen
671fae73b1SRuslan Ermilovfunction
68d74f3e32SRuslan Ermilovopens
69d74f3e32SRuslan Ermilov.Fa file
7058f0484fSRodney W. Grimesfor reading and/or writing.
7158f0484fSRodney W. GrimesFiles never intended to be preserved on disk may be created by setting
72d74f3e32SRuslan Ermilovthe file parameter to
73d74f3e32SRuslan Ermilov.Dv NULL .
74d74f3e32SRuslan Ermilov.Pp
7558f0484fSRodney W. GrimesThe
76d74f3e32SRuslan Ermilov.Fa flags
7758f0484fSRodney W. Grimesand
78d74f3e32SRuslan Ermilov.Fa mode
79d74f3e32SRuslan Ermilovarguments
8058f0484fSRodney W. Grimesare as specified to the
81d74f3e32SRuslan Ermilov.Xr open 2
82d74f3e32SRuslan Ermilovroutine, however, only the
83d74f3e32SRuslan Ermilov.Dv O_CREAT , O_EXCL , O_EXLOCK , O_NONBLOCK ,
84d74f3e32SRuslan Ermilov.Dv O_RDONLY , O_RDWR , O_SHLOCK
85d74f3e32SRuslan Ermilovand
86d74f3e32SRuslan Ermilov.Dv O_TRUNC
87d74f3e32SRuslan Ermilovflags are meaningful.
88d74f3e32SRuslan Ermilov(Note, opening a database file
89d74f3e32SRuslan Ermilov.Dv O_WRONLY
90d74f3e32SRuslan Ermilovis not possible.)
9158f0484fSRodney W. Grimes.\"Three additional options may be specified by
92d74f3e32SRuslan Ermilov.\".Em or Ns 'ing
9358f0484fSRodney W. Grimes.\"them into the
94d74f3e32SRuslan Ermilov.\".Fa flags
9558f0484fSRodney W. Grimes.\"argument.
96d74f3e32SRuslan Ermilov.\".Bl -tag -width indent
97d74f3e32SRuslan Ermilov.\".It Dv DB_LOCK
9858f0484fSRodney W. Grimes.\"Do the necessary locking in the database to support concurrent access.
9958f0484fSRodney W. Grimes.\"If concurrent access isn't needed or the database is read-only this
10058f0484fSRodney W. Grimes.\"flag should not be set, as it tends to have an associated performance
10158f0484fSRodney W. Grimes.\"penalty.
102d74f3e32SRuslan Ermilov.\".It Dv DB_SHMEM
10358f0484fSRodney W. Grimes.\"Place the underlying memory pool used by the database in shared
10458f0484fSRodney W. Grimes.\"memory.
10558f0484fSRodney W. Grimes.\"Necessary for concurrent access.
106d74f3e32SRuslan Ermilov.\".It Dv DB_TXN
10758f0484fSRodney W. Grimes.\"Support transactions in the database.
108d74f3e32SRuslan Ermilov.\"The
109d74f3e32SRuslan Ermilov.\".Dv DB_LOCK
110d74f3e32SRuslan Ermilov.\"and
111d74f3e32SRuslan Ermilov.\".Dv DB_SHMEM
112d74f3e32SRuslan Ermilov.\"flags must be set as well.
113d74f3e32SRuslan Ermilov.\".El
114d74f3e32SRuslan Ermilov.Pp
11558f0484fSRodney W. GrimesThe
116d74f3e32SRuslan Ermilov.Fa type
117d74f3e32SRuslan Ermilovargument is of type
118d74f3e32SRuslan Ermilov.Ft DBTYPE
119d74f3e32SRuslan Ermilov(as defined in the
120d74f3e32SRuslan Ermilov.Aq Pa db.h
121d74f3e32SRuslan Ermilovinclude file) and
122d74f3e32SRuslan Ermilovmay be set to
123d74f3e32SRuslan Ermilov.Dv DB_BTREE , DB_HASH
124d74f3e32SRuslan Ermilovor
125d74f3e32SRuslan Ermilov.Dv DB_RECNO .
126d74f3e32SRuslan Ermilov.Pp
12758f0484fSRodney W. GrimesThe
128d74f3e32SRuslan Ermilov.Fa openinfo
12958f0484fSRodney W. Grimesargument is a pointer to an access method specific structure described
13058f0484fSRodney W. Grimesin the access method's manual page.
13158f0484fSRodney W. GrimesIf
132d74f3e32SRuslan Ermilov.Fa openinfo
133d74f3e32SRuslan Ermilovis
134d74f3e32SRuslan Ermilov.Dv NULL ,
135d74f3e32SRuslan Ermiloveach access method will use defaults appropriate for the system
13658f0484fSRodney W. Grimesand the access method.
137d74f3e32SRuslan Ermilov.Pp
1381fae73b1SRuslan ErmilovThe
1391fae73b1SRuslan Ermilov.Fn dbopen
1401fae73b1SRuslan Ermilovfunction
141d74f3e32SRuslan Ermilovreturns a pointer to a
142d74f3e32SRuslan Ermilov.Ft DB
143d74f3e32SRuslan Ermilovstructure on success and
144d74f3e32SRuslan Ermilov.Dv NULL
145d74f3e32SRuslan Ermilovon error.
146d74f3e32SRuslan ErmilovThe
147d74f3e32SRuslan Ermilov.Ft DB
148d74f3e32SRuslan Ermilovstructure is defined in the
149d74f3e32SRuslan Ermilov.Aq Pa db.h
150d74f3e32SRuslan Ermilovinclude file, and contains at
15158f0484fSRodney W. Grimesleast the following fields:
152d74f3e32SRuslan Ermilov.Bd -literal
15358f0484fSRodney W. Grimestypedef struct {
15458f0484fSRodney W. Grimes	DBTYPE type;
15558f0484fSRodney W. Grimes	int (*close)(const DB *db);
15658f0484fSRodney W. Grimes	int (*del)(const DB *db, const DBT *key, u_int flags);
15758f0484fSRodney W. Grimes	int (*fd)(const DB *db);
15858f0484fSRodney W. Grimes	int (*get)(const DB *db, DBT *key, DBT *data, u_int flags);
15958f0484fSRodney W. Grimes	int (*put)(const DB *db, DBT *key, const DBT *data,
16058f0484fSRodney W. Grimes	     u_int flags);
16158f0484fSRodney W. Grimes	int (*sync)(const DB *db, u_int flags);
16258f0484fSRodney W. Grimes	int (*seq)(const DB *db, DBT *key, DBT *data, u_int flags);
16358f0484fSRodney W. Grimes} DB;
164d74f3e32SRuslan Ermilov.Ed
165d74f3e32SRuslan Ermilov.Pp
16658f0484fSRodney W. GrimesThese elements describe a database type and a set of functions performing
16758f0484fSRodney W. Grimesvarious actions.
16858f0484fSRodney W. GrimesThese functions take a pointer to a structure as returned by
169d74f3e32SRuslan Ermilov.Fn dbopen ,
17058f0484fSRodney W. Grimesand sometimes one or more pointers to key/data structures and a flag value.
171d74f3e32SRuslan Ermilov.Bl -tag -width indent
172d74f3e32SRuslan Ermilov.It Va type
17358f0484fSRodney W. GrimesThe type of the underlying access method (and file format).
174d74f3e32SRuslan Ermilov.It Va close
17558f0484fSRodney W. GrimesA pointer to a routine to flush any cached information to disk, free any
17658f0484fSRodney W. Grimesallocated resources, and close the underlying file(s).
17758f0484fSRodney W. GrimesSince key/data pairs may be cached in memory, failing to sync the file
17858f0484fSRodney W. Grimeswith a
179d74f3e32SRuslan Ermilov.Va close
18058f0484fSRodney W. Grimesor
181d74f3e32SRuslan Ermilov.Va sync
18258f0484fSRodney W. Grimesfunction may result in inconsistent or lost information.
183d74f3e32SRuslan Ermilov.Va Close
18458f0484fSRodney W. Grimesroutines return -1 on error (setting
185d74f3e32SRuslan Ermilov.Va errno )
18658f0484fSRodney W. Grimesand 0 on success.
187d74f3e32SRuslan Ermilov.It Va del
18858f0484fSRodney W. GrimesA pointer to a routine to remove key/data pairs from the database.
189d74f3e32SRuslan Ermilov.Pp
19058f0484fSRodney W. GrimesThe parameter
191d74f3e32SRuslan Ermilov.Fa flags
19258f0484fSRodney W. Grimesmay be set to the following value:
193d74f3e32SRuslan Ermilov.Bl -tag -width indent
194d74f3e32SRuslan Ermilov.It Dv R_CURSOR
19558f0484fSRodney W. GrimesDelete the record referenced by the cursor.
19658f0484fSRodney W. GrimesThe cursor must have previously been initialized.
197d74f3e32SRuslan Ermilov.El
198d74f3e32SRuslan Ermilov.Pp
199d74f3e32SRuslan Ermilov.Va Delete
20058f0484fSRodney W. Grimesroutines return -1 on error (setting
201d74f3e32SRuslan Ermilov.Va errno ) ,
20258f0484fSRodney W. Grimes0 on success, and 1 if the specified
203d74f3e32SRuslan Ermilov.Fa key
20458f0484fSRodney W. Grimeswas not in the file.
205d74f3e32SRuslan Ermilov.It Va fd
20658f0484fSRodney W. GrimesA pointer to a routine which returns a file descriptor representative
20758f0484fSRodney W. Grimesof the underlying database.
20858f0484fSRodney W. GrimesA file descriptor referencing the same file will be returned to all
20958f0484fSRodney W. Grimesprocesses which call
210d74f3e32SRuslan Ermilov.Fn dbopen
21158f0484fSRodney W. Grimeswith the same
212d74f3e32SRuslan Ermilov.Fa file
21358f0484fSRodney W. Grimesname.
21458f0484fSRodney W. GrimesThis file descriptor may be safely used as an argument to the
215d74f3e32SRuslan Ermilov.Xr fcntl 2
21658f0484fSRodney W. Grimesand
217d74f3e32SRuslan Ermilov.Xr flock 2
21858f0484fSRodney W. Grimeslocking functions.
21958f0484fSRodney W. GrimesThe file descriptor is not necessarily associated with any of the
22058f0484fSRodney W. Grimesunderlying files used by the access method.
22158f0484fSRodney W. GrimesNo file descriptor is available for in memory databases.
222d74f3e32SRuslan Ermilov.Va \&Fd
22358f0484fSRodney W. Grimesroutines return -1 on error (setting
224d74f3e32SRuslan Ermilov.Va errno ) ,
22558f0484fSRodney W. Grimesand the file descriptor on success.
226d74f3e32SRuslan Ermilov.It Va get
22758f0484fSRodney W. GrimesA pointer to a routine which is the interface for keyed retrieval from
22858f0484fSRodney W. Grimesthe database.
22958f0484fSRodney W. GrimesThe address and length of the data associated with the specified
230d74f3e32SRuslan Ermilov.Fa key
23158f0484fSRodney W. Grimesare returned in the structure referenced by
232d74f3e32SRuslan Ermilov.Fa data .
233d74f3e32SRuslan Ermilov.Va Get
23458f0484fSRodney W. Grimesroutines return -1 on error (setting
235d74f3e32SRuslan Ermilov.Va errno ) ,
23658f0484fSRodney W. Grimes0 on success, and 1 if the
237d74f3e32SRuslan Ermilov.Fa key
23858f0484fSRodney W. Grimeswas not in the file.
239d74f3e32SRuslan Ermilov.It Va put
24058f0484fSRodney W. GrimesA pointer to a routine to store key/data pairs in the database.
241d74f3e32SRuslan Ermilov.Pp
24258f0484fSRodney W. GrimesThe parameter
243d74f3e32SRuslan Ermilov.Fa flags
24458f0484fSRodney W. Grimesmay be set to one of the following values:
245d74f3e32SRuslan Ermilov.Bl -tag -width indent
246d74f3e32SRuslan Ermilov.It Dv R_CURSOR
24758f0484fSRodney W. GrimesReplace the key/data pair referenced by the cursor.
24858f0484fSRodney W. GrimesThe cursor must have previously been initialized.
249d74f3e32SRuslan Ermilov.It Dv R_IAFTER
25058f0484fSRodney W. GrimesAppend the data immediately after the data referenced by
251d74f3e32SRuslan Ermilov.Fa key ,
25258f0484fSRodney W. Grimescreating a new key/data pair.
25358f0484fSRodney W. GrimesThe record number of the appended key/data pair is returned in the
254d74f3e32SRuslan Ermilov.Fa key
25558f0484fSRodney W. Grimesstructure.
256d74f3e32SRuslan Ermilov(Applicable only to the
257d74f3e32SRuslan Ermilov.Dv DB_RECNO
258d74f3e32SRuslan Ermilovaccess method.)
259d74f3e32SRuslan Ermilov.It Dv R_IBEFORE
26058f0484fSRodney W. GrimesInsert the data immediately before the data referenced by
261d74f3e32SRuslan Ermilov.Fa key ,
26258f0484fSRodney W. Grimescreating a new key/data pair.
26358f0484fSRodney W. GrimesThe record number of the inserted key/data pair is returned in the
264d74f3e32SRuslan Ermilov.Fa key
26558f0484fSRodney W. Grimesstructure.
266d74f3e32SRuslan Ermilov(Applicable only to the
267d74f3e32SRuslan Ermilov.Dv DB_RECNO
268d74f3e32SRuslan Ermilovaccess method.)
269d74f3e32SRuslan Ermilov.It Dv R_NOOVERWRITE
27058f0484fSRodney W. GrimesEnter the new key/data pair only if the key does not previously exist.
271d74f3e32SRuslan Ermilov.It Dv R_SETCURSOR
27258f0484fSRodney W. GrimesStore the key/data pair, setting or initializing the position of the
27358f0484fSRodney W. Grimescursor to reference it.
274d74f3e32SRuslan Ermilov(Applicable only to the
275d74f3e32SRuslan Ermilov.Dv DB_BTREE
276d74f3e32SRuslan Ermilovand
277d74f3e32SRuslan Ermilov.Dv DB_RECNO
278d74f3e32SRuslan Ermilovaccess methods.)
279d74f3e32SRuslan Ermilov.El
280d74f3e32SRuslan Ermilov.Pp
281d74f3e32SRuslan Ermilov.Dv R_SETCURSOR
282d74f3e32SRuslan Ermilovis available only for the
283d74f3e32SRuslan Ermilov.Dv DB_BTREE
284d74f3e32SRuslan Ermilovand
285d74f3e32SRuslan Ermilov.Dv DB_RECNO
286d74f3e32SRuslan Ermilovaccess
28758f0484fSRodney W. Grimesmethods because it implies that the keys have an inherent order
28858f0484fSRodney W. Grimeswhich does not change.
289d74f3e32SRuslan Ermilov.Pp
290d74f3e32SRuslan Ermilov.Dv R_IAFTER
291d74f3e32SRuslan Ermilovand
292d74f3e32SRuslan Ermilov.Dv R_IBEFORE
293d74f3e32SRuslan Ermilovare available only for the
294d74f3e32SRuslan Ermilov.Dv DB_RECNO
29558f0484fSRodney W. Grimesaccess method because they each imply that the access method is able to
29658f0484fSRodney W. Grimescreate new keys.
29758f0484fSRodney W. GrimesThis is only true if the keys are ordered and independent, record numbers
29858f0484fSRodney W. Grimesfor example.
299d74f3e32SRuslan Ermilov.Pp
30058f0484fSRodney W. GrimesThe default behavior of the
301d74f3e32SRuslan Ermilov.Va put
30258f0484fSRodney W. Grimesroutines is to enter the new key/data pair, replacing any previously
30358f0484fSRodney W. Grimesexisting key.
304d74f3e32SRuslan Ermilov.Pp
305d74f3e32SRuslan Ermilov.Va Put
30658f0484fSRodney W. Grimesroutines return -1 on error (setting
307d74f3e32SRuslan Ermilov.Va errno ) ,
308d74f3e32SRuslan Ermilov0 on success, and 1 if the
309d74f3e32SRuslan Ermilov.Dv R_NOOVERWRITE
310d74f3e32SRuslan Ermilovflag
31158f0484fSRodney W. Grimeswas set and the key already exists in the file.
312d74f3e32SRuslan Ermilov.It Va seq
31358f0484fSRodney W. GrimesA pointer to a routine which is the interface for sequential
31458f0484fSRodney W. Grimesretrieval from the database.
31558f0484fSRodney W. GrimesThe address and length of the key are returned in the structure
31658f0484fSRodney W. Grimesreferenced by
317d74f3e32SRuslan Ermilov.Fa key ,
31858f0484fSRodney W. Grimesand the address and length of the data are returned in the
31958f0484fSRodney W. Grimesstructure referenced
32058f0484fSRodney W. Grimesby
321d74f3e32SRuslan Ermilov.Fa data .
322d74f3e32SRuslan Ermilov.Pp
32358f0484fSRodney W. GrimesSequential key/data pair retrieval may begin at any time, and the
324d74f3e32SRuslan Ermilovposition of the
325d74f3e32SRuslan Ermilov.Dq cursor
326d74f3e32SRuslan Ermilovis not affected by calls to the
327d74f3e32SRuslan Ermilov.Va del ,
328d74f3e32SRuslan Ermilov.Va get ,
329d74f3e32SRuslan Ermilov.Va put ,
33058f0484fSRodney W. Grimesor
331d74f3e32SRuslan Ermilov.Va sync
33258f0484fSRodney W. Grimesroutines.
33358f0484fSRodney W. GrimesModifications to the database during a sequential scan will be reflected
33458f0484fSRodney W. Grimesin the scan, i.e. records inserted behind the cursor will not be returned
33558f0484fSRodney W. Grimeswhile records inserted in front of the cursor will be returned.
336d74f3e32SRuslan Ermilov.Pp
337d74f3e32SRuslan ErmilovThe
338d74f3e32SRuslan Ermilov.Fa flags
339d74f3e32SRuslan Ermilovvalue
340d74f3e32SRuslan Ermilov.Em must
34158f0484fSRodney W. Grimesbe set to one of the following values:
342d74f3e32SRuslan Ermilov.Bl -tag -width indent
343d74f3e32SRuslan Ermilov.It Dv R_CURSOR
34458f0484fSRodney W. GrimesThe data associated with the specified key is returned.
34558f0484fSRodney W. GrimesThis differs from the
346d74f3e32SRuslan Ermilov.Va get
34758f0484fSRodney W. Grimesroutines in that it sets or initializes the cursor to the location of
34858f0484fSRodney W. Grimesthe key as well.
349d74f3e32SRuslan Ermilov(Note, for the
350d74f3e32SRuslan Ermilov.Dv DB_BTREE
351d74f3e32SRuslan Ermilovaccess method, the returned key is not necessarily an
35258f0484fSRodney W. Grimesexact match for the specified key.
35358f0484fSRodney W. GrimesThe returned key is the smallest key greater than or equal to the specified
35458f0484fSRodney W. Grimeskey, permitting partial key matches and range searches.)
355d74f3e32SRuslan Ermilov.It Dv R_FIRST
35658f0484fSRodney W. GrimesThe first key/data pair of the database is returned, and the cursor
35758f0484fSRodney W. Grimesis set or initialized to reference it.
358d74f3e32SRuslan Ermilov.It Dv R_LAST
35958f0484fSRodney W. GrimesThe last key/data pair of the database is returned, and the cursor
36058f0484fSRodney W. Grimesis set or initialized to reference it.
361d74f3e32SRuslan Ermilov(Applicable only to the
362d74f3e32SRuslan Ermilov.Dv DB_BTREE
363d74f3e32SRuslan Ermilovand
364d74f3e32SRuslan Ermilov.Dv DB_RECNO
365d74f3e32SRuslan Ermilovaccess methods.)
366d74f3e32SRuslan Ermilov.It Dv R_NEXT
36758f0484fSRodney W. GrimesRetrieve the key/data pair immediately after the cursor.
368d74f3e32SRuslan ErmilovIf the cursor is not yet set, this is the same as the
369d74f3e32SRuslan Ermilov.Dv R_FIRST
370d74f3e32SRuslan Ermilovflag.
371d74f3e32SRuslan Ermilov.It Dv R_PREV
37258f0484fSRodney W. GrimesRetrieve the key/data pair immediately before the cursor.
373d74f3e32SRuslan ErmilovIf the cursor is not yet set, this is the same as the
374d74f3e32SRuslan Ermilov.Dv R_LAST
375d74f3e32SRuslan Ermilovflag.
376d74f3e32SRuslan Ermilov(Applicable only to the
377d74f3e32SRuslan Ermilov.Dv DB_BTREE
378d74f3e32SRuslan Ermilovand
379d74f3e32SRuslan Ermilov.Dv DB_RECNO
380d74f3e32SRuslan Ermilovaccess methods.)
381d74f3e32SRuslan Ermilov.El
382d74f3e32SRuslan Ermilov.Pp
383d74f3e32SRuslan Ermilov.Dv R_LAST
384d74f3e32SRuslan Ermilovand
385d74f3e32SRuslan Ermilov.Dv R_PREV
386d74f3e32SRuslan Ermilovare available only for the
387d74f3e32SRuslan Ermilov.Dv DB_BTREE
388d74f3e32SRuslan Ermilovand
389d74f3e32SRuslan Ermilov.Dv DB_RECNO
39058f0484fSRodney W. Grimesaccess methods because they each imply that the keys have an inherent
39158f0484fSRodney W. Grimesorder which does not change.
392d74f3e32SRuslan Ermilov.Pp
393d74f3e32SRuslan Ermilov.Va Seq
39458f0484fSRodney W. Grimesroutines return -1 on error (setting
395d74f3e32SRuslan Ermilov.Va errno ) ,
39658f0484fSRodney W. Grimes0 on success and 1 if there are no key/data pairs less than or greater
39758f0484fSRodney W. Grimesthan the specified or current key.
398d74f3e32SRuslan ErmilovIf the
399d74f3e32SRuslan Ermilov.Dv DB_RECNO
400d74f3e32SRuslan Ermilovaccess method is being used, and if the database file
40158f0484fSRodney W. Grimesis a character special file and no complete key/data pairs are currently
40258f0484fSRodney W. Grimesavailable, the
403d74f3e32SRuslan Ermilov.Va seq
40458f0484fSRodney W. Grimesroutines return 2.
405d74f3e32SRuslan Ermilov.It Va sync
40658f0484fSRodney W. GrimesA pointer to a routine to flush any cached information to disk.
40758f0484fSRodney W. GrimesIf the database is in memory only, the
408d74f3e32SRuslan Ermilov.Va sync
40958f0484fSRodney W. Grimesroutine has no effect and will always succeed.
410d74f3e32SRuslan Ermilov.Pp
411d74f3e32SRuslan ErmilovThe
412d74f3e32SRuslan Ermilov.Fa flags
413d74f3e32SRuslan Ermilovvalue may be set to the following value:
414d74f3e32SRuslan Ermilov.Bl -tag -width indent
415d74f3e32SRuslan Ermilov.It Dv R_RECNOSYNC
416d74f3e32SRuslan ErmilovIf the
417d74f3e32SRuslan Ermilov.Dv DB_RECNO
418d74f3e32SRuslan Ermilovaccess method is being used, this flag causes
419d74f3e32SRuslan Ermilovthe
420d74f3e32SRuslan Ermilov.Va sync
421d74f3e32SRuslan Ermilovroutine to apply to the btree file which underlies the
42258f0484fSRodney W. Grimesrecno file, not the recno file itself.
42358f0484fSRodney W. Grimes(See the
424d74f3e32SRuslan Ermilov.Va bfname
42558f0484fSRodney W. Grimesfield of the
426d74f3e32SRuslan Ermilov.Xr recno 3
42758f0484fSRodney W. Grimesmanual page for more information.)
428d74f3e32SRuslan Ermilov.El
429d74f3e32SRuslan Ermilov.Pp
430d74f3e32SRuslan Ermilov.Va Sync
43158f0484fSRodney W. Grimesroutines return -1 on error (setting
432d74f3e32SRuslan Ermilov.Va errno )
43358f0484fSRodney W. Grimesand 0 on success.
434d74f3e32SRuslan Ermilov.El
435d74f3e32SRuslan Ermilov.Sh "KEY/DATA PAIRS"
43658f0484fSRodney W. GrimesAccess to all file types is based on key/data pairs.
43758f0484fSRodney W. GrimesBoth keys and data are represented by the following data structure:
438d74f3e32SRuslan Ermilov.Bd -literal
43958f0484fSRodney W. Grimestypedef struct {
44058f0484fSRodney W. Grimes	void *data;
44158f0484fSRodney W. Grimes	size_t size;
44258f0484fSRodney W. Grimes} DBT;
443d74f3e32SRuslan Ermilov.Ed
444d74f3e32SRuslan Ermilov.Pp
445d74f3e32SRuslan ErmilovThe elements of the
446d74f3e32SRuslan Ermilov.Ft DBT
447d74f3e32SRuslan Ermilovstructure are defined as follows:
448d74f3e32SRuslan Ermilov.Bl -tag -width "data"
449d74f3e32SRuslan Ermilov.It Va data
45058f0484fSRodney W. GrimesA pointer to a byte string.
451d74f3e32SRuslan Ermilov.It Va size
45258f0484fSRodney W. GrimesThe length of the byte string.
453d74f3e32SRuslan Ermilov.El
454d74f3e32SRuslan Ermilov.Pp
45558f0484fSRodney W. GrimesKey and data byte strings may reference strings of essentially unlimited
45658f0484fSRodney W. Grimeslength although any two of them must fit into available memory at the same
45758f0484fSRodney W. Grimestime.
45858f0484fSRodney W. GrimesIt should be noted that the access methods provide no guarantees about
45958f0484fSRodney W. Grimesbyte string alignment.
460d74f3e32SRuslan Ermilov.Sh ERRORS
46158f0484fSRodney W. GrimesThe
462d74f3e32SRuslan Ermilov.Fn dbopen
46358f0484fSRodney W. Grimesroutine may fail and set
464d74f3e32SRuslan Ermilov.Va errno
46558f0484fSRodney W. Grimesfor any of the errors specified for the library routines
466d74f3e32SRuslan Ermilov.Xr open 2
46758f0484fSRodney W. Grimesand
468d74f3e32SRuslan Ermilov.Xr malloc 3
46958f0484fSRodney W. Grimesor the following:
470d74f3e32SRuslan Ermilov.Bl -tag -width Er
471d74f3e32SRuslan Ermilov.It Bq Er EFTYPE
47258f0484fSRodney W. GrimesA file is incorrectly formatted.
473d74f3e32SRuslan Ermilov.It Bq Er EINVAL
47458f0484fSRodney W. GrimesA parameter has been specified (hash function, pad byte etc.) that is
47558f0484fSRodney W. Grimesincompatible with the current file specification or which is not
47658f0484fSRodney W. Grimesmeaningful for the function (for example, use of the cursor without
47758f0484fSRodney W. Grimesprior initialization) or there is a mismatch between the version
47858f0484fSRodney W. Grimesnumber of file and the software.
479d74f3e32SRuslan Ermilov.El
480d74f3e32SRuslan Ermilov.Pp
48158f0484fSRodney W. GrimesThe
482d74f3e32SRuslan Ermilov.Va close
48358f0484fSRodney W. Grimesroutines may fail and set
484d74f3e32SRuslan Ermilov.Va errno
48558f0484fSRodney W. Grimesfor any of the errors specified for the library routines
486d74f3e32SRuslan Ermilov.Xr close 2 ,
487d74f3e32SRuslan Ermilov.Xr read 2 ,
488d74f3e32SRuslan Ermilov.Xr write 2 ,
489d74f3e32SRuslan Ermilov.Xr free 3 ,
49058f0484fSRodney W. Grimesor
491d74f3e32SRuslan Ermilov.Xr fsync 2 .
492d74f3e32SRuslan Ermilov.Pp
49358f0484fSRodney W. GrimesThe
494d74f3e32SRuslan Ermilov.Va del ,
495d74f3e32SRuslan Ermilov.Va get ,
496d74f3e32SRuslan Ermilov.Va put
49758f0484fSRodney W. Grimesand
498d74f3e32SRuslan Ermilov.Va seq
49958f0484fSRodney W. Grimesroutines may fail and set
500d74f3e32SRuslan Ermilov.Va errno
50158f0484fSRodney W. Grimesfor any of the errors specified for the library routines
502d74f3e32SRuslan Ermilov.Xr read 2 ,
503d74f3e32SRuslan Ermilov.Xr write 2 ,
504d74f3e32SRuslan Ermilov.Xr free 3
50558f0484fSRodney W. Grimesor
506d74f3e32SRuslan Ermilov.Xr malloc 3 .
507d74f3e32SRuslan Ermilov.Pp
50858f0484fSRodney W. GrimesThe
509d74f3e32SRuslan Ermilov.Va fd
51058f0484fSRodney W. Grimesroutines will fail and set
511d74f3e32SRuslan Ermilov.Va errno
512d74f3e32SRuslan Ermilovto
513d74f3e32SRuslan Ermilov.Er ENOENT
514d74f3e32SRuslan Ermilovfor in memory databases.
515d74f3e32SRuslan Ermilov.Pp
51658f0484fSRodney W. GrimesThe
517d74f3e32SRuslan Ermilov.Va sync
51858f0484fSRodney W. Grimesroutines may fail and set
519d74f3e32SRuslan Ermilov.Va errno
52058f0484fSRodney W. Grimesfor any of the errors specified for the library routine
521d74f3e32SRuslan Ermilov.Xr fsync 2 .
522d74f3e32SRuslan Ermilov.Sh SEE ALSO
523d74f3e32SRuslan Ermilov.Xr btree 3 ,
524d74f3e32SRuslan Ermilov.Xr hash 3 ,
525d74f3e32SRuslan Ermilov.Xr mpool 3 ,
526d74f3e32SRuslan Ermilov.Xr recno 3
527d74f3e32SRuslan Ermilov.Rs
528d74f3e32SRuslan Ermilov.%T "LIBTP: Portable, Modular Transactions for UNIX"
529d74f3e32SRuslan Ermilov.%A Margo Seltzer
530d74f3e32SRuslan Ermilov.%A Michael Olson
531d74f3e32SRuslan Ermilov.%R "USENIX proceedings"
532d74f3e32SRuslan Ermilov.%D Winter 1992
533d74f3e32SRuslan Ermilov.Re
534d74f3e32SRuslan Ermilov.Sh BUGS
535d74f3e32SRuslan ErmilovThe typedef
536d74f3e32SRuslan Ermilov.Ft DBT
537d74f3e32SRuslan Ermilovis a mnemonic for
538d74f3e32SRuslan Ermilov.Dq "data base thang" ,
539d74f3e32SRuslan Ermilovand was used
54058f0484fSRodney W. Grimesbecause noone could think of a reasonable name that wasn't already used.
541d74f3e32SRuslan Ermilov.Pp
54258f0484fSRodney W. GrimesThe file descriptor interface is a kluge and will be deleted in a
54358f0484fSRodney W. Grimesfuture version of the interface.
544d74f3e32SRuslan Ermilov.Pp
54558f0484fSRodney W. GrimesNone of the access methods provide any form of concurrent access,
54658f0484fSRodney W. Grimeslocking, or transactions.
547