/*
 ******************************************************************************
 *  Copyright 1984-1993 United States Data Corporation. All Rights Reserved.
 ******************************************************************************
 *                                - NOTICE -
 *
 *  The information contained herein is confidential information of United
 *  States Data Corporation, a Delaware corporation, and is protected by
 *  United States copyright and trade secret law and international treaties.
 *  This information is not to be disclosed, used or copied by or transferred
 *  to any individual, corporation, company or other person without the
 *  express written permission of United States Data Corporation.
 ******************************************************************************
 *
 * Module:	HDT_DBMT.H
 *
 *	Header file for master table API.
 *
 * History:
 *		bjc 05/03/93	Created. 
 */


#ifndef _DBMT_INCLUDED
#define _DBMT_INCLUDED

#include <hdt_base.h>		/* Base Definitions for the API */
#include <hdt_dbs.h>
#include <hdt_dbt.h>
#include <hdt_srl.h>

/*
 ************************************************************************
 *                              Constants                               *       
 ************************************************************************
 */


/*
 ************************************************************************
 *                              Structures                              * 
 ************************************************************************
 */


/* 
 * DBMT - DataBase Master Table structure
 *
 * A database master table (DBMT) structure describes the schema of
 * an HDT master table.
 */

typedef struct
{
	char	*tblname;			/* table name */
	DBT	*master;			/* master table schema */
	DBTCOL	*id_col;			/* id column */
	DBTCOL	*name_col;			/* name column */
	short	persist;			/* DB cursor persistance */

	char	srl_tbl[SRLID_LEN_TBL+1];	/* serial table name */
} DBMT;


/*
 ************************************************************************
 *                              Macros                                  *       
 ************************************************************************
 */

#define dbmt_get_tblname(p)	((p)->tblname)
#define dbmt_get_tbldef(p)	((p)->master)
#define dbmt_get_id_col(p)	((p)->id_col)
#define dbmt_get_name_col(p)	((p)->name_col)

#define dbmt_get_srl_tbl(p)	((p)->srl_tbl)
#define dbmt_set_srl_tbl(p, t)	(strncpy((p)->srl_tbl, t, SRLID_LEN_TBL))

#define	dbmt_is_persist(p)	((p)->persist)
#define dbmt_set_persist(p, v)	((p)->persist = (v == 0) ? 0 : 1);


/*
 ************************************************************************
 *                         Function Prototypes                          * 
 ************************************************************************
 */

extern DBMT*	dbmt_create(char *tblname, DBT *dbt, 
		            char *id_fld, char *name_fld);
extern void	dbmt_destroy(DBMT *dbmt);
extern int	dbmt_init_sess(DBS *dbs, DBMT *dbmt);
extern long	dbmt_insert_name(DBS *dbs, DBMT *dbmt, char *name);
extern long	dbmt_fetch_id(DBS *dbs, DBMT *dbmt, char *value);
extern int	dbmt_fetch_name(DBS *dbs, DBMT *dbmt, long id, 
		                char *name, int len);
extern int	dbmt_zap(DBS *dbs, DBMT *dbmt);
extern int	dbmt_close_sess(DBS *dbs, DBMT *dbmt);

#endif

