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. 12*fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors 1358f0484fSRodney W. Grimes.\" may be used to endorse or promote products derived from this software 1458f0484fSRodney W. Grimes.\" without specific prior written permission. 1558f0484fSRodney W. Grimes.\" 1658f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1758f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1858f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1958f0484fSRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2058f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2158f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2258f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2358f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2458f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2558f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2658f0484fSRodney W. Grimes.\" SUCH DAMAGE. 2758f0484fSRodney W. Grimes.\" 2858f0484fSRodney W. Grimes.\" @(#)dbopen.3 8.5 (Berkeley) 1/2/94 297f3dea24SPeter Wemm.\" $FreeBSD$ 3058f0484fSRodney W. Grimes.\" 31416d1e6fSGlen Barber.Dd September 10, 2010 32d74f3e32SRuslan Ermilov.Dt DBOPEN 3 33d74f3e32SRuslan Ermilov.Os 34d74f3e32SRuslan Ermilov.Sh NAME 35d74f3e32SRuslan Ermilov.Nm dbopen 36d74f3e32SRuslan Ermilov.Nd "database access methods" 37d74f3e32SRuslan Ermilov.Sh SYNOPSIS 3832eef9aeSRuslan Ermilov.In sys/types.h 3932eef9aeSRuslan Ermilov.In db.h 409e542d7dSMark Murray.In fcntl.h 419e542d7dSMark Murray.In limits.h 42d74f3e32SRuslan Ermilov.Ft DB * 43d74f3e32SRuslan Ermilov.Fn dbopen "const char *file" "int flags" "int mode" "DBTYPE type" "const void *openinfo" 44d74f3e32SRuslan Ermilov.Sh DESCRIPTION 451fae73b1SRuslan ErmilovThe 461fae73b1SRuslan Ermilov.Fn dbopen 471fae73b1SRuslan Ermilovfunction 4858f0484fSRodney W. Grimesis the library interface to database files. 4958f0484fSRodney W. GrimesThe supported file formats are btree, hashed and UNIX file oriented. 5058f0484fSRodney W. GrimesThe btree format is a representation of a sorted, balanced tree structure. 5158f0484fSRodney W. GrimesThe hashed format is an extensible, dynamic hashing scheme. 5258f0484fSRodney W. GrimesThe flat-file format is a byte stream file with fixed or variable length 5358f0484fSRodney W. Grimesrecords. 5458f0484fSRodney W. GrimesThe formats and file format specific information are described in detail 5558f0484fSRodney W. Grimesin their respective manual pages 56d74f3e32SRuslan Ermilov.Xr btree 3 , 57d74f3e32SRuslan Ermilov.Xr hash 3 5858f0484fSRodney W. Grimesand 59d74f3e32SRuslan Ermilov.Xr recno 3 . 60d74f3e32SRuslan Ermilov.Pp 611fae73b1SRuslan ErmilovThe 621fae73b1SRuslan Ermilov.Fn dbopen 631fae73b1SRuslan Ermilovfunction 64d74f3e32SRuslan Ermilovopens 65d74f3e32SRuslan Ermilov.Fa file 6658f0484fSRodney W. Grimesfor reading and/or writing. 6758f0484fSRodney W. GrimesFiles never intended to be preserved on disk may be created by setting 682efeeba5SRuslan Ermilovthe 692efeeba5SRuslan Ermilov.Fa file 702efeeba5SRuslan Ermilovargument to 71d74f3e32SRuslan Ermilov.Dv NULL . 72d74f3e32SRuslan Ermilov.Pp 7358f0484fSRodney W. GrimesThe 74d74f3e32SRuslan Ermilov.Fa flags 7558f0484fSRodney W. Grimesand 76d74f3e32SRuslan Ermilov.Fa mode 77d74f3e32SRuslan Ermilovarguments 7858f0484fSRodney W. Grimesare as specified to the 79d74f3e32SRuslan Ermilov.Xr open 2 80d74f3e32SRuslan Ermilovroutine, however, only the 811569ab8cSGlen Barber.Dv O_CREAT , O_EXCL , O_EXLOCK , O_NOFOLLOW , O_NONBLOCK , 821569ab8cSGlen Barber.Dv O_RDONLY , O_RDWR , O_SHLOCK , O_SYNC 83d74f3e32SRuslan Ermilovand 84d74f3e32SRuslan Ermilov.Dv O_TRUNC 85d74f3e32SRuslan Ermilovflags are meaningful. 86d74f3e32SRuslan Ermilov(Note, opening a database file 87d74f3e32SRuslan Ermilov.Dv O_WRONLY 88d74f3e32SRuslan Ermilovis not possible.) 8958f0484fSRodney W. Grimes.\"Three additional options may be specified by 90d74f3e32SRuslan Ermilov.\".Em or Ns 'ing 9158f0484fSRodney W. Grimes.\"them into the 92d74f3e32SRuslan Ermilov.\".Fa flags 9358f0484fSRodney W. Grimes.\"argument. 94d74f3e32SRuslan Ermilov.\".Bl -tag -width indent 95d74f3e32SRuslan Ermilov.\".It Dv DB_LOCK 9658f0484fSRodney W. Grimes.\"Do the necessary locking in the database to support concurrent access. 970227791bSRuslan Ermilov.\"If concurrent access is not needed or the database is read-only this 9858f0484fSRodney W. Grimes.\"flag should not be set, as it tends to have an associated performance 9958f0484fSRodney W. Grimes.\"penalty. 100d74f3e32SRuslan Ermilov.\".It Dv DB_SHMEM 10158f0484fSRodney W. Grimes.\"Place the underlying memory pool used by the database in shared 10258f0484fSRodney W. Grimes.\"memory. 10358f0484fSRodney W. Grimes.\"Necessary for concurrent access. 104d74f3e32SRuslan Ermilov.\".It Dv DB_TXN 10558f0484fSRodney W. Grimes.\"Support transactions in the database. 106d74f3e32SRuslan Ermilov.\"The 107d74f3e32SRuslan Ermilov.\".Dv DB_LOCK 108d74f3e32SRuslan Ermilov.\"and 109d74f3e32SRuslan Ermilov.\".Dv DB_SHMEM 110d74f3e32SRuslan Ermilov.\"flags must be set as well. 111d74f3e32SRuslan Ermilov.\".El 112d74f3e32SRuslan Ermilov.Pp 11358f0484fSRodney W. GrimesThe 114d74f3e32SRuslan Ermilov.Fa type 115d74f3e32SRuslan Ermilovargument is of type 116d74f3e32SRuslan Ermilov.Ft DBTYPE 117d74f3e32SRuslan Ermilov(as defined in the 118fe08efe6SRuslan Ermilov.In db.h 119d74f3e32SRuslan Ermilovinclude file) and 120d74f3e32SRuslan Ermilovmay be set to 121d74f3e32SRuslan Ermilov.Dv DB_BTREE , DB_HASH 122d74f3e32SRuslan Ermilovor 123d74f3e32SRuslan Ermilov.Dv DB_RECNO . 124d74f3e32SRuslan Ermilov.Pp 12558f0484fSRodney W. GrimesThe 126d74f3e32SRuslan Ermilov.Fa openinfo 12758f0484fSRodney W. Grimesargument is a pointer to an access method specific structure described 12858f0484fSRodney W. Grimesin the access method's manual page. 12958f0484fSRodney W. GrimesIf 130d74f3e32SRuslan Ermilov.Fa openinfo 131d74f3e32SRuslan Ermilovis 132d74f3e32SRuslan Ermilov.Dv NULL , 133d74f3e32SRuslan Ermiloveach access method will use defaults appropriate for the system 13458f0484fSRodney W. Grimesand the access method. 135d74f3e32SRuslan Ermilov.Pp 1361fae73b1SRuslan ErmilovThe 1371fae73b1SRuslan Ermilov.Fn dbopen 1381fae73b1SRuslan Ermilovfunction 139d74f3e32SRuslan Ermilovreturns a pointer to a 140d74f3e32SRuslan Ermilov.Ft DB 141d74f3e32SRuslan Ermilovstructure on success and 142d74f3e32SRuslan Ermilov.Dv NULL 143d74f3e32SRuslan Ermilovon error. 144d74f3e32SRuslan ErmilovThe 145d74f3e32SRuslan Ermilov.Ft DB 146d74f3e32SRuslan Ermilovstructure is defined in the 147fe08efe6SRuslan Ermilov.In db.h 148d74f3e32SRuslan Ermilovinclude file, and contains at 14958f0484fSRodney W. Grimesleast the following fields: 150d74f3e32SRuslan Ermilov.Bd -literal 15158f0484fSRodney W. Grimestypedef struct { 15258f0484fSRodney W. Grimes DBTYPE type; 15316ca32b3SStefan Farfeleder int (*close)(DB *db); 15458f0484fSRodney W. Grimes int (*del)(const DB *db, const DBT *key, u_int flags); 15558f0484fSRodney W. Grimes int (*fd)(const DB *db); 15616ca32b3SStefan Farfeleder int (*get)(const DB *db, const DBT *key, DBT *data, u_int flags); 15758f0484fSRodney W. Grimes int (*put)(const DB *db, DBT *key, const DBT *data, 15858f0484fSRodney W. Grimes u_int flags); 15958f0484fSRodney W. Grimes int (*sync)(const DB *db, u_int flags); 16058f0484fSRodney W. Grimes int (*seq)(const DB *db, DBT *key, DBT *data, u_int flags); 16158f0484fSRodney W. Grimes} DB; 162d74f3e32SRuslan Ermilov.Ed 163d74f3e32SRuslan Ermilov.Pp 16458f0484fSRodney W. GrimesThese elements describe a database type and a set of functions performing 16558f0484fSRodney W. Grimesvarious actions. 16658f0484fSRodney W. GrimesThese functions take a pointer to a structure as returned by 167d74f3e32SRuslan Ermilov.Fn dbopen , 16858f0484fSRodney W. Grimesand sometimes one or more pointers to key/data structures and a flag value. 169d74f3e32SRuslan Ermilov.Bl -tag -width indent 170d74f3e32SRuslan Ermilov.It Va type 17158f0484fSRodney W. GrimesThe type of the underlying access method (and file format). 172d74f3e32SRuslan Ermilov.It Va close 17358f0484fSRodney W. GrimesA pointer to a routine to flush any cached information to disk, free any 17458f0484fSRodney W. Grimesallocated resources, and close the underlying file(s). 17558f0484fSRodney W. GrimesSince key/data pairs may be cached in memory, failing to sync the file 17658f0484fSRodney W. Grimeswith a 177d74f3e32SRuslan Ermilov.Va close 17858f0484fSRodney W. Grimesor 179d74f3e32SRuslan Ermilov.Va sync 18058f0484fSRodney W. Grimesfunction may result in inconsistent or lost information. 1812efeeba5SRuslan Ermilov.Va close 18258f0484fSRodney W. Grimesroutines return -1 on error (setting 183d74f3e32SRuslan Ermilov.Va errno ) 18458f0484fSRodney W. Grimesand 0 on success. 185d74f3e32SRuslan Ermilov.It Va del 18658f0484fSRodney W. GrimesA pointer to a routine to remove key/data pairs from the database. 187d74f3e32SRuslan Ermilov.Pp 1882efeeba5SRuslan ErmilovThe 189d74f3e32SRuslan Ermilov.Fa flags 1902efeeba5SRuslan Ermilovargument 19158f0484fSRodney W. Grimesmay be set to the following value: 192d74f3e32SRuslan Ermilov.Bl -tag -width indent 193d74f3e32SRuslan Ermilov.It Dv R_CURSOR 19458f0484fSRodney W. GrimesDelete the record referenced by the cursor. 19558f0484fSRodney W. GrimesThe cursor must have previously been initialized. 196d74f3e32SRuslan Ermilov.El 197d74f3e32SRuslan Ermilov.Pp 1982efeeba5SRuslan Ermilov.Va delete 19958f0484fSRodney W. Grimesroutines return -1 on error (setting 200d74f3e32SRuslan Ermilov.Va errno ) , 20158f0484fSRodney W. Grimes0 on success, and 1 if the specified 202d74f3e32SRuslan Ermilov.Fa key 20358f0484fSRodney W. Grimeswas not in the file. 204d74f3e32SRuslan Ermilov.It Va fd 20558f0484fSRodney W. GrimesA pointer to a routine which returns a file descriptor representative 20658f0484fSRodney W. Grimesof the underlying database. 20758f0484fSRodney W. GrimesA file descriptor referencing the same file will be returned to all 20858f0484fSRodney W. Grimesprocesses which call 209d74f3e32SRuslan Ermilov.Fn dbopen 21058f0484fSRodney W. Grimeswith the same 211d74f3e32SRuslan Ermilov.Fa file 21258f0484fSRodney W. Grimesname. 21358f0484fSRodney W. GrimesThis file descriptor may be safely used as an argument to the 214d74f3e32SRuslan Ermilov.Xr fcntl 2 21558f0484fSRodney W. Grimesand 216d74f3e32SRuslan Ermilov.Xr flock 2 21758f0484fSRodney W. Grimeslocking functions. 21858f0484fSRodney W. GrimesThe file descriptor is not necessarily associated with any of the 21958f0484fSRodney W. Grimesunderlying files used by the access method. 22058f0484fSRodney W. GrimesNo file descriptor is available for in memory databases. 221d74f3e32SRuslan Ermilov.Va \&Fd 22258f0484fSRodney W. Grimesroutines return -1 on error (setting 223d74f3e32SRuslan Ermilov.Va errno ) , 22458f0484fSRodney W. Grimesand the file descriptor on success. 225d74f3e32SRuslan Ermilov.It Va get 22658f0484fSRodney W. GrimesA pointer to a routine which is the interface for keyed retrieval from 22758f0484fSRodney W. Grimesthe database. 22858f0484fSRodney W. GrimesThe address and length of the data associated with the specified 229d74f3e32SRuslan Ermilov.Fa key 23058f0484fSRodney W. Grimesare returned in the structure referenced by 231d74f3e32SRuslan Ermilov.Fa data . 2322efeeba5SRuslan Ermilov.Va get 23358f0484fSRodney W. Grimesroutines return -1 on error (setting 234d74f3e32SRuslan Ermilov.Va errno ) , 23558f0484fSRodney W. Grimes0 on success, and 1 if the 236d74f3e32SRuslan Ermilov.Fa key 23758f0484fSRodney W. Grimeswas not in the file. 238d74f3e32SRuslan Ermilov.It Va put 23958f0484fSRodney W. GrimesA pointer to a routine to store key/data pairs in the database. 240d74f3e32SRuslan Ermilov.Pp 2412efeeba5SRuslan ErmilovThe 242d74f3e32SRuslan Ermilov.Fa flags 2432efeeba5SRuslan Ermilovargument 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 3052efeeba5SRuslan 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 3341a0a9345SRuslan Ermilovin 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 3392efeeba5SRuslan Ermilovargument 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 3932efeeba5SRuslan 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 4132efeeba5SRuslan Ermilovargument 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 4302efeeba5SRuslan 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 4742efeeba5SRuslan ErmilovAn argument 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 5400227791bSRuslan Ermilovbecause noone could think of a reasonable name that was not 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