-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.c
257 lines (241 loc) · 10.2 KB
/
setup.c
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#include "driver.h"
#if defined(__IODBC__)
# include <iodbcinst.h>
#else
# include <odbcinst.h>
#endif
#ifndef INSTAPI
#define INSTAPI
#endif
BOOL INSTAPI ConfigDriver(HWND hwnd,
WORD fRequest,
LPCSTR lpszDriver,
LPCSTR lpszArgs,
LPSTR lpszMsg,
WORD cbMsgMax,
WORD *pcbMsgOut)
{
if (fRequest != ODBC_INSTALL_DRIVER)
return FALSE;
if (lpszDriver == NULL)
return FALSE;
if (!SQLWritePrivateProfileString(lpszDriver, "APILevel", "1", ODBCINST_INI))
return FALSE;
if (!SQLWritePrivateProfileString(lpszDriver, "ConnectFunctions", "YYN", ODBCINST_INI))
return FALSE;
if (!SQLWritePrivateProfileString(lpszDriver, "FileUsage", "0", ODBCINST_INI))
return FALSE;
if (!SQLWritePrivateProfileString(lpszDriver, "SQLLevel", "1", ODBCINST_INI))
return FALSE;
if (!SQLWritePrivateProfileString(lpszDriver, "DriverODBCVer", DRVODBCVER, ODBCINST_INI))
return FALSE;
return SQL_TRUE;
}
BOOL INSTAPI ConfigDSN(
HWND hwnd,
WORD fRequest,
LPCSTR lpszDriver,
LPCSTR lpszAttributes)
{
char *dsn, *db, *cluster, **dst;
const char *pos, *kv;
dsn = db = cluster = NULL;
dst = NULL;
if (lpszDriver == NULL)
return FALSE;
for (pos = lpszAttributes; *pos; ++pos) {
dst = NULL;
kv = pos;
for ( ; ; ++pos) {
if (*pos == '\0')
return FALSE;
else if (*pos == '=')
break;
}
if (strncasecmp("dsn", kv, 3) == 0)
dst = &dsn;
else if (strncasecmp("database", kv, 8) == 0)
dst = &db;
else if (strncasecmp("cluster", kv, 7) == 0)
dst = &cluster;
/* Skip values */
kv = ++pos;
for (; *pos != '\0'; ++pos) { /* blank */ };
if (dst != NULL)
*dst = strdup(kv);
}
switch (fRequest) {
case ODBC_ADD_DSN:
case ODBC_CONFIG_DSN:
if (dsn == NULL || db == NULL || cluster == NULL) {
if (hwnd != NULL) {
MessageBox(hwnd,
"Please use odbcconf.exe to configure DSN",
"Unsupported GUI feature",
MB_ICONEXCLAMATION | MB_OK);
}
return FALSE;
}
if (!SQLWriteDSNToIni(dsn, lpszDriver))
return FALSE;
if (!SQLWritePrivateProfileString(dsn, "DATABASE", db, ODBC_INI))
return FALSE;
if (!SQLWritePrivateProfileString(dsn, "CLUSTER", cluster, ODBC_INI))
return FALSE;
free(dsn);
free(db);
free(cluster);
return SQL_TRUE;
case ODBC_REMOVE_DSN:
if (dsn == NULL)
return FALSE;
return SQLRemoveDSNFromIni(dsn);
}
return FALSE;
}
#define SQL_FUNC_SET(arr, id) \
(*(((SQLSMALLINT*)(arr)) + ((id) >> 4)) |= (1 << ((id) & 0x000F)))
SQLRETURN SQL_API SQLGetFunctions(
HDBC hdbc,
SQLUSMALLINT func,
SQLUSMALLINT *supported)
{
(void)hdbc;
__debug("enters method.");
if (func == SQL_API_ODBC3_ALL_FUNCTIONS) {
//memset(supported, 0x00, sizeof(SQLSMALLINT) * SQL_API_ODBC3_ALL_FUNCTIONS_SIZE);
SQL_FUNC_SET(supported, SQL_API_SQLBINDCOL);
SQL_FUNC_SET(supported, SQL_API_SQLCOLATTRIBUTE);
SQL_FUNC_SET(supported, SQL_API_SQLCONNECT);
SQL_FUNC_SET(supported, SQL_API_SQLDESCRIBECOL);
SQL_FUNC_SET(supported, SQL_API_SQLDISCONNECT);
SQL_FUNC_SET(supported, SQL_API_SQLEXECDIRECT);
SQL_FUNC_SET(supported, SQL_API_SQLEXECUTE);
SQL_FUNC_SET(supported, SQL_API_SQLFETCH);
SQL_FUNC_SET(supported, SQL_API_SQLFREECONNECT);
SQL_FUNC_SET(supported, SQL_API_SQLFREEENV);
SQL_FUNC_SET(supported, SQL_API_SQLFREESTMT);
SQL_FUNC_SET(supported, SQL_API_SQLNUMRESULTCOLS);
SQL_FUNC_SET(supported, SQL_API_SQLPREPARE);
SQL_FUNC_SET(supported, SQL_API_SQLROWCOUNT);
SQL_FUNC_SET(supported, SQL_API_SQLTRANSACT);
SQL_FUNC_SET(supported, SQL_API_SQLCOLUMNS);
SQL_FUNC_SET(supported, SQL_API_SQLDRIVERCONNECT);
SQL_FUNC_SET(supported, SQL_API_SQLGETDATA);
SQL_FUNC_SET(supported, SQL_API_SQLGETFUNCTIONS);
SQL_FUNC_SET(supported, SQL_API_SQLGETINFO);
SQL_FUNC_SET(supported, SQL_API_SQLGETSTMTOPTION);
SQL_FUNC_SET(supported, SQL_API_SQLGETTYPEINFO);
SQL_FUNC_SET(supported, SQL_API_SQLSETSTMTOPTION);
SQL_FUNC_SET(supported, SQL_API_SQLSPECIALCOLUMNS);
SQL_FUNC_SET(supported, SQL_API_SQLSTATISTICS);
SQL_FUNC_SET(supported, SQL_API_SQLTABLES);
SQL_FUNC_SET(supported, SQL_API_SQLCOLUMNPRIVILEGES);
SQL_FUNC_SET(supported, SQL_API_SQLFOREIGNKEYS);
SQL_FUNC_SET(supported, SQL_API_SQLMORERESULTS);
SQL_FUNC_SET(supported, SQL_API_SQLNUMPARAMS);
SQL_FUNC_SET(supported, SQL_API_SQLPRIMARYKEYS);
SQL_FUNC_SET(supported, SQL_API_SQLPROCEDURECOLUMNS);
SQL_FUNC_SET(supported, SQL_API_SQLPROCEDURES);
SQL_FUNC_SET(supported, SQL_API_SQLBINDPARAMETER);
SQL_FUNC_SET(supported, SQL_API_SQLALLOCHANDLE);
SQL_FUNC_SET(supported, SQL_API_SQLENDTRAN);
SQL_FUNC_SET(supported, SQL_API_SQLFREEHANDLE);
SQL_FUNC_SET(supported, SQL_API_SQLGETCONNECTATTR);
SQL_FUNC_SET(supported, SQL_API_SQLGETDIAGFIELD);
SQL_FUNC_SET(supported, SQL_API_SQLGETDIAGREC);
SQL_FUNC_SET(supported, SQL_API_SQLGETSTMTATTR);
SQL_FUNC_SET(supported, SQL_API_SQLSETCONNECTATTR);
SQL_FUNC_SET(supported, SQL_API_SQLSETDESCFIELD);
SQL_FUNC_SET(supported, SQL_API_SQLSETSTMTATTR);
} else if (func == SQL_API_ALL_FUNCTIONS) {
//memset(supported, 0, sizeof(SQLSMALLINT) * 100);
supported[SQL_API_SQLALLOCCONNECT] = SQL_TRUE;
supported[SQL_API_SQLALLOCENV] = SQL_TRUE;
supported[SQL_API_SQLALLOCSTMT] = SQL_TRUE;
supported[SQL_API_SQLBINDCOL] = SQL_TRUE;
supported[SQL_API_SQLCOLATTRIBUTES] = SQL_TRUE;
supported[SQL_API_SQLCONNECT] = SQL_TRUE;
supported[SQL_API_SQLDESCRIBECOL] = SQL_TRUE;
supported[SQL_API_SQLDISCONNECT] = SQL_TRUE;
supported[SQL_API_SQLEXECDIRECT] = SQL_TRUE;
supported[SQL_API_SQLEXECUTE] = SQL_TRUE;
supported[SQL_API_SQLFETCH] = SQL_TRUE;
supported[SQL_API_SQLFREECONNECT] = SQL_TRUE;
supported[SQL_API_SQLFREEENV] = SQL_TRUE;
supported[SQL_API_SQLFREESTMT] = SQL_TRUE;
supported[SQL_API_SQLNUMRESULTCOLS] = SQL_TRUE;
supported[SQL_API_SQLPREPARE] = SQL_TRUE;
supported[SQL_API_SQLROWCOUNT] = SQL_TRUE;
supported[SQL_API_SQLTRANSACT] = SQL_TRUE;
supported[SQL_API_SQLBINDPARAMETER] = SQL_TRUE;
supported[SQL_API_SQLCOLUMNS] = SQL_TRUE;
supported[SQL_API_SQLDRIVERCONNECT] = SQL_TRUE;
supported[SQL_API_SQLGETDATA] = SQL_TRUE;
supported[SQL_API_SQLGETFUNCTIONS] = SQL_TRUE;
supported[SQL_API_SQLGETINFO] = SQL_TRUE;
supported[SQL_API_SQLGETSTMTOPTION] = SQL_TRUE;
supported[SQL_API_SQLGETTYPEINFO] = SQL_TRUE;
supported[SQL_API_SQLSETCONNECTOPTION] = SQL_TRUE;
supported[SQL_API_SQLSETSTMTOPTION] = SQL_TRUE;
supported[SQL_API_SQLSPECIALCOLUMNS] = SQL_TRUE;
supported[SQL_API_SQLSTATISTICS] = SQL_TRUE;
supported[SQL_API_SQLTABLES] = SQL_TRUE;
supported[SQL_API_SQLCOLUMNPRIVILEGES] = FALSE;
supported[SQL_API_SQLFOREIGNKEYS] = SQL_TRUE;
supported[SQL_API_SQLMORERESULTS] = SQL_TRUE;
supported[SQL_API_SQLNUMPARAMS] = SQL_TRUE;
supported[SQL_API_SQLPRIMARYKEYS] = SQL_TRUE;
supported[SQL_API_SQLPROCEDURECOLUMNS] = SQL_TRUE;
supported[SQL_API_SQLPROCEDURES] = SQL_TRUE;
supported[SQL_API_SQLTABLEPRIVILEGES] = SQL_TRUE;
} else {
switch (func) {
case SQL_API_SQLALLOCCONNECT:
case SQL_API_SQLALLOCENV:
case SQL_API_SQLALLOCSTMT:
case SQL_API_SQLBINDCOL:
case SQL_API_SQLCOLATTRIBUTES:
case SQL_API_SQLCONNECT:
case SQL_API_SQLDESCRIBECOL:
case SQL_API_SQLDISCONNECT:
case SQL_API_SQLEXECDIRECT:
case SQL_API_SQLEXECUTE:
case SQL_API_SQLFETCH:
case SQL_API_SQLFREECONNECT:
case SQL_API_SQLFREEENV:
case SQL_API_SQLFREESTMT:
case SQL_API_SQLNUMRESULTCOLS:
case SQL_API_SQLPREPARE:
case SQL_API_SQLROWCOUNT:
case SQL_API_SQLTRANSACT:
case SQL_API_SQLBINDPARAMETER:
case SQL_API_SQLCOLUMNS:
case SQL_API_SQLDRIVERCONNECT:
case SQL_API_SQLGETDATA:
case SQL_API_SQLGETFUNCTIONS:
case SQL_API_SQLGETINFO:
case SQL_API_SQLGETSTMTOPTION:
case SQL_API_SQLGETTYPEINFO:
case SQL_API_SQLSETCONNECTOPTION:
case SQL_API_SQLSETSTMTOPTION:
case SQL_API_SQLSPECIALCOLUMNS:
case SQL_API_SQLSTATISTICS:
case SQL_API_SQLTABLES:
case SQL_API_SQLCOLUMNPRIVILEGES:
case SQL_API_SQLFOREIGNKEYS:
case SQL_API_SQLMORERESULTS:
case SQL_API_SQLNUMPARAMS:
case SQL_API_SQLPRIMARYKEYS:
case SQL_API_SQLPROCEDURECOLUMNS:
case SQL_API_SQLPROCEDURES:
case SQL_API_SQLTABLEPRIVILEGES:
*supported = SQL_TRUE;
break;
default:
*supported = SQL_FALSE;
break;
}
}
return SQL_SUCCESS;
}