dbf文件C、C++的操作库程序

上传人:仙*** 文档编号:32145740 上传时间:2021-10-13 格式:DOC 页数:48 大小:113KB
收藏 版权申诉 举报 下载
dbf文件C、C++的操作库程序_第1页
第1页 / 共48页
dbf文件C、C++的操作库程序_第2页
第2页 / 共48页
dbf文件C、C++的操作库程序_第3页
第3页 / 共48页
资源描述:

《dbf文件C、C++的操作库程序》由会员分享,可在线阅读,更多相关《dbf文件C、C++的操作库程序(48页珍藏版)》请在装配图网上搜索。

1、求:dbf文件C/C+的操作库程序。/*DBFOP for C+ V1.00 ,1995.1.10Develop by John,LiaoModified by Zhanghao. 1998.05.18This Module include the C+ headfile dbfop.hpp,and C+ resource file dbfop.cpp.This module is develop for use DBF(DBASEIII,DBASEII,MFOXBASE,FOXPRO 2.x)and IDX(MFOXBASE).but use IDX only allow read or c

2、hange the field thatisnt key word.Support netware share .flielock,fileunlock,recordlock,recordunlock.*/* -The class DBF is interface to custom,all function that givencan be invoked by use the class DBF.-1995.7.29 Change file option fxxx to xxx like _fsopen replace with sopen1995.7.31 Change dowith o

3、ption when type=N1995.7.31 Add option DBF:append(),DBF:clear();1998.5.18 Add Foxpro 2.x DBF process.-*/#include stdafx.h#ifdef DEBUG#define debugm AfxMessageBox#define new DEBUG_NEW#endifstatic INT2 ccc(CHAR *,INT2,INT2);INT2 ccc(CHAR * ptsr,INT2 len,INT2 bit) CHAR temp130,temp1130,i1; CHAR temp230,

4、temp2230,i2; INT2tempi,i; CHAR * ps,*ps1; for(ps1=ptsr;(*ps1= )&(*ps1!=x0);ps1+); ps=strchr(ps1,.); if(ps=NULL)/ NOT HAVE . strcpy(temp1,ps1); temp20=x0; else *ps=x0; strcpy(temp1,ps1); ps+; strcpy(temp2,ps); i1=len-(bit?(bit+1):0); if(int)strlen(temp1);(int)i1) strncpy(temp11,temp1,i1); temp11i1=x0

5、; else tempi=i1-strlen(temp1); for(i=0;i;0) if(int)strlen(temp2);(int)bit) strncpy(temp22,temp2,bit); temp22bit=x0; else i2=strlen(temp2); tempi=bit-strlen(temp2); strcpy(temp22,temp2); for(i=0;i;=(INT2)items-1) return -2; curp+; / double return 0;INT2 IDX_BLOCK:find(CHAR * key) INT2 compi=keylen; C

6、HAR *p=buff+12; INT2 RetCode,i; if(int)strlen(key)(int)keylen) compi=strlen(key); for(i=0,p=buff+12;i;=2) / .and. this is a leaf or leaf&root node curp=i; return 0; / Founded ,OK return to master else / .and. this is a frame or root node curp=i; return -10; / This is a ROOT,Maybe in gaven BLOCK if(R

7、etCode0) /if the key curent key in idx file if(flag;handle!=-1) close(handle); handle=-1; / open function open the idx fileINT2 IDX:pen(CHAR * filename) CHAR buff30; / fp=_fsopen(filename,rb,SH_DENYNONE); / change by liaoj int 1999.3.22 handle=sopen(filename,_O_RDONLY|_O_BINARY,_SH_DENYNO,_S_IREAD);

8、 /* handle=sopen(filename,O_RDWR|O_BINARY|O_DENYNONE, SH_DENYNONE,S_IREAD|S_I_write); */ / if(fp=NULL) return -1; if(handle=-1) return -1; if(_lseek(handle,0,SEEK_SET)!=0) return -1; if(read(handle,buff,30)!=30) return -1; rootpos=*(UINT4 *)buff; blocks=*(UINT4 *)(buff+; key_len=*(INT2 *)(buff+12);

9、block.SetKeyLen(key_len); block.ReadBlock(this-;handle,rootpos); while(block.GetFlag();handle,block.GetResult(); GoHome(); return 0;INT2 IDX:rev() UINT4 PrevBlock; if(block.Prev()!=0) PrevBlock=block.GetPrev(); if(PrevBlock=0xffffffffl) return -1; block.ReadBlock(this-;handle,(INT4)PrevBlock); block

10、.End(); return 0;INT2 IDX:Next() UINT4 NextBlock; if(block.Next()!=0)/ Is already in the last node in this block NextBlock=block.GetNext(); if(NextBlock=0xffffffffl) return -2; block.ReadBlock(this-;handle,(INT4)NextBlock); block.Home(); return 0;INT2 IDX:Find(CHAR * key) INT2 RetCode; block.ReadBlo

11、ck(this-;handle,rootpos); for(; RetCode=block.find(key); switch(RetCode) case 0: return 0; case -1: return -1; case -2: if(block.GetPrev()=(UINT4)0xffffffffl) return -1; else block.ReadBlock(this-;handle,block.GetPrev(); break; case -3: if(block.GetNext()=(UINT4)0xffffffffl) return -1; else block.Re

12、adBlock(this-;handle,block.GetNext(); break; case -10: block.ReadBlock(this-;handle,block.GetResult(); break; default: / - / Fatal Error : return code is not allow / in class IDX_BLOCK:find(CHAR * ); / - break; INT2 IDX:Skip() return Next();INT2IDX:GoHome() while(block.GetPrev()!=(UINT4)0xffffffffl)

13、 block.ReadBlock(this-;handle,block.GetPrev(); ; block.Home(); return 0;INT2 IDX:GoEnd() while(block.GetNext()!=(UINT4)0xffffffffl) block.ReadBlock(this-;handle,block.GetNext(); ; block.End(); return 0;UINT4 IDX_BLOCK:GetResult() CHAR tf5; CHAR * p=buff+12+curp*(keylen+4); p+=keylen; tf3=p0;tf2=p1;t

14、f1=p2;tf0=p3; return *(UINT4 * )tf;/INT2 IDX_BLOCK:ReadBlock(FILE * fp,UINT4 pos)INT2 IDX_BLOCK:ReadBlock(INT2 handle,UINT4 pos) / fseek(fp,pos,SEEK_SET); _lseek(handle,pos,SEEK_SET); / fread(buff,512l,1,fp); read(handle,buff,512); flag=buff0; count=buff1; items=buff2; prev=*(UINT4 *)(buff+4); next=

15、*(UINT4 *)(buff+; curp=0; return 0;/-Next is DBF -DBF:BF() Installed=0; First=NULL; pIDX=NULL; handle=-1; buff=NULL; / - SwapBuffer=NULL; MaxRecNum=0; CurRecNum=0; / - current_recno=record_no=0l; record_len=0; Name0=x0; changeflag=0; dbferrno=0; fieldvalue=NULL;DBF:DBF() if(First!=NULL) delete First

16、; First=NULL; if(SwapBuffer!=NULL) delete SwapBuffer; SwapBuffer=NULL; MaxRecNum=0; CurRecNum=0; if(pIDX!=NULL) delete First; pIDX=NULL; if(handle!=-1) / this :close(handle); handle=-1; if(buff!=NULL) delete buff; buff=NULL; if(fieldvalue!=NULL) delete fieldvalue; fieldvalue=NULL; return;INT2 DBF:Cl

17、ear() memset(buff, ,record_len); return 0;INT2 DBF:AppendBlank() CHAR tempbuf100; UINT4temp_recno; INT2 i; INT4 offset; /- if(!Installed)/ Not open this file dbferrno=ClassNotInit; sprintf(this-;dbferrmsg,ClassNotInit!; return ClassNotInit; if(_lseek(handle,0l,SEEK_SET)!=0) dbferrno=SeekFileError; s

18、printf(this-;dbferrmsg,SeekFileError!; return this-;dbferrno; if(read(handle,tempbuf,!= this-;dbferrno=ReadFileError; sprintf(this-;dbferrmsg,ReadFileError!; return this-;dbferrno; temp_recno=+(*(UINT4*)(tempbuf+4); if(_lseek(handle,0l,SEEK_SET)!=0) this-;dbferrno=SeekFileError; sprintf(this-;dbferr

19、msg,SeekFileError!; return dbferrno; if(_write(handle,tempbuf,!= this-;dbferrno=WriteFileError; sprintf(this-;dbferrmsg,WriteFileError!; return dbferrno; offset=(INT4)head_len+(temp_recno-1l)*record_len; _lseek(handle,offset,SEEK_SET); for(i=0;i;ReOpen(); this-;GoTo(temp_recno); return 0;INT2 DBF:Ap

20、pend() CHAR tempbuf100; UINT4temp_recno; INT4 offset; if(!Installed)/ Not open this file dbferrno=ClassNotInit; sprintf(this-;dbferrmsg,ClassNotInit!; return ClassNotInit; if(_lseek(handle,0l,SEEK_SET)!=0) dbferrno=SeekFileError; sprintf(this-;dbferrmsg,SeekFileError!; return SeekFileError; if(read(

21、handle,tempbuf,!= this-;dbferrno=ReadFileError; sprintf(this-;dbferrmsg,ReadFileError!; return dbferrno; temp_recno=+(*(UINT4*)(tempbuf+4);/ recordnum+1; if(_lseek(handle,0l,SEEK_SET)!=0) this-;dbferrno=SeekFileError; sprintf(this-;dbferrmsg,SeekFileError!); return dbferrno; if(_write(handle,tempbuf

22、,!= this-;dbferrno=WriteFileError; sprintf(this-;dbferrmsg,WriteFileError!); return dbferrno; offset=(INT4)head_len+(temp_recno-1l)*record_len; if(_lseek(handle,offset,SEEK_SET)!=offset) this-;dbferrno=SeekFileError; sprintf(this-;dbferrmsg,SeekFileError!); return dbferrno; _write(handle,buff,(UINT2

23、)record_len); _write(handle,x1a,1); this-;ReOpen(); this-;GoTo(temp_recno); return 0;INT2 DBF:dbf_wbuff() /CHAR tempbuf100; INT4 offset; offset=(INT4)head_len+(current_recno-1l)*record_len; if(current_recno;dbferrmsg,RecordOutOfRange!); return dbferrno; if(changeflag=0) dbferrno=DBFOK; sprintf(this-

24、;dbferrmsg,DBFOK!); return DBFOK; if(_lseek(handle,offset,SEEK_SET)!=offset) dbferrno=SeekFileError; sprintf(this-;dbferrmsg,SeekFileError!); return dbferrno; if(_write(handle,buff,(UINT2)record_len)!=(UINT2)record_len) dbferrno=WriteFileError; sprintf(this-;dbferrmsg,WriteFileError!); return dbferr

25、no; dbferrno=DBFOK; sprintf(this-;dbferrmsg,DBFOK!); return DBFOK;INT2 DBF:dbf_buff() INT4 offset=(INT4)head_len+(current_recno-1l)*record_len; if(current_recno;dbferrmsg,RecordOutOfRange!); return dbferrno; if(_lseek(handle,offset,SEEK_SET)!=offset) dbferrno=SeekFileError; sprintf(this-;dbferrmsg,S

26、eekFileError!); return dbferrno; if(:eof(handle) dbferrno=SeekFileError; sprintf(this-;dbferrmsg,SeekFileError!); return dbferrno; if(read(handle,buff,(UINT2)record_len)!=(UINT2)record_len) dbferrno=ReadFileError; sprintf(this-;dbferrmsg,ReadFileError!); return dbferrno; changeflag=0; dbferrno=0; sp

27、rintf(this-;dbferrmsg,DBFOK!); return 0;INT2 DBF:Zap() CHAR tempbuf100; if(!Installed)/ Not open this file dbferrno=ClassNotInit; sprintf(this-;dbferrmsg,ClassNotInit!); return dbferrno; _lseek(handle,0l,SEEK_SET); /if(fread(tempbuf,32l,1l,fp)!=1) if(read(handle,tempbuf,32)!=32) this-;Close(); dbfer

28、rno=NotDBFFile; sprintf(this-;dbferrmsg,NotDBFFile!); return dbferrno; *(UINT4 *)(tempbuf+4)=0l; / record_no if(chsize(handle,head_len)!=0) / - this-;dbferrno=ChsizeFileError; sprintf(this-;dbferrmsg,ChsizeFileError!); return dbferrno; _lseek(handle,0l,SEEK_SET); if(_write(handle,tempbuf,32)!=32) /t

29、his-;close(); this-;dbferrno=WriteFileError; sprintf(this-;dbferrmsg,WriteFileError!); return WriteFileError; _lseek(handle,0l,SEEK_END); _write(handle,x1ax0,2); MaxRecNum=0; CurRecNum=0; lock_flag=0; ReOpen(); dbferrno=DBFOK; sprintf(this-;dbferrmsg,DBFOK!); return this-;dbferrno;INT2 DBF:Open(CHAR

30、 * filename,INT2 OpenMode_Par,INT2 DBFType_Par) CHAR tempbuf100; INT2i,j,FieldOffset; struct FIELD * tpf; if(Installed) this-;Close(); strcpy(Name,filename); OpenMode=OpenMode_Par; DBFType=DBFType_Par; if(OpenMode=ReadWrite) handle=_sopen(Name,_O_RDWR|_O_BINARY,_SH_DENYNO,_S_IREAD|_S_IWRITE); else h

31、andle=_sopen(Name,_O_RDONLY|_O_BINARY,_SH_DENYNO,_S_IREAD); if(handle=-1) dbferrno=FileOpenFailure; sprintf(this-;dbferrmsg,FileOpenFailure!); return dbferrno; _lseek(handle,0l,SEEK_SET); if(read(handle,tempbuf,32)!=32) this-;Close(); dbferrno=ReadFileError; sprintf(this-;dbferrmsg,ReadFileError!);

32、return dbferrno; record_no=*(UINT4 *)(tempbuf+4); head_len=*(UINT2 *)(tempbuf+8); record_len=*(UINT2*)(tempbuf+10); fieldnum=(head_len)/32-1; / need automatic detect the dbf file type is foxbase or clipper if(DBFType=AutoDetect) if(head_len-1)%32=0) DBFType=Foxbase; else DBFType=Clipper; if(buff!=NU

33、LL) delete buff; buff=NULL; buff=(CHAR *) new CHARrecord_len+20; if(buff=NULL)#ifdef DEBUG debugm(DBF:Open alloc failure!);#endif this-;Close(); dbferrno=NotEnoughMemory; sprintf(this-;dbferrmsg,NotEnoughMemory!); return dbferrno; / memset strset Clear();/ add by liaoj 1996.12.24 if(record_no=0l) cu

34、rrent_recno=Empty; else current_recno=1; dbf_buff(); pFIELD=new FIELDfieldnum; if(pFIELD=NULL)#ifdef DEBUG debugm(DBF:pen alloc failure!);#endif this-;Close(); dbferrno=NotEnoughMemory; sprintf(this-;dbferrmsg,NotEnoughMemory!); return dbferrno; _lseek(handle,32l,SEEK_SET); tpf=&(pFIELD0); FieldOffs

35、et=1; for(i=0;i;name); / - Cliepper or Foxbase - if(DBFType=Foxbase) j=j;11?11:j; else j=7?7:j; tpf-;namej=0; for(j-;j;=0;j-) if(tpf-;namej= ) tpf-;namej=0; else break; if(DBFType=Clipper) tpf-;address=FieldOffset; FieldOffset+=tpf-;len; else tpf-;address=FieldOffset; FieldOffset+=tpf-;len; Installed=1; changeflag=0; dbferrno=DBFOK; sprintf(this-;dbferrmsg,DBFOK!); return 0;INT2 DBF:SetSwp(INT2 buffer_number) if (SwapBuffer!=NULL) delete SwapBuffer; CurRecNum=0; MaxRecNum=0; SwapBuffer=(CHAR *) new CHAR(record_len+1)*buffer_number; if (SwapBuffer=NULL)#i

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!