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