xref: /freebsd/lib/libc/db/man/dbopen.3 (revision 2efeeba554cbd7bdee9cfe17641c8bd335c7972f)
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
722efeeba5SRuslan Ermilovthe
732efeeba5SRuslan Ermilov.Fa file
742efeeba5SRuslan Ermilovargument to
75d74f3e32SRuslan Ermilov.Dv NULL .
76d74f3e32SRuslan Ermilov.Pp
7758f0484fSRodney W. GrimesThe
78d74f3e32SRuslan Ermilov.Fa flags
7958f0484fSRodney W. Grimesand
80d74f3e32SRuslan Ermilov.Fa mode
81d74f3e32SRuslan Ermilovarguments
8258f0484fSRodney W. Grimesare as specified to the
83d74f3e32SRuslan Ermilov.Xr open 2
84d74f3e32SRuslan Ermilovroutine, however, only the
85d74f3e32SRuslan Ermilov.Dv O_CREAT , O_EXCL , O_EXLOCK , O_NONBLOCK ,
86d74f3e32SRuslan Ermilov.Dv O_RDONLY , O_RDWR , O_SHLOCK
87d74f3e32SRuslan Ermilovand
88d74f3e32SRuslan Ermilov.Dv O_TRUNC
89d74f3e32SRuslan Ermilovflags are meaningful.
90d74f3e32SRuslan Ermilov(Note, opening a database file
91d74f3e32SRuslan Ermilov.Dv O_WRONLY
92d74f3e32SRuslan Ermilovis not possible.)
9358f0484fSRodney W. Grimes.\"Three additional options may be specified by
94d74f3e32SRuslan Ermilov.\".Em or Ns 'ing
9558f0484fSRodney W. Grimes.\"them into the
96d74f3e32SRuslan Ermilov.\".Fa flags
9758f0484fSRodney W. Grimes.\"argument.
98d74f3e32SRuslan Ermilov.\".Bl -tag -width indent
99d74f3e32SRuslan Ermilov.\".It Dv DB_LOCK
10058f0484fSRodney W. Grimes.\"Do the necessary locking in the database to support concurrent access.
10158f0484fSRodney W. Grimes.\"If concurrent access isn't needed or the database is read-only this
10258f0484fSRodney W. Grimes.\"flag should not be set, as it tends to have an associated performance
10358f0484fSRodney W. Grimes.\"penalty.
104d74f3e32SRuslan Ermilov.\".It Dv DB_SHMEM
10558f0484fSRodney W. Grimes.\"Place the underlying memory pool used by the database in shared
10658f0484fSRodney W. Grimes.\"memory.
10758f0484fSRodney W. Grimes.\"Necessary for concurrent access.
108d74f3e32SRuslan Ermilov.\".It Dv DB_TXN
10958f0484fSRodney W. Grimes.\"Support transactions in the database.
110d74f3e32SRuslan Ermilov.\"The
111d74f3e32SRuslan Ermilov.\".Dv DB_LOCK
112d74f3e32SRuslan Ermilov.\"and
113d74f3e32SRuslan Ermilov.\".Dv DB_SHMEM
114d74f3e32SRuslan Ermilov.\"flags must be set as well.
115d74f3e32SRuslan Ermilov.\".El
116d74f3e32SRuslan Ermilov.Pp
11758f0484fSRodney W. GrimesThe
118d74f3e32SRuslan Ermilov.Fa type
119d74f3e32SRuslan Ermilovargument is of type
120d74f3e32SRuslan Ermilov.Ft DBTYPE
121d74f3e32SRuslan Ermilov(as defined in the
122d74f3e32SRuslan Ermilov.Aq Pa db.h
123d74f3e32SRuslan Ermilovinclude file) and
124d74f3e32SRuslan Ermilovmay be set to
125d74f3e32SRuslan Ermilov.Dv DB_BTREE , DB_HASH
126d74f3e32SRuslan Ermilovor
127d74f3e32SRuslan Ermilov.Dv DB_RECNO .
128d74f3e32SRuslan Ermilov.Pp
12958f0484fSRodney W. GrimesThe
130d74f3e32SRuslan Ermilov.Fa openinfo
13158f0484fSRodney W. Grimesargument is a pointer to an access method specific structure described
13258f0484fSRodney W. Grimesin the access method's manual page.
13358f0484fSRodney W. GrimesIf
134d74f3e32SRuslan Ermilov.Fa openinfo
135d74f3e32SRuslan Ermilovis
136d74f3e32SRuslan Ermilov.Dv NULL ,
137d74f3e32SRuslan Ermiloveach access method will use defaults appropriate for the system
13858f0484fSRodney W. Grimesand the access method.
139d74f3e32SRuslan Ermilov.Pp
1401fae73b1SRuslan ErmilovThe
1411fae73b1SRuslan Ermilov.Fn dbopen
1421fae73b1SRuslan Ermilovfunction
143d74f3e32SRuslan Ermilovreturns a pointer to a
144d74f3e32SRuslan Ermilov.Ft DB
145d74f3e32SRuslan Ermilovstructure on success and
146d74f3e32SRuslan Ermilov.Dv NULL
147d74f3e32SRuslan Ermilovon error.
148d74f3e32SRuslan ErmilovThe
149d74f3e32SRuslan Ermilov.Ft DB
150d74f3e32SRuslan Ermilovstructure is defined in the
151d74f3e32SRuslan Ermilov.Aq Pa db.h
152d74f3e32SRuslan Ermilovinclude file, and contains at
15358f0484fSRodney W. Grimesleast the following fields:
154d74f3e32SRuslan Ermilov.Bd -literal
15558f0484fSRodney W. Grimestypedef struct {
15658f0484fSRodney W. Grimes	DBTYPE type;
15758f0484fSRodney W. Grimes	int (*close)(const DB *db);
15858f0484fSRodney W. Grimes	int (*del)(const DB *db, const DBT *key, u_int flags);
15958f0484fSRodney W. Grimes	int (*fd)(const DB *db);
16058f0484fSRodney W. Grimes	int (*get)(const DB *db, DBT *key, DBT *data, u_int flags);
16158f0484fSRodney W. Grimes	int (*put)(const DB *db, DBT *key, const DBT *data,
16258f0484fSRodney W. Grimes	     u_int flags);
16358f0484fSRodney W. Grimes	int (*sync)(const DB *db, u_int flags);
16458f0484fSRodney W. Grimes	int (*seq)(const DB *db, DBT *key, DBT *data, u_int flags);
16558f0484fSRodney W. Grimes} DB;
166d74f3e32SRuslan Ermilov.Ed
167d74f3e32SRuslan Ermilov.Pp
16858f0484fSRodney W. GrimesThese elements describe a database type and a set of functions performing
16958f0484fSRodney W. Grimesvarious actions.
17058f0484fSRodney W. GrimesThese functions take a pointer to a structure as returned by
171d74f3e32SRuslan Ermilov.Fn dbopen ,
17258f0484fSRodney W. Grimesand sometimes one or more pointers to key/data structures and a flag value.
173d74f3e32SRuslan Ermilov.Bl -tag -width indent
174d74f3e32SRuslan Ermilov.It Va type
17558f0484fSRodney W. GrimesThe type of the underlying access method (and file format).
176d74f3e32SRuslan Ermilov.It Va close
17758f0484fSRodney W. GrimesA pointer to a routine to flush any cached information to disk, free any
17858f0484fSRodney W. Grimesallocated resources, and close the underlying file(s).
17958f0484fSRodney W. GrimesSince key/data pairs may be cached in memory, failing to sync the file
18058f0484fSRodney W. Grimeswith a
181d74f3e32SRuslan Ermilov.Va close
18258f0484fSRodney W. Grimesor
183d74f3e32SRuslan Ermilov.Va sync
18458f0484fSRodney W. Grimesfunction may result in inconsistent or lost information.
1852efeeba5SRuslan Ermilov.Va close
18658f0484fSRodney W. Grimesroutines return -1 on error (setting
187d74f3e32SRuslan Ermilov.Va errno )
18858f0484fSRodney W. Grimesand 0 on success.
189d74f3e32SRuslan Ermilov.It Va del
19058f0484fSRodney W. GrimesA pointer to a routine to remove key/data pairs from the database.
191d74f3e32SRuslan Ermilov.Pp
1922efeeba5SRuslan ErmilovThe
193d74f3e32SRuslan Ermilov.Fa flags
1942efeeba5SRuslan Ermilovargument
19558f0484fSRodney W. Grimesmay be set to the following value:
196d74f3e32SRuslan Ermilov.Bl -tag -width indent
197d74f3e32SRuslan Ermilov.It Dv R_CURSOR
19858f0484fSRodney W. GrimesDelete the record referenced by the cursor.
19958f0484fSRodney W. GrimesThe cursor must have previously been initialized.
200d74f3e32SRuslan Ermilov.El
201d74f3e32SRuslan Ermilov.Pp
2022efeeba5SRuslan Ermilov.Va delete
20358f0484fSRodney W. Grimesroutines return -1 on error (setting
204d74f3e32SRuslan Ermilov.Va errno ) ,
20558f0484fSRodney W. Grimes0 on success, and 1 if the specified
206d74f3e32SRuslan Ermilov.Fa key
20758f0484fSRodney W. Grimeswas not in the file.
208d74f3e32SRuslan Ermilov.It Va fd
20958f0484fSRodney W. GrimesA pointer to a routine which returns a file descriptor representative
21058f0484fSRodney W. Grimesof the underlying database.
21158f0484fSRodney W. GrimesA file descriptor referencing the same file will be returned to all
21258f0484fSRodney W. Grimesprocesses which call
213d74f3e32SRuslan Ermilov.Fn dbopen
21458f0484fSRodney W. Grimeswith the same
215d74f3e32SRuslan Ermilov.Fa file
21658f0484fSRodney W. Grimesname.
21758f0484fSRodney W. GrimesThis file descriptor may be safely used as an argument to the
218d74f3e32SRuslan Ermilov.Xr fcntl 2
21958f0484fSRodney W. Grimesand
220d74f3e32SRuslan Ermilov.Xr flock 2
22158f0484fSRodney W. Grimeslocking functions.
22258f0484fSRodney W. GrimesThe file descriptor is not necessarily associated with any of the
22358f0484fSRodney W. Grimesunderlying files used by the access method.
22458f0484fSRodney W. GrimesNo file descriptor is available for in memory databases.
225d74f3e32SRuslan Ermilov.Va \&Fd
22658f0484fSRodney W. Grimesroutines return -1 on error (setting
227d74f3e32SRuslan Ermilov.Va errno ) ,
22858f0484fSRodney W. Grimesand the file descriptor on success.
229d74f3e32SRuslan Ermilov.It Va get
23058f0484fSRodney W. GrimesA pointer to a routine which is the interface for keyed retrieval from
23158f0484fSRodney W. Grimesthe database.
23258f0484fSRodney W. GrimesThe address and length of the data associated with the specified
233d74f3e32SRuslan Ermilov.Fa key
23458f0484fSRodney W. Grimesare returned in the structure referenced by
235d74f3e32SRuslan Ermilov.Fa data .
2362efeeba5SRuslan Ermilov.Va get
23758f0484fSRodney W. Grimesroutines return -1 on error (setting
238d74f3e32SRuslan Ermilov.Va errno ) ,
23958f0484fSRodney W. Grimes0 on success, and 1 if the
240d74f3e32SRuslan Ermilov.Fa key
24158f0484fSRodney W. Grimeswas not in the file.
242d74f3e32SRuslan Ermilov.It Va put
24358f0484fSRodney W. GrimesA pointer to a routine to store key/data pairs in the database.
244d74f3e32SRuslan Ermilov.Pp
2452efeeba5SRuslan ErmilovThe
246d74f3e32SRuslan Ermilov.Fa flags
2472efeeba5SRuslan Ermilovargument
24858f0484fSRodney W. Grimesmay be set to one of the following values:
249d74f3e32SRuslan Ermilov.Bl -tag -width indent
250d74f3e32SRuslan Ermilov.It Dv R_CURSOR
25158f0484fSRodney W. GrimesReplace the key/data pair referenced by the cursor.
25258f0484fSRodney W. GrimesThe cursor must have previously been initialized.
253d74f3e32SRuslan Ermilov.It Dv R_IAFTER
25458f0484fSRodney W. GrimesAppend the data immediately after the data referenced by
255d74f3e32SRuslan Ermilov.Fa key ,
25658f0484fSRodney W. Grimescreating a new key/data pair.
25758f0484fSRodney W. GrimesThe record number of the appended key/data pair is returned in the
258d74f3e32SRuslan Ermilov.Fa key
25958f0484fSRodney W. Grimesstructure.
260d74f3e32SRuslan Ermilov(Applicable only to the
261d74f3e32SRuslan Ermilov.Dv DB_RECNO
262d74f3e32SRuslan Ermilovaccess method.)
263d74f3e32SRuslan Ermilov.It Dv R_IBEFORE
26458f0484fSRodney W. GrimesInsert the data immediately before the data referenced by
265d74f3e32SRuslan Ermilov.Fa key ,
26658f0484fSRodney W. Grimescreating a new key/data pair.
26758f0484fSRodney W. GrimesThe record number of the inserted key/data pair is returned in the
268d74f3e32SRuslan Ermilov.Fa key
26958f0484fSRodney W. Grimesstructure.
270d74f3e32SRuslan Ermilov(Applicable only to the
271d74f3e32SRuslan Ermilov.Dv DB_RECNO
272d74f3e32SRuslan Ermilovaccess method.)
273d74f3e32SRuslan Ermilov.It Dv R_NOOVERWRITE
27458f0484fSRodney W. GrimesEnter the new key/data pair only if the key does not previously exist.
275d74f3e32SRuslan Ermilov.It Dv R_SETCURSOR
27658f0484fSRodney W. GrimesStore the key/data pair, setting or initializing the position of the
27758f0484fSRodney W. Grimescursor to reference it.
278d74f3e32SRuslan Ermilov(Applicable only to the
279d74f3e32SRuslan Ermilov.Dv DB_BTREE
280d74f3e32SRuslan Ermilovand
281d74f3e32SRuslan Ermilov.Dv DB_RECNO
282d74f3e32SRuslan Ermilovaccess methods.)
283d74f3e32SRuslan Ermilov.El
284d74f3e32SRuslan Ermilov.Pp
285d74f3e32SRuslan Ermilov.Dv R_SETCURSOR
286d74f3e32SRuslan Ermilovis available only for the
287d74f3e32SRuslan Ermilov.Dv DB_BTREE
288d74f3e32SRuslan Ermilovand
289d74f3e32SRuslan Ermilov.Dv DB_RECNO
290d74f3e32SRuslan Ermilovaccess
29158f0484fSRodney W. Grimesmethods because it implies that the keys have an inherent order
29258f0484fSRodney W. Grimeswhich does not change.
293d74f3e32SRuslan Ermilov.Pp
294d74f3e32SRuslan Ermilov.Dv R_IAFTER
295d74f3e32SRuslan Ermilovand
296d74f3e32SRuslan Ermilov.Dv R_IBEFORE
297d74f3e32SRuslan Ermilovare available only for the
298d74f3e32SRuslan Ermilov.Dv DB_RECNO
29958f0484fSRodney W. Grimesaccess method because they each imply that the access method is able to
30058f0484fSRodney W. Grimescreate new keys.
30158f0484fSRodney W. GrimesThis is only true if the keys are ordered and independent, record numbers
30258f0484fSRodney W. Grimesfor example.
303d74f3e32SRuslan Ermilov.Pp
30458f0484fSRodney W. GrimesThe default behavior of the
305d74f3e32SRuslan Ermilov.Va put
30658f0484fSRodney W. Grimesroutines is to enter the new key/data pair, replacing any previously
30758f0484fSRodney W. Grimesexisting key.
308d74f3e32SRuslan Ermilov.Pp
3092efeeba5SRuslan Ermilov.Va put
31058f0484fSRodney W. Grimesroutines return -1 on error (setting
311d74f3e32SRuslan Ermilov.Va errno ) ,
312d74f3e32SRuslan Ermilov0 on success, and 1 if the
313d74f3e32SRuslan Ermilov.Dv R_NOOVERWRITE
314d74f3e32SRuslan Ermilovflag
31558f0484fSRodney W. Grimeswas set and the key already exists in the file.
316d74f3e32SRuslan Ermilov.It Va seq
31758f0484fSRodney W. GrimesA pointer to a routine which is the interface for sequential
31858f0484fSRodney W. Grimesretrieval from the database.
31958f0484fSRodney W. GrimesThe address and length of the key are returned in the structure
32058f0484fSRodney W. Grimesreferenced by
321d74f3e32SRuslan Ermilov.Fa key ,
32258f0484fSRodney W. Grimesand the address and length of the data are returned in the
32358f0484fSRodney W. Grimesstructure referenced
32458f0484fSRodney W. Grimesby
325d74f3e32SRuslan Ermilov.Fa data .
326d74f3e32SRuslan Ermilov.Pp
32758f0484fSRodney W. GrimesSequential key/data pair retrieval may begin at any time, and the
328d74f3e32SRuslan Ermilovposition of the
329d74f3e32SRuslan Ermilov.Dq cursor
330d74f3e32SRuslan Ermilovis not affected by calls to the
331d74f3e32SRuslan Ermilov.Va del ,
332d74f3e32SRuslan Ermilov.Va get ,
333d74f3e32SRuslan Ermilov.Va put ,
33458f0484fSRodney W. Grimesor
335d74f3e32SRuslan Ermilov.Va sync
33658f0484fSRodney W. Grimesroutines.
33758f0484fSRodney W. GrimesModifications to the database during a sequential scan will be reflected
33858f0484fSRodney W. Grimesin the scan, i.e. records inserted behind the cursor will not be returned
33958f0484fSRodney W. Grimeswhile records inserted in front of the cursor will be returned.
340d74f3e32SRuslan Ermilov.Pp
341d74f3e32SRuslan ErmilovThe
342d74f3e32SRuslan Ermilov.Fa flags
3432efeeba5SRuslan Ermilovargument
344d74f3e32SRuslan Ermilov.Em must
34558f0484fSRodney W. Grimesbe set to one of the following values:
346d74f3e32SRuslan Ermilov.Bl -tag -width indent
347d74f3e32SRuslan Ermilov.It Dv R_CURSOR
34858f0484fSRodney W. GrimesThe data associated with the specified key is returned.
34958f0484fSRodney W. GrimesThis differs from the
350d74f3e32SRuslan Ermilov.Va get
35158f0484fSRodney W. Grimesroutines in that it sets or initializes the cursor to the location of
35258f0484fSRodney W. Grimesthe key as well.
353d74f3e32SRuslan Ermilov(Note, for the
354d74f3e32SRuslan Ermilov.Dv DB_BTREE
355d74f3e32SRuslan Ermilovaccess method, the returned key is not necessarily an
35658f0484fSRodney W. Grimesexact match for the specified key.
35758f0484fSRodney W. GrimesThe returned key is the smallest key greater than or equal to the specified
35858f0484fSRodney W. Grimeskey, permitting partial key matches and range searches.)
359d74f3e32SRuslan Ermilov.It Dv R_FIRST
36058f0484fSRodney W. GrimesThe first key/data pair of the database is returned, and the cursor
36158f0484fSRodney W. Grimesis set or initialized to reference it.
362d74f3e32SRuslan Ermilov.It Dv R_LAST
36358f0484fSRodney W. GrimesThe last key/data pair of the database is returned, and the cursor
36458f0484fSRodney W. Grimesis set or initialized to reference it.
365d74f3e32SRuslan Ermilov(Applicable only to the
366d74f3e32SRuslan Ermilov.Dv DB_BTREE
367d74f3e32SRuslan Ermilovand
368d74f3e32SRuslan Ermilov.Dv DB_RECNO
369d74f3e32SRuslan Ermilovaccess methods.)
370d74f3e32SRuslan Ermilov.It Dv R_NEXT
37158f0484fSRodney W. GrimesRetrieve the key/data pair immediately after the cursor.
372d74f3e32SRuslan ErmilovIf the cursor is not yet set, this is the same as the
373d74f3e32SRuslan Ermilov.Dv R_FIRST
374d74f3e32SRuslan Ermilovflag.
375d74f3e32SRuslan Ermilov.It Dv R_PREV
37658f0484fSRodney W. GrimesRetrieve the key/data pair immediately before the cursor.
377d74f3e32SRuslan ErmilovIf the cursor is not yet set, this is the same as the
378d74f3e32SRuslan Ermilov.Dv R_LAST
379d74f3e32SRuslan Ermilovflag.
380d74f3e32SRuslan Ermilov(Applicable only to the
381d74f3e32SRuslan Ermilov.Dv DB_BTREE
382d74f3e32SRuslan Ermilovand
383d74f3e32SRuslan Ermilov.Dv DB_RECNO
384d74f3e32SRuslan Ermilovaccess methods.)
385d74f3e32SRuslan Ermilov.El
386d74f3e32SRuslan Ermilov.Pp
387d74f3e32SRuslan Ermilov.Dv R_LAST
388d74f3e32SRuslan Ermilovand
389d74f3e32SRuslan Ermilov.Dv R_PREV
390d74f3e32SRuslan Ermilovare available only for the
391d74f3e32SRuslan Ermilov.Dv DB_BTREE
392d74f3e32SRuslan Ermilovand
393d74f3e32SRuslan Ermilov.Dv DB_RECNO
39458f0484fSRodney W. Grimesaccess methods because they each imply that the keys have an inherent
39558f0484fSRodney W. Grimesorder which does not change.
396d74f3e32SRuslan Ermilov.Pp
3972efeeba5SRuslan Ermilov.Va seq
39858f0484fSRodney W. Grimesroutines return -1 on error (setting
399d74f3e32SRuslan Ermilov.Va errno ) ,
40058f0484fSRodney W. Grimes0 on success and 1 if there are no key/data pairs less than or greater
40158f0484fSRodney W. Grimesthan the specified or current key.
402d74f3e32SRuslan ErmilovIf the
403d74f3e32SRuslan Ermilov.Dv DB_RECNO
404d74f3e32SRuslan Ermilovaccess method is being used, and if the database file
40558f0484fSRodney W. Grimesis a character special file and no complete key/data pairs are currently
40658f0484fSRodney W. Grimesavailable, the
407d74f3e32SRuslan Ermilov.Va seq
40858f0484fSRodney W. Grimesroutines return 2.
409d74f3e32SRuslan Ermilov.It Va sync
41058f0484fSRodney W. GrimesA pointer to a routine to flush any cached information to disk.
41158f0484fSRodney W. GrimesIf the database is in memory only, the
412d74f3e32SRuslan Ermilov.Va sync
41358f0484fSRodney W. Grimesroutine has no effect and will always succeed.
414d74f3e32SRuslan Ermilov.Pp
415d74f3e32SRuslan ErmilovThe
416d74f3e32SRuslan Ermilov.Fa flags
4172efeeba5SRuslan Ermilovargument may be set to the following value:
418d74f3e32SRuslan Ermilov.Bl -tag -width indent
419d74f3e32SRuslan Ermilov.It Dv R_RECNOSYNC
420d74f3e32SRuslan ErmilovIf the
421d74f3e32SRuslan Ermilov.Dv DB_RECNO
422d74f3e32SRuslan Ermilovaccess method is being used, this flag causes
423d74f3e32SRuslan Ermilovthe
424d74f3e32SRuslan Ermilov.Va sync
425d74f3e32SRuslan Ermilovroutine to apply to the btree file which underlies the
42658f0484fSRodney W. Grimesrecno file, not the recno file itself.
42758f0484fSRodney W. Grimes(See the
428d74f3e32SRuslan Ermilov.Va bfname
42958f0484fSRodney W. Grimesfield of the
430d74f3e32SRuslan Ermilov.Xr recno 3
43158f0484fSRodney W. Grimesmanual page for more information.)
432d74f3e32SRuslan Ermilov.El
433d74f3e32SRuslan Ermilov.Pp
4342efeeba5SRuslan Ermilov.Va sync
43558f0484fSRodney W. Grimesroutines return -1 on error (setting
436d74f3e32SRuslan Ermilov.Va errno )
43758f0484fSRodney W. Grimesand 0 on success.
438d74f3e32SRuslan Ermilov.El
439d74f3e32SRuslan Ermilov.Sh "KEY/DATA PAIRS"
44058f0484fSRodney W. GrimesAccess to all file types is based on key/data pairs.
44158f0484fSRodney W. GrimesBoth keys and data are represented by the following data structure:
442d74f3e32SRuslan Ermilov.Bd -literal
44358f0484fSRodney W. Grimestypedef struct {
44458f0484fSRodney W. Grimes	void *data;
44558f0484fSRodney W. Grimes	size_t size;
44658f0484fSRodney W. Grimes} DBT;
447d74f3e32SRuslan Ermilov.Ed
448d74f3e32SRuslan Ermilov.Pp
449d74f3e32SRuslan ErmilovThe elements of the
450d74f3e32SRuslan Ermilov.Ft DBT
451d74f3e32SRuslan Ermilovstructure are defined as follows:
452d74f3e32SRuslan Ermilov.Bl -tag -width "data"
453d74f3e32SRuslan Ermilov.It Va data
45458f0484fSRodney W. GrimesA pointer to a byte string.
455d74f3e32SRuslan Ermilov.It Va size
45658f0484fSRodney W. GrimesThe length of the byte string.
457d74f3e32SRuslan Ermilov.El
458d74f3e32SRuslan Ermilov.Pp
45958f0484fSRodney W. GrimesKey and data byte strings may reference strings of essentially unlimited
46058f0484fSRodney W. Grimeslength although any two of them must fit into available memory at the same
46158f0484fSRodney W. Grimestime.
46258f0484fSRodney W. GrimesIt should be noted that the access methods provide no guarantees about
46358f0484fSRodney W. Grimesbyte string alignment.
464d74f3e32SRuslan Ermilov.Sh ERRORS
46558f0484fSRodney W. GrimesThe
466d74f3e32SRuslan Ermilov.Fn dbopen
46758f0484fSRodney W. Grimesroutine may fail and set
468d74f3e32SRuslan Ermilov.Va errno
46958f0484fSRodney W. Grimesfor any of the errors specified for the library routines
470d74f3e32SRuslan Ermilov.Xr open 2
47158f0484fSRodney W. Grimesand
472d74f3e32SRuslan Ermilov.Xr malloc 3
47358f0484fSRodney W. Grimesor the following:
474d74f3e32SRuslan Ermilov.Bl -tag -width Er
475d74f3e32SRuslan Ermilov.It Bq Er EFTYPE
47658f0484fSRodney W. GrimesA file is incorrectly formatted.
477d74f3e32SRuslan Ermilov.It Bq Er EINVAL
4782efeeba5SRuslan ErmilovAn argument has been specified (hash function, pad byte etc.) that is
47958f0484fSRodney W. Grimesincompatible with the current file specification or which is not
48058f0484fSRodney W. Grimesmeaningful for the function (for example, use of the cursor without
48158f0484fSRodney W. Grimesprior initialization) or there is a mismatch between the version
48258f0484fSRodney W. Grimesnumber of file and the software.
483d74f3e32SRuslan Ermilov.El
484d74f3e32SRuslan Ermilov.Pp
48558f0484fSRodney W. GrimesThe
486d74f3e32SRuslan Ermilov.Va close
48758f0484fSRodney W. Grimesroutines may fail and set
488d74f3e32SRuslan Ermilov.Va errno
48958f0484fSRodney W. Grimesfor any of the errors specified for the library routines
490d74f3e32SRuslan Ermilov.Xr close 2 ,
491d74f3e32SRuslan Ermilov.Xr read 2 ,
492d74f3e32SRuslan Ermilov.Xr write 2 ,
493d74f3e32SRuslan Ermilov.Xr free 3 ,
49458f0484fSRodney W. Grimesor
495d74f3e32SRuslan Ermilov.Xr fsync 2 .
496d74f3e32SRuslan Ermilov.Pp
49758f0484fSRodney W. GrimesThe
498d74f3e32SRuslan Ermilov.Va del ,
499d74f3e32SRuslan Ermilov.Va get ,
500d74f3e32SRuslan Ermilov.Va put
50158f0484fSRodney W. Grimesand
502d74f3e32SRuslan Ermilov.Va seq
50358f0484fSRodney W. Grimesroutines may fail and set
504d74f3e32SRuslan Ermilov.Va errno
50558f0484fSRodney W. Grimesfor any of the errors specified for the library routines
506d74f3e32SRuslan Ermilov.Xr read 2 ,
507d74f3e32SRuslan Ermilov.Xr write 2 ,
508d74f3e32SRuslan Ermilov.Xr free 3
50958f0484fSRodney W. Grimesor
510d74f3e32SRuslan Ermilov.Xr malloc 3 .
511d74f3e32SRuslan Ermilov.Pp
51258f0484fSRodney W. GrimesThe
513d74f3e32SRuslan Ermilov.Va fd
51458f0484fSRodney W. Grimesroutines will fail and set
515d74f3e32SRuslan Ermilov.Va errno
516d74f3e32SRuslan Ermilovto
517d74f3e32SRuslan Ermilov.Er ENOENT
518d74f3e32SRuslan Ermilovfor in memory databases.
519d74f3e32SRuslan Ermilov.Pp
52058f0484fSRodney W. GrimesThe
521d74f3e32SRuslan Ermilov.Va sync
52258f0484fSRodney W. Grimesroutines may fail and set
523d74f3e32SRuslan Ermilov.Va errno
52458f0484fSRodney W. Grimesfor any of the errors specified for the library routine
525d74f3e32SRuslan Ermilov.Xr fsync 2 .
526d74f3e32SRuslan Ermilov.Sh SEE ALSO
527d74f3e32SRuslan Ermilov.Xr btree 3 ,
528d74f3e32SRuslan Ermilov.Xr hash 3 ,
529d74f3e32SRuslan Ermilov.Xr mpool 3 ,
530d74f3e32SRuslan Ermilov.Xr recno 3
531d74f3e32SRuslan Ermilov.Rs
532d74f3e32SRuslan Ermilov.%T "LIBTP: Portable, Modular Transactions for UNIX"
533d74f3e32SRuslan Ermilov.%A Margo Seltzer
534d74f3e32SRuslan Ermilov.%A Michael Olson
535d74f3e32SRuslan Ermilov.%R "USENIX proceedings"
536d74f3e32SRuslan Ermilov.%D Winter 1992
537d74f3e32SRuslan Ermilov.Re
538d74f3e32SRuslan Ermilov.Sh BUGS
539d74f3e32SRuslan ErmilovThe typedef
540d74f3e32SRuslan Ermilov.Ft DBT
541d74f3e32SRuslan Ermilovis a mnemonic for
542d74f3e32SRuslan Ermilov.Dq "data base thang" ,
543d74f3e32SRuslan Ermilovand was used
54458f0484fSRodney W. Grimesbecause noone could think of a reasonable name that wasn't already used.
545d74f3e32SRuslan Ermilov.Pp
54658f0484fSRodney W. GrimesThe file descriptor interface is a kluge and will be deleted in a
54758f0484fSRodney W. Grimesfuture version of the interface.
548d74f3e32SRuslan Ermilov.Pp
54958f0484fSRodney W. GrimesNone of the access methods provide any form of concurrent access,
55058f0484fSRodney W. Grimeslocking, or transactions.
551