/*
 ******************************************************************************
 *  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_DBE.H
 *
 *	Header file for misc. database utility functions.
 *
 * History:
 *		bjc 07/21/93	Created. 
 */


#ifndef _DBE_INCLUDED
#define _DBE_INCLUDED

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

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

#define DBE_LEN_ERRMSG		1023	/* maximum error message length */

/*
 *  Database API error codes:
 *
 *	When a database API function returns ERROR, the global variable
 *  	'Dbe_errno' is set to either one of the following negative error
 *	codes.  A corresponding error message is placed into global
 *	variable 'Dbe_errmsg'.
 */

#define DBE_GOOD	(0)		/* No error occurred */
#define DBE_ERROR	(-1)		/* General error indicator */

/*  
 *  HLIB Derived error codes
 */

#define DBE_MAXOPENS	(-HSMAXOPENS)	/* Too many open sessions */
#define DBE_MEMORY	(-HSMEMORY)	/* Memory error malloc failed */
#define DBE_CONNECT	(-HSCONNECT)	/* Failed to connect to historian */
#define DBE_PREPARE	(-HSPREPARE)	/* Failed to prepare stmtid */
#define DBE_STMTID	(-HSSTMTID)	/* Invalid stmtid return from hist */
#define DBE_ENDOFETCH	(-HSENDOFETCH)	/* Last row fetched, no more rows */
#define DBE_NOMATCH	(-HSNOMATCH)	/* Database alias unknown to hist */
#define DBE_IPCSEND	(-HSIPCSEND)	/* Cant send a message to historian */
#define DBE_IPCCREATE	(-HSIPCCREATE)	/* Cant create an IPC shared data */
#define DBE_IPCOPEN	(-HSIPCOPEN)	/* Cant open an IPC mailbox */
#define DBE_NOSPAWN	(-HSNOSPAWN)	/* Cant spawn a historian client */
#define DBE_NOTSUPPORTED (-HSNOTSUPPORTED) /* not supported by DBIV hist */
#define DBE_DBERROR	(-HSDBERROR)	/* Historian f() returned db error */
#define DBE_UNKNOWN	(-HSUNKNOWN)	/* Unknown function request */
#define DBE_DUPLICATE	(-HSDUPLICATE)	/* Tried to insert a duplicate row */
#define DBE_TBLEXISTS	(-HSTBLEXISTS)	/* Tried to existing table */
#define DBE_FLDEXISTS	(-HSFLDEXISTS)	/* Tried to add field that exists */
#define DBE_NOTABLE	(-HSNOTABLE)	/* Access table that doesn't exist. */
#define DBE_NOFIELD	(-HSNOFIELD)	/* Access field that doesn't exist */ 

/*  
 *  HADTLIB Derived error codes
 */

#define DBE_INTERNAL	(-HSMAXCODE)	/* inconsistency in operation */
#define DBE_BAD_FLDTYPE	(-HSMAXCODE-1)	/* invalid field type in table def */
#define DBE_MIS_FLDNUM	(-HSMAXCODE-2)	/* mismatched field counts */
#define DBE_NO_FIELD	(-HSMAXCODE-3)	/* missing field */
#define DBE_MIS_FLDTYPE	(-HSMAXCODE-4)	/* mismatched field type */
#define DBE_MIS_FLDSIZE	(-HSMAXCODE-5)	/* mismatched field size */
#define DBE_NOMEM	(-HSMAXCODE-6)	/* memory allocation failed */
#define DBE_DUP_CSR	(-HSMAXCODE-7)	/* attaching duplicate cursor */
#define DBE_NOPREP	(-HSMAXCODE-8)	/* executed unprepared cursor */
#define DBE_NOEXEC	(-HSMAXCODE-9)	/* fetched un-executed cursor */
#define DBE_NONAME4ID	(-HSMAXCODE-10)	/* no name exists for id value */
#define DBE_NOID4NAME	(-HSMAXCODE-11)	/* no id exists for name value */
#define DBE_Q2LONG	(-HSMAXCODE-12)	/* query string too long */
#define DBE_TBLDIFF	(-HSMAXCODE-13) /* Table in sess doesn't match DBT */
#define DBE_FH_RETVAL	(-HSMAXCODE-14) /* Bad ret val from fetch handler */
#define DBE_DATA_IN_TMP	(-HSMAXCODE-15) /* copy alter left data in tmp tbl */
#define DBE_DBCNOSESS	(-HSMAXCODE-16) /* cursor not tied to session */
#define DBE_DBC2SESS	(-HSMAXCODE-17) /* attempt dbc attach to two sess */
#define DBE_INVARG	(-HSMAXCODE-18) /* invalid arguments */

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

/*
 ************************************************************************
 *                            Global Variables                          * 
 ************************************************************************
 */

extern short	Dbe_status;			/* db error number */
extern long	Dbe_server;			/* db error from historian */
extern char	*Dbe_errmsg;			/* error text */

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

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

extern void	dbe_clear(void);
extern void	dbe_set(int ecode, char *emsg);
extern void	dbe_append(char *emsg);
extern void	dbe_prepend(char *emsg);
extern void	dbe_format_hserror(char *emsg);

#endif

