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

📄 gdbm.html

📁 开源的数据库管理系统 说明文档! gdbm 适用场合很多
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<html lang="en">
<head>
<title>gdbm</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="gdbm">
<meta name="generator" content="makeinfo 4.6">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
--></style>
</head>
<body>
<h1 class="settitle">gdbm</h1>
<div class="node">
<p><hr>
Node:&nbsp;<a name="Top">Top</a>,
Next:&nbsp;<a rel="next" accesskey="n" href="#Copying">Copying</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#dir">(dir)</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#dir">(dir)</a>
<br>
</div>

<p>Introduction:

<ul class="menu">
<li><a accesskey="1" href="#Copying">Copying</a>:                     Your rights. 
<li><a accesskey="2" href="#Intro">Intro</a>:                       Introduction to GNU dbm. 
<li><a accesskey="3" href="#List">List</a>:                        List of functions.

<p>Functions:

</p><li><a accesskey="4" href="#Open">Open</a>:                        Opening the database. 
<li><a accesskey="5" href="#Close">Close</a>:                       Closing the database. 
<li><a accesskey="6" href="#Store">Store</a>:                       Inserting and replacing records in the database. 
<li><a accesskey="7" href="#Fetch">Fetch</a>:                       Searching records in the database. 
<li><a accesskey="8" href="#Delete">Delete</a>:                      Removing records from the database. 
<li><a accesskey="9" href="#Sequential">Sequential</a>:                  Sequential access to records. 
<li><a href="#Reorganization">Reorganization</a>:              Database reorganization. 
<li><a href="#Sync">Sync</a>:                        Insure all writes to disk have competed. 
<li><a href="#Errors">Errors</a>:                      Convert internal error codes into English. 
<li><a href="#Options">Options</a>:                     Setting internal options. 
<li><a href="#Locking">Locking</a>:                     File locking.

<p>Other topics:

</p><li><a href="#Variables">Variables</a>:                   Two useful variables. 
<li><a href="#Compatibility">Compatibility</a>:               Compatibility with UNIX dbm and ndbm. 
<li><a href="#Conversion">Conversion</a>:                  Converting dbm files to gdbm format. 
<li><a href="#Bugs">Bugs</a>:                        Problems and bugs. 
</ul>

<div class="node">
<p><hr>
Node:&nbsp;<a name="Copying">Copying</a>,
Next:&nbsp;<a rel="next" accesskey="n" href="#Intro">Intro</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Top">Top</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>
<br>
</div>

<h2 class="chapter">1 Copying Conditions.</h2>

<p>This library is <dfn>free</dfn>; this means that everyone is free to use
it and free to redistribute it on a free basis.  GNU <code>dbm</code> (<code>gdbm</code>)
is not in the public domain; it is copyrighted and there
are restrictions on its distribution, but these restrictions are
designed to permit everything that a good cooperating citizen would want
to do.  What is not allowed is to try to prevent others from further
sharing any version of <code>gdbm</code> that they might get from
you.

   <p>Specifically, we want to make sure that you have the right to give
away copies <code>gdbm</code>, that you receive
source code or else can get it if you want it, that you can change these
functions or use pieces of them in new free programs, and that you know
you can do these things.

   <p>To make sure that everyone has such rights, we have to forbid you to
deprive anyone else of these rights.  For example, if you distribute
copies <code>gdbm</code>, you must give the recipients all
the rights that you have.  You must make sure that they, too, receive or
can get the source code.  And you must tell them their rights.

   <p>Also, for our own protection, we must make certain that everyone finds
out that there is no warranty for anything in the <code>gdbm</code> distribution. 
If these functions are modified by someone else and passed on, we want
their recipients to know that what they have is not what we distributed,
so that any problems introduced by others will not reflect on our
reputation.

   <p><code>gdbm</code> is currently distributed under the terms of the GNU General
Public License, Version 2.  (<em>NOT</em> under the GNU General Library
Public License.)  A copy the GNU General Public License is included with
the distribution of <code>gdbm</code>.

<div class="node">
<p><hr>
Node:&nbsp;<a name="Intro">Intro</a>,
Next:&nbsp;<a rel="next" accesskey="n" href="#List">List</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Copying">Copying</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>
<br>
</div>

<h2 class="chapter">2 Introduction to GNU <code>dbm</code>.</h2>

<p>GNU <code>dbm</code> (<code>gdbm</code>)is a library of database functions that use
extendible hashing and works similar to the standard UNIX <code>dbm</code>
functions.  These routines are provided to a programmer needing to
create and manipulate a hashed database. (<code>gdbm</code> is <em>NOT</em> a
complete database package for an end user.)

   <p>The basic use of <code>gdbm</code> 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 unit
of data in <code>gdbm</code> is the structure:

<pre class="example">       typedef struct {
                  char *dptr;
                  int  dsize;
               } datum;
     </pre>

   <p>This structure allows for arbitrary sized keys and data items.

   <p>The key/data pairs are stored in a <code>gdbm</code> disk file, called a
<code>gdbm</code> database.  An application must open a <code>gdbm</code> database
to be able manipulate the keys and data contained in the database. 
<code>gdbm</code> allows an application to have multiple databases open at the
same time.  When an application opens a <code>gdbm</code> database, it is
designated as a <code>reader</code> or a <code>writer</code>.  A <code>gdbm</code>
database opened by at most one writer at a time.  However, many readers
may open the database open simultaneously.  Readers and writers can not
open the <code>gdbm</code> database at the same time.

<div class="node">
<p><hr>
Node:&nbsp;<a name="List">List</a>,
Next:&nbsp;<a rel="next" accesskey="n" href="#Open">Open</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Intro">Intro</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>
<br>
</div>

<h2 class="chapter">3 List of functions.</h2>

<p>The following is a quick list of the functions contained in the <code>gdbm</code>
library. The include file <code>gdbm.h</code>, that can be included by the user,
contains a definition of these functions.

<pre class="example">     #include &lt;gdbm.h&gt;
     
     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);
     </pre>

   <p>The <code>gdbm.h</code> include file is often in the <code>/usr/local/include</code>
directory. (The actual location of <code>gdbm.h</code> depends on your local
installation of <code>gdbm</code>.)

<div class="node">
<p><hr>
Node:&nbsp;<a name="Open">Open</a>,
Next:&nbsp;<a rel="next" accesskey="n" href="#Close">Close</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#List">List</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>
<br>
</div>

<h2 class="chapter">4 Opening the database.</h2>

<p>Initialize <code>gdbm</code> system. If the file has a size of zero bytes, a file
initialization procedure is performed, setting up the initial structure in the
file.

   <p>The procedure for opening a <code>gdbm</code> file is:

<pre class="example">     GDBM_FILE dbf;
     
     dbf = gdbm_open(name, block_size, flags, mode, fatal_func);
     </pre>

   <p>The parameters are:

     <dl>
<dt>char *name
     <dd>The name of the file (the complete name, <code>gdbm</code> does not append any
characters to this name). 
<br><dt>int block_size
     <dd>It is used during initialization to determine the size of various constructs. It
is the size of a single transfer from disk to memory. This parameter is ignored
if 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 the
value of <code>block_size</code> is used. 
<br><dt>int flags
     <dd>If <code>flags</code> is set to GDBM_READER, the user wants to just read the
database and any call to <code>gdbm_store</code> or <code>gdbm_delete</code> will fail. 
Many readers can access the database at the same time. If <code>flags</code> is
set to GDBM_WRITER, the user wants both read and write access to the database
and requires exclusive access. If <code>flags</code> is set to GDBM_WRCREAT, the
user wants both read and write access to the database and if the database does
not exist, create a new one. If <code>flags</code> is set to GDBM_NEWDB, the
user want a new database created, regardless of whether one existed, and wants
read and write access to the new database.  The following may also be logically
or'd into the database flags: GDBM_SYNC, which causes all database operations
to be synchronized to the disk, and GDBM_NOLOCK, which prevents the library
from performing any locking on the database file.  The option GDBM_FAST is
now obsolete, since <code>gdbm</code> defaults to no-sync mode.  Any error detected
will cause a return value of NULL and an appropriate value will be in
<code>gdbm_errno</code> (see Variables). If no errors occur, a pointer to the
<code>gdbm</code> file descriptor will be returned. 
<br><dt>int mode
     <dd>File mode (see chmod(2) and open(2) if the file is created). 
<br><dt>void (*fatal_func) ()
     <dd>A function for <code>gdbm</code> to call if it detects a fatal error. The only
parameter of this function is a string. If the value of NULL is provided,
<code>gdbm</code> will use a default function. 
</dl>

   <p>The return value, <code>dbf</code>, is the pointer needed by all other functions to
access that <code>gdbm</code> file. If the return is the NULL pointer,
<code>gdbm_open</code> was not successful. The errors can be found in
<code>gdbm_errno</code> for <code>gdbm</code> errors and in <code>errno</code> for file system
errors (for error codes, see <code>gdbm.h</code>).

   <p>In all of the following calls, the parameter <code>dbf</code> refers to the pointer
returned from <code>gdbm_open</code>.

<div class="node">
<p><hr>
Node:&nbsp;<a name="Close">Close</a>,
Next:&nbsp;<a rel="next" accesskey="n" href="#Store">Store</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Open">Open</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>
<br>
</div>

<h2 class="chapter">5 Closing the database.</h2>

<p>It is important that every file opened is also closed. This is needed to
update the reader/writer count on the file. This is done by:

<pre class="example">     gdbm_close(dbf);
     </pre>

   <p>The parameter is:

     <dl>
<dt>GDBM_FILE dbf
     <dd>The pointer returned by <code>gdbm_open</code>. 
</dl>

   <p>Closes the <code>gdbm</code> file and frees all memory associated with the file
<code>dbf</code>.

<div class="node">
<p><hr>
Node:&nbsp;<a name="Store">Store</a>,
Next:&nbsp;<a rel="next" accesskey="n" href="#Fetch">Fetch</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Close">Close</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>
<br>
</div>

<h2 class="chapter">6 Inserting and replacing records in the database.</h2>

⌨️ 快捷键说明

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