/*
**    Name: ODBC.h
**
**    Date: Thu Jan 17 13:03:19 2002
**
*/

#ifndef ODBC_H
#define ODBC_H

#include <stdlib.h>
#include "kernel.h"
#include "rmamem.h"
#include "ODBCLib.h"

extern ODBCLibQueryType odbcquerytype;

extern int odbcparameter_index;

_kernel_oserror *user_init(char *cmd_fail,int podule_base,void *pw);
_kernel_oserror *cmd_handler(char *arg_string,int argc,int cmd_no,void *pw);
void sc_handler(int service_number, _kernel_swi_regs *r,void *pw);
_kernel_oserror *user_final(int fatal,int podule,void *pw);
_kernel_oserror *swi_handler(int swi_no,int *r,void *pw);

/* Bound buffer kinds */

#define ODBC_BOUND_COLUMN 1
#define ODBC_BOUND_INPUT  2
#define ODBC_BOUND_OUTPUT 3
#define ODBC_BOUND_INOUT  4

/* free_bound_parameters selections */

#define ODBC_FREE_ALL     0
#define ODBC_FREE_COLUMNS 1
#define ODBC_FREE_PARAMS  2

/* RMA scratch for outputs whose length the driver does not take from the caller */

#define ODBC_SCRATCH_SIZE 32

/* Largest ColumnSize used to size an input parameter buffer */

#define ODBC_MAX_COLUMN_COPY 65536

#define ODBC_MAX_NEW_BOUND 2

typedef struct _ODBCBoundInfo {
    int kind;
    int number;
    int ctype;
    int bufferlength;
    int indicator;
    int indslot;
    int isindicator;
    int superseded;
} ODBCBoundInfo;

extern ODBCBoundInfo odbcboundinfo[ODBCLIBMAXBOUNDPARAMETERS];

extern int odbcparameter_copyback[ODBCLIBMAXPARAMETERS];

extern _kernel_oserror *odbcrequest_error;

extern int odbcnewbound[ODBC_MAX_NEW_BOUND];

extern int odbcnewbound_count;

extern _kernel_oserror odbcerror_memory;
extern _kernel_oserror odbcerror_parameters;
extern _kernel_oserror odbcerror_bound;
extern _kernel_oserror odbcerror_busy;
extern _kernel_oserror odbcerror_block;

void initialise_parameters(int type,int subtype);
void begin_request(void);
void request_error(_kernel_oserror *error);
int request_succeeded(void);
void store_parameter(int parameter,ODBCLibParameterType type,int size);
void store_output_parameter(int parameter,int size);
int store_bound_parameter(int stmt,int parameter,int size,ODBCBoundInfo *info);
int bound_parameter_kind(int iotype);
int bound_parameter_size(int kind,int ctype,int columnsize,int bufferlength,int indicator,int data);
int bound_data_at_exec(int indicator);
void supersede_bound_parameters(int stmt,int number,int kind);
void commit_bound_parameters(int stmt);
void fetch_parameter(int parameter,ODBCLibParameterType type,int size);
void free_parameters(void);
void free_bound_slot(int slot);
void free_bound_parameters(int stmt,int which);
void track_statement(int stmt,int dbc);
void free_connection_statements(int dbc);
void copy_bound_parameters(int stmt);
void copy_bound_inputs(int stmt);
void copy_bound_outputs(int stmt);
void copy_bound_input_slot(int slot);
int bound_capacity(int slot);
int data_size(int type,int size);

/*
#define rmamalloc(sz) rmadebugmalloc(__LINE__,__FILE__,sz)
#define rmafree(p) {rmadebugfree(__LINE__,__FILE__,p);p=NULL;}
#define rmacalloc(n,s) rmadebugcalloc(__LINE__,__FILE__,n,s)
#define rmarealloc(p,s) rmadebugrealloc(__LINE__,__FILE__,p,s)
*/

#endif
