xref: /openbsd-src/lib/libc/db/man/recno.3 (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1.\"	$OpenBSD: recno.3,v 1.11 2001/08/06 10:42:25 mpech Exp $
2.\"	$NetBSD: recno.3,v 1.6 1996/05/03 21:26:51 cgd Exp $
3.\"
4.\" Copyright (c) 1997, Phillip F Knaack. All rights reserved.
5.\"
6.\" Copyright (c) 1990, 1993
7.\"	The Regents of the University of California.  All rights reserved.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"	This product includes software developed by the University of
20.\"	California, Berkeley and its contributors.
21.\" 4. Neither the name of the University nor the names of its contributors
22.\"    may be used to endorse or promote products derived from this software
23.\"    without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35.\" SUCH DAMAGE.
36.\"
37.\"	@(#)recno.3	8.5 (Berkeley) 8/18/94
38.\"
39.Dd August 18, 1994
40.Dt RECNO 3
41.Os
42.Sh NAME
43.Nm recno
44.Nd record number database access method
45.Sh SYNOPSIS
46.Fd #include <sys/types.h>
47.Fd #include <db.h>
48.Sh DESCRIPTION
49The
50.Fn dbopen
51routine is the library interface to database files.
52One of the supported file formats is record number files.
53The general description of the database access methods is in
54.Xr dbopen 3 ,
55this manual page describes only the recno specific information.
56.Pp
57The record number data structure is either variable or fixed-length
58records stored in a flat-file format, accessed by the logical record
59number.
60The existence of record number five implies the existence of records
61one through four, and the deletion of record number one causes
62record number five to be renumbered to record number four, as well
63as the cursor, if positioned after record number one, to shift down
64one record.
65.Pp
66The
67.Nm
68access method specific data structure provided to
69.Fn dbopen
70is defined in the <db.h> include file as follows:
71.Pp
72.Bl -item -compact
73.It
74typedef struct {
75.It
76.Bl -item -compact -offset indent
77.It
78u_long flags;
79.It
80u_int cachesize;
81.It
82u_int psize;
83.It
84int lorder;
85.It
86size_t reclen;
87.It
88u_char bval;
89.It
90char *bfname;
91.El
92.It
93} RECNOINFO;
94.El
95.Pp
96The elements of this structure are defined as follows:
97.Bl -tag -width XXXXXX
98.It Fa flags
99The flag value is specified by
100.Tn OR Ns 'ing
101any of the following values:
102.Bl -tag -width XXXXXX
103.It Dv R_FIXEDLEN
104The records are fixed-length, not byte delimited.
105The structure element
106.Fa reclen
107specifies the length of the record, and the structure element
108.Fa bval
109is used as the pad character.
110Any records, inserted into the database, that are less than
111.Fa reclen
112bytes long are automatically padded.
113.It Dv R_NOKEY
114In the interface specified by
115.Fn dbopen ,
116the sequential record retrieval fills in both the caller's key and
117data structures.
118If the R_NOKEY flag is specified, the
119.Fa cursor
120routines are not required to fill in the key structure.
121This permits applications to retrieve records at the end of files without
122reading all of the intervening records.
123.It Dv R_SNAPSHOT
124This flag requires that a snapshot of the file be taken when
125.Fn dbopen
126is called, instead of permitting any unmodified records to be read from
127the original file.
128.El
129.It Fa cachesize
130A suggested maximum size, in bytes, of the memory cache.
131This value is
132.Em only
133advisory, and the access method will allocate more memory rather than fail.
134If
135.Fa cachesize
136is 0 (no size is specified) a default cache is used.
137.It Fa psize
138The recno access method stores the in-memory copies of its records
139in a btree.
140This value is the size (in bytes) of the pages used for nodes in that tree.
141If
142.Fa psize
143is 0 (no page size is specified) a page size is chosen based on the
144underlying file system I/O block size.
145See
146.Xr btree 3
147for more information.
148.It Fa lorder
149The byte order for integers in the stored database metadata.
150The number should represent the order as an integer; for example,
151big endian order would be the number 4,321.
152If
153.Fa lorder
154is 0 (no order is specified) the current host order is used.
155.It Fa reclen
156The length of a fixed-length record.
157.It Fa bval
158The delimiting byte to be used to mark the end of a record for
159variable-length records, and the pad character for fixed-length
160records.
161If no value is specified, newlines
162.Pq Ql \en
163are used to mark the end
164of variable-length records and fixed-length records are padded with
165spaces.
166.It Fa bfname
167The recno access method stores the in-memory copies of its records
168in a btree.
169If bfname is non-NULL, it specifies the name of the btree file,
170as if specified as the file name for a dbopen of a btree file.
171.Pp
172The data part of the key/data pair used by the recno access method
173is the same as other access methods.
174The key is different.
175The
176.Fa data
177field of the key should be a pointer to a memory location of type
178.Ft recno_t ,
179as defined in the <db.h> include file.
180This type is normally the largest unsigned integral type available to
181the implementation.
182The
183.Fa size
184field of the key should be the size of that type.
185.Pp
186Because there can be no meta-data associated with the underlying
187recno access method files, any changes made to the default values
188(e.g., fixed record length or byte separator value) must be explicitly
189specified each time the file is opened.
190.Pp
191In the interface specified by
192.Fn dbopen ,
193using the
194.Fa put
195interface to create a new record will cause the creation of multiple,
196empty records if the record number is more than one greater than the
197largest record currently in the database.
198.Sh ERRORS
199The
200.Fa recno
201access method routines may fail and set
202.Va errno
203for any of the errors specified for the library routine
204.Xr dbopen 3 ,
205or the following:
206.Bl -tag -width XEINVALX
207.It Bq Er EINVAL
208An attempt was made to add a record to a fixed-length database that
209was too large to fit.
210.El
211.Sh SEE ALSO
212.Xr btree 3 ,
213.Xr dbopen 3 ,
214.Xr hash 3 ,
215.Xr mpool 3
216.Rs
217.%T "Document Processing in a Relational Database System"
218.%A Michael Stonebraker
219.%A Heidi Stettner
220.%A Joseph Kalash
221.%A Antonin Guttman
222.%A Nadene Lynn
223.%J Memorandum No. UCB/ERL M82/32
224.%D May 1982
225.Re
226.Sh BUGS
227Only big and little endian byte order is supported.
228