DBF文件格式

1.文件头(32字节)  
  0   文件类型    
  0x02FoxBASE    
  0x03FoxBASE+/dBASE   III   PLUS,无备注    
  0x30Visual   FoxPro    
  0x43dBASE   IV   SQL   表文件,无备注    
  0x63dBASE   IV   SQL   系统文件,无备注    
  0x83FoxBASE+/dBASE   III   PLUS,有备注    
  0x8BdBASE   IV   有备注    
  0xCBdBASE   IV   SQL   表文件,有备注    
  0xF5FoxPro   2.x(或更早版本)有备注    
  0xFBFoxBASE    
  1   -   3   最近一次更新的时间(YYMMDD)    
  4   -   7   文件中的记录数目    
  8   -   9   第一个数据记录的位置    
  10   -   11   每个数据记录的长度(包括删除标记)    
  12   -   27   保留    
  28   表的标记   0x01具有   .cdx   结构的文件    
  0x02文件包含备注。    
  0x04文件是数据库(.dbc)    
  29   代码页标记  
  30   -   31   保留,包含   0x00    
  32   -   n   字段子记录    
  字段的数目决定了字段子记录的数目。表中每个字段都对应一个字段子记录。    
  n+1   头记录终止符(0x0D),n+2   到   n+264   此范围内的   263   个字节包含后链信息(相关数据库   (.dbc)   的相对路径)。如果第一个字节为   0x00,则该文件不与数据库关联。因此数据库文件本身总是包含   0x00。  
   
  2.字段描述结构(32字节)  
   
  字节   说明   备注  
  0   -   10   字段名(最多   10   个字符   -若少于   10   则用空字符   (0x00)   填充)  
  11   字段类型    
  12   -   15   记录中该字段的偏移量    
  16   字段长度(以字节为单位)    
  17   小数位数    
  18   字段标记  
  0x01系统列(用户不可见)  
  0x02可存储   null   值的列    
  0x04二进制列(只适于字符型和备注型)  
  19   -   32   保留   

————————————————————————————

dbf文件头结构和字段类型描述结构用C语言表示如下:  
   
  struct   dbf_head    
   
  {   /*   DBF文件头结构   */  
  char   vers;   /*   版本标志*/  
  unsigned   char   yy,mm,dd;   /*   最后更新年、月、日   */  
  unsigned   long   no_recs;   /*   文件包含的总记录数   */  
  unsigned   short   head_len,rec_len;   /*   文件头长度,记录长度   */  
  char   reserved[20];   /*   保留   */  
  };  
  struct   field_element  
   
  {   /*   字段描述结构   */  
  char   field_name[11];   /*   字段名称   */  
  char   field_type;   /*   字段类型   */  
  unsigned   long   offset;   /*   偏移量   */  
  unsigned   char   field_length;   /*   字段长度   */  
  unsigned   char   field_decimal;   /*   浮点数整数部分长度   */  
  char   reserved1[2];   /*   保留   */  
  char   dbaseiv_id;   /*   dBASE   IV   work   area   id   */  
  char   reserved2[10];   /*  
  char   production_index;    
  };  
   
   
   
   
  //   参考2  
  dbf   file   structure  
  ~~~~~~~~~~~~~~~~~~  
   
  bytes   description  
  00         foxbase+,   foxpro,   dbaseiii+,   dbaseiv,   no   memo   -   0x03  
  foxbase+,   dbaseiii+   with   memo   -   0x83  
          foxpro   with   memo   -   0xf5  
          dbaseiv   with   memo   -   0x8b  
          dbaseiv   with   sql   table   -   0x8e  
   
  01-03   last   update,   format   yyyymmdd   **correction:   it   is   yymmdd**  
  04-07         number   of   records   in   file   (32-bit   number)  
  08-09         number   of   bytes   in   header   (16-bit   number)  
  10-11         number   of   bytes   in   record   (16-bit   number)  
  12-13         reserved,   fill   with   0x00  
  14         dbaseiv   flag,   incomplete   transaction  
  begin   transaction   sets   it   to   0x01  
          end   transaction   or   rollback   reset   it   to   0x00  
   
  15   encryption   flag,   encrypted   0x01   else   0x00  
  changing   the   flag   does   not   encrypt   or   decrypt   the   records  
   
  16-27   dbaseiv   multi-user   environment   use  
  28         production   index   exists   -   0x01   else   0x00  
  29         dbaseiv   language   driver   id  
  30-31   reserved   fill   with   0x00  
  32-n         field   descriptor   array  
  n+1         header   record   terminator   -   0x0d  
   
  field   descriptor   array   table  
  bytes   description  
  0-10   field   name   ascii   padded   with   0x00  
  11         field   type   identifier   (see   table)  
  12-15         displacement   of   field   in   record  
  16         field   length   in   bytes  
  17         field   decimal   places  
  18-19         reserved  
  20         dbaseiv   work   area   id  
  21-30         reserved  
  31           field   is   part   of   production   index   -   0x01   else   0x00  
   
  field   identifier   table  
  ascii   description  
  c   character  
  d   date,   format   yyyymmdd  
  f   floating   point  
  g   general   -   foxpro   addition  
  l   logical,   t:t,f:f,y:y,n:n,?-not   initialized  
  m   memo   (stored   as   10   digits   representing   the   dbt   block   number)  
  n   numeric  
  p   picture   -   foxpro   addition  
   
  note   all   dbf   field   records   begin   with   a   deleted   flag   field.  
  if   record   is   deleted   -   0x2a   (asterisk)   else   0x20   (space)  
  end   of   file   is   marked   with   0x1a   
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值