📄 dbase.htm
字号:
<!-- This document was created with HomeSite v2.5 -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>UDDF - DBase</TITLE>
<META NAME="Description" CONTENT="dbase DBF structure section of the Delphi Developers FAQ" >
<META NAME="Keywords" CONTENT=" ">
</HEAD>
<body bgcolor="#FFFFFF">
<CENTER>
<IMG SRC="../images/uddf.jpg"> </CENTER>
<HR SIZE="6" COLOR="#00FF00">
<p align="center"><font color="#FF0000" size="7"
face="Arial Black">DBase</font> </p>
<H1><A NAME="dbase0">TI2821 - dBASE .DBF File Structure</A></H1>
Sometimes it is necessary to delve into a dBASE table outside the control
of the Borland Database Engine (BDE). For instance, if the .DBT file (that
contains memo data) for a given table is irretrievably lost, the file will
not be usable because the byte in the file header indicates that there
should be a corresponding memo file. This necessitates toggling this byte
to indicate no such accompanying memo file. Or, you may just want to write
your own data access routine.<P>
Below are the file structures for dBASE table files. Represented are the
file structures as used for various versions of dBASE: dBASE III PLUS 1.1,
dBASE IV 2.0, dBASE 5.0 for DOS, and dBASE 5.0 for Windows.<P>
<H2>The data file header structure for dBASE III PLUS table file.</H2>
<TABLE BORDER=1 ALIGN="CENTER">
<CAPTION><STRONG>The table file header</STRONG></CAPTION>
<TR>
<TH>Byte</TH>
<TH>Contents</TH>
<TH>Description</TH>
</TR>
<TR><TD>0</TD><TD>1 byte</TD><TD> Valid dBASE III PLUS table file (03h without a memo
(.DBT file;) 83h with a memo).<TD>
</TR>
<TR><TD>1-3 </TD><TD> 3 bytes </TD><TD> Date of last update; in YYMMDD format.</TD>
</TR>
<TR><TD>4-7 </TD><TD> 32-bit number</TD><TD> Number of records in the table.
</TD>
</TR>
<TR><TD>8-9 </TD><TD> 16-bit number </TD><TD> Number of bytes in the header.
</TD>
</TR>
<TR><TD>10-11</TD><TD> 16-bit number</TD><TD> Number of bytes in the record.
</TD>
</TR>
<TR><TD>12-14 </TD><TD>3 bytes </TD><TD> Reserved bytes.</TD>
</TR>
<TR><TD>15-27 </TD><TD>13 bytes </TD><TD> Reserved for dBASE III PLUS on a LAN.</TD>
</TR>
<TR><TD>28-31</TD><TD> 4 bytes </TD><TD> Reserved bytes.</TD>
</TR>
<TR><TD>32-n </TD><TD> 32 bytes </TD><TD> Field descriptor array (the structure of this array is
each shown below)</TD>
</TR>
<TR><TD>n+1 </TD><TD> 1 byte </TD><TD> 0Dh stored as the field terminator.</TD>
</TR>
</TABLE>
n above is the last byte in the field descriptor array. The size of the
array depends on the number of fields in the table file.<P>
<H2>Table Field Descriptor Bytes</H2>
<TABLE BORDER=1 ALIGN="CENTER">
<TR>
<TH>Byte</TH>
<TH>Contents</TH>
<TH>Description</TH>
</TR>
<TR><TD>0-10 </TD><TD> 11 bytes </TD><TD> Field name in ASCII (zero-filled).</TD>
</TR>
<TR><TD>11 </TD><TD> 1 byte </TD><TD> Field type in ASCII (C, D, L, M, or N).</TD>
</TR>
<TR><TD>12-15</TD><TD> 4 bytes </TD><TD> Field data address (address is set in memory; not useful
on disk).</TD>
</TR>
<TR><TD>16 </TD><TD> 1 byte </TD><TD> Field length in binary.</TD>
</TR>
<TR><TD>17 </TD><TD> 1 byte </TD><TD> Field decimal count in binary.</TD>
</TR>
<TR><TD>18-19</TD><TD> 2 bytes </TD><TD> Reserved for dBASE III PLUS on a LAN.</TD>
</TR>
<TR><TD>20 </TD><TD> 1 byte </TD><TD> Work area ID.</TD>
</TR>
<TR><TD>21-22 </TD><TD>2 bytes </TD><TD> Reserved for dBASE III PLUS on a LAN.</TD>
</TR>
<TR><TD>23 </TD><TD> 1 byte </TD><TD> SET FIELDS flag.</TD>
</TR>
<TR><TD>24-31</TD><TD> 1 byte </TD><TD> Reserved bytes.</TD>
</TR>
</TABLE>
<H2>Table Records</H2>
The records follow the header in the table file. Data records are preceded
by one byte, that is, a space (20h) if the record is not deleted, an
asterisk (2Ah) if the record is deleted. Fields are packed into records
without field separators orrecord terminators. The end of the file is
marked by a single byte, with the end-of-file marker, an OEM code page
character value of 26 (1Ah). You can input OEM code page data as indicated
below. <P>
<H2>Allowable Input for dBASE Data Types</H2>
<TABLE BORDER=1 ALIGN="CENTER">
<TR>
<TH>Data Type</TH> <TH>Data Input</TH>
</TR>
<TR>
<TD>C (Character) </TD><TD>All OEM code page characters.</TD>
</TR>
<TR>
<TD>D (Date) </TD><TD> Numbers and a character to separate month, day, and year
(stored internally as 8 digits in YYYYMMDD format).</TD>
</TR>
<TR>
<TD>N (Numeric) </TD><TD>- . 0 1 2 3 4 5 6 7 8 9</TD>
</TR>
<TR>
<TD>L (Logical) </TD><TD> ? Y y N n T t F f (? when not initialized).</TD>
</TR>
<TR>
<TD>M (Memo) </TD><TD> All OEM code page characters (stored internally as 10
digits representing a .DBT block number).</TD>
</TR>
</TABLE>
<H2>Binary, Memo, and OLE Fields And .DBT Files</H2>
Memo fields store data in .DBT files consisting of blocks numbered
sequentially (0, 1, 2, and so on). The size of these blocks are internally
set to 512 bytes. The first block in the .DBT file, block 0, is the .DBT
file header.<P>
Memo field of each record in the .DBF file contains the number of the
block (in OEM code page values) where the field's data actually begins. If
a field contains no data, the .DBF file contains blanks (20h) rather than
a number.<P>
When data is changed in a field, the block numbers may also change and the
number in the .DBF may be changed to reflect the new location.<P>
This information is from the Using dBASE III PLUS manual, Appendix C.<P>
<H2>The data file header structure for dBASE IV 2.0 table file.</H2>
<TABLE BORDER=1 ALIGN="CENTER">
<CAPTION><STRONG>File Structure</STRONG></CAPTION>
<TR>
<TH>Byte</TH>
<TH>Contents</TH>
<TH>Description</TH>
</TR>
<TR>
<TD>0</TD><TD> 1byte </TD><TD> Valid dBASE IV file; bits 0-2 indicate version
number, bit 3 the presence of a dBASE IV memo
file, bits 4-6 the presence of an SQL table, bit
7 the presence of any memo file (either dBASE III
PLUS or dBASE IV).</TD>
</TR>
<TR>
<TD>1-3 </TD><TD> 3 bytes </TD><TD> Date of last update; formattted as YYMMDD.</TD>
</TR>
<TR>
<TD>4-7 </TD><TD> 32-bit number </TD><TD> Number of records in the file.</TD>
</TR>
<TR>
<TD>8-9 </TD><TD> 16-bit number</TD><TD> Number of bytes in the header.</TD>
</TR>
<TR>
<TD>10-11 </TD><TD> 16-bit number </TD><TD> Number of bytes in the record.</TD>
</TR>
<TR>
<TD>12-13 </TD><TD> 2 bytes </TD><TD> Reserved; fill with 0.</TD>
</TR>
<TR>
<TD>14 </TD><TD> 1 byte </TD><TD> Flag indicating incomplete transaction.</TD>
</TR>
<TR>
<TD>15 </TD><TD> 1 byte </TD><TD> Encryption flag.</TD>
</TR>
<TR>
<TD>16-27 </TD><TD> 12 bytes </TD><TD> Reserved for dBASE IV in a multi-user environment.</TD>
</TR>
<TR>
<TD>28 </TD><TD> 1 bytes </TD><TD> Production MDX file flag; 01H if there is an MDX,
00H if not.</TD>
</TR>
<TR>
<TD>29 </TD><TD> 1 byte </TD><TD> Language driver ID.</TD>
</TR>
<TR>
<TD>30-31 </TD><TD> 2 bytes </TD><TD> Reserved; fill with 0.</TD>
</TR>
<TR>
<TD>32-n* </TD><TD> 32 bytes each </TD><TD>Field descriptor array (see below).</TD>
</TR>
<TR>
<TD>n + 1 </TD><TD> 1 byte </TD><TD> 0DH as the field terminator.</TD>
</TR>
</TABLE>
* n is the last byte in the field descriptor array. The size of the array
depends on the number of fields in the database file.<P>
<TABLE BORDER=1 ALIGN="CENTER">
<CAPTION><STRONG>Field Descriptor Array</STRONG></CAPTION>
<TR>
<TH>Byte</TH>
<TH>Contents</TH>
<TH>Description</TH>
</TR>
<TR>
<TD>0-10 </TD><TD> 11 bytes </TD><TD> Field name in ASCII (zero-filled).</TD>
</TR>
<TR>
<TD>11 </TD><TD> 1 byte </TD><TD> Field type in ASCII (C, D, F, L, M, or N).</TD>
</TR>
<TR>
<TD>12-15 </TD><TD> 4 bytes </TD><TD> Reserved.</TD>
</TR>
<TR>
<TD>16 </TD><TD> 1 byte </TD><TD> Field length in binary.</TD>
</TR>
<TR>
<TD>17 </TD><TD> 1 byte </TD><TD> Field decimal count in binary.</TD>
</TR>
<TR>
<TD>18-19 </TD><TD> 2 bytes </TD><TD> Reserved.</TD>
</TR>
<TR>
<TD>20 </TD><TD> 1 byte </TD><TD> Work area ID.</TD>
</TR>
<TR>
<TD>21-30 </TD><TD> 10 bytes </TD><TD> Reserved.</TD>
</TR>
<TR>
<TD>31 </TD><TD> 1 byte </TD><TD> Production MDX field flag; 01H if field has an
index tag in the production MDX file, 00H if not.</TD>
</TR>
</TABLE>
<H2>Database records:</H2>
The records follow the header in the database file. Data records are
preceded by one byte; that is, a space (20H) if the record is not deleted,
an asterisk (2AH) if the record is deleted. Fields are packed into
records without field separators or record terminators. The end of the
file is marked by a single byte, with the end-of-file marker an ASCII 26
(1AH) character.<P>
<PRE>
<U>Allowable Input for dBASE Data Types:</U>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -