1 .\" Copyright (c) 1990, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)dbopen.3 8.5 (Berkeley) 1/2/94
34 .\" Japanese Version Copyright (c) 1999 Shouichi Saito
35 .\" all rights reserved.
36 .\" Translated Thu Jul 22 00:00:00 JST 1999
37 .\" by Shouichi Saito <ss236rx@ymg.urban.ne.jp>
38 .\" Proofed Tue Aug 19 1999 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
40 .\"WORD: descriptor デスクリプタ
41 .TH DBOPEN 3 1994-01-02 "" "Linux Programmer's Manual"
45 .\"O dbopen \- database access methods
46 dbopen \- データベースアクセスメソッド
50 .B #include <sys/types.h>
51 .B #include <limits.h>
54 .BI "DB *dbopen(const char *" file ", int " flags ", int " mode \
56 .BI " const void *" openinfo );
61 .\"O is the library interface to database files.
63 はデータベースファイルに対するライブラリインターフェースである。
64 .\"O The supported file formats are btree, hashed and UNIX file oriented.
65 .\"O The btree format is a representation of a sorted, balanced tree structure.
66 .\"O The hashed format is an extensible, dynamic hashing scheme.
67 .\"O The flat-file format is a byte stream file with fixed or variable length
69 サポートされているファイルフォーマットは btree, hash,
70 UNIX ファイルに指向したフォーマット, の 3 つである。
71 btree フォーマットは、ソートされたバランスツリー構造である。
72 hashed フォーマットは、拡張可能な動的 hash スキームである。
73 フラットファイル (flat-file) フォーマットは、
74 固定長/可変長のレコードからなるバイトストリームファイルである。
75 .\"O The formats and file format specific information are described in detail
76 .\"O in their respective manual pages
81 それぞれのフォーマットと、ファイルフォーマットに特有の情報は
91 .\"O for reading and/or writing.
95 を読み込み (読み書き) するためにオープンする。
96 .\"O Files never intended to be preserved on disk may be created by setting
99 .\"O argument to NULL.
102 ディスク上に保存したくないファイルを作ることもできる。
108 .\"O arguments are as specified to the
110 .\"O routine, however, only the
114 .\"O .BR O_NONBLOCK ,
120 .\"O flags are meaningful.
137 .\"O (Note, opening a database file
139 .\"O is not possible.)
142 でデータベースファイルを開く事は出来ない)
143 .\"Three additional options may be specified by ORing
149 .\"Do the necessary locking in the database to support concurrent access.
150 .\"If concurrent access isn't needed or the database is read-only this
151 .\"flag should not be set, as it tends to have an associated performance
155 .\"Place the underlying memory pool used by the database in shared
157 .\"Necessary for concurrent access.
160 .\"Support transactions in the database.
161 .\"The DB_LOCK and DB_SHMEM flags must be set as well.
165 .\"O argument is of type
167 .\"O (as defined in the
169 .\"O include file) and
188 .\"O argument is a pointer to an access method specific structure described
189 .\"O in the access method's manual page.
192 .\"O is NULL, each access method will use defaults appropriate for the system
193 .\"O and the access method.
195 引き数はアクセスメソッドに固有な構造体へのポインタである。
196 それぞれの構造体に関しては各アクセスメソッドの
199 が NULL の場合、それぞれのアクセスメソッドとシステムとに適合した
203 .\"O returns a pointer to a
205 .\"O structure on success and NULL on error.
208 .\"O structure is defined in the
210 .\"O include file, and contains at
211 .\"O least the following fields:
215 構造体へのポインタを、エラーの場合 NULL を返す。
219 インクルードファイルの中で定義されており、
220 少なくとも以下のようなフィールドを持っている。
226 int (*close)(const DB *db);
227 int (*del)(const DB *db, const DBT *key, unsigned int flags);
228 int (*fd)(const DB *db);
229 int (*get)(const DB *db, DBT *key, DBT *data,
231 int (*put)(const DB *db, DBT *key, const DBT *data,
233 int (*sync)(const DB *db, unsigned int flags);
234 int (*seq)(const DB *db, DBT *key, DBT *data,
240 .\"O These elements describe a database type and a set of functions performing
241 .\"O various actions.
242 .\"O These functions take a pointer to a structure as returned by
244 .\"O and sometimes one or more pointers to key/data structures and a flag value.
246 様々な動作をする関数のセットが記述されている。
249 によって返される構造体へのポインタを引き数にとる。
250 キー/データ構造体へのポインタやフラグ値を取るものもある。
253 .\"O The type of the underlying access method (and file format).
254 用いられているアクセスメソッド (とファイルフォーマット) の型。
257 .\"O A pointer to a routine to flush any cached information to disk, free any
258 .\"O allocated resources, and close the underlying file(s).
259 キャッシュされた情報をディスクに掃きだすためのルーチンへのポインタ。
260 割り当てられたリソースを解放し、利用したファイル(群)をクローズする。
261 .\"O Since key/data pairs may be cached in memory, failing to sync the file
266 .\"O function may result in inconsistent or lost information.
267 キー/データ対がメモリにキャッシュされている場合、
271 関数での同期に失敗すると、情報に矛盾が生じるか情報を失う可能性がある。
273 .\"O routines return \-1 on error (setting
275 .\"O and 0 on success.
282 .\"O A pointer to a routine to remove key/data pairs from the database.
283 データベースからキー/データ対を削除するルーチンへのポインタ。
287 .\"O may be set to the following value:
293 .\"O Delete the record referenced by the cursor.
294 .\"O The cursor must have previously been initialized.
295 カーソル (cursor) が参照しているレコードを削除する。
296 カーソルは前もって初期化されていなくてはならない。
300 .\"O routines return \-1 on error (setting
302 .\"O 0 on success, and 1 if the specified
304 .\"O was not in the file.
308 をセットする)、成功すると 0 を返す。また指定の
313 .\"O A pointer to a routine which returns a file descriptor representative
314 .\"O of the underlying database.
315 用いているデータベースのファイルデスクリプタを返すルーチン
317 .\"O A file descriptor referencing the same file will be returned to all
318 .\"O processes which call
328 そのファイルを示す単一のファイルデスクリプタが返される。
329 .\"O This file descriptor may be safely used as an argument to the
333 .\"O locking functions.
339 .\"O The file descriptor is not necessarily associated with any of the
340 .\"O underlying files used by the access method.
341 .\"O No file descriptor is available for in memory databases.
343 .\"O routines return \-1 on error (setting
345 .\"O and the file descriptor on success.
346 このファイルデスクリプタは、必ずしもアクセスメソッドで
347 用いられているファイルのいずれかに関連づけられていなくても良い。
348 メモリ内のデータベースにはファイルデスクリプタは無い。
352 をセットする)、成功するとファイルデスクリプタを返す。
355 .\"O A pointer to a routine which is the interface for keyed retrieval from
357 データベースからキーを用いてデータを取り出すための
359 .\"O The address and length of the data associated with the specified
361 .\"O are returned in the structure referenced by
369 .\"O routines return \-1 on error (setting
371 .\"O 0 on success, and 1 if the
373 .\"O was not in the file.
377 をセットする)、成功すると 0 を返す。また
382 .\"O A pointer to a routine to store key/data pairs in the database.
383 キー/データ対をデータベースに納めるルーチンへのポインタ。
387 .\"O may be set to one of the following values:
389 引き数には次の値のうちのどれか一つがセットできる。
393 .\"O Replace the key/data pair referenced by the cursor.
394 .\"O The cursor must have previously been initialized.
395 カーソルが参照しているキー/データ対を置き換える。
396 カーソルは前もって初期化されている必要がある。
399 .\"O Append the data immediately after the data referenced by
401 .\"O creating a new key/data pair.
402 .\"O The record number of the appended key/data pair is returned in the
405 .\"O (Applicable only to the
410 新しいキー/データ対を作ってデータを追加する。
418 .\"O Insert the data immediately before the data referenced by
420 .\"O creating a new key/data pair.
421 .\"O The record number of the inserted key/data pair is returned in the
424 .\"O (Applicable only to the
429 新しいキー/データ対を作ってデータを挿入する。
437 .\"O Enter the new key/data pair only if the key does not previously exist.
438 キーがあらかじめ存在しない場合に限り、新しいキー/データ対をいれる。
441 .\"O Store the key/data pair, setting or initializing the position of the
442 .\"O cursor to reference it.
443 .\"O (Applicable only to the
447 .\"O access methods.)
448 キー/データ対を納め、それを指すようにカーソル位置をセットあるいは初期
457 .\"O is available only for the
462 .\"O methods because it implies that the keys have an inherent order
463 .\"O which does not change.
472 を用いるには、変更される事の無い固有の順序をキー
478 .\"O are available only for the
480 .\"O access method because they each imply that the access method is able to
481 .\"O create new keys.
482 .\"O This is only true if the keys are ordered and independent, record numbers
491 新しいキーを作れなければならないからである。
492 これが成立するのは、例えば、順序づけらた独立なレコード番号が
495 .\"O The default behavior of the
497 .\"O routines is to enter the new key/data pair, replacing any previously
499 ルーチンのデフォルトの動作は、新しいキー/データ対を
500 既に存在するキーを置き換える事て格納する動作である。
503 .\"O routines return \-1 on error (setting
505 .\"O 0 on success, and 1 if the
506 .\"O .B R_NOOVERWRITE
508 .\"O was set and the key already exists in the file.
511 をセットする)、成功すると 0 を返す。また
515 がセットされていてキーが既に存在する場合 1 を返す。
518 .\"O A pointer to a routine which is the interface for sequential
519 .\"O retrieval from the database.
520 .\"O The address and length of the key are returned in the structure
523 .\"O and the address and length of the data are returned in the
524 .\"O structure referenced
527 データベースからシーケンシャルにデータを取り出すための
531 が参照する構造体に返される。データのアドレスと長さが
535 .\"O Sequential key/data pair retrieval may begin at any time, and the
536 .\"O position of the "cursor" is not affected by calls to the
537 シーケンシャルなキー/データ対の取得はいつでも行える。また
546 .\"O Modifications to the database during a sequential scan will be reflected
547 .\"O in the scan, that is,
548 .\"O records inserted behind the cursor will not be returned
549 .\"O while records inserted in front of the cursor will be returned.
550 シーケンシャルなスキャンの途中に行われたデータベースへの変更は
551 スキャンに反映される。すなわち、カーソルの後ろに挿入されたレコードは
552 返されないが、カーソルの前に挿入されたレコードは返される。
556 .\"O be set to one of the following values:
557 フラグ値には\fB必ず\fP以下に示すうちの
562 .\"O The data associated with the specified key is returned.
563 .\"O This differs from the
565 .\"O routines in that it sets or initializes the cursor to the location of
566 .\"O the key as well.
569 .\"O access method, the returned key is not necessarily an
570 .\"O exact match for the specified key.
571 .\"O The returned key is the smallest key greater than or equal to the specified
572 .\"O key, permitting partial key matches and range searches.)
573 指定したキーに関連づけられたデータが返される。
575 ルーチンとの違いは、カーソルがキーの位置にセットあるいは
580 必ずしも指定したキーに正しくマッチしないかもしれない。
581 返されたキーは、指定されたキーに等しいかより大きいもののうち
583 (部分キーマッチか範囲検索が許可されている場合)。)
586 .\"O The first key/data pair of the database is returned, and the cursor
587 .\"O is set or initialized to reference it.
588 データベースの最初のキー/データ対が返される。
589 カーソルはそれを参照するようにセットまたは初期化される。
592 .\"O The last key/data pair of the database is returned, and the cursor
593 .\"O is set or initialized to reference it.
594 .\"O (Applicable only to the
598 .\"O access methods.)
599 データベースの最後のキー/データ対が返される。カーソルはそれを参照する
607 .\"O Retrieve the key/data pair immediately after the cursor.
608 .\"O If the cursor is not yet set, this is the same as the
617 .\"O Retrieve the key/data pair immediately before the cursor.
618 .\"O If the cursor is not yet set, this is the same as the
621 .\"O (Applicable only to the
625 .\"O access methods.)
639 .\"O are available only for the
643 .\"O access methods because they each imply that the keys have an inherent
644 .\"O order which does not change.
655 を用いるには、変更される事の無い固有の順序をキーが持っていなければならないからである。
658 .\"O routines return \-1 on error (setting
660 .\"O 0 on success and 1 if there are no key/data pairs less than or greater
661 .\"O than the specified or current key.
664 .\"O access method is being used, and if the database file
665 .\"O is a character special file and no complete key/data pairs are currently
668 .\"O routines return 2.
673 指定したキーやカレントキーよりも大きい/小さいキー/データ対がない場合は
677 かつデータベースファイルが文字型のスペシャルファイルで、
678 完成しているキー/データ対が無い場合には、
683 .\"O A pointer to a routine to flush any cached information to disk.
684 .\"O If the database is in memory only, the
686 .\"O routine has no effect and will always succeed.
687 キャッシュされた情報をディスクに掃き出すルーチンへのポインタ。
692 .\"O The flag value may be set to the following value:
699 .\"O access method is being used, this flag causes
700 .\"O the sync routine to apply to the btree file which underlies the
701 .\"O recno file, not the recno file itself.
706 そのベースになっている btree ファイルに sync が行われる。
711 .\"O manual page for more information.)
716 フィールドを説明している部分を参照のこと。)
720 .\"O routines return \-1 on error (setting
722 .\"O and 0 on success.
726 .\"O .SS "Key/Data Pairs"
728 .\"O Access to all file types is based on key/data pairs.
729 .\"O Both keys and data are represented by the following data structure:
731 キー/データ対をベースにしてアクセスが行われる。
732 キーとデータのいずれも、次のデータ構造で記述される。
742 .\"O The elements of the
744 .\"O structure are defined as follows:
746 構造体の各要素は次のように定義されている。
749 .\"O A pointer to a byte string.
753 .\"O The length of the byte string.
756 .\"O Key and data byte strings may reference strings of essentially unlimited
757 .\"O length although any two of them must fit into available memory at the same
760 基本的には無制限の長さの文字列を参照できるが、
761 しかしいずれも使用可能なメモリに収まっていなくてはならない。
762 .\"O It should be noted that the access methods provide no guarantees about
763 .\"O byte string alignment.
764 アクセスメソッドはバイト文字列のアラインメントについては
769 .\"O routine may fail and set
771 .\"O for any of the errors specified for the library routines
775 .\"O or the following:
786 .\"O A file is incorrectly formatted.
787 ファイルが正しくフォーマットされていない。
790 .\"O A parameter has been specified (hash function, pad byte etc.) that is
791 .\"O incompatible with the current file specification or which is not
792 .\"O meaningful for the function (for example, use of the cursor without
793 .\"O prior initialization) or there is a mismatch between the version
794 .\"O number of file and the software.
795 指定したパラメータ(ハッシュ関数、バイト埋めなど)が現在のファイル仕様に
796 合っていない、パラメータが関数にとって無意味
797 (例えばあらかじめ初期化しないでカーソルを使うとか)、
798 ファイルとソフトウェアのバージョンが合っていない。
802 .\"O routines may fail and set
805 .\"O for any of the errors specified for the library routines
823 .\"O routines may fail and set
826 .\"O for any of the errors specified for the library routines
838 .\"O routines will fail and set
842 .\"O for in memory databases.
844 ルーチンはメモリ内データベースに対し失敗すると
852 .\"O routines may fail and set
855 .\"O for any of the errors specified for the library routine
863 .\"O is a mnemonic for "data base thang", and was used
864 .\"O because no-one could think of a reasonable name that wasn't already used.
867 は ``data base thang''の略語であるが、これが使われているのは、
868 まだ使われていない妥当な名前が思い付かなかったためである。
870 .\"O The file descriptor interface is a kludge and will be deleted in a
871 .\"O future version of the interface.
872 ファイルデスクリプタを使ったやりとりはひどい代物であり、
875 .\"O None of the access methods provide any form of concurrent access,
876 .\"O locking, or transactions.
877 どのアクセスメソッドも、同時アクセス、ロック、トランザクション
885 .IR "LIBTP: Portable, Modular Transactions for UNIX" ,
886 Margo Seltzer, Michael Olson, USENIX proceedings, Winter 1992.