⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdbm.texinfo

📁 开源的数据库管理系统
💻 TEXINFO
📖 第 1 页 / 共 2 页
字号:
\input texinfo	@c -*- Texinfo -*-@comment %**start of header (This is for running Texinfo on a region.)@setfilename gdbm.info@settitle gdbm@dircategory Programming & development tools@direntry* GDBM: (gdbm).			The GNU database manager.@end direntry@c @setchapternewpage odd@comment %**end of header (This is for running Texinfo on a region.)@iftex@finalout@end iftex@ifinfoThis file documents the GNU dbm utility.Copyright (C) 1989-1999 Free Software Foundation, Inc.Permission is granted to make and distribute verbatim copies ofthis manual provided the copyright notice and this permission noticeare preserved on all copies.@ignorePermission is granted to process this file through Tex and print theresults, provided the printed document carries copying permissionnotice identical to this one except for the removal of this paragraph(this paragraph not being relevant to the printed manual).@end ignorePermission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided also thatthe entire resulting derived work is distributed under the terms of apermission notice identical to this one.Permission is granted to copy and distribute translations of this manualinto another language, under the above conditions for modified versions.@end ifinfo@titlepage@null@sp 6@center @titlefont{GNU dbm}@sp 2@center A Database Manager@sp 2@center by Philip A. Nelson and Jason Downs@sp 4@center Manual by Pierre Gaumond, Philip A. Nelson and Jason Downs@sp 1@center Edition 1.5@sp 1@center for GNU @code{dbm}, Version 1.8.3.@page@null@vskip 0pt plus 1filllCopyright @copyright{} 1993-99 Free Software Foundation, Inc.@sp 2This is Edition 1.5 of the @cite{GNU @code{dbm} Manual}, for @code{gdbm}Version 1.8.3. @*Last updated October 15, 2002Published by the Free Software Foundation @*675 Massachusetts Avenue, @*Cambridge, MA 02139 USA @*Permission is granted to make and distribute verbatim copies ofthis manual provided the copyright notice and this permission noticeare preserved on all copies.Permission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided also thatthe entire resulting derived work is distributed under the terms of apermission notice identical to this one.Permission is granted to copy and distribute translations of this manualinto another language, under the above conditions for modified versions,except that this permission notice may be stated in a translation approvedby the Free Software Foundation.@end titlepage@page@node Top, Copying, (dir), (dir)@ifinfoGNU @code{dbm} is a library of functions implementing a hashed databaseon a disk file.  This manual documents GNU @code{dbm} Version 1.8.3(@code{gdbm}).  The software was written by Philip A. Nelson. Thisdocument was originally written by Pierre Gaumond from texts written byPhil.@end ifinfo@menuIntroduction:* Copying::                    Your rights.* Intro::                      Introduction to GNU dbm.* List::                       List of functions.Functions:* Open::                       Opening the database.* Close::                      Closing the database.* Store::                      Inserting and replacing records in the database.* Fetch::                      Searching records in the database.* Delete::                     Removing records from the database.* Sequential::                 Sequential access to records.* Reorganization::             Database reorganization.* Sync::                       Insure all writes to disk have competed.* Errors::                     Convert internal error codes into English.* Options::                    Setting internal options.* Locking::                    File locking.Other topics:* Variables::                  Two useful variables.* Compatibility::              Compatibility with UNIX dbm and ndbm.* Conversion::                 Converting dbm files to gdbm format.* Bugs::                       Problems and bugs.@end menu@node Copying, Intro, Top, Top@chapter Copying Conditions.This library is @dfn{free}; this means that everyone is free to useit and free to redistribute it on a free basis.  GNU @code{dbm} (@code{gdbm})is not in the public domain; it is copyrighted and thereare restrictions on its distribution, but these restrictions aredesigned to permit everything that a good cooperating citizen would wantto do.  What is not allowed is to try to prevent others from furthersharing any version of @code{gdbm} that they might get fromyou.@refill  Specifically, we want to make sure that you have the right to giveaway copies @code{gdbm}, that you receivesource code or else can get it if you want it, that you can change thesefunctions or use pieces of them in new free programs, and that you knowyou can do these things.@refill  To make sure that everyone has such rights, we have to forbid you todeprive anyone else of these rights.  For example, if you distributecopies @code{gdbm}, you must give the recipients allthe rights that you have.  You must make sure that they, too, receive orcan get the source code.  And you must tell them their rights.@refill  Also, for our own protection, we must make certain that everyone findsout that there is no warranty for anything in the @code{gdbm} distribution.If these functions are modified by someone else and passed on, we wanttheir recipients to know that what they have is not what we distributed,so that any problems introduced by others will not reflect on ourreputation.@refill@code{gdbm} is currently distributed under the terms of the GNU GeneralPublic License, Version 2.  (@emph{NOT} under the GNU General LibraryPublic License.)  A copy the GNU General Public License is included withthe distribution of @code{gdbm}.@node Intro, List, Copying, Top@chapter Introduction to GNU @code{dbm}.GNU @code{dbm} (@code{gdbm})is a library of database functions that useextendible hashing and works similar to the standard UNIX @code{dbm}functions.  These routines are provided to a programmer needing tocreate and manipulate a hashed database. (@code{gdbm} is @emph{NOT} acomplete database package for an end user.)The basic use of @code{gdbm} is to store key/data pairs in a data file.Each key must be unique and each key is paired with only one data item.The keys can not be directly accessed in sorted order.  The basic unitof data in @code{gdbm} is the structure:@example  typedef struct @{             char *dptr;             int  dsize;          @} datum;@end exampleThis structure allows for arbitrary sized keys and data items.The key/data pairs are stored in a @code{gdbm} disk file, called a@code{gdbm} database.  An application must open a @code{gdbm} databaseto be able manipulate the keys and data contained in the database.@code{gdbm} allows an application to have multiple databases open at thesame time.  When an application opens a @code{gdbm} database, it isdesignated as a @code{reader} or a @code{writer}.  A @code{gdbm}database opened by at most one writer at a time.  However, many readersmay open the database open simultaneously.  Readers and writers can notopen the @code{gdbm} database at the same time.@node List, Open, Intro, Top@chapter List of functions.The following is a quick list of the functions contained in the @code{gdbm}library. The include file @code{gdbm.h}, that can be included by the user,contains a definition of these functions.@example#include <gdbm.h>GDBM_FILE gdbm_open(name, block_size, flags, mode, fatal_func);void gdbm_close(dbf);int gdbm_store(dbf, key, content, flag);datum gdbm_fetch(dbf, key);int gdbm_delete(dbf, key);datum gdbm_firstkey(dbf);datum gdbm_nextkey(dbf, key);int gdbm_reorganize(dbf);void gdbm_sync(dbf);int gdbm_exists(dbf, key);char *gdbm_strerror(errno);int gdbm_setopt(dbf, option, value, size);int gdbm_fdesc(dbf);@end exampleThe @code{gdbm.h} include file is often in the @file{/usr/local/include}directory. (The actual location of @code{gdbm.h} depends on your localinstallation of @code{gdbm}.)@node Open, Close, List, Top@chapter Opening the database.Initialize @code{gdbm} system. If the file has a size of zero bytes, a fileinitialization procedure is performed, setting up the initial structure in thefile.The procedure for opening a @code{gdbm} file is:@exampleGDBM_FILE dbf;dbf = gdbm_open(name, block_size, flags, mode, fatal_func);@end exampleThe parameters are:@table @asis@item char *nameThe name of the file (the complete name, @code{gdbm} does not append anycharacters to this name).@item int block_sizeIt is used during initialization to determine the size of various constructs. Itis the size of a single transfer from disk to memory. This parameter is ignoredif the file has been previously initialized. The minimum size is 512.If the value is less than 512, the file system blocksize is used, otherwise thevalue of @code{block_size} is used.@item int flagsIf @code{flags} is set to GDBM_READER, the user wants to just read thedatabase and any call to @code{gdbm_store} or @code{gdbm_delete} will fail.Many readers can access the database at the same time. If @code{flags} isset to GDBM_WRITER, the user wants both read and write access to the databaseand requires exclusive access. If @code{flags} is set to GDBM_WRCREAT, theuser wants both read and write access to the database and if the database doesnot exist, create a new one. If @code{flags} is set to GDBM_NEWDB, theuser want a new database created, regardless of whether one existed, and wantsread and write access to the new database.  The following may also be logicallyor'd into the database flags: GDBM_SYNC, which causes all database operationsto be synchronized to the disk, and GDBM_NOLOCK, which prevents the libraryfrom performing any locking on the database file.  The option GDBM_FAST isnow obsolete, since @code{gdbm} defaults to no-sync mode.  Any error detectedwill cause a return value of NULL and an appropriate value will be in@code{gdbm_errno} (see Variables). If no errors occur, a pointer to the@code{gdbm} file descriptor will be returned.@item int modeFile mode (see chmod(2) and open(2) if the file is created).@item void (*fatal_func) ()A function for @code{gdbm} to call if it detects a fatal error. The onlyparameter of this function is a string. If the value of NULL is provided,@code{gdbm} will use a default function.@end tableThe return value, @code{dbf}, is the pointer needed by all other functions toaccess that @code{gdbm} file. If the return is the NULL pointer,@code{gdbm_open} was not successful. The errors can be found in@code{gdbm_errno} for @code{gdbm} errors and in @code{errno} for file systemerrors (for error codes, see @code{gdbm.h}).In all of the following calls, the parameter @code{dbf} refers to the pointerreturned from @code{gdbm_open}.@node Close, Store, Open, Top@chapter Closing the database.It is important that every file opened is also closed. This is needed toupdate the reader/writer count on the file. This is done by:@examplegdbm_close(dbf);@end exampleThe parameter is:@table @asis@item GDBM_FILE dbfThe pointer returned by @code{gdbm_open}.@end tableCloses the @code{gdbm} file and frees all memory associated with the file @code{dbf}. @node Store, Fetch, Close, Top@chapter Inserting and replacing records in the database.The function @code{gdbm_store} inserts or replaces records in the database.@exampleret = gdbm_store(dbf, key, content, flag);@end exampleThe parameters are:@table @asis@item GDBM_FILE dbfThe pointer returned by @code{gdbm_open}.@item datum keyThe @code{key} data.@item datum contentThe data to be associated with the key.@item int flagDefines the action to take when the key is already in the database. The valueGDBM_REPLACE (defined in @code{gdbm.h}) asks that the old data be replaced bythe new @code{content}. The value GDBM_INSERT asks that an error be returnedand no action taken if the @code{key} already exists.@end tableThe values returned in @code{ret} are:@table @asis@item -1The item was not stored in the database because the caller was not anofficial writer or either @code{key} or @code{content} have a NULL dptr field.Both @code{key} and @code{content} must have the dptr field be a non-NULL value.Since a NULL dptr field is used by other functions to indicate an error, a NULLfield cannot be valid data.@item +1The item was not stored because the argument @code{flag} was GDBM_INSERT andthe @code{key} was already in the database.@item 0No error. @code{content} is keyed by @code{key}. The file on disk is updatedto reflect the structure of the new database before returning from thisfunction.@end tableIf you store data for a @code{key} that is already in the data base,@code{gdbm} replaces the old data with the new data if called withGDBM_REPLACE. You do not get two data items for the same @code{key} and you donot get an error from @code{gdbm_store}.The size in @code{gdbm} is not restricted like @code{dbm} or @code{ndbm}. Yourdata can be as large as you want.@node Fetch, Delete, Store,Top@chapter Searching for records in the database.Looks up a given @code{key} and returns the information associated with thatkey. The pointer in the structure that is  returned is a pointer to dynamicallyallocated memory block. To search for some data:@examplecontent = gdbm_fetch(dbf, key);@end exampleThe parameters are:@table @asis@item GDBM_FILE dbfThe pointer returned by @code{gdbm_open}.@item datum keyThe @code{key} data.@end tableThe datum returned in @code{content} is a pointer to the data found. If thedptr is NULL, no data was found. If dptr is not NULL, then it pointsto data allocated by malloc. @code{gdbm} does not automatically free this data.The user must free this storage when done using it. This eliminates theneed to copy the result to save it for later use (you just save the pointer).You may also search for a particular key without retrieving it, using:@exampleret = gdbm_exists(dbf, key);@end exampleThe parameters are:@table @asis@item GDBM_FILE dbfThe pointer returned by @code{gdbm_open}.@item datum keyThe @code{key} data.@end tableUnlike @code{gdbm_fetch}, this routine does not allocate any memory, andsimply returns true or false, depending on whether the @code{key} exists,or not.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -