xref: /freebsd/lib/libc/db/man/dbopen.3 (revision 32eef9aeb1f39a1623cea55da147c89abbd5b9a5)
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 limits.h
4432eef9aeSRuslan Ermilov.In db.h
45d74f3e32SRuslan Ermilov.Ft DB *
46d74f3e32SRuslan Ermilov.Fn dbopen "const char *file" "int flags" "int mode" "DBTYPE type" "const void *openinfo"
47d74f3e32SRuslan Ermilov.Sh DESCRIPTION
48d74f3e32SRuslan Ermilov.Fn Dbopen
4958f0484fSRodney W. Grimesis the library interface to database files.
5058f0484fSRodney W. GrimesThe supported file formats are btree, hashed and UNIX file oriented.
5158f0484fSRodney W. GrimesThe btree format is a representation of a sorted, balanced tree structure.
5258f0484fSRodney W. GrimesThe hashed format is an extensible, dynamic hashing scheme.
5358f0484fSRodney W. GrimesThe flat-file format is a byte stream file with fixed or variable length
5458f0484fSRodney W. Grimesrecords.
5558f0484fSRodney W. GrimesThe formats and file format specific information are described in detail
5658f0484fSRodney W. Grimesin their respective manual pages
57d74f3e32SRuslan Ermilov.Xr btree 3 ,
58d74f3e32SRuslan Ermilov.Xr hash 3
5958f0484fSRodney W. Grimesand
60d74f3e32SRuslan Ermilov.Xr recno 3 .
61d74f3e32SRuslan Ermilov.Pp
62d74f3e32SRuslan Ermilov.Fn Dbopen
63d74f3e32SRuslan Ermilovopens
64d74f3e32SRuslan Ermilov.Fa file
6558f0484fSRodney W. Grimesfor reading and/or writing.
6658f0484fSRodney W. GrimesFiles never intended to be preserved on disk may be created by setting
67d74f3e32SRuslan Ermilovthe file parameter to
68d74f3e32SRuslan Ermilov.Dv NULL .
69d74f3e32SRuslan Ermilov.Pp
7058f0484fSRodney W. GrimesThe
71d74f3e32SRuslan Ermilov.Fa flags
7258f0484fSRodney W. Grimesand
73d74f3e32SRuslan Ermilov.Fa mode
74d74f3e32SRuslan Ermilovarguments
7558f0484fSRodney W. Grimesare as specified to the
76d74f3e32SRuslan Ermilov.Xr open 2
77d74f3e32SRuslan Ermilovroutine, however, only the
78d74f3e32SRuslan Ermilov.Dv O_CREAT , O_EXCL , O_EXLOCK , O_NONBLOCK ,
79d74f3e32SRuslan Ermilov.Dv O_RDONLY , O_RDWR , O_SHLOCK
80d74f3e32SRuslan Ermilovand
81d74f3e32SRuslan Ermilov.Dv O_TRUNC
82d74f3e32SRuslan Ermilovflags are meaningful.
83d74f3e32SRuslan Ermilov(Note, opening a database file
84d74f3e32SRuslan Ermilov.Dv O_WRONLY
85d74f3e32SRuslan Ermilovis not possible.)
8658f0484fSRodney W. Grimes.\"Three additional options may be specified by
87d74f3e32SRuslan Ermilov.\".Em or Ns 'ing
8858f0484fSRodney W. Grimes.\"them into the
89d74f3e32SRuslan Ermilov.\".Fa flags
9058f0484fSRodney W. Grimes.\"argument.
91d74f3e32SRuslan Ermilov.\".Bl -tag -width indent
92d74f3e32SRuslan Ermilov.\".It Dv DB_LOCK
9358f0484fSRodney W. Grimes.\"Do the necessary locking in the database to support concurrent access.
9458f0484fSRodney W. Grimes.\"If concurrent access isn't needed or the database is read-only this
9558f0484fSRodney W. Grimes.\"flag should not be set, as it tends to have an associated performance
9658f0484fSRodney W. Grimes.\"penalty.
97d74f3e32SRuslan Ermilov.\".It Dv DB_SHMEM
9858f0484fSRodney W. Grimes.\"Place the underlying memory pool used by the database in shared
9958f0484fSRodney W. Grimes.\"memory.
10058f0484fSRodney W. Grimes.\"Necessary for concurrent access.
101d74f3e32SRuslan Ermilov.\".It Dv DB_TXN
10258f0484fSRodney W. Grimes.\"Support transactions in the database.
103d74f3e32SRuslan Ermilov.\"The
104d74f3e32SRuslan Ermilov.\".Dv DB_LOCK
105d74f3e32SRuslan Ermilov.\"and
106d74f3e32SRuslan Ermilov.\".Dv DB_SHMEM
107d74f3e32SRuslan Ermilov.\"flags must be set as well.
108d74f3e32SRuslan Ermilov.\".El
109d74f3e32SRuslan Ermilov.Pp
11058f0484fSRodney W. GrimesThe
111d74f3e32SRuslan Ermilov.Fa type
112d74f3e32SRuslan Ermilovargument is of type
113d74f3e32SRuslan Ermilov.Ft DBTYPE
114d74f3e32SRuslan Ermilov(as defined in the
115d74f3e32SRuslan Ermilov.Aq Pa db.h
116d74f3e32SRuslan Ermilovinclude file) and
117d74f3e32SRuslan Ermilovmay be set to
118d74f3e32SRuslan Ermilov.Dv DB_BTREE , DB_HASH
119d74f3e32SRuslan Ermilovor
120d74f3e32SRuslan Ermilov.Dv DB_RECNO .
121d74f3e32SRuslan Ermilov.Pp
12258f0484fSRodney W. GrimesThe
123d74f3e32SRuslan Ermilov.Fa openinfo
12458f0484fSRodney W. Grimesargument is a pointer to an access method specific structure described
12558f0484fSRodney W. Grimesin the access method's manual page.
12658f0484fSRodney W. GrimesIf
127d74f3e32SRuslan Ermilov.Fa openinfo
128d74f3e32SRuslan Ermilovis
129d74f3e32SRuslan Ermilov.Dv NULL ,
130d74f3e32SRuslan Ermiloveach access method will use defaults appropriate for the system
13158f0484fSRodney W. Grimesand the access method.
132d74f3e32SRuslan Ermilov.Pp
133d74f3e32SRuslan Ermilov.Fn Dbopen
134d74f3e32SRuslan Ermilovreturns a pointer to a
135d74f3e32SRuslan Ermilov.Ft DB
136d74f3e32SRuslan Ermilovstructure on success and
137d74f3e32SRuslan Ermilov.Dv NULL
138d74f3e32SRuslan Ermilovon error.
139d74f3e32SRuslan ErmilovThe
140d74f3e32SRuslan Ermilov.Ft DB
141d74f3e32SRuslan Ermilovstructure is defined in the
142d74f3e32SRuslan Ermilov.Aq Pa db.h
143d74f3e32SRuslan Ermilovinclude file, and contains at
14458f0484fSRodney W. Grimesleast the following fields:
145d74f3e32SRuslan Ermilov.Bd -literal
14658f0484fSRodney W. Grimestypedef struct {
14758f0484fSRodney W. Grimes	DBTYPE type;
14858f0484fSRodney W. Grimes	int (*close)(const DB *db);
14958f0484fSRodney W. Grimes	int (*del)(const DB *db, const DBT *key, u_int flags);
15058f0484fSRodney W. Grimes	int (*fd)(const DB *db);
15158f0484fSRodney W. Grimes	int (*get)(const DB *db, DBT *key, DBT *data, u_int flags);
15258f0484fSRodney W. Grimes	int (*put)(const DB *db, DBT *key, const DBT *data,
15358f0484fSRodney W. Grimes	     u_int flags);
15458f0484fSRodney W. Grimes	int (*sync)(const DB *db, u_int flags);
15558f0484fSRodney W. Grimes	int (*seq)(const DB *db, DBT *key, DBT *data, u_int flags);
15658f0484fSRodney W. Grimes} DB;
157d74f3e32SRuslan Ermilov.Ed
158d74f3e32SRuslan Ermilov.Pp
15958f0484fSRodney W. GrimesThese elements describe a database type and a set of functions performing
16058f0484fSRodney W. Grimesvarious actions.
16158f0484fSRodney W. GrimesThese functions take a pointer to a structure as returned by
162d74f3e32SRuslan Ermilov.Fn dbopen ,
16358f0484fSRodney W. Grimesand sometimes one or more pointers to key/data structures and a flag value.
164d74f3e32SRuslan Ermilov.Bl -tag -width indent
165d74f3e32SRuslan Ermilov.It Va type
16658f0484fSRodney W. GrimesThe type of the underlying access method (and file format).
167d74f3e32SRuslan Ermilov.It Va close
16858f0484fSRodney W. GrimesA pointer to a routine to flush any cached information to disk, free any
16958f0484fSRodney W. Grimesallocated resources, and close the underlying file(s).
17058f0484fSRodney W. GrimesSince key/data pairs may be cached in memory, failing to sync the file
17158f0484fSRodney W. Grimeswith a
172d74f3e32SRuslan Ermilov.Va close
17358f0484fSRodney W. Grimesor
174d74f3e32SRuslan Ermilov.Va sync
17558f0484fSRodney W. Grimesfunction may result in inconsistent or lost information.
176d74f3e32SRuslan Ermilov.Va Close
17758f0484fSRodney W. Grimesroutines return -1 on error (setting
178d74f3e32SRuslan Ermilov.Va errno )
17958f0484fSRodney W. Grimesand 0 on success.
180d74f3e32SRuslan Ermilov.It Va del
18158f0484fSRodney W. GrimesA pointer to a routine to remove key/data pairs from the database.
182d74f3e32SRuslan Ermilov.Pp
18358f0484fSRodney W. GrimesThe parameter
184d74f3e32SRuslan Ermilov.Fa flags
18558f0484fSRodney W. Grimesmay be set to the following value:
186d74f3e32SRuslan Ermilov.Bl -tag -width indent
187d74f3e32SRuslan Ermilov.It Dv R_CURSOR
18858f0484fSRodney W. GrimesDelete the record referenced by the cursor.
18958f0484fSRodney W. GrimesThe cursor must have previously been initialized.
190d74f3e32SRuslan Ermilov.El
191d74f3e32SRuslan Ermilov.Pp
192d74f3e32SRuslan Ermilov.Va Delete
19358f0484fSRodney W. Grimesroutines return -1 on error (setting
194d74f3e32SRuslan Ermilov.Va errno ) ,
19558f0484fSRodney W. Grimes0 on success, and 1 if the specified
196d74f3e32SRuslan Ermilov.Fa key
19758f0484fSRodney W. Grimeswas not in the file.
198d74f3e32SRuslan Ermilov.It Va fd
19958f0484fSRodney W. GrimesA pointer to a routine which returns a file descriptor representative
20058f0484fSRodney W. Grimesof the underlying database.
20158f0484fSRodney W. GrimesA file descriptor referencing the same file will be returned to all
20258f0484fSRodney W. Grimesprocesses which call
203d74f3e32SRuslan Ermilov.Fn dbopen
20458f0484fSRodney W. Grimeswith the same
205d74f3e32SRuslan Ermilov.Fa file
20658f0484fSRodney W. Grimesname.
20758f0484fSRodney W. GrimesThis file descriptor may be safely used as an argument to the
208d74f3e32SRuslan Ermilov.Xr fcntl 2
20958f0484fSRodney W. Grimesand
210d74f3e32SRuslan Ermilov.Xr flock 2
21158f0484fSRodney W. Grimeslocking functions.
21258f0484fSRodney W. GrimesThe file descriptor is not necessarily associated with any of the
21358f0484fSRodney W. Grimesunderlying files used by the access method.
21458f0484fSRodney W. GrimesNo file descriptor is available for in memory databases.
215d74f3e32SRuslan Ermilov.Va \&Fd
21658f0484fSRodney W. Grimesroutines return -1 on error (setting
217d74f3e32SRuslan Ermilov.Va errno ) ,
21858f0484fSRodney W. Grimesand the file descriptor on success.
219d74f3e32SRuslan Ermilov.It Va get
22058f0484fSRodney W. GrimesA pointer to a routine which is the interface for keyed retrieval from
22158f0484fSRodney W. Grimesthe database.
22258f0484fSRodney W. GrimesThe address and length of the data associated with the specified
223d74f3e32SRuslan Ermilov.Fa key
22458f0484fSRodney W. Grimesare returned in the structure referenced by
225d74f3e32SRuslan Ermilov.Fa data .
226d74f3e32SRuslan Ermilov.Va Get
22758f0484fSRodney W. Grimesroutines return -1 on error (setting
228d74f3e32SRuslan Ermilov.Va errno ) ,
22958f0484fSRodney W. Grimes0 on success, and 1 if the
230d74f3e32SRuslan Ermilov.Fa key
23158f0484fSRodney W. Grimeswas not in the file.
232d74f3e32SRuslan Ermilov.It Va put
23358f0484fSRodney W. GrimesA pointer to a routine to store key/data pairs in the database.
234d74f3e32SRuslan Ermilov.Pp
23558f0484fSRodney W. GrimesThe parameter
236d74f3e32SRuslan Ermilov.Fa flags
23758f0484fSRodney W. Grimesmay be set to one of the following values:
238d74f3e32SRuslan Ermilov.Bl -tag -width indent
239d74f3e32SRuslan Ermilov.It Dv R_CURSOR
24058f0484fSRodney W. GrimesReplace the key/data pair referenced by the cursor.
24158f0484fSRodney W. GrimesThe cursor must have previously been initialized.
242d74f3e32SRuslan Ermilov.It Dv R_IAFTER
24358f0484fSRodney W. GrimesAppend the data immediately after the data referenced by
244d74f3e32SRuslan Ermilov.Fa key ,
24558f0484fSRodney W. Grimescreating a new key/data pair.
24658f0484fSRodney W. GrimesThe record number of the appended key/data pair is returned in the
247d74f3e32SRuslan Ermilov.Fa key
24858f0484fSRodney W. Grimesstructure.
249d74f3e32SRuslan Ermilov(Applicable only to the
250d74f3e32SRuslan Ermilov.Dv DB_RECNO
251d74f3e32SRuslan Ermilovaccess method.)
252d74f3e32SRuslan Ermilov.It Dv R_IBEFORE
25358f0484fSRodney W. GrimesInsert the data immediately before the data referenced by
254d74f3e32SRuslan Ermilov.Fa key ,
25558f0484fSRodney W. Grimescreating a new key/data pair.
25658f0484fSRodney W. GrimesThe record number of the inserted key/data pair is returned in the
257d74f3e32SRuslan Ermilov.Fa key
25858f0484fSRodney W. Grimesstructure.
259d74f3e32SRuslan Ermilov(Applicable only to the
260d74f3e32SRuslan Ermilov.Dv DB_RECNO
261d74f3e32SRuslan Ermilovaccess method.)
262d74f3e32SRuslan Ermilov.It Dv R_NOOVERWRITE
26358f0484fSRodney W. GrimesEnter the new key/data pair only if the key does not previously exist.
264d74f3e32SRuslan Ermilov.It Dv R_SETCURSOR
26558f0484fSRodney W. GrimesStore the key/data pair, setting or initializing the position of the
26658f0484fSRodney W. Grimescursor to reference it.
267d74f3e32SRuslan Ermilov(Applicable only to the
268d74f3e32SRuslan Ermilov.Dv DB_BTREE
269d74f3e32SRuslan Ermilovand
270d74f3e32SRuslan Ermilov.Dv DB_RECNO
271d74f3e32SRuslan Ermilovaccess methods.)
272d74f3e32SRuslan Ermilov.El
273d74f3e32SRuslan Ermilov.Pp
274d74f3e32SRuslan Ermilov.Dv R_SETCURSOR
275d74f3e32SRuslan Ermilovis available only for the
276d74f3e32SRuslan Ermilov.Dv DB_BTREE
277d74f3e32SRuslan Ermilovand
278d74f3e32SRuslan Ermilov.Dv DB_RECNO
279d74f3e32SRuslan Ermilovaccess
28058f0484fSRodney W. Grimesmethods because it implies that the keys have an inherent order
28158f0484fSRodney W. Grimeswhich does not change.
282d74f3e32SRuslan Ermilov.Pp
283d74f3e32SRuslan Ermilov.Dv R_IAFTER
284d74f3e32SRuslan Ermilovand
285d74f3e32SRuslan Ermilov.Dv R_IBEFORE
286d74f3e32SRuslan Ermilovare available only for the
287d74f3e32SRuslan Ermilov.Dv DB_RECNO
28858f0484fSRodney W. Grimesaccess method because they each imply that the access method is able to
28958f0484fSRodney W. Grimescreate new keys.
29058f0484fSRodney W. GrimesThis is only true if the keys are ordered and independent, record numbers
29158f0484fSRodney W. Grimesfor example.
292d74f3e32SRuslan Ermilov.Pp
29358f0484fSRodney W. GrimesThe default behavior of the
294d74f3e32SRuslan Ermilov.Va put
29558f0484fSRodney W. Grimesroutines is to enter the new key/data pair, replacing any previously
29658f0484fSRodney W. Grimesexisting key.
297d74f3e32SRuslan Ermilov.Pp
298d74f3e32SRuslan Ermilov.Va Put
29958f0484fSRodney W. Grimesroutines return -1 on error (setting
300d74f3e32SRuslan Ermilov.Va errno ) ,
301d74f3e32SRuslan Ermilov0 on success, and 1 if the
302d74f3e32SRuslan Ermilov.Dv R_NOOVERWRITE
303d74f3e32SRuslan Ermilovflag
30458f0484fSRodney W. Grimeswas set and the key already exists in the file.
305d74f3e32SRuslan Ermilov.It Va seq
30658f0484fSRodney W. GrimesA pointer to a routine which is the interface for sequential
30758f0484fSRodney W. Grimesretrieval from the database.
30858f0484fSRodney W. GrimesThe address and length of the key are returned in the structure
30958f0484fSRodney W. Grimesreferenced by
310d74f3e32SRuslan Ermilov.Fa key ,
31158f0484fSRodney W. Grimesand the address and length of the data are returned in the
31258f0484fSRodney W. Grimesstructure referenced
31358f0484fSRodney W. Grimesby
314d74f3e32SRuslan Ermilov.Fa data .
315d74f3e32SRuslan Ermilov.Pp
31658f0484fSRodney W. GrimesSequential key/data pair retrieval may begin at any time, and the
317d74f3e32SRuslan Ermilovposition of the
318d74f3e32SRuslan Ermilov.Dq cursor
319d74f3e32SRuslan Ermilovis not affected by calls to the
320d74f3e32SRuslan Ermilov.Va del ,
321d74f3e32SRuslan Ermilov.Va get ,
322d74f3e32SRuslan Ermilov.Va put ,
32358f0484fSRodney W. Grimesor
324d74f3e32SRuslan Ermilov.Va sync
32558f0484fSRodney W. Grimesroutines.
32658f0484fSRodney W. GrimesModifications to the database during a sequential scan will be reflected
32758f0484fSRodney W. Grimesin the scan, i.e. records inserted behind the cursor will not be returned
32858f0484fSRodney W. Grimeswhile records inserted in front of the cursor will be returned.
329d74f3e32SRuslan Ermilov.Pp
330d74f3e32SRuslan ErmilovThe
331d74f3e32SRuslan Ermilov.Fa flags
332d74f3e32SRuslan Ermilovvalue
333d74f3e32SRuslan Ermilov.Em must
33458f0484fSRodney W. Grimesbe set to one of the following values:
335d74f3e32SRuslan Ermilov.Bl -tag -width indent
336d74f3e32SRuslan Ermilov.It Dv R_CURSOR
33758f0484fSRodney W. GrimesThe data associated with the specified key is returned.
33858f0484fSRodney W. GrimesThis differs from the
339d74f3e32SRuslan Ermilov.Va get
34058f0484fSRodney W. Grimesroutines in that it sets or initializes the cursor to the location of
34158f0484fSRodney W. Grimesthe key as well.
342d74f3e32SRuslan Ermilov(Note, for the
343d74f3e32SRuslan Ermilov.Dv DB_BTREE
344d74f3e32SRuslan Ermilovaccess method, the returned key is not necessarily an
34558f0484fSRodney W. Grimesexact match for the specified key.
34658f0484fSRodney W. GrimesThe returned key is the smallest key greater than or equal to the specified
34758f0484fSRodney W. Grimeskey, permitting partial key matches and range searches.)
348d74f3e32SRuslan Ermilov.It Dv R_FIRST
34958f0484fSRodney W. GrimesThe first key/data pair of the database is returned, and the cursor
35058f0484fSRodney W. Grimesis set or initialized to reference it.
351d74f3e32SRuslan Ermilov.It Dv R_LAST
35258f0484fSRodney W. GrimesThe last key/data pair of the database is returned, and the cursor
35358f0484fSRodney W. Grimesis set or initialized to reference it.
354d74f3e32SRuslan Ermilov(Applicable only to the
355d74f3e32SRuslan Ermilov.Dv DB_BTREE
356d74f3e32SRuslan Ermilovand
357d74f3e32SRuslan Ermilov.Dv DB_RECNO
358d74f3e32SRuslan Ermilovaccess methods.)
359d74f3e32SRuslan Ermilov.It Dv R_NEXT
36058f0484fSRodney W. GrimesRetrieve the key/data pair immediately after the cursor.
361d74f3e32SRuslan ErmilovIf the cursor is not yet set, this is the same as the
362d74f3e32SRuslan Ermilov.Dv R_FIRST
363d74f3e32SRuslan Ermilovflag.
364d74f3e32SRuslan Ermilov.It Dv R_PREV
36558f0484fSRodney W. GrimesRetrieve the key/data pair immediately before the cursor.
366d74f3e32SRuslan ErmilovIf the cursor is not yet set, this is the same as the
367d74f3e32SRuslan Ermilov.Dv R_LAST
368d74f3e32SRuslan Ermilovflag.
369d74f3e32SRuslan Ermilov(Applicable only to the
370d74f3e32SRuslan Ermilov.Dv DB_BTREE
371d74f3e32SRuslan Ermilovand
372d74f3e32SRuslan Ermilov.Dv DB_RECNO
373d74f3e32SRuslan Ermilovaccess methods.)
374d74f3e32SRuslan Ermilov.El
375d74f3e32SRuslan Ermilov.Pp
376d74f3e32SRuslan Ermilov.Dv R_LAST
377d74f3e32SRuslan Ermilovand
378d74f3e32SRuslan Ermilov.Dv R_PREV
379d74f3e32SRuslan Ermilovare available only for the
380d74f3e32SRuslan Ermilov.Dv DB_BTREE
381d74f3e32SRuslan Ermilovand
382d74f3e32SRuslan Ermilov.Dv DB_RECNO
38358f0484fSRodney W. Grimesaccess methods because they each imply that the keys have an inherent
38458f0484fSRodney W. Grimesorder which does not change.
385d74f3e32SRuslan Ermilov.Pp
386d74f3e32SRuslan Ermilov.Va Seq
38758f0484fSRodney W. Grimesroutines return -1 on error (setting
388d74f3e32SRuslan Ermilov.Va errno ) ,
38958f0484fSRodney W. Grimes0 on success and 1 if there are no key/data pairs less than or greater
39058f0484fSRodney W. Grimesthan the specified or current key.
391d74f3e32SRuslan ErmilovIf the
392d74f3e32SRuslan Ermilov.Dv DB_RECNO
393d74f3e32SRuslan Ermilovaccess method is being used, and if the database file
39458f0484fSRodney W. Grimesis a character special file and no complete key/data pairs are currently
39558f0484fSRodney W. Grimesavailable, the
396d74f3e32SRuslan Ermilov.Va seq
39758f0484fSRodney W. Grimesroutines return 2.
398d74f3e32SRuslan Ermilov.It Va sync
39958f0484fSRodney W. GrimesA pointer to a routine to flush any cached information to disk.
40058f0484fSRodney W. GrimesIf the database is in memory only, the
401d74f3e32SRuslan Ermilov.Va sync
40258f0484fSRodney W. Grimesroutine has no effect and will always succeed.
403d74f3e32SRuslan Ermilov.Pp
404d74f3e32SRuslan ErmilovThe
405d74f3e32SRuslan Ermilov.Fa flags
406d74f3e32SRuslan Ermilovvalue may be set to the following value:
407d74f3e32SRuslan Ermilov.Bl -tag -width indent
408d74f3e32SRuslan Ermilov.It Dv R_RECNOSYNC
409d74f3e32SRuslan ErmilovIf the
410d74f3e32SRuslan Ermilov.Dv DB_RECNO
411d74f3e32SRuslan Ermilovaccess method is being used, this flag causes
412d74f3e32SRuslan Ermilovthe
413d74f3e32SRuslan Ermilov.Va sync
414d74f3e32SRuslan Ermilovroutine to apply to the btree file which underlies the
41558f0484fSRodney W. Grimesrecno file, not the recno file itself.
41658f0484fSRodney W. Grimes(See the
417d74f3e32SRuslan Ermilov.Va bfname
41858f0484fSRodney W. Grimesfield of the
419d74f3e32SRuslan Ermilov.Xr recno 3
42058f0484fSRodney W. Grimesmanual page for more information.)
421d74f3e32SRuslan Ermilov.El
422d74f3e32SRuslan Ermilov.Pp
423d74f3e32SRuslan Ermilov.Va Sync
42458f0484fSRodney W. Grimesroutines return -1 on error (setting
425d74f3e32SRuslan Ermilov.Va errno )
42658f0484fSRodney W. Grimesand 0 on success.
427d74f3e32SRuslan Ermilov.El
428d74f3e32SRuslan Ermilov.Sh "KEY/DATA PAIRS"
42958f0484fSRodney W. GrimesAccess to all file types is based on key/data pairs.
43058f0484fSRodney W. GrimesBoth keys and data are represented by the following data structure:
431d74f3e32SRuslan Ermilov.Bd -literal
43258f0484fSRodney W. Grimestypedef struct {
43358f0484fSRodney W. Grimes	void *data;
43458f0484fSRodney W. Grimes	size_t size;
43558f0484fSRodney W. Grimes} DBT;
436d74f3e32SRuslan Ermilov.Ed
437d74f3e32SRuslan Ermilov.Pp
438d74f3e32SRuslan ErmilovThe elements of the
439d74f3e32SRuslan Ermilov.Ft DBT
440d74f3e32SRuslan Ermilovstructure are defined as follows:
441d74f3e32SRuslan Ermilov.Bl -tag -width "data"
442d74f3e32SRuslan Ermilov.It Va data
44358f0484fSRodney W. GrimesA pointer to a byte string.
444d74f3e32SRuslan Ermilov.It Va size
44558f0484fSRodney W. GrimesThe length of the byte string.
446d74f3e32SRuslan Ermilov.El
447d74f3e32SRuslan Ermilov.Pp
44858f0484fSRodney W. GrimesKey and data byte strings may reference strings of essentially unlimited
44958f0484fSRodney W. Grimeslength although any two of them must fit into available memory at the same
45058f0484fSRodney W. Grimestime.
45158f0484fSRodney W. GrimesIt should be noted that the access methods provide no guarantees about
45258f0484fSRodney W. Grimesbyte string alignment.
453d74f3e32SRuslan Ermilov.Sh ERRORS
45458f0484fSRodney W. GrimesThe
455d74f3e32SRuslan Ermilov.Fn dbopen
45658f0484fSRodney W. Grimesroutine may fail and set
457d74f3e32SRuslan Ermilov.Va errno
45858f0484fSRodney W. Grimesfor any of the errors specified for the library routines
459d74f3e32SRuslan Ermilov.Xr open 2
46058f0484fSRodney W. Grimesand
461d74f3e32SRuslan Ermilov.Xr malloc 3
46258f0484fSRodney W. Grimesor the following:
463d74f3e32SRuslan Ermilov.Bl -tag -width Er
464d74f3e32SRuslan Ermilov.It Bq Er EFTYPE
46558f0484fSRodney W. GrimesA file is incorrectly formatted.
466d74f3e32SRuslan Ermilov.It Bq Er EINVAL
46758f0484fSRodney W. GrimesA parameter has been specified (hash function, pad byte etc.) that is
46858f0484fSRodney W. Grimesincompatible with the current file specification or which is not
46958f0484fSRodney W. Grimesmeaningful for the function (for example, use of the cursor without
47058f0484fSRodney W. Grimesprior initialization) or there is a mismatch between the version
47158f0484fSRodney W. Grimesnumber of file and the software.
472d74f3e32SRuslan Ermilov.El
473d74f3e32SRuslan Ermilov.Pp
47458f0484fSRodney W. GrimesThe
475d74f3e32SRuslan Ermilov.Va close
47658f0484fSRodney W. Grimesroutines may fail and set
477d74f3e32SRuslan Ermilov.Va errno
47858f0484fSRodney W. Grimesfor any of the errors specified for the library routines
479d74f3e32SRuslan Ermilov.Xr close 2 ,
480d74f3e32SRuslan Ermilov.Xr read 2 ,
481d74f3e32SRuslan Ermilov.Xr write 2 ,
482d74f3e32SRuslan Ermilov.Xr free 3 ,
48358f0484fSRodney W. Grimesor
484d74f3e32SRuslan Ermilov.Xr fsync 2 .
485d74f3e32SRuslan Ermilov.Pp
48658f0484fSRodney W. GrimesThe
487d74f3e32SRuslan Ermilov.Va del ,
488d74f3e32SRuslan Ermilov.Va get ,
489d74f3e32SRuslan Ermilov.Va put
49058f0484fSRodney W. Grimesand
491d74f3e32SRuslan Ermilov.Va seq
49258f0484fSRodney W. Grimesroutines may fail and set
493d74f3e32SRuslan Ermilov.Va errno
49458f0484fSRodney W. Grimesfor any of the errors specified for the library routines
495d74f3e32SRuslan Ermilov.Xr read 2 ,
496d74f3e32SRuslan Ermilov.Xr write 2 ,
497d74f3e32SRuslan Ermilov.Xr free 3
49858f0484fSRodney W. Grimesor
499d74f3e32SRuslan Ermilov.Xr malloc 3 .
500d74f3e32SRuslan Ermilov.Pp
50158f0484fSRodney W. GrimesThe
502d74f3e32SRuslan Ermilov.Va fd
50358f0484fSRodney W. Grimesroutines will fail and set
504d74f3e32SRuslan Ermilov.Va errno
505d74f3e32SRuslan Ermilovto
506d74f3e32SRuslan Ermilov.Er ENOENT
507d74f3e32SRuslan Ermilovfor in memory databases.
508d74f3e32SRuslan Ermilov.Pp
50958f0484fSRodney W. GrimesThe
510d74f3e32SRuslan Ermilov.Va sync
51158f0484fSRodney W. Grimesroutines may fail and set
512d74f3e32SRuslan Ermilov.Va errno
51358f0484fSRodney W. Grimesfor any of the errors specified for the library routine
514d74f3e32SRuslan Ermilov.Xr fsync 2 .
515d74f3e32SRuslan Ermilov.Sh SEE ALSO
516d74f3e32SRuslan Ermilov.Xr btree 3 ,
517d74f3e32SRuslan Ermilov.Xr hash 3 ,
518d74f3e32SRuslan Ermilov.Xr mpool 3 ,
519d74f3e32SRuslan Ermilov.Xr recno 3
520d74f3e32SRuslan Ermilov.Rs
521d74f3e32SRuslan Ermilov.%T "LIBTP: Portable, Modular Transactions for UNIX"
522d74f3e32SRuslan Ermilov.%A Margo Seltzer
523d74f3e32SRuslan Ermilov.%A Michael Olson
524d74f3e32SRuslan Ermilov.%R "USENIX proceedings"
525d74f3e32SRuslan Ermilov.%D Winter 1992
526d74f3e32SRuslan Ermilov.Re
527d74f3e32SRuslan Ermilov.Sh BUGS
528d74f3e32SRuslan ErmilovThe typedef
529d74f3e32SRuslan Ermilov.Ft DBT
530d74f3e32SRuslan Ermilovis a mnemonic for
531d74f3e32SRuslan Ermilov.Dq "data base thang" ,
532d74f3e32SRuslan Ermilovand was used
53358f0484fSRodney W. Grimesbecause noone could think of a reasonable name that wasn't already used.
534d74f3e32SRuslan Ermilov.Pp
53558f0484fSRodney W. GrimesThe file descriptor interface is a kluge and will be deleted in a
53658f0484fSRodney W. Grimesfuture version of the interface.
537d74f3e32SRuslan Ermilov.Pp
53858f0484fSRodney W. GrimesNone of the access methods provide any form of concurrent access,
53958f0484fSRodney W. Grimeslocking, or transactions.
540