154 lines
3.7 KiB
C++
154 lines
3.7 KiB
C++
//-----------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : DbfUtility.h
|
|
// = Version : ver2.0
|
|
// = Author : wlw
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: Dbf工具类的声明
|
|
// = Maintainers:
|
|
//
|
|
//-----------------------------------------------------------------------------+
|
|
/*
|
|
Copyright?2002, Alexey Dolgachov
|
|
mail: alxsoft@gazinter.net
|
|
web: http://www.alxsoft.narod.ru
|
|
*/
|
|
#ifndef _DBFUTILITY_H_
|
|
#define _DBFUTILITY_H_
|
|
|
|
#include "d4all.h"
|
|
|
|
#ifndef _TACSTRINGLIST_H_
|
|
#include "TACStringList.h"
|
|
#endif
|
|
|
|
#ifndef _TWCSTRINGLIST_H_
|
|
#include "TWCStringlist.h"
|
|
#endif
|
|
|
|
class DbfTable;
|
|
|
|
class GEOAPI FieldInfo : public FIELD4INFO
|
|
{
|
|
public:
|
|
FieldInfo(const TCHAR *n=NULL, int t=0, int l=0, int d=0);
|
|
FieldInfo(const FieldInfo &src);
|
|
~FieldInfo();
|
|
|
|
FieldInfo& operator= (const FieldInfo &src);
|
|
void InitClear();
|
|
int operator !();
|
|
|
|
static void ReleaseArray(FieldInfo *p);
|
|
};
|
|
|
|
class GEOAPI CodeBase : public CODE4
|
|
{
|
|
public:
|
|
CodeBase();
|
|
~CodeBase();
|
|
|
|
DbfTable *Open(const TCHAR *);
|
|
DbfTable *Create(const TCHAR *szFile, const FieldInfo *pFieldArray);
|
|
};
|
|
|
|
class GEOAPI FieldContent : public FIELD4
|
|
{
|
|
private:
|
|
static TCHAR szValue[256];
|
|
public:
|
|
FieldContent();
|
|
|
|
operator int () const;
|
|
operator float () const;
|
|
operator double () const;
|
|
operator const TCHAR * () const;
|
|
char GetFieldType() const;
|
|
|
|
FieldContent & operator = (int i);
|
|
FieldContent & operator = (double d);
|
|
FieldContent & operator = (const TCHAR *str);
|
|
|
|
int CompareTo(const FieldContent &otherOne) const;
|
|
#ifdef __AFXDISP_H__
|
|
COleVariant AsVariant() const;
|
|
FieldContent & operator = (const COleVariant &src);
|
|
#endif
|
|
};
|
|
|
|
#define CMP_SENSITIVE 0
|
|
#define CMP_INSENSITIVE 1
|
|
#define CMP_MATCH 2
|
|
|
|
class GEOAPI DbfTable : public DATA4
|
|
{
|
|
public:
|
|
DbfTable();
|
|
FieldInfo *GetFieldInfo(); // use u4free to free the result
|
|
int GetFieldNum();
|
|
FieldContent *GetFieldContent(const TCHAR *szFieldName);
|
|
FieldContent *GetFieldContent(int n);
|
|
|
|
void Close();
|
|
long GetRecordCount(int bSkipDeleted);
|
|
|
|
// Append operation
|
|
void AppendBegin();
|
|
void AppendEnd();
|
|
|
|
void Delete();
|
|
void Recall();
|
|
BOOL Pack();
|
|
|
|
// Iteration
|
|
BOOL MoveFirst(int bSkipDeleted=1);
|
|
BOOL MoveLast(int bSkipDeleted=1);
|
|
BOOL MoveNext(int bSkipDeleted=1);
|
|
BOOL MovePrev(int bSkipDeleted=1);
|
|
|
|
BOOL IsEOF();
|
|
BOOL IsBOF();
|
|
BOOL MoveTo(long nRecNo);
|
|
BOOL MoveTo(const TCHAR *szKey, const TCHAR *szValue, int nMethod=CMP_SENSITIVE, int bSkipDeleted=1);
|
|
BOOL MoveFirst(const TCHAR *szKey, const TCHAR *szValue, int nMethod=CMP_SENSITIVE, int bSkipDeleted=1);
|
|
BOOL MoveNext(const TCHAR *szKey, const TCHAR *szValue, int nMethod=CMP_SENSITIVE, int bSkipDeleted=1);
|
|
void Move(long offset, int bSkipDeleted=1);
|
|
long GetPosition();
|
|
|
|
BOOL IsDeleted();
|
|
BOOL operator !();
|
|
};
|
|
|
|
|
|
#define GET_FIELD(table, fname, fvalue) fvalue = (*((table)->GetFieldContent(fname)))
|
|
#define SET_FIELD(table, fname, fvalue) *((table)->GetFieldContent(fname))=fvalue
|
|
|
|
#define FLAG_READ 0
|
|
#define FLAG_WRITE 1
|
|
#define FLAG_APPEND 2
|
|
#define FLAG_DELETE 3
|
|
#define FLAG_PACK 4
|
|
|
|
struct GEOAPI DbfAccess
|
|
{
|
|
TCHAR dbfname[256]; // 数据库名称
|
|
int flag; // 读写标志
|
|
int keynum; // 关键字段数
|
|
char **keyFieldName; // 关键字的序号
|
|
char **keyinfo; // 关键字段的内容
|
|
int datanum; // 查询或更新的字段数
|
|
char **dataFieldName; // 数据字段的名称(1,2,...)
|
|
union
|
|
{
|
|
char *resFileName; // 数据字段的内容 read result
|
|
char **dataIn;
|
|
};
|
|
|
|
DbfAccess(const TCHAR *tabName, int isWrite, int kn, int dn);
|
|
~DbfAccess();
|
|
};
|
|
|
|
int GEOAPI DBFFUN(DbfAccess &kz);
|
|
int GEOAPI SqlExec(const TCHAR *sqlcmd, const TCHAR *quiryOut=NULL, TDPtrList<TCStringList> *res=NULL);
|
|
|
|
#endif |