5
* Description: This module contains any specific code for handling
6
* dialog boxes such as driver/datasource options. Both the
7
* ConfigDSN() and the SQLDriverConnect() functions use
8
* functions in this module. If you were to add a new option
9
* to any dialog box, you would most likely only have to change
10
* things in here rather than in 2 separate places as before.
16
* Comments: See "notice.txt" for copyright and license information.
19
/* Multibyte support Eiji Tokuya 2001-03-15 */
21
#include "dlg_specific.h"
22
#include "win_setup.h"
26
#include "multibyte.h"
27
#include "pgapifunc.h"
39
extern GLOBAL_VALUES globals;
41
extern HINSTANCE NEAR s_hModule;
42
static int driver_optionsDraw(HWND, const ConnInfo *, int src, BOOL enable);
43
static int driver_options_update(HWND hdlg, ConnInfo *ci, const char *);
46
SetDlgStuff(HWND hdlg, const ConnInfo *ci)
49
* If driver attribute NOT present, then set the datasource name and
52
/**if (ci->driver[0] == '\0')
54
SetDlgItemText(hdlg, IDC_DSNAME, ci->dsn);
55
SetDlgItemText(hdlg, IDC_DESC, ci->desc);
58
SetDlgItemText(hdlg, IDC_DATABASE, ci->database);
59
SetDlgItemText(hdlg, IDC_SERVER, ci->server);
60
SetDlgItemText(hdlg, IDC_USER, ci->username);
61
SetDlgItemText(hdlg, IDC_PASSWORD, ci->password);
62
SetDlgItemText(hdlg, IDC_PORT, ci->port);
67
GetDlgStuff(HWND hdlg, ConnInfo *ci)
69
GetDlgItemText(hdlg, IDC_DESC, ci->desc, sizeof(ci->desc));
71
GetDlgItemText(hdlg, IDC_DATABASE, ci->database, sizeof(ci->database));
72
GetDlgItemText(hdlg, IDC_SERVER, ci->server, sizeof(ci->server));
73
GetDlgItemText(hdlg, IDC_USER, ci->username, sizeof(ci->username));
74
GetDlgItemText(hdlg, IDC_PASSWORD, ci->password, sizeof(ci->password));
75
GetDlgItemText(hdlg, IDC_PORT, ci->port, sizeof(ci->port));
80
driver_optionsDraw(HWND hdlg, const ConnInfo *ci, int src, BOOL enable)
82
const GLOBAL_VALUES *comval;
83
static BOOL defset = FALSE;
84
static GLOBAL_VALUES defval;
88
case 0: /* driver common */
91
case 1: /* dsn specific */
92
comval = &(ci->drivers);
97
defval.commlog = DEFAULT_COMMLOG;
98
defval.disable_optimizer = DEFAULT_OPTIMIZER;
99
defval.ksqo = DEFAULT_KSQO;
100
defval.unique_index = DEFAULT_UNIQUEINDEX;
101
defval.onlyread = DEFAULT_READONLY;
102
defval.use_declarefetch = DEFAULT_USEDECLAREFETCH;
104
defval.parse = DEFAULT_PARSE;
105
defval.cancel_as_freestmt = DEFAULT_CANCELASFREESTMT;
106
defval.debug = DEFAULT_DEBUG;
109
defval.unknown_sizes = DEFAULT_UNKNOWNSIZES;
110
defval.text_as_longvarchar = DEFAULT_TEXTASLONGVARCHAR;
111
defval.unknowns_as_longvarchar = DEFAULT_UNKNOWNSASLONGVARCHAR;
112
defval.bools_as_char = DEFAULT_BOOLSASCHAR;
119
ShowWindow(GetDlgItem(hdlg, DRV_MSG_LABEL2), enable ? SW_SHOW : SW_HIDE);
120
CheckDlgButton(hdlg, DRV_COMMLOG, comval->commlog);
122
EnableWindow(GetDlgItem(hdlg, DRV_COMMLOG), FALSE);
124
CheckDlgButton(hdlg, DRV_OPTIMIZER, comval->disable_optimizer);
125
CheckDlgButton(hdlg, DRV_KSQO, comval->ksqo);
126
CheckDlgButton(hdlg, DRV_UNIQUEINDEX, comval->unique_index);
127
/* EnableWindow(GetDlgItem(hdlg, DRV_UNIQUEINDEX), enable); */
128
CheckDlgButton(hdlg, DRV_READONLY, comval->onlyread);
129
EnableWindow(GetDlgItem(hdlg, DRV_READONLY), enable);
130
CheckDlgButton(hdlg, DRV_USEDECLAREFETCH, comval->use_declarefetch);
132
/* Unknown Sizes clear */
133
CheckDlgButton(hdlg, DRV_UNKNOWN_DONTKNOW, 0);
134
CheckDlgButton(hdlg, DRV_UNKNOWN_LONGEST, 0);
135
CheckDlgButton(hdlg, DRV_UNKNOWN_MAX, 0);
136
/* Unknown (Default) Data Type sizes */
137
switch (comval->unknown_sizes)
139
case UNKNOWNS_AS_DONTKNOW:
140
CheckDlgButton(hdlg, DRV_UNKNOWN_DONTKNOW, 1);
142
case UNKNOWNS_AS_LONGEST:
143
CheckDlgButton(hdlg, DRV_UNKNOWN_LONGEST, 1);
145
case UNKNOWNS_AS_MAX:
147
CheckDlgButton(hdlg, DRV_UNKNOWN_MAX, 1);
151
CheckDlgButton(hdlg, DRV_TEXT_LONGVARCHAR, comval->text_as_longvarchar);
152
CheckDlgButton(hdlg, DRV_UNKNOWNS_LONGVARCHAR, comval->unknowns_as_longvarchar);
153
CheckDlgButton(hdlg, DRV_BOOLS_CHAR, comval->bools_as_char);
154
CheckDlgButton(hdlg, DRV_PARSE, comval->parse);
155
CheckDlgButton(hdlg, DRV_CANCELASFREESTMT, comval->cancel_as_freestmt);
156
CheckDlgButton(hdlg, DRV_DEBUG, comval->debug);
158
EnableWindow(GetDlgItem(hdlg, DRV_DEBUG), FALSE);
160
SetDlgItemInt(hdlg, DRV_CACHE_SIZE, comval->fetch_max, FALSE);
161
SetDlgItemInt(hdlg, DRV_VARCHAR_SIZE, comval->max_varchar_size, FALSE);
162
SetDlgItemInt(hdlg, DRV_LONGVARCHAR_SIZE, comval->max_longvarchar_size, TRUE);
163
SetDlgItemText(hdlg, DRV_EXTRASYSTABLEPREFIXES, comval->extra_systable_prefixes);
165
/* Driver Connection Settings */
166
SetDlgItemText(hdlg, DRV_CONNSETTINGS, comval->conn_settings);
167
EnableWindow(GetDlgItem(hdlg, DRV_CONNSETTINGS), enable);
168
ShowWindow(GetDlgItem(hdlg, IDPREVPAGE), enable ? SW_HIDE : SW_SHOW);
169
ShowWindow(GetDlgItem(hdlg, IDNEXTPAGE), enable ? SW_HIDE : SW_SHOW);
174
driver_options_update(HWND hdlg, ConnInfo *ci, const char *updateDriver)
176
GLOBAL_VALUES *comval;
179
comval = &(ci->drivers);
182
comval->commlog = IsDlgButtonChecked(hdlg, DRV_COMMLOG);
183
comval->disable_optimizer = IsDlgButtonChecked(hdlg, DRV_OPTIMIZER);
184
comval->ksqo = IsDlgButtonChecked(hdlg, DRV_KSQO);
185
comval->unique_index = IsDlgButtonChecked(hdlg, DRV_UNIQUEINDEX);
188
comval->onlyread = IsDlgButtonChecked(hdlg, DRV_READONLY);
190
comval->use_declarefetch = IsDlgButtonChecked(hdlg, DRV_USEDECLAREFETCH);
192
/* Unknown (Default) Data Type sizes */
193
if (IsDlgButtonChecked(hdlg, DRV_UNKNOWN_MAX))
194
comval->unknown_sizes = UNKNOWNS_AS_MAX;
195
else if (IsDlgButtonChecked(hdlg, DRV_UNKNOWN_DONTKNOW))
196
comval->unknown_sizes = UNKNOWNS_AS_DONTKNOW;
197
else if (IsDlgButtonChecked(hdlg, DRV_UNKNOWN_LONGEST))
198
comval->unknown_sizes = UNKNOWNS_AS_LONGEST;
200
comval->unknown_sizes = UNKNOWNS_AS_MAX;
202
comval->text_as_longvarchar = IsDlgButtonChecked(hdlg, DRV_TEXT_LONGVARCHAR);
203
comval->unknowns_as_longvarchar = IsDlgButtonChecked(hdlg, DRV_UNKNOWNS_LONGVARCHAR);
204
comval->bools_as_char = IsDlgButtonChecked(hdlg, DRV_BOOLS_CHAR);
206
comval->parse = IsDlgButtonChecked(hdlg, DRV_PARSE);
208
comval->cancel_as_freestmt = IsDlgButtonChecked(hdlg, DRV_CANCELASFREESTMT);
209
comval->debug = IsDlgButtonChecked(hdlg, DRV_DEBUG);
211
comval->fetch_max = GetDlgItemInt(hdlg, DRV_CACHE_SIZE, NULL, FALSE);
212
comval->max_varchar_size = GetDlgItemInt(hdlg, DRV_VARCHAR_SIZE, NULL, FALSE);
213
comval->max_longvarchar_size = GetDlgItemInt(hdlg, DRV_LONGVARCHAR_SIZE, NULL, TRUE); /* allows for
216
GetDlgItemText(hdlg, DRV_EXTRASYSTABLEPREFIXES, comval->extra_systable_prefixes, sizeof(comval->extra_systable_prefixes));
218
/* Driver Connection Settings */
220
GetDlgItemText(hdlg, DRV_CONNSETTINGS, comval->conn_settings, sizeof(comval->conn_settings));
223
writeDriverCommoninfo(ODBCINST_INI, updateDriver, comval);
230
driver_optionsProc(HWND hdlg,
241
SetWindowLong(hdlg, DWL_USER, lParam); /* save for OK etc */
242
ci = (ConnInfo *) lParam;
243
LoadString(s_hModule, IDS_ADVANCE_OPTION_DEF, strbuf, sizeof(strbuf));
244
SetWindowText(hdlg, strbuf);
245
LoadString(s_hModule, IDS_ADVANCE_SAVE, strbuf, sizeof(strbuf));
246
SetWindowText(GetDlgItem(hdlg, IDOK), strbuf);
247
ShowWindow(GetDlgItem(hdlg, IDAPPLY), SW_HIDE);
248
driver_optionsDraw(hdlg, ci, 0, TRUE);
252
switch (GET_WM_COMMAND_ID(wParam, lParam))
255
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
256
driver_options_update(hdlg, NULL,
257
ci ? ci->drivername : NULL);
260
EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
264
driver_optionsDraw(hdlg, NULL, 2, TRUE);
273
global_optionsProc(HWND hdlg,
282
CheckDlgButton(hdlg, DRV_COMMLOG, globals.commlog);
284
EnableWindow(GetDlgItem(hdlg, DRV_COMMLOG), FALSE);
286
CheckDlgButton(hdlg, DRV_DEBUG, globals.debug);
288
EnableWindow(GetDlgItem(hdlg, DRV_DEBUG), FALSE);
293
switch (GET_WM_COMMAND_ID(wParam, lParam))
296
globals.commlog = IsDlgButtonChecked(hdlg, DRV_COMMLOG);
297
globals.debug = IsDlgButtonChecked(hdlg, DRV_DEBUG);
298
writeDriverCommoninfo(ODBCINST_INI, NULL, &globals);
301
EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
310
ds_options1Proc(HWND hdlg,
321
SetWindowLong(hdlg, DWL_USER, lParam); /* save for OK etc */
322
ci = (ConnInfo *) lParam;
323
if (ci && ci->dsn && ci->dsn[0])
328
cmd = LoadString(s_hModule,
329
IDS_ADVANCE_OPTION_DSN1,
333
strcpy(fbuf, "Advanced Options (%s) 1/2");
334
sprintf(strbuf, fbuf, ci->dsn);
335
SetWindowText(hdlg, strbuf);
339
LoadString(s_hModule, IDS_ADVANCE_OPTION_CON1, strbuf, sizeof(strbuf));
340
SetWindowText(hdlg, strbuf);
341
ShowWindow(GetDlgItem(hdlg, IDAPPLY), SW_HIDE);
343
driver_optionsDraw(hdlg, ci, 1, FALSE);
347
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
348
switch (GET_WM_COMMAND_ID(wParam, lParam))
351
driver_options_update(hdlg, ci, NULL);
354
EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
358
driver_options_update(hdlg, ci, NULL);
359
SendMessage(GetWindow(hdlg, GW_OWNER), WM_COMMAND, wParam, lParam);
363
driver_optionsDraw(hdlg, ci, 0, FALSE);
367
driver_options_update(hdlg, ci, NULL);
369
EndDialog(hdlg, FALSE);
370
DialogBoxParam(s_hModule,
371
MAKEINTRESOURCE(DLG_OPTIONS_DS),
372
hdlg, ds_options2Proc, (LPARAM)
383
ds_options2Proc(HWND hdlg,
395
ci = (ConnInfo *) lParam;
396
SetWindowLong(hdlg, DWL_USER, lParam); /* save for OK */
398
/* Change window caption */
399
if (ci && ci->dsn && ci->dsn[0])
403
cmd = LoadString(s_hModule,
404
IDS_ADVANCE_OPTION_DSN2,
408
strcpy(fbuf, "Advanced Options (%s) 2/2");
409
sprintf(buf, fbuf, ci->dsn);
410
SetWindowText(hdlg, buf);
414
LoadString(s_hModule, IDS_ADVANCE_OPTION_CON2, buf, sizeof(buf));
415
SetWindowText(hdlg, buf);
416
ShowWindow(GetDlgItem(hdlg, IDAPPLY), SW_HIDE); }
419
CheckDlgButton(hdlg, DS_READONLY, atoi(ci->onlyread));
422
if (strncmp(ci->protocol, PG62, strlen(PG62)) == 0)
423
CheckDlgButton(hdlg, DS_PG62, 1);
424
else if (strncmp(ci->protocol, PG63, strlen(PG63)) == 0)
425
CheckDlgButton(hdlg, DS_PG63, 1);
428
CheckDlgButton(hdlg, DS_PG64, 1);
434
CheckDlgButton(hdlg, DS_INT8_AS_BIGINT, 1);
437
CheckDlgButton(hdlg, DS_INT8_AS_NUMERIC, 1);
440
CheckDlgButton(hdlg, DS_INT8_AS_VARCHAR, 1);
443
CheckDlgButton(hdlg, DS_INT8_AS_DOUBLE, 1);
446
CheckDlgButton(hdlg, DS_INT8_AS_INT4, 1);
449
CheckDlgButton(hdlg, DS_INT8_AS_DEFAULT, 1);
452
CheckDlgButton(hdlg, DS_SHOWOIDCOLUMN, atoi(ci->show_oid_column));
453
CheckDlgButton(hdlg, DS_FAKEOIDINDEX, atoi(ci->fake_oid_index));
454
CheckDlgButton(hdlg, DS_ROWVERSIONING, atoi(ci->row_versioning));
455
CheckDlgButton(hdlg, DS_SHOWSYSTEMTABLES, atoi(ci->show_system_tables));
456
CheckDlgButton(hdlg, DS_DISALLOWPREMATURE, ci->disallow_premature);
457
CheckDlgButton(hdlg, DS_LFCONVERSION, ci->lf_conversion);
458
CheckDlgButton(hdlg, DS_TRUEISMINUS1, ci->true_is_minus1);
459
CheckDlgButton(hdlg, DS_UPDATABLECURSORS, ci->allow_keyset);
460
#ifndef DRIVER_CURSOR_IMPLEMENT
461
EnableWindow(GetDlgItem(hdlg, DS_UPDATABLECURSORS), FALSE);
462
#endif /* DRIVER_CURSOR_IMPLEMENT */
463
CheckDlgButton(hdlg, DS_SERVERSIDEPREPARE, ci->use_server_side_prepare);
464
CheckDlgButton(hdlg, DS_BYTEAASLONGVARBINARY, ci->bytea_as_longvarbinary);
465
/*CheckDlgButton(hdlg, DS_LOWERCASEIDENTIFIER, ci->lower_case_identifier);*/
467
EnableWindow(GetDlgItem(hdlg, DS_FAKEOIDINDEX), atoi(ci->show_oid_column));
469
/* Datasource Connection Settings */
470
SetDlgItemText(hdlg, DS_CONNSETTINGS, ci->conn_settings);
474
switch (cmd = GET_WM_COMMAND_ID(wParam, lParam))
476
case DS_SHOWOIDCOLUMN:
477
mylog("WM_COMMAND: DS_SHOWOIDCOLUMN\n");
478
EnableWindow(GetDlgItem(hdlg, DS_FAKEOIDINDEX), IsDlgButtonChecked(hdlg, DS_SHOWOIDCOLUMN));
484
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
485
mylog("IDOK: got ci = %u\n", ci);
488
sprintf(ci->onlyread, "%d", IsDlgButtonChecked(hdlg, DS_READONLY));
491
if (IsDlgButtonChecked(hdlg, DS_PG62))
492
strcpy(ci->protocol, PG62);
493
else if (IsDlgButtonChecked(hdlg, DS_PG63))
494
strcpy(ci->protocol, PG63);
497
strcpy(ci->protocol, PG64);
500
if (IsDlgButtonChecked(hdlg, DS_INT8_AS_DEFAULT))
502
else if (IsDlgButtonChecked(hdlg, DS_INT8_AS_BIGINT))
503
ci->int8_as = SQL_BIGINT;
504
else if (IsDlgButtonChecked(hdlg, DS_INT8_AS_NUMERIC))
505
ci->int8_as = SQL_NUMERIC;
506
else if (IsDlgButtonChecked(hdlg, DS_INT8_AS_DOUBLE))
507
ci->int8_as = SQL_DOUBLE;
508
else if (IsDlgButtonChecked(hdlg, DS_INT8_AS_INT4))
509
ci->int8_as = SQL_INTEGER;
511
ci->int8_as = SQL_VARCHAR;
513
sprintf(ci->show_system_tables, "%d", IsDlgButtonChecked(hdlg, DS_SHOWSYSTEMTABLES));
515
sprintf(ci->row_versioning, "%d", IsDlgButtonChecked(hdlg, DS_ROWVERSIONING));
516
ci->disallow_premature = IsDlgButtonChecked(hdlg, DS_DISALLOWPREMATURE);
517
ci->lf_conversion = IsDlgButtonChecked(hdlg, DS_LFCONVERSION);
518
ci->true_is_minus1 = IsDlgButtonChecked(hdlg, DS_TRUEISMINUS1);
519
#ifdef DRIVER_CURSOR_IMPLEMENT
520
ci->allow_keyset = IsDlgButtonChecked(hdlg, DS_UPDATABLECURSORS);
521
#endif /* DRIVER_CURSOR_IMPLEMENT */
522
ci->use_server_side_prepare = IsDlgButtonChecked(hdlg, DS_SERVERSIDEPREPARE);
523
ci->bytea_as_longvarbinary = IsDlgButtonChecked(hdlg, DS_BYTEAASLONGVARBINARY);
524
/*ci->lower_case_identifier = IsDlgButtonChecked(hdlg, DS_LOWERCASEIDENTIFIER);*/
527
sprintf(ci->fake_oid_index, "%d", IsDlgButtonChecked(hdlg, DS_FAKEOIDINDEX));
528
sprintf(ci->show_oid_column, "%d", IsDlgButtonChecked(hdlg, DS_SHOWOIDCOLUMN));
530
/* Datasource Connection Settings */
531
GetDlgItemText(hdlg, DS_CONNSETTINGS, ci->conn_settings, sizeof(ci->conn_settings));
534
SendMessage(GetWindow(hdlg, GW_OWNER), WM_COMMAND, wParam, lParam);
538
EndDialog(hdlg, cmd == IDOK);
541
DialogBoxParam(s_hModule,
542
MAKEINTRESOURCE(DLG_OPTIONS_DRV),
543
hdlg, ds_options1Proc, (LPARAM) ci);
547
EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
556
makeDriversList(HWND lwnd, const ConnInfo *ci)
560
int lcount = 0, iidx;
561
char drvname[64], drvatt[128];
562
SQLUSMALLINT direction = SQL_FETCH_FIRST;
563
SQLSMALLINT drvncount, drvacount;
567
hmodule = GetModuleHandle("ODBC32");
568
if (!hmodule) return lcount;
569
addr = GetProcAddress(hmodule, "SQLAllocEnv");
570
if (!addr) return lcount;
571
ret = (*addr)(&henv);
572
if (SQL_SUCCESS != ret) return lcount;
575
ret = SQLDrivers(henv, direction,
576
drvname, sizeof(drvname), &drvncount,
577
drvatt, sizeof(drvatt), &drvacount);
578
if (SQL_SUCCESS != ret && SQL_SUCCESS_WITH_INFO != ret)
580
if (strnicmp(drvname, "postgresql", 10) == 0)
582
iidx = SendMessage(lwnd, LB_ADDSTRING, 0, (LPARAM) drvname);
583
if (LB_ERR != iidx && stricmp(drvname, ci->drivername) == 0)
585
SendMessage(lwnd, LB_SETCURSEL, (WPARAM) iidx, (LPARAM) 0);
589
direction = SQL_FETCH_NEXT;
591
addr = GetProcAddress(hmodule, "SQLFreeEnv");
599
manage_dsnProc(HWND hdlg, UINT wMsg,
600
WPARAM wParam, LPARAM lParam)
602
LPSETUPDLG lpsetupdlg;
611
SetWindowLong(hdlg, DWL_USER, lParam);
612
lpsetupdlg = (LPSETUPDLG) lParam;
613
ci = &lpsetupdlg->ci;
614
lwnd = GetDlgItem(hdlg, IDC_DRIVER_LIST);
615
makeDriversList(lwnd, ci);
619
switch (GET_WM_COMMAND_ID(wParam, lParam))
622
lpsetupdlg = (LPSETUPDLG) GetWindowLong(hdlg, DWL_USER);
623
lwnd = GetDlgItem(hdlg, IDC_DRIVER_LIST);
624
sidx = SendMessage(lwnd, LB_GETCURSEL,
625
(WPARAM) 0, (LPARAM) 0);
628
sidx = SendMessage(lwnd, LB_GETTEXT,
629
(WPARAM) sidx, (LPARAM) drvname);
632
ChangeDriverName(hdlg, lpsetupdlg, drvname);
635
EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);