appds_h

/*
**    Copyright 1996, Universities Research Association.  All rights reserved.
*/
/******************************************************************************/
/* appds.h
**
**    This file contains the type and protoype definitions for the
**    public application data storage (APPDS) routines.
**
**    K. Yacoben
**
*/
/******************************************************************************/

#ifndef __APPDS_H__
#define __APPDS_H__

/******************************************************************************/
/* 
**    defined constants for APPDS routines
*/
/******************************************************************************/

#define    APPDS_TBL_NAME_LEN        26 /* max table name length in BYTES     */
#define    APPDS_DEFAULT_NAME_LEN    26 /* default name string length in BYTES*/
#define    APPDS_DATE_LEN            21 /* max # of char in a date string     */
#define    APPDS_DEFAULT_TO          60 /* default SQL timeout value          */

/*
** define user settable parameters
*/
#define    APPDS_READ_ONLY         0x01 /* set table Read Only                */
#define    APPDS_READ_WRITE        0x02 /* set table Read / Write             */
#define    APPDS_SEQ_ACCESS        0x04 /* set access mode Sequential         */
#define    APPDS_INDEX_ACCESS      0x08 /* set access mode Indexed            */
#define    APPDS_KEY_ACCESS        0x10 /* set access mode Keyed              */
#define    APPDS_OVERWRITE_ON      0x20 /* set Overwrite permit ON            */
#define    APPDS_OVERWRITE_OFF     0x40 /* set overwrite permit OFF           */

#define    APPDS_DEFAULT_SERVER    "ADBS"
#define    APPDS_DEFAULT_DB        "APPDB"

/*
** define access mode types 
**    APPDS_SEQ        sequential access    - INDEX 0
**    APPDS_INDX       index access         - INDEX 1
**    APPDS_KEY        keyed access         - INDEX 2
*/
typedef enum {APPDS_SEQ, APPDS_INDX, APPDS_KEY,APPDS_UNKNOWN_ACCESS_TYPE} 
        APPDS_ACCESS_TYPE;

/* 
** define read/write mode type 
**    APPDS_RO        read only     - INDEX 0
**    APPDS_RW        read write    - INDEX 1
*/
typedef enum {APPDS_RO, APPDS_RW} APPDS_RW_TYPE;

/* 
** define WRITE TYPE 
**    APPDS_ADD       add record(s)       - INDEX 0
**    APPDS_UPDATE    update record(s)    - INDEX 1
*/
typedef enum {APPDS_ADD, APPDS_UPDATE} APPDS_WRITE_TYPE;

		/* APPDS action type */

typedef enum {APPDS_READ,APPDS_WRITE,APPDS_DELETE,APPDS_UNKNOWN_ACTION_TYPE} 
        APPDS_ACTION_TYPE;



/******************************************************************************/
/* 
**    data structures for APPDS routines
*/
/******************************************************************************/

/*
**  Data structure that describes the database storage table(s)
*/
typedef struct APPDS_DATA_INFO
{
    int    data_type;      /* Data type of the data stored                   */
    int    data_len;       /* The length of the data stored,                 */
                            /* used for byte & character strings, otherwise 0 */
    int    elm_count;      /* Element count, used for arrays, otherwise 0    */
} __attribute__((packed)) /* Added by the PACKINATOR(tm) */ APPDS_DATA_INFO;

/*
**    Application Data Storage table information structure
*/
typedef struct APPDS_TABLE_INFO
{
    char    name[APPDS_TBL_NAME_LEN];   /* name of the table */
    char    lock_owner[APPDS_DEFAULT_NAME_LEN];    /* name of the table lock owner */
    short   lock;                       /* boolean table lock [ 0 | 1 ] */
    short   overwrite;                  /* boolean overwrite flag [ 0 | 1 ] */
    APPDS_ACCESS_TYPE   access_mode;    /* table default access mode */
    APPDS_RW_TYPE       rw_mode;        /* read/write mode */
    int    retry_wait;                 /* wait time, in seconds, between retries */
    int    max_records;                /* maximum records allowed */
    int    rec_size;                   /* size of a record in BYTES */
    int    element_cnt;                /* number of data elements */
    APPDS_DATA_INFO    *element_list;   /* link list of 1 or more data info structs */
} __attribute__((packed)) /* Added by the PACKINATOR(tm) */ APPDS_TABLE_INFO;

/*
** data storage table status structure
*/
typedef struct APPDS_TABLE_STATUS
{
    int    last_record_id;             /* record ID of the last record */
    int    record_count;               /* number of data record that contain data */
    char    last_access_date[APPDS_DATE_LEN];    /* last Read/Write Date */
    unsigned char    access_log_status; /* boolean value [0 | 1], ON or OFF */
} __attribute__((packed)) /* Added by the PACKINATOR(tm) */ APPDS_TABLE_STATUS;
	

/******************************************************************************/
/*
**    function prototypes for APPDS routines
*/
/******************************************************************************/

#ifdef __cplusplus
extern "C" {
#endif

int appds_read_record(char *tbl_name,
                       const int recs_requested,
                             void *select_key,
                             void *return_buff,
                             int *recs_returned,
                             char *error_text,
                       char *db_name,
                       char *db_server);

int appds_write_record(char              *tbl_name,
                              APPDS_WRITE_TYPE  write_type,
                        const int              recs_in_buff,
                              void              *input_buff,
                              void              *select_value,
                              char              *error_text,
                        char              *db_name,
                        char              *db_server);

int appds_delete_record(char *tbl_name,
                         void *select_list,
                         const int recs_req,
                               int *recs_del,
                               char *error_text,
                         char *db_name,
                         char *db_server);

int appds_free_table_cache(void);

int appds_set_inter_mode(char *tbl_name,
                          unsigned int options,
                                   char *error_text,
                          char *db_name,
                          char *db_server);

int appds_get_inter_mode(char             *tbl_name,
                                APPDS_TABLE_INFO *table_info,
                                char             *error_text,
                          char             *db_name,
                          char             *db_server);

int appds_get_table_status(char               *tbl_name,
                                  APPDS_TABLE_STATUS *status_ptr,
                                  char               *error_text,
                            char               *db_name,
                            char               *db_server);

int appds_key_match_count(char *tbl_name,
                                 void *key_value,
                                 int *match_count,
                                 char *error_text,
                           char *db_name,
                           char *db_server);

int appds_set_db_timeout(char *db_name,
                          char *db_server,
                          const int timeOut,
                                char *error_text);

int appds_get_db_timeout(char *db_name,
                          char *db_server,
                                int *timeOut,
                                char *error_text);

#ifdef __cplusplus
}
#endif

#endif