2
* Module: dlg_specific.c
4
* Description: This module contains any specific code for handling
5
* dialog boxes such as driver/datasource options. Both the
6
* ConfigDSN() and the SQLDriverConnect() functions use
7
* functions in this module. If you were to add a new option
8
* to any dialog box, you would most likely only have to change
9
* things in here rather than in 2 separate places as before.
15
* Comments: See "notice.txt" for copyright and license information.
18
/* Multibyte support Eiji Tokuya 2001-03-15 */
20
#include "dlg_specific.h"
24
#include "multibyte.h"
25
#include "pgapifunc.h"
37
extern GLOBAL_VALUES globals;
40
makeConnectString(char *connect_string, const ConnInfo *ci, UWORD len)
42
char got_dsn = (ci->dsn[0] != '\0');
43
char encoded_conn_settings[LARGE_REGISTRY_LEN];
45
/*BOOL abbrev = (len <= 400);*/
46
BOOL abbrev = (len < 1024);
48
/* fundamental info */
49
sprintf(connect_string, "%s=%s;DATABASE=%s;SERVER=%s;PORT=%s;UID=%s;PWD=%s",
50
got_dsn ? "DSN" : "DRIVER",
51
got_dsn ? ci->dsn : ci->drivername,
58
encode(ci->conn_settings, encoded_conn_settings);
61
hlen = strlen(connect_string);
63
sprintf(&connect_string[hlen],
64
";%s=%s;%s=%s;%s=%s;%s=%s;%s=%s;%s=%s;%s=%s;%s=%d;%s=%d;%s=%d;%s=%d;%s=%d;%s=%d;%s=%d;%s=%d;%s=%d;%s=%d;%s=%d;%s=%d;%s=%d;%s=%d;%s=%d;%s=%s;%s=%d;%s=%d;%s=%d;%s=%d;%s=%d;%s=%d;%s=%d",
76
ci->show_system_tables,
78
encoded_conn_settings,
80
ci->drivers.fetch_max,
82
ci->drivers.socket_buffersize,
84
ci->drivers.unknown_sizes,
86
ci->drivers.max_varchar_size,
87
INI_MAXLONGVARCHARSIZE,
88
ci->drivers.max_longvarchar_size,
94
ci->drivers.disable_optimizer,
98
ci->drivers.use_declarefetch,
99
INI_TEXTASLONGVARCHAR,
100
ci->drivers.text_as_longvarchar,
101
INI_UNKNOWNSASLONGVARCHAR,
102
ci->drivers.unknowns_as_longvarchar,
104
ci->drivers.bools_as_char,
107
INI_CANCELASFREESTMT,
108
ci->drivers.cancel_as_freestmt,
109
INI_EXTRASYSTABLEPREFIXES,
110
ci->drivers.extra_systable_prefixes,
113
INI_UPDATABLECURSORS,
115
INI_DISALLOWPREMATURE,
116
ci->disallow_premature,
121
INI_BYTEAASLONGVARBINARY,
122
ci->bytea_as_longvarbinary,
123
INI_USESERVERSIDEPREPARE,
124
ci->use_server_side_prepare,
125
INI_LOWERCASEIDENTIFIER,
126
ci->lower_case_identifier);
127
/* Abbrebiation is needed ? */
128
if (abbrev || strlen(connect_string) >= len)
130
unsigned long flag = 0;
131
if (ci->disallow_premature)
132
flag |= BIT_DISALLOWPREMATURE;
133
if (ci->allow_keyset)
134
flag |= BIT_UPDATABLECURSORS;
135
if (ci->lf_conversion)
136
flag |= BIT_LFCONVERSION;
137
if (ci->drivers.unique_index)
138
flag |= BIT_UNIQUEINDEX;
139
if (strncmp(ci->protocol, PG64, strlen(PG64)) == 0)
140
flag |= BIT_PROTOCOL_64;
141
else if (strncmp(ci->protocol, PG63, strlen(PG63)) == 0)
142
flag |= BIT_PROTOCOL_63;
143
switch (ci->drivers.unknown_sizes)
145
case UNKNOWNS_AS_DONTKNOW:
146
flag |= BIT_UNKNOWN_DONTKNOW;
148
case UNKNOWNS_AS_MAX:
149
flag |= BIT_UNKNOWN_ASMAX;
152
if (ci->drivers.disable_optimizer)
153
flag |= BIT_OPTIMIZER;
154
if (ci->drivers.ksqo)
156
if (ci->drivers.commlog)
158
if (ci->drivers.debug)
160
if (ci->drivers.parse)
162
if (ci->drivers.cancel_as_freestmt)
163
flag |= BIT_CANCELASFREESTMT;
164
if (ci->drivers.use_declarefetch)
165
flag |= BIT_USEDECLAREFETCH;
166
if (ci->onlyread[0] == '1')
167
flag |= BIT_READONLY;
168
if (ci->drivers.text_as_longvarchar)
169
flag |= BIT_TEXTASLONGVARCHAR;
170
if (ci->drivers.unknowns_as_longvarchar)
171
flag |= BIT_UNKNOWNSASLONGVARCHAR;
172
if (ci->drivers.bools_as_char)
173
flag |= BIT_BOOLSASCHAR;
174
if (ci->row_versioning[0] == '1')
175
flag |= BIT_ROWVERSIONING;
176
if (ci->show_system_tables[0] == '1')
177
flag |= BIT_SHOWSYSTEMTABLES;
178
if (ci->show_oid_column[0] == '1')
179
flag |= BIT_SHOWOIDCOLUMN;
180
if (ci->fake_oid_index[0] == '1')
181
flag |= BIT_FAKEOIDINDEX;
182
if (ci->true_is_minus1)
183
flag |= BIT_TRUEISMINUS1;
184
if (ci->bytea_as_longvarbinary)
185
flag |= BIT_BYTEAASLONGVARBINARY;
186
if (ci->use_server_side_prepare)
187
flag |= BIT_USESERVERSIDEPREPARE;
188
if (ci->lower_case_identifier)
189
flag |= BIT_LOWERCASEIDENTIFIER;
191
sprintf(&connect_string[hlen],
192
";A6=%s;A7=%d;A8=%d;B0=%d;B1=%d;%s=%d;C2=%s;CX=%02x%lx",
193
encoded_conn_settings,
194
ci->drivers.fetch_max,
195
ci->drivers.socket_buffersize,
196
ci->drivers.max_varchar_size,
197
ci->drivers.max_longvarchar_size,
200
ci->drivers.extra_systable_prefixes,
207
unfoldCXAttribute(ConnInfo *ci, const char *value)
212
if (strlen(value) < 2)
215
sscanf(value, "%lx", &flag);
220
memcpy(cnt, value, 2);
222
sscanf(cnt, "%x", &count);
223
sscanf(value + 2, "%lx", &flag);
225
ci->disallow_premature = (char)((flag & BIT_DISALLOWPREMATURE) != 0);
226
ci->allow_keyset = (char)((flag & BIT_UPDATABLECURSORS) != 0);
227
ci->lf_conversion = (char)((flag & BIT_LFCONVERSION) != 0);
230
ci->drivers.unique_index = (char)((flag & BIT_UNIQUEINDEX) != 0);
231
if ((flag & BIT_PROTOCOL_64) != 0)
232
strcpy(ci->protocol, PG64);
233
else if ((flag & BIT_PROTOCOL_63) != 0)
234
strcpy(ci->protocol, PG63);
236
strcpy(ci->protocol, PG62);
237
if ((flag & BIT_UNKNOWN_DONTKNOW) != 0)
238
ci->drivers.unknown_sizes = UNKNOWNS_AS_DONTKNOW;
239
else if ((flag & BIT_UNKNOWN_ASMAX) != 0)
240
ci->drivers.unknown_sizes = UNKNOWNS_AS_MAX;
242
ci->drivers.unknown_sizes = UNKNOWNS_AS_LONGEST;
243
ci->drivers.disable_optimizer = (char)((flag & BIT_OPTIMIZER) != 0);
244
ci->drivers.ksqo = (char)((flag & BIT_KSQO) != 0);
245
ci->drivers.commlog = (char)((flag & BIT_COMMLOG) != 0);
246
ci->drivers.debug = (char)((flag & BIT_DEBUG) != 0);
247
ci->drivers.parse = (char)((flag & BIT_PARSE) != 0);
248
ci->drivers.cancel_as_freestmt = (char)((flag & BIT_CANCELASFREESTMT) != 0);
249
ci->drivers.use_declarefetch = (char)((flag & BIT_USEDECLAREFETCH) != 0);
250
sprintf(ci->onlyread, "%d", (char)((flag & BIT_READONLY) != 0));
251
ci->drivers.text_as_longvarchar = (char)((flag & BIT_TEXTASLONGVARCHAR) !=0);
252
ci->drivers.unknowns_as_longvarchar = (char)((flag & BIT_UNKNOWNSASLONGVARCHAR) !=0);
253
ci->drivers.bools_as_char = (char)((flag & BIT_BOOLSASCHAR) != 0);
254
sprintf(ci->row_versioning, "%d", (char)((flag & BIT_ROWVERSIONING) != 0));
255
sprintf(ci->show_system_tables, "%d", (char)((flag & BIT_SHOWSYSTEMTABLES) != 0));
256
sprintf(ci->show_oid_column, "%d", (char)((flag & BIT_SHOWOIDCOLUMN) != 0));
257
sprintf(ci->fake_oid_index, "%d", (char)((flag & BIT_FAKEOIDINDEX) != 0));
258
ci->true_is_minus1 = (char)((flag & BIT_TRUEISMINUS1) != 0);
259
ci->bytea_as_longvarbinary = (char)((flag & BIT_BYTEAASLONGVARBINARY) != 0);
260
ci->use_server_side_prepare = (char)((flag & BIT_USESERVERSIDEPREPARE) != 0);
261
ci->lower_case_identifier = (char)((flag & BIT_LOWERCASEIDENTIFIER) != 0);
264
copyAttributes(ConnInfo *ci, const char *attribute, const char *value)
266
if (stricmp(attribute, "DSN") == 0)
267
strcpy(ci->dsn, value);
269
else if (stricmp(attribute, "driver") == 0)
270
strcpy(ci->drivername, value);
272
else if (stricmp(attribute, INI_DATABASE) == 0)
273
strcpy(ci->database, value);
275
else if (stricmp(attribute, INI_SERVER) == 0 || stricmp(attribute, "server") == 0)
276
strcpy(ci->server, value);
278
else if (stricmp(attribute, INI_USER) == 0 || stricmp(attribute, "uid") == 0)
279
strcpy(ci->username, value);
281
else if (stricmp(attribute, INI_PASSWORD) == 0 || stricmp(attribute, "pwd") == 0)
282
strcpy(ci->password, value);
284
else if (stricmp(attribute, INI_PORT) == 0)
285
strcpy(ci->port, value);
287
else if (stricmp(attribute, INI_READONLY) == 0 || stricmp(attribute, "A0") == 0)
288
strcpy(ci->onlyread, value);
290
else if (stricmp(attribute, INI_PROTOCOL) == 0 || stricmp(attribute, "A1") == 0)
291
strcpy(ci->protocol, value);
293
else if (stricmp(attribute, INI_SHOWOIDCOLUMN) == 0 || stricmp(attribute, "A3") == 0)
294
strcpy(ci->show_oid_column, value);
296
else if (stricmp(attribute, INI_FAKEOIDINDEX) == 0 || stricmp(attribute, "A2") == 0)
297
strcpy(ci->fake_oid_index, value);
299
else if (stricmp(attribute, INI_ROWVERSIONING) == 0 || stricmp(attribute, "A4") == 0)
300
strcpy(ci->row_versioning, value);
302
else if (stricmp(attribute, INI_SHOWSYSTEMTABLES) == 0 || stricmp(attribute, "A5") == 0)
303
strcpy(ci->show_system_tables, value);
305
else if (stricmp(attribute, INI_CONNSETTINGS) == 0 || stricmp(attribute, "A6") == 0)
307
decode(value, ci->conn_settings);
308
/* strcpy(ci->conn_settings, value); */
310
else if (stricmp(attribute, INI_DISALLOWPREMATURE) == 0 || stricmp(attribute, "C3") == 0)
311
ci->disallow_premature = atoi(value);
312
else if (stricmp(attribute, INI_UPDATABLECURSORS) == 0 || stricmp(attribute, "C4") == 0)
313
ci->allow_keyset = atoi(value);
314
else if (stricmp(attribute, INI_LFCONVERSION) == 0)
315
ci->lf_conversion = atoi(value);
316
else if (stricmp(attribute, INI_TRUEISMINUS1) == 0)
317
ci->true_is_minus1 = atoi(value);
318
else if (stricmp(attribute, INI_INT8AS) == 0)
319
ci->int8_as = atoi(value);
320
else if (stricmp(attribute, INI_BYTEAASLONGVARBINARY) == 0)
321
ci->bytea_as_longvarbinary = atoi(value);
322
else if (stricmp(attribute, INI_USESERVERSIDEPREPARE) == 0)
323
ci->use_server_side_prepare = atoi(value);
324
else if (stricmp(attribute, INI_LOWERCASEIDENTIFIER) == 0)
325
ci->lower_case_identifier = atoi(value);
326
else if (stricmp(attribute, "CX") == 0)
327
unfoldCXAttribute(ci, value);
329
mylog("copyAttributes: DSN='%s',server='%s',dbase='%s',user='%s',passwd='%s',port='%s',onlyread='%s',protocol='%s',conn_settings='%s',disallow_premature=%d)\n", ci->dsn, ci->server, ci->database, ci->username, ci->password ? "xxxxx" : "", ci->port, ci->onlyread, ci->protocol, ci->conn_settings, ci->disallow_premature);
333
copyCommonAttributes(ConnInfo *ci, const char *attribute, const char *value)
335
if (stricmp(attribute, INI_FETCH) == 0 || stricmp(attribute, "A7") == 0)
336
ci->drivers.fetch_max = atoi(value);
337
else if (stricmp(attribute, INI_SOCKET) == 0 || stricmp(attribute, "A8") == 0)
338
ci->drivers.socket_buffersize = atoi(value);
339
else if (stricmp(attribute, INI_DEBUG) == 0 || stricmp(attribute, "B2") == 0)
340
ci->drivers.debug = atoi(value);
341
else if (stricmp(attribute, INI_COMMLOG) == 0 || stricmp(attribute, "B3") == 0)
342
ci->drivers.commlog = atoi(value);
343
else if (stricmp(attribute, INI_OPTIMIZER) == 0 || stricmp(attribute, "B4") == 0)
344
ci->drivers.disable_optimizer = atoi(value);
345
else if (stricmp(attribute, INI_KSQO) == 0 || stricmp(attribute, "B5") == 0)
346
ci->drivers.ksqo = atoi(value);
349
* else if (stricmp(attribute, INI_UNIQUEINDEX) == 0 ||
350
* stricmp(attribute, "UIX") == 0) ci->drivers.unique_index =
353
else if (stricmp(attribute, INI_UNKNOWNSIZES) == 0 || stricmp(attribute, "A9") == 0)
354
ci->drivers.unknown_sizes = atoi(value);
355
else if (stricmp(attribute, INI_LIE) == 0)
356
ci->drivers.lie = atoi(value);
357
else if (stricmp(attribute, INI_PARSE) == 0 || stricmp(attribute, "C0") == 0)
358
ci->drivers.parse = atoi(value);
359
else if (stricmp(attribute, INI_CANCELASFREESTMT) == 0 || stricmp(attribute, "C1") == 0)
360
ci->drivers.cancel_as_freestmt = atoi(value);
361
else if (stricmp(attribute, INI_USEDECLAREFETCH) == 0 || stricmp(attribute, "B6") == 0)
362
ci->drivers.use_declarefetch = atoi(value);
363
else if (stricmp(attribute, INI_MAXVARCHARSIZE) == 0 || stricmp(attribute, "B0") == 0)
364
ci->drivers.max_varchar_size = atoi(value);
365
else if (stricmp(attribute, INI_MAXLONGVARCHARSIZE) == 0 || stricmp(attribute, "B1") == 0)
366
ci->drivers.max_longvarchar_size = atoi(value);
367
else if (stricmp(attribute, INI_TEXTASLONGVARCHAR) == 0 || stricmp(attribute, "B7") == 0)
368
ci->drivers.text_as_longvarchar = atoi(value);
369
else if (stricmp(attribute, INI_UNKNOWNSASLONGVARCHAR) == 0 || stricmp(attribute, "B8") == 0)
370
ci->drivers.unknowns_as_longvarchar = atoi(value);
371
else if (stricmp(attribute, INI_BOOLSASCHAR) == 0 || stricmp(attribute, "B9") == 0)
372
ci->drivers.bools_as_char = atoi(value);
373
else if (stricmp(attribute, INI_EXTRASYSTABLEPREFIXES) == 0 || stricmp(attribute, "C2") == 0)
374
strcpy(ci->drivers.extra_systable_prefixes, value);
375
mylog("CopyCommonAttributes: A7=%d;A8=%d;A9=%d;B0=%d;B1=%d;B2=%d;B3=%d;B4=%d;B5=%d;B6=%d;B7=%d;B8=%d;B9=%d;C0=%d;C1=%d;C2=%s",
376
ci->drivers.fetch_max,
377
ci->drivers.socket_buffersize,
378
ci->drivers.unknown_sizes,
379
ci->drivers.max_varchar_size,
380
ci->drivers.max_longvarchar_size,
383
ci->drivers.disable_optimizer,
385
ci->drivers.use_declarefetch,
386
ci->drivers.text_as_longvarchar,
387
ci->drivers.unknowns_as_longvarchar,
388
ci->drivers.bools_as_char,
390
ci->drivers.cancel_as_freestmt,
391
ci->drivers.extra_systable_prefixes);
396
getDSNdefaults(ConnInfo *ci)
398
if (ci->port[0] == '\0')
399
strcpy(ci->port, DEFAULT_PORT);
401
if (ci->onlyread[0] == '\0')
402
sprintf(ci->onlyread, "%d", globals.onlyread);
404
if (ci->protocol[0] == '\0')
405
strcpy(ci->protocol, globals.protocol);
407
if (ci->fake_oid_index[0] == '\0')
408
sprintf(ci->fake_oid_index, "%d", DEFAULT_FAKEOIDINDEX);
410
if (ci->show_oid_column[0] == '\0')
411
sprintf(ci->show_oid_column, "%d", DEFAULT_SHOWOIDCOLUMN);
413
if (ci->show_system_tables[0] == '\0')
414
sprintf(ci->show_system_tables, "%d", DEFAULT_SHOWSYSTEMTABLES);
416
if (ci->row_versioning[0] == '\0')
417
sprintf(ci->row_versioning, "%d", DEFAULT_ROWVERSIONING);
419
if (ci->disallow_premature < 0)
420
ci->disallow_premature = DEFAULT_DISALLOWPREMATURE;
421
if (ci->allow_keyset < 0)
422
ci->allow_keyset = DEFAULT_UPDATABLECURSORS;
423
if (ci->lf_conversion < 0)
424
ci->lf_conversion = DEFAULT_LFCONVERSION;
425
if (ci->true_is_minus1 < 0)
426
ci->true_is_minus1 = DEFAULT_TRUEISMINUS1;
427
if (ci->int8_as < -100)
428
ci->int8_as = DEFAULT_INT8AS;
429
if (ci->bytea_as_longvarbinary < 0)
430
ci->bytea_as_longvarbinary = DEFAULT_BYTEAASLONGVARBINARY;
431
if (ci->use_server_side_prepare < 0)
432
ci->use_server_side_prepare = DEFAULT_USESERVERSIDEPREPARE;
433
if (ci->lower_case_identifier < 0)
434
ci->lower_case_identifier = DEFAULT_LOWERCASEIDENTIFIER;
438
getDriverNameFromDSN(const char *dsn, char *driver_name, int namelen)
440
return SQLGetPrivateProfileString(ODBC_DATASOURCES, dsn, "", driver_name, namelen, ODBC_INI);
444
getDSNinfo(ConnInfo *ci, char overwrite)
447
char encoded_conn_settings[LARGE_REGISTRY_LEN],
448
temp[SMALL_REGISTRY_LEN];
451
* If a driver keyword was present, then dont use a DSN and return.
452
* If DSN is null and no driver, then use the default datasource.
456
if (ci->drivername[0] != '\0')
459
strcpy(DSN, INI_DSN);
462
/* brute-force chop off trailing blanks... */
463
while (*(DSN + strlen(DSN) - 1) == ' ')
464
*(DSN + strlen(DSN) - 1) = '\0';
466
if (ci->drivername[0] == '\0' || overwrite)
468
getDriverNameFromDSN(DSN, ci->drivername, sizeof(ci->drivername));
469
if (ci->drivername[0] && stricmp(ci->drivername, DBMS_NAME))
470
getCommonDefaults(ci->drivername, ODBCINST_INI, ci);
473
/* Proceed with getting info for the given DSN. */
475
if (ci->desc[0] == '\0' || overwrite)
476
SQLGetPrivateProfileString(DSN, INI_KDESC, "", ci->desc, sizeof(ci->desc), ODBC_INI);
478
if (ci->server[0] == '\0' || overwrite)
479
SQLGetPrivateProfileString(DSN, INI_SERVER, "", ci->server, sizeof(ci->server), ODBC_INI);
481
if (ci->database[0] == '\0' || overwrite)
482
SQLGetPrivateProfileString(DSN, INI_DATABASE, "", ci->database, sizeof(ci->database), ODBC_INI);
484
if (ci->username[0] == '\0' || overwrite)
485
SQLGetPrivateProfileString(DSN, INI_USER, "", ci->username, sizeof(ci->username), ODBC_INI);
487
if (ci->password[0] == '\0' || overwrite)
488
SQLGetPrivateProfileString(DSN, INI_PASSWORD, "", ci->password, sizeof(ci->password), ODBC_INI);
490
if (ci->port[0] == '\0' || overwrite)
491
SQLGetPrivateProfileString(DSN, INI_PORT, "", ci->port, sizeof(ci->port), ODBC_INI);
493
if (ci->onlyread[0] == '\0' || overwrite)
494
SQLGetPrivateProfileString(DSN, INI_READONLY, "", ci->onlyread, sizeof(ci->onlyread), ODBC_INI);
496
if (ci->show_oid_column[0] == '\0' || overwrite)
497
SQLGetPrivateProfileString(DSN, INI_SHOWOIDCOLUMN, "", ci->show_oid_column, sizeof(ci->show_oid_column), ODBC_INI);
499
if (ci->fake_oid_index[0] == '\0' || overwrite)
500
SQLGetPrivateProfileString(DSN, INI_FAKEOIDINDEX, "", ci->fake_oid_index, sizeof(ci->fake_oid_index), ODBC_INI);
502
if (ci->row_versioning[0] == '\0' || overwrite)
503
SQLGetPrivateProfileString(DSN, INI_ROWVERSIONING, "", ci->row_versioning, sizeof(ci->row_versioning), ODBC_INI);
505
if (ci->show_system_tables[0] == '\0' || overwrite)
506
SQLGetPrivateProfileString(DSN, INI_SHOWSYSTEMTABLES, "", ci->show_system_tables, sizeof(ci->show_system_tables), ODBC_INI);
508
if (ci->protocol[0] == '\0' || overwrite)
509
SQLGetPrivateProfileString(DSN, INI_PROTOCOL, "", ci->protocol, sizeof(ci->protocol), ODBC_INI);
511
if (ci->conn_settings[0] == '\0' || overwrite)
513
SQLGetPrivateProfileString(DSN, INI_CONNSETTINGS, "", encoded_conn_settings, sizeof(encoded_conn_settings), ODBC_INI);
514
decode(encoded_conn_settings, ci->conn_settings);
517
if (ci->translation_dll[0] == '\0' || overwrite)
518
SQLGetPrivateProfileString(DSN, INI_TRANSLATIONDLL, "", ci->translation_dll, sizeof(ci->translation_dll), ODBC_INI);
520
if (ci->translation_option[0] == '\0' || overwrite)
521
SQLGetPrivateProfileString(DSN, INI_TRANSLATIONOPTION, "", ci->translation_option, sizeof(ci->translation_option), ODBC_INI);
523
if (ci->disallow_premature < 0 || overwrite)
525
SQLGetPrivateProfileString(DSN, INI_DISALLOWPREMATURE, "", temp, sizeof(temp), ODBC_INI);
527
ci->disallow_premature = atoi(temp);
530
if (ci->allow_keyset < 0 || overwrite)
532
SQLGetPrivateProfileString(DSN, INI_UPDATABLECURSORS, "", temp, sizeof(temp), ODBC_INI);
534
ci->allow_keyset = atoi(temp);
537
if (ci->lf_conversion < 0 || overwrite)
539
SQLGetPrivateProfileString(DSN, INI_LFCONVERSION, "", temp, sizeof(temp), ODBC_INI);
541
ci->lf_conversion = atoi(temp);
544
if (ci->true_is_minus1 < 0 || overwrite)
546
SQLGetPrivateProfileString(DSN, INI_TRUEISMINUS1, "", temp, sizeof(temp), ODBC_INI);
548
ci->true_is_minus1 = atoi(temp);
551
if (ci->int8_as < -100 || overwrite)
553
SQLGetPrivateProfileString(DSN, INI_INT8AS, "", temp, sizeof(temp), ODBC_INI);
555
ci->int8_as = atoi(temp);
558
if (ci->bytea_as_longvarbinary < 0 || overwrite)
560
SQLGetPrivateProfileString(DSN, INI_BYTEAASLONGVARBINARY, "", temp, sizeof(temp), ODBC_INI);
562
ci->bytea_as_longvarbinary = atoi(temp);
565
if (ci->use_server_side_prepare < 0 || overwrite)
567
SQLGetPrivateProfileString(DSN, INI_USESERVERSIDEPREPARE, "", temp, sizeof(temp), ODBC_INI);
569
ci->use_server_side_prepare = atoi(temp);
572
if (ci->lower_case_identifier < 0 || overwrite)
574
SQLGetPrivateProfileString(DSN, INI_LOWERCASEIDENTIFIER, "", temp, sizeof(temp), ODBC_INI);
576
ci->lower_case_identifier = atoi(temp);
579
/* Allow override of odbcinst.ini parameters here */
580
getCommonDefaults(DSN, ODBC_INI, ci);
582
qlog("DSN info: DSN='%s',server='%s',port='%s',dbase='%s',user='%s',passwd='%s'\n",
588
ci->password ? "xxxxx" : "");
589
qlog(" onlyread='%s',protocol='%s',showoid='%s',fakeoidindex='%s',showsystable='%s'\n",
594
ci->show_system_tables);
596
check_client_encoding(ci->conn_settings);
597
qlog(" conn_settings='%s',conn_encoding='%s'\n",
599
check_client_encoding(ci->conn_settings));
600
qlog(" translation_dll='%s',translation_option='%s'\n",
602
ci->translation_option);
606
* This function writes any global parameters (that can be manipulated)
607
* to the ODBCINST.INI portion of the registry
610
writeDriverCommoninfo(const char *fileName, const char *sectionName,
611
const GLOBAL_VALUES *comval)
615
if (ODBCINST_INI == fileName && NULL == sectionName)
616
sectionName = DBMS_NAME;
618
sprintf(tmp, "%d", comval->fetch_max);
619
SQLWritePrivateProfileString(sectionName,
620
INI_FETCH, tmp, fileName);
622
sprintf(tmp, "%d", comval->commlog);
623
SQLWritePrivateProfileString(sectionName,
624
INI_COMMLOG, tmp, fileName);
626
sprintf(tmp, "%d", comval->debug);
627
SQLWritePrivateProfileString(sectionName,
628
INI_DEBUG, tmp, fileName);
630
sprintf(tmp, "%d", comval->disable_optimizer);
631
SQLWritePrivateProfileString(sectionName,
632
INI_OPTIMIZER, tmp, fileName);
634
sprintf(tmp, "%d", comval->ksqo);
635
SQLWritePrivateProfileString(sectionName,
636
INI_KSQO, tmp, fileName);
638
sprintf(tmp, "%d", comval->unique_index);
639
SQLWritePrivateProfileString(sectionName, INI_UNIQUEINDEX, tmp, fileName);
641
* Never update the onlyread from this module.
643
if (ODBCINST_INI == fileName)
645
sprintf(tmp, "%d", comval->onlyread);
646
SQLWritePrivateProfileString(sectionName, INI_READONLY, tmp,
650
sprintf(tmp, "%d", comval->use_declarefetch);
651
SQLWritePrivateProfileString(sectionName,
652
INI_USEDECLAREFETCH, tmp, fileName);
654
sprintf(tmp, "%d", comval->unknown_sizes);
655
SQLWritePrivateProfileString(sectionName,
656
INI_UNKNOWNSIZES, tmp, fileName);
658
sprintf(tmp, "%d", comval->text_as_longvarchar);
659
SQLWritePrivateProfileString(sectionName,
660
INI_TEXTASLONGVARCHAR, tmp, fileName);
662
sprintf(tmp, "%d", comval->unknowns_as_longvarchar);
663
SQLWritePrivateProfileString(sectionName,
664
INI_UNKNOWNSASLONGVARCHAR, tmp, fileName);
666
sprintf(tmp, "%d", comval->bools_as_char);
667
SQLWritePrivateProfileString(sectionName,
668
INI_BOOLSASCHAR, tmp, fileName);
670
sprintf(tmp, "%d", comval->parse);
671
SQLWritePrivateProfileString(sectionName,
672
INI_PARSE, tmp, fileName);
674
sprintf(tmp, "%d", comval->cancel_as_freestmt);
675
SQLWritePrivateProfileString(sectionName,
676
INI_CANCELASFREESTMT, tmp, fileName);
678
sprintf(tmp, "%d", comval->max_varchar_size);
679
SQLWritePrivateProfileString(sectionName,
680
INI_MAXVARCHARSIZE, tmp, fileName);
682
sprintf(tmp, "%d", comval->max_longvarchar_size);
683
SQLWritePrivateProfileString(sectionName,
684
INI_MAXLONGVARCHARSIZE, tmp, fileName);
686
SQLWritePrivateProfileString(sectionName,
687
INI_EXTRASYSTABLEPREFIXES, comval->extra_systable_prefixes, fileName);
690
* Never update the conn_setting from this module
691
* SQLWritePrivateProfileString(sectionName, INI_CONNSETTINGS,
692
* comval->conn_settings, fileName);
696
/* This is for datasource based options only */
698
writeDSNinfo(const ConnInfo *ci)
700
const char *DSN = ci->dsn;
701
char encoded_conn_settings[LARGE_REGISTRY_LEN],
702
temp[SMALL_REGISTRY_LEN];
704
encode(ci->conn_settings, encoded_conn_settings);
706
SQLWritePrivateProfileString(DSN,
711
SQLWritePrivateProfileString(DSN,
716
SQLWritePrivateProfileString(DSN,
721
SQLWritePrivateProfileString(DSN,
726
SQLWritePrivateProfileString(DSN,
731
SQLWritePrivateProfileString(DSN,
736
SQLWritePrivateProfileString(DSN,
741
SQLWritePrivateProfileString(DSN,
746
SQLWritePrivateProfileString(DSN,
751
SQLWritePrivateProfileString(DSN,
756
SQLWritePrivateProfileString(DSN,
757
INI_SHOWSYSTEMTABLES,
758
ci->show_system_tables,
761
SQLWritePrivateProfileString(DSN,
766
SQLWritePrivateProfileString(DSN,
768
encoded_conn_settings,
771
sprintf(temp, "%d", ci->disallow_premature);
772
SQLWritePrivateProfileString(DSN,
773
INI_DISALLOWPREMATURE,
776
sprintf(temp, "%d", ci->allow_keyset);
777
SQLWritePrivateProfileString(DSN,
778
INI_UPDATABLECURSORS,
781
sprintf(temp, "%d", ci->lf_conversion);
782
SQLWritePrivateProfileString(DSN,
786
sprintf(temp, "%d", ci->true_is_minus1);
787
SQLWritePrivateProfileString(DSN,
791
sprintf(temp, "%d", ci->int8_as);
792
SQLWritePrivateProfileString(DSN,
796
sprintf(temp, "%d", ci->bytea_as_longvarbinary);
797
SQLWritePrivateProfileString(DSN,
798
INI_BYTEAASLONGVARBINARY,
801
sprintf(temp, "%d", ci->use_server_side_prepare);
802
SQLWritePrivateProfileString(DSN,
803
INI_USESERVERSIDEPREPARE,
806
sprintf(temp, "%d", ci->lower_case_identifier);
807
SQLWritePrivateProfileString(DSN,
808
INI_LOWERCASEIDENTIFIER,
815
* This function reads the ODBCINST.INI portion of
816
* the registry and gets any driver defaults.
819
getCommonDefaults(const char *section, const char *filename, ConnInfo *ci)
822
GLOBAL_VALUES *comval;
825
comval = &(ci->drivers);
828
/* Fetch Count is stored in driver section */
829
SQLGetPrivateProfileString(section, INI_FETCH, "",
830
temp, sizeof(temp), filename);
833
comval->fetch_max = atoi(temp);
834
/* sanity check if using cursors */
835
if (comval->fetch_max <= 0)
836
comval->fetch_max = FETCH_MAX;
839
comval->fetch_max = FETCH_MAX;
841
/* Socket Buffersize is stored in driver section */
842
SQLGetPrivateProfileString(section, INI_SOCKET, "",
843
temp, sizeof(temp), filename);
845
comval->socket_buffersize = atoi(temp);
847
comval->socket_buffersize = SOCK_BUFFER_SIZE;
849
/* Debug is stored in the driver section */
850
SQLGetPrivateProfileString(section, INI_DEBUG, "",
851
temp, sizeof(temp), filename);
853
comval->debug = atoi(temp);
855
comval->debug = DEFAULT_DEBUG;
857
/* CommLog is stored in the driver section */
858
SQLGetPrivateProfileString(section, INI_COMMLOG, "",
859
temp, sizeof(temp), filename);
861
comval->commlog = atoi(temp);
863
comval->commlog = DEFAULT_COMMLOG;
866
logs_on_off(0, 0, 0);
867
/* Optimizer is stored in the driver section only */
868
SQLGetPrivateProfileString(section, INI_OPTIMIZER, "",
869
temp, sizeof(temp), filename);
871
comval->disable_optimizer = atoi(temp);
873
comval->disable_optimizer = DEFAULT_OPTIMIZER;
875
/* KSQO is stored in the driver section only */
876
SQLGetPrivateProfileString(section, INI_KSQO, "",
877
temp, sizeof(temp), filename);
879
comval->ksqo = atoi(temp);
881
comval->ksqo = DEFAULT_KSQO;
883
/* Recognize Unique Index is stored in the driver section only */
884
SQLGetPrivateProfileString(section, INI_UNIQUEINDEX, "",
885
temp, sizeof(temp), filename);
887
comval->unique_index = atoi(temp);
889
comval->unique_index = DEFAULT_UNIQUEINDEX;
892
/* Unknown Sizes is stored in the driver section only */
893
SQLGetPrivateProfileString(section, INI_UNKNOWNSIZES, "",
894
temp, sizeof(temp), filename);
896
comval->unknown_sizes = atoi(temp);
898
comval->unknown_sizes = DEFAULT_UNKNOWNSIZES;
901
/* Lie about supported functions? */
902
SQLGetPrivateProfileString(section, INI_LIE, "",
903
temp, sizeof(temp), filename);
905
comval->lie = atoi(temp);
907
comval->lie = DEFAULT_LIE;
909
/* Parse statements */
910
SQLGetPrivateProfileString(section, INI_PARSE, "",
911
temp, sizeof(temp), filename);
913
comval->parse = atoi(temp);
915
comval->parse = DEFAULT_PARSE;
917
/* SQLCancel calls SQLFreeStmt in Driver Manager */
918
SQLGetPrivateProfileString(section, INI_CANCELASFREESTMT, "",
919
temp, sizeof(temp), filename);
921
comval->cancel_as_freestmt = atoi(temp);
923
comval->cancel_as_freestmt = DEFAULT_CANCELASFREESTMT;
925
/* UseDeclareFetch is stored in the driver section only */
926
SQLGetPrivateProfileString(section, INI_USEDECLAREFETCH, "",
927
temp, sizeof(temp), filename);
929
comval->use_declarefetch = atoi(temp);
931
comval->use_declarefetch = DEFAULT_USEDECLAREFETCH;
933
/* Max Varchar Size */
934
SQLGetPrivateProfileString(section, INI_MAXVARCHARSIZE, "",
935
temp, sizeof(temp), filename);
937
comval->max_varchar_size = atoi(temp);
939
comval->max_varchar_size = MAX_VARCHAR_SIZE;
941
/* Max TextField Size */
942
SQLGetPrivateProfileString(section, INI_MAXLONGVARCHARSIZE, "",
943
temp, sizeof(temp), filename);
945
comval->max_longvarchar_size = atoi(temp);
947
comval->max_longvarchar_size = TEXT_FIELD_SIZE;
949
/* Text As LongVarchar */
950
SQLGetPrivateProfileString(section, INI_TEXTASLONGVARCHAR, "",
951
temp, sizeof(temp), filename);
953
comval->text_as_longvarchar = atoi(temp);
955
comval->text_as_longvarchar = DEFAULT_TEXTASLONGVARCHAR;
957
/* Unknowns As LongVarchar */
958
SQLGetPrivateProfileString(section, INI_UNKNOWNSASLONGVARCHAR, "",
959
temp, sizeof(temp), filename);
961
comval->unknowns_as_longvarchar = atoi(temp);
963
comval->unknowns_as_longvarchar = DEFAULT_UNKNOWNSASLONGVARCHAR;
966
SQLGetPrivateProfileString(section, INI_BOOLSASCHAR, "",
967
temp, sizeof(temp), filename);
969
comval->bools_as_char = atoi(temp);
971
comval->bools_as_char = DEFAULT_BOOLSASCHAR;
973
/* Extra Systable prefixes */
976
* Use @@@ to distinguish between blank extra prefixes and no key
979
SQLGetPrivateProfileString(section, INI_EXTRASYSTABLEPREFIXES, "@@@",
980
temp, sizeof(temp), filename);
981
if (strcmp(temp, "@@@"))
982
strcpy(comval->extra_systable_prefixes, temp);
984
strcpy(comval->extra_systable_prefixes, DEFAULT_EXTRASYSTABLEPREFIXES);
986
mylog("globals.extra_systable_prefixes = '%s'\n", comval->extra_systable_prefixes);
989
/* Dont allow override of an override! */
993
* ConnSettings is stored in the driver section and per datasource
996
SQLGetPrivateProfileString(section, INI_CONNSETTINGS, "",
997
comval->conn_settings, sizeof(comval->conn_settings), filename);
999
/* Default state for future DSN's Readonly attribute */
1000
SQLGetPrivateProfileString(section, INI_READONLY, "",
1001
temp, sizeof(temp), filename);
1003
comval->onlyread = atoi(temp);
1005
comval->onlyread = DEFAULT_READONLY;
1008
* Default state for future DSN's protocol attribute This isn't a
1009
* real driver option YET. This is more intended for
1010
* customization from the install.
1012
SQLGetPrivateProfileString(section, INI_PROTOCOL, "@@@",
1013
temp, sizeof(temp), filename);
1014
if (strcmp(temp, "@@@"))
1015
strcpy(comval->protocol, temp);
1017
strcpy(comval->protocol, DEFAULT_PROTOCOL);