]> granicus.if.org Git - postgresql/blob - src/interfaces/odbc/dlg_specific.c
Version 06-30-0248
[postgresql] / src / interfaces / odbc / dlg_specific.c
1
2 /* Module:          dlg_specific.c
3  *
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.
10  *
11  * Classes:         none
12  *
13  * API functions:   none
14  *
15  * Comments:        See "notice.txt" for copyright and license information.
16  *
17  */
18
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22
23 #ifdef UNIX
24 #include <string.h>
25 #include "gpps.h"
26 #define SQLGetPrivateProfileString(a,b,c,d,e,f) GetPrivateProfileString(a,b,c,d,e,f)
27 #define SQLWritePrivateProfileString(a,b,c,d) WritePrivateProfileString(a,b,c,d)
28 #if !HAVE_STRICMP
29 #define stricmp(s1,s2)  strcasecmp(s1,s2)
30 #define strnicmp(s1,s2,n)       strncasecmp(s1,s2,n)
31 #endif
32 #endif
33
34 #include "dlg_specific.h"
35 #include "convert.h"
36
37 extern GLOBAL_VALUES globals;
38
39 #ifndef UNIX    /* best to find a #ifdef for WINDOWS */
40 void
41 SetDlgStuff(HWND hdlg, ConnInfo *ci)
42 {
43         /*      If driver attribute NOT present, then set the datasource name and description */
44         if (ci->driver[0] == '\0') {
45                 SetDlgItemText(hdlg, IDC_DSNAME, ci->dsn);
46                 SetDlgItemText(hdlg, IDC_DESC, ci->desc);
47         }
48
49         SetDlgItemText(hdlg, IDC_DATABASE, ci->database);
50         SetDlgItemText(hdlg, IDC_SERVER, ci->server);
51         SetDlgItemText(hdlg, IDC_USER, ci->username);
52         SetDlgItemText(hdlg, IDC_PASSWORD, ci->password);
53         SetDlgItemText(hdlg, IDC_PORT, ci->port);
54 }
55
56 void 
57 GetDlgStuff(HWND hdlg, ConnInfo *ci)
58 {
59         GetDlgItemText(hdlg, IDC_DESC, ci->desc, sizeof(ci->desc));
60
61         GetDlgItemText(hdlg, IDC_DATABASE, ci->database, sizeof(ci->database));
62         GetDlgItemText(hdlg, IDC_SERVER, ci->server, sizeof(ci->server));
63         GetDlgItemText(hdlg, IDC_USER, ci->username, sizeof(ci->username));
64         GetDlgItemText(hdlg, IDC_PASSWORD, ci->password, sizeof(ci->password));
65         GetDlgItemText(hdlg, IDC_PORT, ci->port, sizeof(ci->port));
66 }
67
68
69
70 int CALLBACK driver_optionsProc(HWND   hdlg,
71                            WORD   wMsg,
72                            WPARAM wParam,
73                            LPARAM lParam)
74 {
75         switch (wMsg) {
76         case WM_INITDIALOG:
77
78                 CheckDlgButton(hdlg, DRV_COMMLOG, globals.commlog);
79                 CheckDlgButton(hdlg, DRV_OPTIMIZER, globals.disable_optimizer);
80                 CheckDlgButton(hdlg, DRV_UNIQUEINDEX, globals.unique_index);
81                 CheckDlgButton(hdlg, DRV_READONLY, globals.readonly);
82                 CheckDlgButton(hdlg, DRV_USEDECLAREFETCH, globals.use_declarefetch);
83
84                 /*      Unknown (Default) Data Type sizes */
85                 switch(globals.unknown_sizes) {
86                 case UNKNOWNS_AS_DONTKNOW:
87                         CheckDlgButton(hdlg, DRV_UNKNOWN_DONTKNOW, 1);
88                         break;
89                 case UNKNOWNS_AS_LONGEST:
90                         CheckDlgButton(hdlg, DRV_UNKNOWN_LONGEST, 1);
91                         break;
92                 case UNKNOWNS_AS_MAX:
93                 default:
94                         CheckDlgButton(hdlg, DRV_UNKNOWN_MAX, 1);
95                         break;
96                 }
97
98                 CheckDlgButton(hdlg, DRV_TEXT_LONGVARCHAR, globals.text_as_longvarchar);
99                 CheckDlgButton(hdlg, DRV_UNKNOWNS_LONGVARCHAR, globals.unknowns_as_longvarchar);
100                 CheckDlgButton(hdlg, DRV_BOOLS_CHAR, globals.bools_as_char);
101
102                 CheckDlgButton(hdlg, DRV_PARSE, globals.parse);
103
104                 SetDlgItemInt(hdlg, DRV_CACHE_SIZE, globals.fetch_max, FALSE);
105                 SetDlgItemInt(hdlg, DRV_VARCHAR_SIZE, globals.max_varchar_size, FALSE);
106                 SetDlgItemInt(hdlg, DRV_LONGVARCHAR_SIZE, globals.max_longvarchar_size, TRUE);
107
108                 SetDlgItemText(hdlg, DRV_EXTRASYSTABLEPREFIXES, globals.extra_systable_prefixes);
109
110                 /*      Driver Connection Settings */
111                 SetDlgItemText(hdlg, DRV_CONNSETTINGS, globals.conn_settings);
112
113                 break; 
114
115         case WM_COMMAND:
116                 switch (GET_WM_COMMAND_ID(wParam, lParam)) {
117                 case IDOK:
118
119                         globals.commlog = IsDlgButtonChecked(hdlg, DRV_COMMLOG);
120                         globals.disable_optimizer = IsDlgButtonChecked(hdlg, DRV_OPTIMIZER);
121                         globals.unique_index = IsDlgButtonChecked(hdlg, DRV_UNIQUEINDEX);
122                         globals.readonly = IsDlgButtonChecked(hdlg, DRV_READONLY);
123                         globals.use_declarefetch = IsDlgButtonChecked(hdlg, DRV_USEDECLAREFETCH);
124
125                         /*      Unknown (Default) Data Type sizes */
126                         if (IsDlgButtonChecked(hdlg, DRV_UNKNOWN_MAX))
127                                 globals.unknown_sizes = UNKNOWNS_AS_MAX;
128                         else if (IsDlgButtonChecked(hdlg, DRV_UNKNOWN_DONTKNOW))
129                                 globals.unknown_sizes = UNKNOWNS_AS_DONTKNOW;
130                         else if (IsDlgButtonChecked(hdlg, DRV_UNKNOWN_LONGEST))
131                                 globals.unknown_sizes = UNKNOWNS_AS_LONGEST;
132                         else
133                                 globals.unknown_sizes = UNKNOWNS_AS_MAX;
134
135                         globals.text_as_longvarchar = IsDlgButtonChecked(hdlg, DRV_TEXT_LONGVARCHAR);
136                         globals.unknowns_as_longvarchar = IsDlgButtonChecked(hdlg, DRV_UNKNOWNS_LONGVARCHAR);
137                         globals.bools_as_char = IsDlgButtonChecked(hdlg, DRV_BOOLS_CHAR);
138
139                         globals.parse = IsDlgButtonChecked(hdlg, DRV_PARSE);
140
141                         globals.fetch_max = GetDlgItemInt(hdlg, DRV_CACHE_SIZE, NULL, FALSE);
142                         globals.max_varchar_size = GetDlgItemInt(hdlg, DRV_VARCHAR_SIZE, NULL, FALSE);
143                         globals.max_longvarchar_size= GetDlgItemInt(hdlg, DRV_LONGVARCHAR_SIZE, NULL, TRUE);    // allows for SQL_NO_TOTAL
144
145                         GetDlgItemText(hdlg, DRV_EXTRASYSTABLEPREFIXES, globals.extra_systable_prefixes, sizeof(globals.extra_systable_prefixes));
146
147                         /*      Driver Connection Settings */
148                         GetDlgItemText(hdlg, DRV_CONNSETTINGS, globals.conn_settings, sizeof(globals.conn_settings));
149
150                         updateGlobals();
151
152                         //      fall through
153
154                 case IDCANCEL:
155                         EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
156                         return TRUE;
157
158                 case IDDEFAULTS:
159                         CheckDlgButton(hdlg, DRV_COMMLOG, DEFAULT_COMMLOG);
160                         CheckDlgButton(hdlg, DRV_OPTIMIZER, DEFAULT_OPTIMIZER);
161                         CheckDlgButton(hdlg, DRV_UNIQUEINDEX, DEFAULT_UNIQUEINDEX);
162                         CheckDlgButton(hdlg, DRV_READONLY, DEFAULT_READONLY);
163                         CheckDlgButton(hdlg, DRV_USEDECLAREFETCH, DEFAULT_USEDECLAREFETCH);
164         
165                         CheckDlgButton(hdlg, DRV_PARSE, DEFAULT_PARSE);
166
167                         /*      Unknown Sizes */
168                         CheckDlgButton(hdlg, DRV_UNKNOWN_DONTKNOW, 0);
169                         CheckDlgButton(hdlg, DRV_UNKNOWN_LONGEST, 0);
170                         CheckDlgButton(hdlg, DRV_UNKNOWN_MAX, 0);
171                         switch(DEFAULT_UNKNOWNSIZES) {
172                         case UNKNOWNS_AS_DONTKNOW:
173                                 CheckDlgButton(hdlg, DRV_UNKNOWN_DONTKNOW, 1);
174                                 break;
175                         case UNKNOWNS_AS_LONGEST:
176                                 CheckDlgButton(hdlg, DRV_UNKNOWN_LONGEST, 1);
177                                 break;
178                         case UNKNOWNS_AS_MAX:
179                                 CheckDlgButton(hdlg, DRV_UNKNOWN_MAX, 1);
180                                 break;
181                         }
182
183                         CheckDlgButton(hdlg, DRV_TEXT_LONGVARCHAR, DEFAULT_TEXTASLONGVARCHAR);
184                         CheckDlgButton(hdlg, DRV_UNKNOWNS_LONGVARCHAR, DEFAULT_UNKNOWNSASLONGVARCHAR);
185                         CheckDlgButton(hdlg, DRV_BOOLS_CHAR, DEFAULT_BOOLSASCHAR);
186
187                         SetDlgItemInt(hdlg, DRV_CACHE_SIZE, FETCH_MAX, FALSE);
188                         SetDlgItemInt(hdlg, DRV_VARCHAR_SIZE, MAX_VARCHAR_SIZE, FALSE);
189                         SetDlgItemInt(hdlg, DRV_LONGVARCHAR_SIZE, TEXT_FIELD_SIZE, TRUE);
190
191                         SetDlgItemText(hdlg, DRV_EXTRASYSTABLEPREFIXES, DEFAULT_EXTRASYSTABLEPREFIXES);
192
193                         /*      Driver Connection Settings */
194                         SetDlgItemText(hdlg, DRV_CONNSETTINGS, "");
195
196                         break;
197                 }
198
199         }
200
201         return FALSE;
202 }
203
204 int CALLBACK ds_optionsProc(HWND   hdlg,
205                            WORD   wMsg,
206                            WPARAM wParam,
207                            LPARAM lParam)
208 {
209 ConnInfo *ci;
210 char buf[128];
211
212         switch (wMsg) {
213         case WM_INITDIALOG:
214                 ci = (ConnInfo *) lParam;               
215                 SetWindowLong(hdlg, DWL_USER, lParam);  // save for OK
216
217                 /*      Change window caption */
218                 if (ci->driver[0])
219                         SetWindowText(hdlg, "Advanced Options (Connection)");
220                 else {
221                         sprintf(buf, "Advanced Options (%s)", ci->dsn);
222                         SetWindowText(hdlg, buf);
223                 }
224
225                 /*      Readonly */
226                 CheckDlgButton(hdlg, DS_READONLY, atoi(ci->readonly));
227
228                 /*      Protocol */
229                 if (strncmp(ci->protocol, PG62, strlen(PG62)) == 0)
230                         CheckDlgButton(hdlg, DS_PG62, 1);
231                 else
232                         CheckDlgButton(hdlg, DS_PG62, 0);
233
234
235                 CheckDlgButton(hdlg, DS_SHOWOIDCOLUMN, atoi(ci->show_oid_column));
236                 CheckDlgButton(hdlg, DS_FAKEOIDINDEX, atoi(ci->fake_oid_index));
237                 CheckDlgButton(hdlg, DS_ROWVERSIONING, atoi(ci->row_versioning));
238                 CheckDlgButton(hdlg, DS_SHOWSYSTEMTABLES, atoi(ci->show_system_tables));
239
240                 EnableWindow(GetDlgItem(hdlg, DS_FAKEOIDINDEX), atoi(ci->show_oid_column));
241
242                 /*      Datasource Connection Settings */
243                 SetDlgItemText(hdlg, DS_CONNSETTINGS, ci->conn_settings);
244                 break; 
245
246
247         case WM_COMMAND:
248                 switch (GET_WM_COMMAND_ID(wParam, lParam)) {
249                 case DS_SHOWOIDCOLUMN:
250                         mylog("WM_COMMAND: DS_SHOWOIDCOLUMN\n");
251                         EnableWindow(GetDlgItem(hdlg, DS_FAKEOIDINDEX), IsDlgButtonChecked(hdlg, DS_SHOWOIDCOLUMN));
252                         return TRUE;
253
254
255                 case IDOK: 
256
257                         ci = (ConnInfo *)GetWindowLong(hdlg, DWL_USER);
258                         mylog("IDOK: got ci = %u\n", ci);
259
260                         /*      Readonly */
261                         sprintf(ci->readonly, "%d", IsDlgButtonChecked(hdlg, DS_READONLY));
262
263                         /*      Protocol */
264                         if ( IsDlgButtonChecked(hdlg, DS_PG62))
265                                 strcpy(ci->protocol, PG62);
266                         else 
267                                 ci->protocol[0] = '\0';
268
269
270
271                         sprintf(ci->show_system_tables, "%d", IsDlgButtonChecked(hdlg, DS_SHOWSYSTEMTABLES));
272
273                         sprintf(ci->row_versioning, "%d", IsDlgButtonChecked(hdlg, DS_ROWVERSIONING));
274
275                         /*      OID Options*/
276                         sprintf(ci->fake_oid_index, "%d", IsDlgButtonChecked(hdlg, DS_FAKEOIDINDEX));
277                         sprintf(ci->show_oid_column, "%d", IsDlgButtonChecked(hdlg, DS_SHOWOIDCOLUMN));
278
279                         /*      Datasource Connection Settings */
280                         GetDlgItemText(hdlg, DS_CONNSETTINGS, ci->conn_settings, sizeof(ci->conn_settings));
281
282
283                         //      fall through
284
285                 case IDCANCEL:
286                         EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
287                         return TRUE;
288                 }
289         }
290
291         return FALSE;
292 }
293
294 #endif  /* !UNIX */
295
296 void
297 makeConnectString(char *connect_string, ConnInfo *ci)
298 {
299 char got_dsn = (ci->dsn[0] != '\0');
300 char encoded_conn_settings[LARGE_REGISTRY_LEN];
301
302         /*      fundamental info */
303         sprintf(connect_string, "%s=%s;DATABASE=%s;SERVER=%s;PORT=%s;UID=%s;PWD=%s",
304                 got_dsn ? "DSN" : "DRIVER", 
305                 got_dsn ? ci->dsn : ci->driver,
306                 ci->database,
307                 ci->server,
308                 ci->port,
309                 ci->username,
310                 ci->password);
311
312         encode(ci->conn_settings, encoded_conn_settings);
313
314         /*      extra info */
315         sprintf(&connect_string[strlen(connect_string)], 
316                 ";READONLY=%s;PROTOCOL=%s;FAKEOIDINDEX=%s;SHOWOIDCOLUMN=%s;ROWVERSIONING=%s;SHOWSYSTEMTABLES=%s;CONNSETTINGS=%s", 
317                 ci->readonly,
318                 ci->protocol,
319                 ci->fake_oid_index,
320                 ci->show_oid_column,
321                 ci->row_versioning,
322                 ci->show_system_tables,
323                 encoded_conn_settings);
324 }
325
326 void
327 copyAttributes(ConnInfo *ci, char *attribute, char *value)
328 {
329
330         if(stricmp(attribute, "DSN") == 0)
331                 strcpy(ci->dsn, value);
332
333         else if(stricmp(attribute, "driver") == 0)
334                 strcpy(ci->driver, value);
335
336         else if(stricmp(attribute, INI_DATABASE) == 0)
337                 strcpy(ci->database, value);
338
339         else if(stricmp(attribute, INI_SERVER) == 0 || stricmp(attribute, "server") == 0)
340                 strcpy(ci->server, value);
341
342         else if(stricmp(attribute, INI_USER) == 0 || stricmp(attribute, "uid") == 0)
343                 strcpy(ci->username, value);
344
345         else if(stricmp(attribute, INI_PASSWORD) == 0 || stricmp(attribute, "pwd") == 0)
346                 strcpy(ci->password, value);
347
348         else if(stricmp(attribute, INI_PORT) == 0)
349                 strcpy(ci->port, value);
350
351         else if (stricmp(attribute, INI_READONLY) == 0)
352                 strcpy(ci->readonly, value);
353
354         else if (stricmp(attribute, INI_PROTOCOL) == 0)
355                 strcpy(ci->protocol, value);
356
357         else if (stricmp(attribute, INI_SHOWOIDCOLUMN) == 0)
358                 strcpy(ci->show_oid_column, value);
359
360         else if (stricmp(attribute, INI_FAKEOIDINDEX) == 0)
361                 strcpy(ci->fake_oid_index, value);
362
363         else if (stricmp(attribute, INI_ROWVERSIONING) == 0)
364                 strcpy(ci->row_versioning, value);
365
366         else if (stricmp(attribute, INI_SHOWSYSTEMTABLES) == 0)
367                 strcpy(ci->show_system_tables, value);
368
369         else if (stricmp(attribute, INI_CONNSETTINGS) == 0) {
370                 decode(value, ci->conn_settings);
371                 // strcpy(ci->conn_settings, value);
372         }
373
374         mylog("copyAttributes: DSN='%s',server='%s',dbase='%s',user='%s',passwd='%s',port='%s',readonly='%s',protocol='%s', conn_settings='%s')\n", 
375                 ci->dsn, 
376                 ci->server,
377                 ci->database,
378                 ci->username,
379                 ci->password,
380                 ci->port,
381                 ci->readonly,
382                 ci->protocol,
383                 ci->conn_settings);
384
385 }
386
387 void
388 getDSNdefaults(ConnInfo *ci)
389 {
390         if (ci->port[0] == '\0')
391                 strcpy(ci->port, DEFAULT_PORT);
392
393         if (ci->readonly[0] == '\0')
394                 sprintf(ci->readonly, "%d", globals.readonly);
395
396         if (ci->fake_oid_index[0] == '\0')
397                 sprintf(ci->fake_oid_index, "%d", DEFAULT_FAKEOIDINDEX);
398
399         if (ci->show_oid_column[0] == '\0')
400                 sprintf(ci->show_oid_column, "%d", DEFAULT_SHOWOIDCOLUMN);
401
402         if (ci->show_system_tables[0] == '\0')
403                 sprintf(ci->show_system_tables, "%d", DEFAULT_SHOWSYSTEMTABLES);
404
405         if (ci->row_versioning[0] == '\0')
406                 sprintf(ci->row_versioning, "%d", DEFAULT_ROWVERSIONING);
407 }
408
409
410 void 
411 getDSNinfo(ConnInfo *ci, char overwrite)
412 {
413 char *DSN = ci->dsn;
414 char encoded_conn_settings[LARGE_REGISTRY_LEN];
415
416         //      If a driver keyword was present, then dont use a DSN and return.
417         //      If DSN is null and no driver, then use the default datasource.
418         if ( DSN[0] == '\0') {
419                 if ( ci->driver[0] != '\0')
420                         return;
421                 else
422                         strcpy(DSN, INI_DSN);
423         }
424
425         //      Proceed with getting info for the given DSN.
426
427         if ( ci->desc[0] == '\0' || overwrite)
428                 SQLGetPrivateProfileString(DSN, INI_KDESC, "", ci->desc, sizeof(ci->desc), ODBC_INI);
429
430         if ( ci->server[0] == '\0' || overwrite)
431                 SQLGetPrivateProfileString(DSN, INI_SERVER, "", ci->server, sizeof(ci->server), ODBC_INI);
432
433         if ( ci->database[0] == '\0' || overwrite)
434             SQLGetPrivateProfileString(DSN, INI_DATABASE, "", ci->database, sizeof(ci->database), ODBC_INI);
435
436         if ( ci->username[0] == '\0' || overwrite)
437                 SQLGetPrivateProfileString(DSN, INI_USER, "", ci->username, sizeof(ci->username), ODBC_INI);
438
439         if ( ci->password[0] == '\0' || overwrite)
440                 SQLGetPrivateProfileString(DSN, INI_PASSWORD, "", ci->password, sizeof(ci->password), ODBC_INI);
441
442         if ( ci->port[0] == '\0' || overwrite)
443                 SQLGetPrivateProfileString(DSN, INI_PORT, "", ci->port, sizeof(ci->port), ODBC_INI);
444
445         if ( ci->readonly[0] == '\0' || overwrite)
446                 SQLGetPrivateProfileString(DSN, INI_READONLY, "", ci->readonly, sizeof(ci->readonly), ODBC_INI);
447
448         if ( ci->show_oid_column[0] == '\0' || overwrite)
449                 SQLGetPrivateProfileString(DSN, INI_SHOWOIDCOLUMN, "", ci->show_oid_column, sizeof(ci->show_oid_column), ODBC_INI);
450
451         if ( ci->fake_oid_index[0] == '\0' || overwrite)
452                 SQLGetPrivateProfileString(DSN, INI_FAKEOIDINDEX, "", ci->fake_oid_index, sizeof(ci->fake_oid_index), ODBC_INI);
453
454         if ( ci->row_versioning[0] == '\0' || overwrite)
455                 SQLGetPrivateProfileString(DSN, INI_ROWVERSIONING, "", ci->row_versioning, sizeof(ci->row_versioning), ODBC_INI);
456
457         if ( ci->show_system_tables[0] == '\0' || overwrite)
458                 SQLGetPrivateProfileString(DSN, INI_SHOWSYSTEMTABLES, "", ci->show_system_tables, sizeof(ci->show_system_tables), ODBC_INI);
459
460         if ( ci->protocol[0] == '\0' || overwrite)
461                 SQLGetPrivateProfileString(DSN, INI_PROTOCOL, "", ci->protocol, sizeof(ci->protocol), ODBC_INI);
462
463         if ( ci->conn_settings[0] == '\0' || overwrite) {
464                 SQLGetPrivateProfileString(DSN, INI_CONNSETTINGS, "", encoded_conn_settings, sizeof(encoded_conn_settings), ODBC_INI);
465                 decode(encoded_conn_settings, ci->conn_settings);
466         }
467
468         if ( ci->translation_dll[0] == '\0' || overwrite)
469                 SQLGetPrivateProfileString(DSN, INI_TRANSLATIONDLL, "", ci->translation_dll, sizeof(ci->translation_dll), ODBC_INI);
470
471         if ( ci->translation_option[0] == '\0' || overwrite)
472                 SQLGetPrivateProfileString(DSN, INI_TRANSLATIONOPTION, "", ci->translation_option, sizeof(ci->translation_option), ODBC_INI);
473
474         qlog("DSN info: DSN='%s',server='%s',port='%s',dbase='%s',user='%s',passwd='%s'\n", 
475                 DSN, 
476                 ci->server,
477                 ci->port,
478                 ci->database,
479                 ci->username,
480                 ci->password);
481         qlog("          readonly='%s',protocol='%s',showoid='%s',fakeoidindex='%s',showsystable='%s'\n",
482                 ci->readonly,
483                 ci->protocol,
484                 ci->show_oid_column,
485                 ci->fake_oid_index,
486                 ci->show_system_tables);
487         qlog("          conn_settings='%s'\n",
488                 ci->conn_settings);
489         qlog("          translation_dll='%s',translation_option='%s'\n",
490                 ci->translation_dll,
491                 ci->translation_option);
492
493 }
494
495
496 /*      This is for datasource based options only */
497 void
498 writeDSNinfo(ConnInfo *ci)
499 {
500 char *DSN = ci->dsn;
501 char encoded_conn_settings[LARGE_REGISTRY_LEN];
502
503                 encode(ci->conn_settings, encoded_conn_settings);
504
505                 SQLWritePrivateProfileString(DSN,
506                         INI_KDESC,
507                         ci->desc,
508                         ODBC_INI);
509                         
510                 SQLWritePrivateProfileString(DSN,
511                         INI_DATABASE,
512                         ci->database,
513                         ODBC_INI);
514                         
515                 SQLWritePrivateProfileString(DSN,
516                         INI_SERVER,
517                         ci->server,
518                         ODBC_INI);
519
520                 SQLWritePrivateProfileString(DSN,
521                         INI_PORT,
522                         ci->port,
523                         ODBC_INI);
524
525                 SQLWritePrivateProfileString(DSN,
526                         INI_USER,
527                         ci->username,
528                         ODBC_INI);
529
530                 SQLWritePrivateProfileString(DSN,
531                         INI_PASSWORD,
532                         ci->password,
533                         ODBC_INI);
534
535                 SQLWritePrivateProfileString(DSN,
536                         INI_READONLY,
537                         ci->readonly,
538                         ODBC_INI);
539
540                 SQLWritePrivateProfileString(DSN,
541                         INI_SHOWOIDCOLUMN,
542                         ci->show_oid_column,
543                         ODBC_INI);
544
545                 SQLWritePrivateProfileString(DSN,
546                         INI_FAKEOIDINDEX,
547                         ci->fake_oid_index,
548                         ODBC_INI);
549
550                 SQLWritePrivateProfileString(DSN,
551                         INI_ROWVERSIONING,
552                         ci->row_versioning,
553                         ODBC_INI);
554
555                 SQLWritePrivateProfileString(DSN,
556                         INI_SHOWSYSTEMTABLES,
557                         ci->show_system_tables,
558                         ODBC_INI);
559
560                 SQLWritePrivateProfileString(DSN,
561                         INI_PROTOCOL,
562                         ci->protocol,
563                         ODBC_INI);
564
565                 SQLWritePrivateProfileString(DSN,
566                         INI_CONNSETTINGS,
567                         encoded_conn_settings,
568                         ODBC_INI);
569 }
570
571
572 /*      This function reads the ODBCINST.INI portion of
573         the registry and gets any driver defaults.
574 */
575 void getGlobalDefaults(void)
576 {
577 char temp[128];
578
579
580         //      Fetch Count is stored in driver section
581     SQLGetPrivateProfileString(DBMS_NAME, INI_FETCH, "",
582                             temp, sizeof(temp), ODBCINST_INI);
583         if ( temp[0] ) {
584                 globals.fetch_max = atoi(temp);
585                 /*      sanity check if using cursors */
586                 if (globals.fetch_max <= 0)
587                         globals.fetch_max = FETCH_MAX;
588         }
589
590         else
591                 globals.fetch_max = FETCH_MAX;
592
593
594         //      Socket Buffersize is stored in driver section
595     SQLGetPrivateProfileString(DBMS_NAME, INI_SOCKET, "",
596                             temp, sizeof(temp), ODBCINST_INI);
597         if ( temp[0] ) 
598                 globals.socket_buffersize = atoi(temp);
599         else
600                 globals.socket_buffersize = SOCK_BUFFER_SIZE;
601
602
603         //      Debug is stored in the driver section
604         SQLGetPrivateProfileString(DBMS_NAME, INI_DEBUG, "0", 
605                                                         temp, sizeof(temp), ODBCINST_INI);
606         globals.debug = atoi(temp);
607
608
609         //      CommLog is stored in the driver section
610         SQLGetPrivateProfileString(DBMS_NAME, INI_COMMLOG, "", 
611                                                         temp, sizeof(temp), ODBCINST_INI);
612         if ( temp[0] == '\0') 
613                 globals.commlog = DEFAULT_COMMLOG;
614         else
615                 globals.commlog = atoi(temp);
616
617
618         //      Optimizer is stored in the driver section only
619         SQLGetPrivateProfileString(DBMS_NAME, INI_OPTIMIZER, "", 
620                                 temp, sizeof(temp), ODBCINST_INI);
621         if ( temp[0] == '\0') 
622                 globals.disable_optimizer = DEFAULT_OPTIMIZER;
623         else
624                 globals.disable_optimizer = atoi(temp);
625
626
627         //      Recognize Unique Index is stored in the driver section only
628         SQLGetPrivateProfileString(DBMS_NAME, INI_UNIQUEINDEX, "", 
629                                 temp, sizeof(temp), ODBCINST_INI);
630         if ( temp[0] == '\0') 
631                 globals.unique_index = DEFAULT_UNIQUEINDEX;
632         else
633                 globals.unique_index = atoi(temp);
634
635
636         //      Unknown Sizes is stored in the driver section only
637         SQLGetPrivateProfileString(DBMS_NAME, INI_UNKNOWNSIZES, "", 
638                                 temp, sizeof(temp), ODBCINST_INI);
639         if ( temp[0] == '\0')
640                 globals.unknown_sizes = DEFAULT_UNKNOWNSIZES;
641         else
642                 globals.unknown_sizes = atoi(temp);
643
644
645         //      Lie about supported functions?
646         SQLGetPrivateProfileString(DBMS_NAME, INI_LIE, "", 
647                                 temp, sizeof(temp), ODBCINST_INI);
648         if ( temp[0] == '\0') 
649                 globals.lie = DEFAULT_LIE;
650         else
651                 globals.lie = atoi(temp);
652
653         //      Parse statements
654         SQLGetPrivateProfileString(DBMS_NAME, INI_PARSE, "", 
655                                 temp, sizeof(temp), ODBCINST_INI);
656         if ( temp[0] == '\0') 
657                 globals.parse = DEFAULT_PARSE;
658         else
659                 globals.parse = atoi(temp);
660
661         //      Readonly is stored in the driver section AND per datasource
662         SQLGetPrivateProfileString(DBMS_NAME, INI_READONLY, "", 
663                                 temp, sizeof(temp), ODBCINST_INI);
664         if ( temp[0] == '\0') 
665                 globals.readonly = DEFAULT_READONLY;
666         else
667                 globals.readonly = atoi(temp);
668
669
670         //      UseDeclareFetch is stored in the driver section only
671         SQLGetPrivateProfileString(DBMS_NAME, INI_USEDECLAREFETCH, "", 
672                                 temp, sizeof(temp), ODBCINST_INI);
673         if ( temp[0] == '\0') 
674                 globals.use_declarefetch = DEFAULT_USEDECLAREFETCH;
675         else
676                 globals.use_declarefetch = atoi(temp);
677
678
679         //      Max Varchar Size
680         SQLGetPrivateProfileString(DBMS_NAME, INI_MAXVARCHARSIZE, "", 
681                                 temp, sizeof(temp), ODBCINST_INI);
682         if ( temp[0] == '\0') 
683                 globals.max_varchar_size = MAX_VARCHAR_SIZE;
684         else
685                 globals.max_varchar_size = atoi(temp);
686
687         //      Max TextField Size
688         SQLGetPrivateProfileString(DBMS_NAME, INI_MAXLONGVARCHARSIZE, "", 
689                                 temp, sizeof(temp), ODBCINST_INI);
690         if ( temp[0] == '\0') 
691                 globals.max_longvarchar_size = TEXT_FIELD_SIZE;
692         else
693                 globals.max_longvarchar_size = atoi(temp);
694
695         //      Text As LongVarchar 
696         SQLGetPrivateProfileString(DBMS_NAME, INI_TEXTASLONGVARCHAR, "", 
697                                 temp, sizeof(temp), ODBCINST_INI);
698         if ( temp[0] == '\0') 
699                 globals.text_as_longvarchar = DEFAULT_TEXTASLONGVARCHAR;
700         else
701                 globals.text_as_longvarchar = atoi(temp);
702
703         //      Unknowns As LongVarchar 
704         SQLGetPrivateProfileString(DBMS_NAME, INI_UNKNOWNSASLONGVARCHAR, "", 
705                                 temp, sizeof(temp), ODBCINST_INI);
706         if ( temp[0] == '\0') 
707                 globals.unknowns_as_longvarchar = DEFAULT_UNKNOWNSASLONGVARCHAR;
708         else
709                 globals.unknowns_as_longvarchar = atoi(temp);
710
711         //      Bools As Char
712         SQLGetPrivateProfileString(DBMS_NAME, INI_BOOLSASCHAR, "", 
713                                 temp, sizeof(temp), ODBCINST_INI);
714         if ( temp[0] == '\0') 
715                 globals.bools_as_char = DEFAULT_BOOLSASCHAR;
716         else
717                 globals.bools_as_char = atoi(temp);
718
719
720         //      Extra System Table prefixes
721         SQLGetPrivateProfileString(DBMS_NAME, INI_EXTRASYSTABLEPREFIXES, "@@@", 
722                         globals.extra_systable_prefixes, sizeof(globals.extra_systable_prefixes), ODBCINST_INI);
723         if ( ! strcmp(globals.extra_systable_prefixes, "@@@")) {
724                 strcpy(globals.extra_systable_prefixes, DEFAULT_EXTRASYSTABLEPREFIXES);
725         }
726         mylog("globals.extra_systable_prefixes = '%s'\n", globals.extra_systable_prefixes);
727
728
729         //      ConnSettings is stored in the driver section and per datasource for override
730         SQLGetPrivateProfileString(DBMS_NAME, INI_CONNSETTINGS, "", 
731                                 globals.conn_settings, sizeof(globals.conn_settings), ODBCINST_INI);
732
733
734 }
735
736
737 /*      This function writes any global parameters (that can be manipulated)
738         to the ODBCINST.INI portion of the registry 
739 */
740 void updateGlobals(void)
741 {
742 char tmp[128];
743
744         sprintf(tmp, "%d", globals.fetch_max);
745         SQLWritePrivateProfileString(DBMS_NAME,
746                 INI_FETCH, tmp, ODBCINST_INI);
747
748         sprintf(tmp, "%d", globals.commlog);
749         SQLWritePrivateProfileString(DBMS_NAME,
750                 INI_COMMLOG, tmp, ODBCINST_INI);
751
752         sprintf(tmp, "%d", globals.disable_optimizer);
753         SQLWritePrivateProfileString(DBMS_NAME,
754                 INI_OPTIMIZER, tmp, ODBCINST_INI);
755
756         sprintf(tmp, "%d", globals.unique_index);
757         SQLWritePrivateProfileString(DBMS_NAME,
758                 INI_UNIQUEINDEX, tmp, ODBCINST_INI);
759
760         sprintf(tmp, "%d", globals.readonly);
761         SQLWritePrivateProfileString(DBMS_NAME,
762                 INI_READONLY, tmp, ODBCINST_INI);
763
764         sprintf(tmp, "%d", globals.use_declarefetch);
765         SQLWritePrivateProfileString(DBMS_NAME,
766                 INI_USEDECLAREFETCH, tmp, ODBCINST_INI);
767
768         sprintf(tmp, "%d", globals.unknown_sizes);
769         SQLWritePrivateProfileString(DBMS_NAME,
770                 INI_UNKNOWNSIZES, tmp, ODBCINST_INI);
771
772         sprintf(tmp, "%d", globals.text_as_longvarchar);
773         SQLWritePrivateProfileString(DBMS_NAME,
774                 INI_TEXTASLONGVARCHAR, tmp, ODBCINST_INI);
775
776         sprintf(tmp, "%d", globals.unknowns_as_longvarchar);
777         SQLWritePrivateProfileString(DBMS_NAME,
778                 INI_UNKNOWNSASLONGVARCHAR, tmp, ODBCINST_INI);
779
780         sprintf(tmp, "%d", globals.bools_as_char);
781         SQLWritePrivateProfileString(DBMS_NAME,
782                 INI_BOOLSASCHAR, tmp, ODBCINST_INI);
783
784         sprintf(tmp, "%d", globals.parse);
785         SQLWritePrivateProfileString(DBMS_NAME,
786                 INI_PARSE, tmp, ODBCINST_INI);
787
788         sprintf(tmp, "%d", globals.max_varchar_size);
789         SQLWritePrivateProfileString(DBMS_NAME,
790                 INI_MAXVARCHARSIZE, tmp, ODBCINST_INI);
791
792         sprintf(tmp, "%d", globals.max_longvarchar_size);
793         SQLWritePrivateProfileString(DBMS_NAME,
794                 INI_MAXLONGVARCHARSIZE, tmp, ODBCINST_INI);
795
796         SQLWritePrivateProfileString(DBMS_NAME,
797                 INI_EXTRASYSTABLEPREFIXES, globals.extra_systable_prefixes, ODBCINST_INI);
798
799         SQLWritePrivateProfileString(DBMS_NAME,
800                 INI_CONNSETTINGS, globals.conn_settings, ODBCINST_INI);
801 }