-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert.h
96 lines (84 loc) · 3.38 KB
/
convert.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef _CONVERT_H_
#define _CONVERT_H_
#include "driver.h"
/* Return types of conversion functions. */
typedef enum {
CONV_UNKNOWN_CDB2_TYPE = -2
, CONV_UNSUPPORTED_C_TYPE = -1
, CONV_YEAH = 0
, CONV_BUF_OVERFLOW
, CONV_INVALID_BUFLEN
, CONV_TRUNCATED
, CONV_TRUNCATED_WHOLE
, CONV_UNKNOWN_C_TYPE
, CONV_IMPOSSIBLE
, CONV_MEM_FAIL
, CONV_NULL
, CONV_INTERNAL_ERR
, CONV_OOPS
} conv_resp;
/* ============ Convert CDB2API types to native types. ============= */
#define CDB2_CONV(type) convert_cdb2 ## type
#define CDB2_CONV_PROTO(type) conv_resp CDB2_CONV(type) (const void *, int, SQLSMALLINT, SQLPOINTER, SQLLEN, SQLLEN *)
/* Convert cdb2 types to c data types.
Internal usage to convert (void *) values retrieved using CDB2API. */
CDB2_CONV_PROTO(int);
CDB2_CONV_PROTO(real);
CDB2_CONV_PROTO(cstring);
CDB2_CONV_PROTO(blob);
CDB2_CONV_PROTO(datetime);
CDB2_CONV_PROTO(inym);
CDB2_CONV_PROTO(inds);
CDB2_CONV_PROTO(datetimeus);
CDB2_CONV_PROTO(indsus);
/* Function prototype of cdb2 convertors. */
typedef conv_resp (*cdb2_conv_func_t)(const void *, /* data retrieved */
int, /* length of @param1 */
SQLSMALLINT, /* c data type */
SQLPOINTER, /* buffer in which converted data will be returned */
SQLLEN, /* length of buffer */
SQLLEN * /* strlen_or_ind */);
/* This array maps cdb2 data type values to conversion functions.
The index may serve as a quick reference to its corresponding conversion function.
So if.. elseif.. or switch/case is no longer needed. */
const static cdb2_conv_func_t CDB2_CONVS[] = {
[CDB2_INTEGER] = CDB2_CONV(int)
,[CDB2_REAL] = CDB2_CONV(real)
,[CDB2_CSTRING] = CDB2_CONV(cstring)
,[CDB2_BLOB] = CDB2_CONV(blob)
,[CDB2_BLOB] = CDB2_CONV(blob) /* Placeholder for type 5. */
,[CDB2_DATETIME] = CDB2_CONV(datetime)
,[CDB2_INTERVALYM] = CDB2_CONV(inym)
,[CDB2_INTERVALDS] = CDB2_CONV(inds)
,[CDB2_DATETIMEUS] = CDB2_CONV(datetimeus)
,[CDB2_INTERVALDSUS] = CDB2_CONV(indsus)
};
const static int NUM_CDB2_CONVS = ALEN(CDB2_CONVS);
/* ============ Convert and bind native types using CDB2API. ============= */
struct param;
#define CDB2_BIND(type) convert_and_bind_ ## type
#define CDB2_BIND_PROTO(type) conv_resp CDB2_BIND(type) (cdb2_hndl_tp *, struct param *)
CDB2_BIND_PROTO(int);
CDB2_BIND_PROTO(real);
CDB2_BIND_PROTO(cstring);
CDB2_BIND_PROTO(blob);
CDB2_BIND_PROTO(datetime);
CDB2_BIND_PROTO(intv_ym);
CDB2_BIND_PROTO(intv_ds);
CDB2_BIND_PROTO(datetimeus);
CDB2_BIND_PROTO(intv_dsus);
typedef conv_resp (*cdb2_bind_func_t)(cdb2_hndl_tp *, /* CDB2 handle */
struct param *); /* Parameter to be processed */
const static cdb2_bind_func_t CDB2_BINDS[] = {
CDB2_BIND(int)
, CDB2_BIND(real)
, CDB2_BIND(cstring)
, CDB2_BIND(blob)
, CDB2_BIND(datetime)
, CDB2_BIND(intv_ym)
, CDB2_BIND(intv_ds)
, CDB2_BIND(datetimeus)
, CDB2_BIND(intv_dsus)
};
const static int NUM_CDB2_BINDS = ALEN(CDB2_BINDS);
#endif /* _CONVERT_H_ */