#ifndef STOREDB_HBG
#define STOREDB_HBG

#include "dbsys.h"


#define STORE_TABLENR    1000
typedef struct {
  int _iSize;
  int iDB;
  int _iTablenr;
  PFNCMP _pfnCmpPk;
  PFNCMP _pfnCmpLk;
  TFSurrogat	fszSTORE_Id;
  TFChar_80	fszFilename;
  TFChar_160	fszDescription;
  TFLong	flSize;
  TFLogical	fcCompressed;
} STORE;


typedef ARRAY MSTORE;

#define MSTORE_New()	(MSTORE *) ARRAY_New()
MSTORE * MSTORE_Init(MSTORE *mstore);
#define MSTORE_Assign(p1,p2)	ARRAY_Assign((ARRAY*)p1,(ARRAY*)p2)
#define MSTORE_Free(p)	ARRAY_Free((ARRAY*)p)
#define MSTORE_Remove(p,i)	ARRAY_Remove((ARRAY*)p,i)
#define MSTORE_Add(p,ps)	ARRAY_Add((ARRAY*)p,(void *)ps)
#define MSTORE_SetDefault(p)	ARRAY_Free((ARRAY*)p)
#define MSTORE_GetPtr(p,i)	((STORE*)ARRAY_GetPtr((ARRAY*)p,i))
#define MSTORE_GetCount(p)	(((ARRAY*)p)->iCount)
#define MSTORE_SetCmpFunc(p,pfn)	(p)->pfnCmp=(PFNCMP)pfn
#define MSTORE_Sort(p)	ARRAY_Sort((ARRAY*)p)

extern int STORE_Sizeof(void);
extern STORE * STORE_New(void);
extern STORE * STORE_Init(STORE *store);
#define STORE_Assign(p1,p2)    (*(STORE*)p1=*(STORE*)p2)
#define STORE_SetDefault(p1)    STORE_Init((STORE*)p1)
#define STORE_SetDB(p1, p2)    (p1)->iDB = p2
extern char * STORE_Definition(void);
extern int STORE_BFill(STORE *store, DBresult *res, int row, int status, DBHANDLE *pbsc);
extern char * STORE_Attribs(void);
extern char * STORE_Data(DBHANDLE *pDBHANDLE, STORE *store);
extern int STORE_IsValid(DBHANDLE *pDBHANDLE, STORE *store);
extern char * STORE_TB_Attribs(int kz_db);
extern int STORE_SelectPk(STORE *store, DBHANDLE *pbsc);
extern int STORE_SelectLk(STORE *store, DBHANDLE *pbsc);
extern int STORE_Insert(STORE *store, DBHANDLE *pbsc);
extern int STORE_Load(STORE *store, DBHANDLE *pbsc);
extern int STORE_Update(STORE *store, DBHANDLE *pbsc);
extern int STORE_Delete(STORE *store, DBHANDLE *pbsc);
#define STORE_DeletePk(p1,p2)    STORE_Delete(p1,p2)
extern int STORE_DeleteAll(DBHANDLE *pbsc);
extern int STORE_Do(STORE *store, DBHANDLE *pbsc);

extern int STORE_CopyPk(STORE *store1, STORE *store2);

extern int STORE_CmpPk(TFSurrogat pkey, STORE *store2);
extern int STORE_CmpLk(STORE *store1, STORE *store2);

extern int STORE_Select(STORE *store, DBHANDLE *pbsc);
extern int STORE_Fetch(STORE *store, DBHANDLE *pbsc);

extern int STORE_Select_Search (STORE * store, DBHANDLE * pDBHANDLE);
extern int STORE_Fetch_Search (STORE * store, DBHANDLE * pDBHANDLE);

extern int STORE_Count (STORE * store, int * iCount, DBHANDLE * pDBHANDLE);


#define BLOBJ_TABLENR    100
typedef struct {
  int _iSize;
  int iDB;
  int _iTablenr;
  PFNCMP _pfnCmpPk;
  PFNCMP _pfnCmpLk;
  TFSurrogat	fszBLOBJ_Id;
  TFSurrogat	fszFK_Id;
  TFShort	fsFK_Table;
  TFShort	fsItemNumber;
  TFBinary	fszComprData;
  TFLogical	fcCompressed;
} BLOBJ;


typedef ARRAY MBLOBJ;

#define MBLOBJ_New()	(MBLOBJ *) ARRAY_New()
MBLOBJ * MBLOBJ_Init(MBLOBJ *mblobj);
#define MBLOBJ_Assign(p1,p2)	ARRAY_Assign((ARRAY*)p1,(ARRAY*)p2)
#define MBLOBJ_Free(p)	ARRAY_Free((ARRAY*)p)
#define MBLOBJ_Remove(p,i)	ARRAY_Remove((ARRAY*)p,i)
#define MBLOBJ_Add(p,ps)	ARRAY_Add((ARRAY*)p,(void *)ps)
#define MBLOBJ_SetDefault(p)	ARRAY_Free((ARRAY*)p)
#define MBLOBJ_GetPtr(p,i)	((BLOBJ*)ARRAY_GetPtr((ARRAY*)p,i))
#define MBLOBJ_GetCount(p)	(((ARRAY*)p)->iCount)
#define MBLOBJ_SetCmpFunc(p,pfn)	(p)->pfnCmp=(PFNCMP)pfn
#define MBLOBJ_Sort(p)	ARRAY_Sort((ARRAY*)p)

extern int BLOBJ_Sizeof(void);
extern BLOBJ * BLOBJ_New(void);
extern BLOBJ * BLOBJ_Init(BLOBJ *blobj);
#define BLOBJ_Assign(p1,p2)    (*(BLOBJ*)p1=*(BLOBJ*)p2)
#define BLOBJ_SetDefault(p1)    BLOBJ_Init((BLOBJ*)p1)
#define BLOBJ_SetDB(p1, p2)    (p1)->iDB = p2
extern char * BLOBJ_Definition(void);
extern int BLOBJ_BFill(BLOBJ *blobj, DBresult *res, int row, int status, DBHANDLE *pbsc);
extern char * BLOBJ_Attribs(void);
extern char * BLOBJ_Data(DBHANDLE *pDBHANDLE, BLOBJ *blobj);
extern int BLOBJ_IsValid(DBHANDLE *pDBHANDLE, BLOBJ *blobj);
extern char * BLOBJ_TB_Attribs(int kz_db);
extern int BLOBJ_SelectPk(BLOBJ *blobj, DBHANDLE *pbsc);
extern int BLOBJ_SelectLk(BLOBJ *blobj, DBHANDLE *pbsc);
extern int BLOBJ_Insert(BLOBJ *blobj, DBHANDLE *pbsc);
extern int BLOBJ_Load(BLOBJ *blobj, DBHANDLE *pbsc);
extern int BLOBJ_Update(BLOBJ *blobj, DBHANDLE *pbsc);
extern int BLOBJ_Delete(BLOBJ *blobj, DBHANDLE *pbsc);
#define BLOBJ_DeletePk(p1,p2)    BLOBJ_Delete(p1,p2)
extern int BLOBJ_DeleteAll(DBHANDLE *pbsc);
extern int BLOBJ_Do(BLOBJ *blobj, DBHANDLE *pbsc);

extern int BLOBJ_CopyPk(BLOBJ *blobj1, BLOBJ *blobj2);

extern int BLOBJ_CmpPk(TFSurrogat pkey, BLOBJ *blobj2);
extern int BLOBJ_CmpLk(BLOBJ *blobj1, BLOBJ *blobj2);

extern int BLOBJ_Select(BLOBJ *blobj, DBHANDLE *pbsc);
extern int BLOBJ_Fetch(BLOBJ *blobj, DBHANDLE *pbsc);

extern int BLOBJ_Select_FK (BLOBJ * blobj, DBHANDLE * pDBHANDLE);
extern int BLOBJ_Fetch_FK (BLOBJ * blobj, DBHANDLE * pDBHANDLE);

extern int BLOBJ_Count (BLOBJ * blobj, int * iCount, DBHANDLE * pDBHANDLE);

extern int BLOBJ_Delete_FK (BLOBJ * blobj, int * iCount, DBHANDLE * pDBHANDLE);


#define Blobj_Data_TABLENR    101
typedef struct {
  int _iSize;
  int iDB;
  int _iTablenr;
  PFNCMP _pfnCmpPk;
  PFNCMP _pfnCmpLk;
  TFBinary	fszBinData;
} Blobj_Data;


typedef ARRAY MBlobj_Data;

#define MBlobj_Data_New()	(MBlobj_Data *) ARRAY_New()
MBlobj_Data * MBlobj_Data_Init(MBlobj_Data *mblobj_data);
#define MBlobj_Data_Assign(p1,p2)	ARRAY_Assign((ARRAY*)p1,(ARRAY*)p2)
#define MBlobj_Data_Free(p)	ARRAY_Free((ARRAY*)p)
#define MBlobj_Data_Remove(p,i)	ARRAY_Remove((ARRAY*)p,i)
#define MBlobj_Data_Add(p,ps)	ARRAY_Add((ARRAY*)p,(void *)ps)
#define MBlobj_Data_SetDefault(p)	ARRAY_Free((ARRAY*)p)
#define MBlobj_Data_GetPtr(p,i)	((Blobj_Data*)ARRAY_GetPtr((ARRAY*)p,i))
#define MBlobj_Data_GetCount(p)	(((ARRAY*)p)->iCount)
#define MBlobj_Data_SetCmpFunc(p,pfn)	(p)->pfnCmp=(PFNCMP)pfn
#define MBlobj_Data_Sort(p)	ARRAY_Sort((ARRAY*)p)

extern int Blobj_Data_Sizeof(void);
extern Blobj_Data * Blobj_Data_New(void);
extern Blobj_Data * Blobj_Data_Init(Blobj_Data *blobj_data);
#define Blobj_Data_Assign(p1,p2)    (*(Blobj_Data*)p1=*(Blobj_Data*)p2)
#define Blobj_Data_SetDefault(p1)    Blobj_Data_Init((Blobj_Data*)p1)
#define Blobj_Data_SetDB(p1, p2)    (p1)->iDB = p2
extern char * Blobj_Data_Definition(void);
extern int Blobj_Data_BFill(Blobj_Data *blobj_data, DBresult *res, int row, int status, DBHANDLE *pbsc);
extern char * Blobj_Data_Attribs(void);
extern char * Blobj_Data_Data(DBHANDLE *pDBHANDLE, Blobj_Data *blobj_data);
extern int Blobj_Data_IsValid(DBHANDLE *pDBHANDLE, Blobj_Data *blobj_data);
extern char * Blobj_Data_TB_Attribs(int kz_db);
extern int Blobj_Data_SelectPk(Blobj_Data *blobj_data, DBHANDLE *pbsc);
extern int Blobj_Data_SelectLk(Blobj_Data *blobj_data, DBHANDLE *pbsc);
extern int Blobj_Data_CopyPk(Blobj_Data *blobj_data1, Blobj_Data *blobj_data2);

extern int Blobj_Data_CmpPk(TFSurrogat pkey, Blobj_Data *blobj_data2);
extern int Blobj_Data_CmpLk(Blobj_Data *blobj_data1, Blobj_Data *blobj_data2);

extern void Get_GRPs (_MGRP * pMGrp);

extern int GRP_Data_Save (DBHANDLE * pDBHANDLE, char * fn, char * kuerzel);

extern int GRP_Data_Load (DBHANDLE * pDBHANDLE, char * fn, char * kuerzel);

extern int GRP_Data_Delete (DBHANDLE * pDBHANDLE, char * kuerzel);

#endif
