/*******************************************************************************
*        : OraLibs.h
* ес :
*          :
*        :
*        : 2018.07.13
*      :
*******************************************************************************/

#ifndef	__ORACLE_DEFINITIONS__
#define	__ORACLE_DEFINITIONS__

/******************************************************************************/
/* include files */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <limits.h>

#include <sqlda.h>
#include <sqlcpr.h>

#ifdef	__cplusplus
extern "C" {
#endif	/*__cplusplus*/

	/**************************************************************************/
	/* literal constants */

	#define	DB_ID						"ORATR"
	#define	DB_PASS						"ORATR"
	#define	DB_SERV						NULL

	#define	DB_MIN						(5)
	#define	DB_SEC						(5)
	#define	DB_CHECK					(10)

	#define	YMDHM_STR					"YYYYMMDDHH24MI"
	#define	YMDH_STR					"YYYYMMDDHH24"
	#define	YMD_STR						"YYYYMMDD"
	#define	YM_STR						"YYYYMM"

	#define	DEL_SQL						"DELETE FROM %s WHERE %s = %d"
	#define	CHK_SQL						"SELECT 1 FROM DUAL"

	#define	RT_OK						(0)
	#define	RT_ER						(-1)
	#define	RT_NO						(-2)

	#ifdef	BUFSIZ
		#undef	BUFSIZ
		#define	BUFSIZ					(1024)
	#endif	/* BUFSIZ */

	/* Maximum length of SQL statement */
	/*#define	MAXSZ_SQLSTATEMENT			(BUFSIZ * 8)*/
	#define	MAXSZ_SQLSTATEMENT			(65535) 

	/* Maximum number of SELECT items or BIND variables */
	#define	MAX_ITEMS					(50)

	/* Maximum length of the names of the SELECT items or INDICATOR variables */
	#define	MAX_VNAME_LEN				(30)
	#define	MAX_INAME_LEN				(50)

	#ifndef	NULL
		#define	NULL					(0)
	#endif	/* NULL */

	/**************************************************************************/
	/* type definitions */

	typedef struct {
		unsigned char	arr[BUFSIZ];
		int				len;
	} TYPE;

	typedef struct {
		TYPE			fd[MAX_ITEMS];
	} TYPE_ST;

	typedef struct {
		int				F;
		int				R;
		int				L[MAX_ITEMS];
	} FIELD_ST;

	/**************************************************************************/
	/* function proto-types */

	extern SQLDA *sqlald();
	extern void	sqlnul( /*_ unsigned short*, unsigned short*, int* _*/ );
	extern void	sqlglm( /*_ char*, size_t*, size_t* _*/ );
	extern void	sqlprc( /*_ unsigned int*, int*, int* _*/ );

	/**************************************************************************/
	/* variables */

	struct sqlca	sqlCA;

	extern SQLDA *selectDES;
	extern SQLDA *bindDES;
	
	extern char  gDBStr[64];
	extern int   gDBOpen;

#ifdef	__cplusplus
}
#endif	/*__cplusplus*/

#endif	/*__ORACLE_DEFINITIONS__*/
