#ifndef DIRDB_HBG
#define DIRDB_HBG

#include "dbsys.h"


#define DIR_TABLENR    2000
typedef struct {
  int _iSize;
  int iDB;
  int _iTablenr;
  PFNCMP _pfnCmpPk;
  PFNCMP _pfnCmpLk;
  TFLong	flDIR_Id;
  TFLong	flIVal;
} DIR;


typedef ARRAY MDIR;

#define MDIR_New()	(MDIR *) ARRAY_New()
MDIR * MDIR_Init(MDIR *mdir);
#define MDIR_Assign(p1,p2)	ARRAY_Assign((ARRAY*)p1,(ARRAY*)p2)
#define MDIR_Free(p)	ARRAY_Free((ARRAY*)p)
#define MDIR_Remove(p,i)	ARRAY_Remove((ARRAY*)p,i)
#define MDIR_Add(p,ps)	ARRAY_Add((ARRAY*)p,(void *)ps)
#define MDIR_SetDefault(p)	ARRAY_Free((ARRAY*)p)
#define MDIR_GetPtr(p,i)	((DIR*)ARRAY_GetPtr((ARRAY*)p,i))
#define MDIR_GetCount(p)	(((ARRAY*)p)->iCount)
#define MDIR_SetCmpFunc(p,pfn)	(p)->pfnCmp=(PFNCMP)pfn
#define MDIR_Sort(p)	ARRAY_Sort((ARRAY*)p)

extern int DIR_Sizeof(void);
extern DIR * DIR_New(void);
extern DIR * DIR_Init(DIR *dir);
#define DIR_Assign(p1,p2)    (*(DIR*)p1=*(DIR*)p2)
#define DIR_SetDefault(p1)    DIR_Init((DIR*)p1)
#define DIR_SetDB(p1, p2)    (p1)->iDB = p2
extern char * DIR_Definition(void);
extern int DIR_BFill(DIR *dir, DBresult *res, int row, int status, DBHANDLE *pbsc);
extern char * DIR_Attribs(void);
extern char * DIR_Data(DBHANDLE *pDBHANDLE, DIR *dir);
extern int DIR_IsValid(DBHANDLE *pDBHANDLE, DIR *dir);
extern char * DIR_TB_Attribs(int kz_db);
extern int DIR_SelectPk(DIR *dir, DBHANDLE *pbsc);
extern int DIR_SelectLk(DIR *dir, DBHANDLE *pbsc);
extern int DIR_Insert(DIR *dir, DBHANDLE *pbsc);
extern int DIR_Load(DIR *dir, DBHANDLE *pbsc);
extern int DIR_Update(DIR *dir, DBHANDLE *pbsc);
extern int DIR_Delete(DIR *dir, DBHANDLE *pbsc);
#define DIR_DeletePk(p1,p2)    DIR_Delete(p1,p2)
extern int DIR_DeleteAll(DBHANDLE *pbsc);
extern int DIR_Do(DIR *dir, DBHANDLE *pbsc);

extern int DIR_CopyPk(DIR *dir1, DIR *dir2);

extern int DIR_CmpPk(TFSurrogat pkey, DIR *dir2);
extern int DIR_CmpLk(DIR *dir1, DIR *dir2);

extern int DIR_Select_DIR_Id (DIR * dir, DBHANDLE * pDBHANDLE);

extern int DIR_Selectcount_Id_Max (DIR * dir, int * iCount, DBHANDLE * pDBHANDLE);

extern int DIR_Select_IVal (DIR * dir, DBHANDLE * pDBHANDLE);
extern int DIR_Fetch_IVal (DIR * dir, DBHANDLE * pDBHANDLE);

extern int DIR_Select_IVal_G (DIR * dir, DBHANDLE * pDBHANDLE);
extern int DIR_Fetch_IVal_G (DIR * dir, DBHANDLE * pDBHANDLE);

extern int DIR_Select_IVal_GE (DIR * dir, DBHANDLE * pDBHANDLE);
extern int DIR_Fetch_IVal_GE (DIR * dir, DBHANDLE * pDBHANDLE);

extern int DIR_Select_IVal_L (DIR * dir, DBHANDLE * pDBHANDLE);
extern int DIR_Fetch_IVal_L (DIR * dir, DBHANDLE * pDBHANDLE);

extern int DIR_Select_IVal_LE (DIR * dir, DBHANDLE * pDBHANDLE);
extern int DIR_Fetch_IVal_LE (DIR * dir, DBHANDLE * pDBHANDLE);

extern int DIR_Select_IVal_BETWEEN (DIR * dir, DBHANDLE * pDBHANDLE);
extern int DIR_Fetch_IVal_BETWEEN (DIR * dir, DBHANDLE * pDBHANDLE);

#endif
