📄 db.doc
字号:
###### ###### ###### ####### #####
# # # # # # # # # #
# # # # # # # # #
# # ###### # # # # #
# # # # ### # # # # #
# # # # ### # # # # # #
###### ###### ### ###### ####### #####
# # # #####
# # ## # #
# # # # #
# # # #####
# # # ### #
# # # ### # #
# ##### ### #####
(c) 1987, 1990
Ken Harris
901 E. Hampton
Milwaukee, WI 53217
(414) 962-1961
harris@cvax.cs.uwm.edu
/****************************************************************************/
/* */
/* This software is made available on an AS-IS basis. Unrestricted */
/* use is granted provided that the copyright notice remains intact. */
/* The author makes no warranties expressed or implied; however, any */
/* feedback is welcome. */
/* */
/****************************************************************************/
V1.2 Release Notes:
---- ------- -----
(1) The DB_READ_LAST and DB_READ_PREV routines have been added
to allow backwards traversal. The routines work for all three
file types. DB_DELETE should not be used with these routines.
The delete routine sets the current record pointer so that a
subsequent DB_READ_NEXT will work correctly. A DB_READ_PREV
loop with DB_DELETES will result in skipped records.
(2) A number of bugs in the file create routine have been fixed.
(3) A file corruption bug in the Index delete routine has been
fixed.
(4) The distribution has been divided into three separately
compiled files.
(5) Large memory model now works correctly.
(6) A lot of "warning" type problems have been cleaned up.
(7) Just before releasing V1.2 Microsoft C V5.0 rolled in
the door so I was able to fix a couple of problems.
There are still some warning messages while compiling
db_main.c. This is the result of ",..." type declarations
used to prevent type checking of the user_data argument.
User programs don't have to type cast user_data to char*
to avoid warnings.
(8) I have avoided the temptation of using too many of the
ANSI C extensions for those folks with old compilers.
Also I'd rather not fill the code with a zillion IFDEF's.
V1.3 Release Notes:
---- ------- -----
(1) A variable type file has been added. It is a sequential file
with variable length records.
(2) A simple object dictionary manager has been added. It works
well for a small data base of non-homogeneous objects, for
example setup data records.
(3) The file descriptor pointer is now called DATA_FILE instead of
DATA_SET. DATA_SET is still defined so that V1.2 programs
will compile.
(4) The db_create routine arguments have changed. An option
string is now passed instead of a df_file_hdr pointer. This
is much cleaner. It will require changing any V1.2 programs
before they will work.
(5) A number of routines now take an optional final record size
argument. This is only required for VAR type files. It may
be ignored for other file types.
(6) Existing V1.2 data files should work with V1.3 routines.
The first time the file is openned and updated the file
version will be changed from 1.2 to 1.3.
(7) Compiler conditionals have been added to DB_MAIN.C to
bracket references to file-type specific routines. This
makes it possible to build a library with support for
only file types you need. The lexical variables are
SEQ, RAN, IDX, VAR and ALL. So if SEQ is defined, then
sequential file support is included, etc. Note that
DB_DICT uses VAR files. If an attempt is made to access
an unsupported file-type an error will occur.
Only the references to routines are IFDEFed. If you build
a subset library you will probably get warning messages
about some unreferenced variables. It's ok.
(8) Compiler conditionals are used to bracket compiler specific
code. The current conditionals are:
MSC - Microsoft C
TURBO - Turbo C
SYSV - Unix Sys V
In addition ANSI can be defined to use ANSI style function
prototypes. You will probably want to edit #defines for
your compiler and ANSI at the beginning of db.h.
(9) A header file, dblib.h, has been added for building the
library. It is not needed for application programs. It
contains compiler specific includes and defines.
V1.3 Release Notes (cont):
---- ------- -----
(10) The header file contains references to DB_LINK routines.
These are routines for linking records between files.
They have not been included in the distribution.
(11) The routines memedt and stredt are no longer used by the
db routines and have been removed from the distribution.
(12) The *test.c files are intended to provide a minimal test
of the routines. If the the tests run to compeletion
without crashing or generating a DB-ERROR then there is
a good chance that you're in business. The tests are
not necessarily good examples of using the routines.
(13) The routines have been built and tested on several
different machines. Most of the development for v1.3
was done under Ultrix on a VAXstation-2000 with gcc.
It has also been sucessfully built using MSC 5.1 and
Turbo C 2.0 under MSDOS and cc under Unix on a 3B1.
If your compiler is not one of these you should still
be able to build the routines without too much trouble.
Search through the code for MSC 's and add an
appropriate case for your compiler.
(14) Note that although this code works fine on Unix systems,
it is still single user. There is no support for record
locking or file sharing.
+----------+ ------------------- +----------+
| db_Intro | - DB Introduction - | db_Intro |
+----------+ ------------------- +----------+
o Description
This document describes the DB package for maintaining
data files. The package consists of a library of file handling
routines which may be linked with user programs.
The following four file organizations are supported:
(1) Sequential - This file is a sequential stream of fixed
length records.
(2) Index - Data records are stored in an ISAM type
organization.
(3) Random - Data records are stored using a hashed method.
(4) Variable - A sequential stream of variable length
records.
The following operations are supported:
db_read_last - Read Last Record
db_read_prev - Read Prev Record
db_add - Add a New Record a File
db_close - Close an Open Data Set
db_create - Create a New Data Set
db_delete - Delete the Current Record
db_dict_add - Dict Add Object
db_dict_close - Dict Close
db_dict_delete - Dict Object Delete
db_dict_delete_all - Dict Delete All
db_dict_dump - Dict Dump to a File
db_dict_find - Dict Find Object
db_dict_find_all - Dict Find All
db_dict_init - Dict Initialize
db_dict_load - Dict Load From File
db_error_msg - Get Error Message Text
db_find - Find a Record by Key
db_get_rec_no - Get Relative Record #
db_open - Open an Existing Data Set
db_read_atr - Read Attribute Data
db_read_direct - Read by Record #
db_read_first - Read First Record
db_read_next - Read Next Record
db_reorg - Reorganize Free Space
db_update - Update the Current Record
db_update_atr - Update Attribute Data
+------+ ------------------------------- +------+
| db.h | - Data Set Structures Defines - | db.h |
+------+ ------------------------------- +------+
o Summary
#include <db.h>
o Description
This header file contains the definitions for the global
structures that are used by all of the DB routines. It
should be included in any program that calls DB routines.
The user program needs only to declare DATA_FILE descriptor
pointers for the data files that are to be used. The
DATA_FILE descriptor pointer is used to refer to the data
files.
A global variable db_error is used to return a status
value after any call to a DB routine. The header file
includes constant declarations for db_error values.
The user program can check for specific conditions
such as DB_END_OF_FILE. A function call db_error_msg()
can be used to get the error message text corresponding
to the value of db_error.
+--------+ ------------------------------------ +--------+
| db_add | - Add a New Record to a Data Set - | db_add |
+--------+ ------------------------------------ +--------+
o Summary
#include <db.h>
ulong db_add(df, user_data, data_size)
DATA_FILE df;
void *user_data;
int data_size;
o Description
This function is used to add a new record to a data file.
The data file is specified by the input df and user_data
points to the data record to be added.
For Indexed and Random data files, the first field of the
data record (user_data) must contain the record key value.
For Variable data files, the data_size field contains the
size of the variable length user_data record. The field
is not used for the other file types.
The value of Current Record (used by db_read_next) is reset
to NONE by this operation.
o Returns
The relative record number of the new record is returned.
If an error occurs a zero value is returned and the global
db_error contains the error number.
+----------+ ---------------------------- +----------+
| db_close | - Close an Open Data Set - | db_close |
+----------+ ---------------------------- +----------+
o Summary
#include <db.h>
DATA_FILE db_close(df)
DATA_FILE df;
o Description
This function terminates all processing for an open data file.
The associated file is closed and all dynamic storage is
released.
o Returns
The completion status of the function is returned in the
global db_error. The function itself returns a NULL pointer
value.
+-----------+ ------------------------- +-----------+
| db_create | - Create a New Data Set - | db_create |
+-----------+ ------------------------- +-----------+
o Summary
#include <db.h>
DATA_FILE db_create(path, fname, options)
char *path, *fname, *options;
o Description
This function is used to create a new data file. The inputs
are as follows:
path - Path name of data directory
fname - File name of new data file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -