1 /* File:			bind.h
2  *
3  * Description:		See "bind.c"
4  *
5  * Comments:		See "readme.txt" for copyright and license information.
6  *
7  */
8 
9 #ifndef __BIND_H__
10 #define __BIND_H__
11 
12 #include "psqlodbc.h"
13 #include "descriptor.h"
14 
15 /*
16  * BindInfoClass -- stores information about a bound column
17  */
18 struct BindInfoClass_
19 {
20 	SQLLEN	buflen;			/* size of buffer */
21 	char	*buffer;		/* pointer to the buffer */
22 	SQLLEN	*used;			/* used space in the buffer (for strings
23 					 * not counting the '\0') */
24 	SQLLEN	*indicator;		/* indicator == used in many cases ? */
25 	SQLSMALLINT	returntype;	/* kind of conversion to be applied when
26 					 * returning (SQL_C_DEFAULT,
27 					 * SQL_C_CHAR... etc) */
28 	SQLSMALLINT	precision;	/* the precision for numeric or timestamp type */
29 	SQLSMALLINT	scale;		/* the scale for numeric type */
30 	/* area for work variables */
31 	char	dummy_data;		/* currently not used */
32 };
33 
34 /* struct for SQLGetData */
35 typedef struct
36 {
37 	/* for BLOBs which don't hold the data */
38 	struct GetBlobDataClass {
39 		Int8	data_left64;	/* amount of large object data
40 					   left to read before conversion */
41 	} blob;
42 	/* for non-BLOBs which hold the data in ttlbuf after conversion */
43 	char	*ttlbuf;		/* to save the large result */
44 	SQLLEN	ttlbuflen;		/* the buffer length */
45 	SQLLEN	ttlbufused;		/* used length of the buffer */
46 	SQLLEN	data_left;		/* amount of data left to read */
47 }	GetDataClass;
48 #define GETDATA_RESET(gdc) ((gdc).blob.data_left64 = (gdc).data_left = -1)
49 
50 /*
51  * ParameterInfoClass -- stores information about a bound parameter
52  */
53 struct ParameterInfoClass_
54 {
55 	SQLLEN	buflen;
56 	char	*buffer;
57 	SQLLEN	*used;
58 	SQLLEN	*indicator;	/* indicator == used in many cases ? */
59 	SQLSMALLINT	CType;
60 	SQLSMALLINT	precision;	/* the precision for numeric or timestamp type */
61 	SQLSMALLINT	scale;		/* the scale for numeric type */
62 	/* area for work variables */
63 	char	data_at_exec;
64 };
65 
66 typedef struct
67 {
68 	SQLLEN	*EXEC_used;	/* amount of data */
69 	char	*EXEC_buffer; 	/* the data */
70 	OID	lobj_oid;
71 }	PutDataClass;
72 
73 /*
74  * ParameterImplClass -- stores implementation information about a parameter
75  */
76 struct ParameterImplClass_
77 {
78 	pgNAME		paramName;	/* this is unavailable even in 8.1 */
79 	SQLSMALLINT	paramType;
80 	SQLSMALLINT	SQLType;
81 	OID		PGType;
82 	SQLULEN		column_size;
83 	SQLSMALLINT	decimal_digits;
84 	SQLSMALLINT	precision;	/* the precision for numeric or timestamp type */
85 	SQLSMALLINT	scale;		/* the scale for numeric type */
86 };
87 
88 typedef struct
89 {
90 	GetDataClass	fdata;
91 	SQLSMALLINT	allocated;
92 	GetDataClass	*gdata;
93 }	GetDataInfo;
94 typedef struct
95 {
96 	SQLSMALLINT	allocated;
97 	PutDataClass	*pdata;
98 }	PutDataInfo;
99 
100 #define	PARSE_PARAM_CAST	FALSE
101 #define	EXEC_PARAM_CAST		TRUE
102 #define	SIMPLE_PARAM_CAST	TRUE
103 
104 #define CALC_BOOKMARK_ADDR(book, offset, bind_size, index) \
105 	(book->buffer + offset + \
106 	(bind_size > 0 ? bind_size : (SQL_C_VARBOOKMARK == book->returntype ? book->buflen : sizeof(UInt4))) * index)
107 
108 /* Macros to handle pgtype of parameters */
109 #define	PIC_get_pgtype(pari) ((pari).PGType)
110 #define	PIC_set_pgtype(pari, type) ((pari).PGType = (type))
111 #define	PIC_dsp_pgtype(conn, pari) ((pari).PGType ? (pari).PGType : sqltype_to_pgtype(conn, (pari).SQLType))
112 
113 void	extend_column_bindings(ARDFields *opts, int num_columns);
114 void	reset_a_column_binding(ARDFields *opts, int icol);
115 void	extend_parameter_bindings(APDFields *opts, int num_params);
116 void	extend_iparameter_bindings(IPDFields *opts, int num_params);
117 void	reset_a_parameter_binding(APDFields *opts, int ipar);
118 void	reset_a_iparameter_binding(IPDFields *opts, int ipar);
119 int	CountParameters(const StatementClass *stmt, Int2 *inCount, Int2 *ioCount, Int2 *outputCount);
120 void	GetDataInfoInitialize(GetDataInfo *gdata);
121 void	extend_getdata_info(GetDataInfo *gdata, int num_columns, BOOL shrink);
122 void	reset_a_getdata_info(GetDataInfo *gdata, int icol);
123 void	GDATA_unbind_cols(GetDataInfo *gdata, BOOL freeall);
124 void	PutDataInfoInitialize(PutDataInfo *pdata);
125 void	extend_putdata_info(PutDataInfo *pdata, int num_params, BOOL shrink);
126 void	reset_a_putdata_info(PutDataInfo *pdata, int ipar);
127 void	PDATA_free_params(PutDataInfo *pdata, char option);
128 void	SC_param_next(const StatementClass*, int *param_number, ParameterInfoClass **, ParameterImplClass **);
129 
130 RETCODE       prepareParameters(StatementClass *stmt, BOOL fake_params);
131 RETCODE       prepareParametersNoDesc(StatementClass *stmt, BOOL fake_params, BOOL param_cast);
132 int	decideHowToPrepare(StatementClass *stmt, BOOL force);
133 
134 #endif
135