dlg_specific.c 34.6 KB
Newer Older
1 2
/*-------
 * Module:			dlg_specific.c
3
 *
4 5 6 7 8 9
 * Description:		This module contains any specific code for handling
 *					dialog boxes such as driver/datasource options.  Both the
 *					ConfigDSN() and the SQLDriverConnect() functions use
 *					functions in this module.  If you were to add a new option
 *					to any dialog box, you would most likely only have to change
 *					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
 */
Hiroshi Inoue's avatar
Hiroshi Inoue committed
18
/* Multibyte support	Eiji Tokuya 2001-03-15 */
19 20

#include "dlg_specific.h"
21

Byron Nikolaidis's avatar
Byron Nikolaidis committed
22
#include "convert.h"
23

Hiroshi Inoue's avatar
Hiroshi Inoue committed
24 25 26
#ifdef MULTIBYTE
#include "multibyte.h"
#endif
27
#include "pgapifunc.h"
Hiroshi Inoue's avatar
Hiroshi Inoue committed
28

29 30 31 32 33 34 35 36 37 38
#ifndef BOOL
#define BOOL	int
#endif
#ifndef FALSE
#define FALSE	(BOOL)0
#endif
#ifndef TRUE
#define TRUE	(BOOL)1
#endif

39
extern GLOBAL_VALUES globals;
40

41
#ifdef	WIN32
42
static int	driver_optionsDraw(HWND, const ConnInfo *, int src, BOOL enable);
43 44
static int	driver_options_update(HWND hdlg, ConnInfo *ci, BOOL);
static void updateCommons(const ConnInfo *ci);
45
#endif
46

47
#ifdef WIN32
48
void
49
SetDlgStuff(HWND hdlg, const ConnInfo *ci)
50
{
51 52 53 54 55 56
	/*
	 * If driver attribute NOT present, then set the datasource name and
	 * description
	 */
	if (ci->driver[0] == '\0')
	{
57 58 59 60 61 62 63 64 65 66 67
		SetDlgItemText(hdlg, IDC_DSNAME, ci->dsn);
		SetDlgItemText(hdlg, IDC_DESC, ci->desc);
	}

	SetDlgItemText(hdlg, IDC_DATABASE, ci->database);
	SetDlgItemText(hdlg, IDC_SERVER, ci->server);
	SetDlgItemText(hdlg, IDC_USER, ci->username);
	SetDlgItemText(hdlg, IDC_PASSWORD, ci->password);
	SetDlgItemText(hdlg, IDC_PORT, ci->port);
}

68

69
void
70
GetDlgStuff(HWND hdlg, ConnInfo *ci)
71 72 73 74 75 76 77 78 79 80 81
{
	GetDlgItemText(hdlg, IDC_DESC, ci->desc, sizeof(ci->desc));

	GetDlgItemText(hdlg, IDC_DATABASE, ci->database, sizeof(ci->database));
	GetDlgItemText(hdlg, IDC_SERVER, ci->server, sizeof(ci->server));
	GetDlgItemText(hdlg, IDC_USER, ci->username, sizeof(ci->username));
	GetDlgItemText(hdlg, IDC_PASSWORD, ci->password, sizeof(ci->password));
	GetDlgItemText(hdlg, IDC_PORT, ci->port, sizeof(ci->port));
}


82
static int
83
driver_optionsDraw(HWND hdlg, const ConnInfo *ci, int src, BOOL enable)
84
{
85 86 87 88
	const GLOBAL_VALUES *comval;
	static BOOL defset = FALSE;
	static GLOBAL_VALUES defval;

89
	switch (src)
90
	{
91
		case 0:			/* driver common */
92 93
			comval = &globals;
			break;
94
		case 1:			/* dsn specific */
95 96
			comval = &(ci->drivers);
			break;
97
		case 2:			/* default */
98
			if (!defset)
99
			{
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
				defval.commlog = DEFAULT_COMMLOG;
				defval.disable_optimizer = DEFAULT_OPTIMIZER;
				defval.ksqo = DEFAULT_KSQO;
				defval.unique_index = DEFAULT_UNIQUEINDEX;
				defval.onlyread = DEFAULT_READONLY;
				defval.use_declarefetch = DEFAULT_USEDECLAREFETCH;

				defval.parse = DEFAULT_PARSE;
				defval.cancel_as_freestmt = DEFAULT_CANCELASFREESTMT;
				defval.debug = DEFAULT_DEBUG;

				/* Unknown Sizes */
				defval.unknown_sizes = DEFAULT_UNKNOWNSIZES;
				defval.text_as_longvarchar = DEFAULT_TEXTASLONGVARCHAR;
				defval.unknowns_as_longvarchar = DEFAULT_UNKNOWNSASLONGVARCHAR;
				defval.bools_as_char = DEFAULT_BOOLSASCHAR;
116
			}
117 118 119 120
			defset = TRUE;
			comval = &defval;
			break;
	}
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
	CheckDlgButton(hdlg, DRV_COMMLOG, comval->commlog);
	CheckDlgButton(hdlg, DRV_OPTIMIZER, comval->disable_optimizer);
	CheckDlgButton(hdlg, DRV_KSQO, comval->ksqo);
	CheckDlgButton(hdlg, DRV_UNIQUEINDEX, comval->unique_index);
	EnableWindow(GetDlgItem(hdlg, DRV_UNIQUEINDEX), enable);
	CheckDlgButton(hdlg, DRV_READONLY, comval->onlyread);
	EnableWindow(GetDlgItem(hdlg, DRV_READONLY), enable);
	CheckDlgButton(hdlg, DRV_USEDECLAREFETCH, comval->use_declarefetch);

	/* Unknown Sizes clear */
	CheckDlgButton(hdlg, DRV_UNKNOWN_DONTKNOW, 0);
	CheckDlgButton(hdlg, DRV_UNKNOWN_LONGEST, 0);
	CheckDlgButton(hdlg, DRV_UNKNOWN_MAX, 0);
	/* Unknown (Default) Data Type sizes */
	switch (comval->unknown_sizes)
	{
		case UNKNOWNS_AS_DONTKNOW:
			CheckDlgButton(hdlg, DRV_UNKNOWN_DONTKNOW, 1);
			break;
		case UNKNOWNS_AS_LONGEST:
			CheckDlgButton(hdlg, DRV_UNKNOWN_LONGEST, 1);
			break;
		case UNKNOWNS_AS_MAX:
		default:
			CheckDlgButton(hdlg, DRV_UNKNOWN_MAX, 1);
			break;
	}
149

150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
	CheckDlgButton(hdlg, DRV_TEXT_LONGVARCHAR, comval->text_as_longvarchar);
	CheckDlgButton(hdlg, DRV_UNKNOWNS_LONGVARCHAR, comval->unknowns_as_longvarchar);
	CheckDlgButton(hdlg, DRV_BOOLS_CHAR, comval->bools_as_char);
	CheckDlgButton(hdlg, DRV_PARSE, comval->parse);
	CheckDlgButton(hdlg, DRV_CANCELASFREESTMT, comval->cancel_as_freestmt);
	CheckDlgButton(hdlg, DRV_DEBUG, comval->debug);
	SetDlgItemInt(hdlg, DRV_CACHE_SIZE, comval->fetch_max, FALSE);
	SetDlgItemInt(hdlg, DRV_VARCHAR_SIZE, comval->max_varchar_size, FALSE);
	SetDlgItemInt(hdlg, DRV_LONGVARCHAR_SIZE, comval->max_longvarchar_size, TRUE);
	SetDlgItemText(hdlg, DRV_EXTRASYSTABLEPREFIXES, comval->extra_systable_prefixes);

	/* Driver Connection Settings */
	SetDlgItemText(hdlg, DRV_CONNSETTINGS, comval->conn_settings);
	EnableWindow(GetDlgItem(hdlg, DRV_CONNSETTINGS), enable);
	return 0;
}
static int
167
driver_options_update(HWND hdlg, ConnInfo *ci, BOOL updateProfile)
168
{
169
	GLOBAL_VALUES *comval;
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

	if (ci)
		comval = &(ci->drivers);
	else
		comval = &globals;
	comval->commlog = IsDlgButtonChecked(hdlg, DRV_COMMLOG);
	comval->disable_optimizer = IsDlgButtonChecked(hdlg, DRV_OPTIMIZER);
	comval->ksqo = IsDlgButtonChecked(hdlg, DRV_KSQO);
	if (!ci)
	{
		comval->unique_index = IsDlgButtonChecked(hdlg, DRV_UNIQUEINDEX);
		comval->onlyread = IsDlgButtonChecked(hdlg, DRV_READONLY);
	}
	comval->use_declarefetch = IsDlgButtonChecked(hdlg, DRV_USEDECLAREFETCH);

	/* Unknown (Default) Data Type sizes */
	if (IsDlgButtonChecked(hdlg, DRV_UNKNOWN_MAX))
		comval->unknown_sizes = UNKNOWNS_AS_MAX;
	else if (IsDlgButtonChecked(hdlg, DRV_UNKNOWN_DONTKNOW))
		comval->unknown_sizes = UNKNOWNS_AS_DONTKNOW;
	else if (IsDlgButtonChecked(hdlg, DRV_UNKNOWN_LONGEST))
		comval->unknown_sizes = UNKNOWNS_AS_LONGEST;
	else
		comval->unknown_sizes = UNKNOWNS_AS_MAX;

	comval->text_as_longvarchar = IsDlgButtonChecked(hdlg, DRV_TEXT_LONGVARCHAR);
	comval->unknowns_as_longvarchar = IsDlgButtonChecked(hdlg, DRV_UNKNOWNS_LONGVARCHAR);
	comval->bools_as_char = IsDlgButtonChecked(hdlg, DRV_BOOLS_CHAR);

	comval->parse = IsDlgButtonChecked(hdlg, DRV_PARSE);

	comval->cancel_as_freestmt = IsDlgButtonChecked(hdlg, DRV_CANCELASFREESTMT);
	comval->debug = IsDlgButtonChecked(hdlg, DRV_DEBUG);

	comval->fetch_max = GetDlgItemInt(hdlg, DRV_CACHE_SIZE, NULL, FALSE);
	comval->max_varchar_size = GetDlgItemInt(hdlg, DRV_VARCHAR_SIZE, NULL, FALSE);
	comval->max_longvarchar_size = GetDlgItemInt(hdlg, DRV_LONGVARCHAR_SIZE, NULL, TRUE);		/* allows for
207
																								 * SQL_NO_TOTAL */
208

209
	GetDlgItemText(hdlg, DRV_EXTRASYSTABLEPREFIXES, comval->extra_systable_prefixes, sizeof(comval->extra_systable_prefixes));
210

211 212 213
	/* Driver Connection Settings */
	if (!ci)
		GetDlgItemText(hdlg, DRV_CONNSETTINGS, comval->conn_settings, sizeof(comval->conn_settings));
214

215 216
	if (updateProfile)
		updateCommons(ci);
217

218 219 220
	/* fall through */
	return 0;
}
221

222 223 224 225 226 227
int			CALLBACK
driver_optionsProc(HWND hdlg,
				   WORD wMsg,
				   WPARAM wParam,
				   LPARAM lParam)
{
228 229
	ConnInfo   *ci;

230 231 232
	switch (wMsg)
	{
		case WM_INITDIALOG:
233
			SetWindowLong(hdlg, DWL_USER, lParam);		/* save for OK etc */
234
			ci = (ConnInfo *) lParam;
Hiroshi Inoue's avatar
Hiroshi Inoue committed
235
			CheckDlgButton(hdlg, DRV_OR_DSN, 0);
236
			if (ci && ci->dsn && ci->dsn[0])
Hiroshi Inoue's avatar
Hiroshi Inoue committed
237
				SetWindowText(hdlg, "Advanced Options (per DSN)");
238 239
			else
			{
240
				SetWindowText(hdlg, "Advanced Options (Connection)");
241 242
				ShowWindow(GetDlgItem(hdlg, DRV_OR_DSN), SW_HIDE);
			}
Hiroshi Inoue's avatar
Hiroshi Inoue committed
243
			driver_optionsDraw(hdlg, ci, 1, FALSE);
244
			break;
245

246 247 248 249
		case WM_COMMAND:
			switch (GET_WM_COMMAND_ID(wParam, lParam))
			{
				case IDOK:
250
					ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
Hiroshi Inoue's avatar
Hiroshi Inoue committed
251
					driver_options_update(hdlg, IsDlgButtonChecked(hdlg, DRV_OR_DSN) ? NULL : ci,
252
										  ci && ci->dsn && ci->dsn[0]);
253 254 255 256 257 258

				case IDCANCEL:
					EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
					return TRUE;

				case IDDEFAULTS:
259
					if (IsDlgButtonChecked(hdlg, DRV_OR_DSN))
Hiroshi Inoue's avatar
Hiroshi Inoue committed
260 261
						driver_optionsDraw(hdlg, NULL, 2, TRUE);
					else
262
					{
263
						ConnInfo   *ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
264

265
						driver_optionsDraw(hdlg, ci, 0, FALSE);
266
					}
267
					break;
268

269 270 271 272 273 274
				case DRV_OR_DSN:
					if (GET_WM_COMMAND_CMD(wParam, lParam) == BN_CLICKED)
					{
						mylog("DRV_OR_DSN clicked\n");
						if (IsDlgButtonChecked(hdlg, DRV_OR_DSN))
						{
Hiroshi Inoue's avatar
Hiroshi Inoue committed
275 276
							SetWindowText(hdlg, "Advanced Options (Common)");
							driver_optionsDraw(hdlg, NULL, 0, TRUE);
277 278
						}
						else
279
						{
Hiroshi Inoue's avatar
Hiroshi Inoue committed
280
							ConnInfo   *ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
281

Hiroshi Inoue's avatar
Hiroshi Inoue committed
282 283
							SetWindowText(hdlg, "Advanced Options (per DSN)");
							driver_optionsDraw(hdlg, ci, ci ? 1 : 0, ci == NULL);
284
						}
285
					}
286
					break;
287 288 289 290 291 292
			}
	}

	return FALSE;
}

293

294
int			CALLBACK
295 296 297 298
ds_optionsProc(HWND hdlg,
			   WORD wMsg,
			   WPARAM wParam,
			   LPARAM lParam)
299
{
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
	ConnInfo   *ci;
	char		buf[128];

	switch (wMsg)
	{
		case WM_INITDIALOG:
			ci = (ConnInfo *) lParam;
			SetWindowLong(hdlg, DWL_USER, lParam);		/* save for OK */

			/* Change window caption */
			if (ci->driver[0])
				SetWindowText(hdlg, "Advanced Options (Connection)");
			else
			{
				sprintf(buf, "Advanced Options (%s)", ci->dsn);
				SetWindowText(hdlg, buf);
			}
317

318 319
			/* Readonly */
			CheckDlgButton(hdlg, DS_READONLY, atoi(ci->onlyread));
320

321 322 323 324 325 326
			/* Protocol */
			if (strncmp(ci->protocol, PG62, strlen(PG62)) == 0)
				CheckDlgButton(hdlg, DS_PG62, 1);
			else if (strncmp(ci->protocol, PG63, strlen(PG63)) == 0)
				CheckDlgButton(hdlg, DS_PG63, 1);
			else
327
				/* latest */
328
				CheckDlgButton(hdlg, DS_PG64, 1);
329

330 331 332 333
			CheckDlgButton(hdlg, DS_SHOWOIDCOLUMN, atoi(ci->show_oid_column));
			CheckDlgButton(hdlg, DS_FAKEOIDINDEX, atoi(ci->fake_oid_index));
			CheckDlgButton(hdlg, DS_ROWVERSIONING, atoi(ci->row_versioning));
			CheckDlgButton(hdlg, DS_SHOWSYSTEMTABLES, atoi(ci->show_system_tables));
334
			CheckDlgButton(hdlg, DS_DISALLOWPREMATURE, ci->disallow_premature);
335

336
			EnableWindow(GetDlgItem(hdlg, DS_FAKEOIDINDEX), atoi(ci->show_oid_column));
337

338 339 340
			/* Datasource Connection Settings */
			SetDlgItemText(hdlg, DS_CONNSETTINGS, ci->conn_settings);
			break;
341

342 343 344 345 346 347 348
		case WM_COMMAND:
			switch (GET_WM_COMMAND_ID(wParam, lParam))
			{
				case DS_SHOWOIDCOLUMN:
					mylog("WM_COMMAND: DS_SHOWOIDCOLUMN\n");
					EnableWindow(GetDlgItem(hdlg, DS_FAKEOIDINDEX), IsDlgButtonChecked(hdlg, DS_SHOWOIDCOLUMN));
					return TRUE;
349

350 351 352
				case IDOK:
					ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
					mylog("IDOK: got ci = %u\n", ci);
353

354 355
					/* Readonly */
					sprintf(ci->onlyread, "%d", IsDlgButtonChecked(hdlg, DS_READONLY));
356

357 358 359 360 361 362
					/* Protocol */
					if (IsDlgButtonChecked(hdlg, DS_PG62))
						strcpy(ci->protocol, PG62);
					else if (IsDlgButtonChecked(hdlg, DS_PG63))
						strcpy(ci->protocol, PG63);
					else
363
						/* latest */
364
						strcpy(ci->protocol, PG64);
365

366
					sprintf(ci->show_system_tables, "%d", IsDlgButtonChecked(hdlg, DS_SHOWSYSTEMTABLES));
367

368
					sprintf(ci->row_versioning, "%d", IsDlgButtonChecked(hdlg, DS_ROWVERSIONING));
369
					ci->disallow_premature = IsDlgButtonChecked(hdlg, DS_DISALLOWPREMATURE);
Byron Nikolaidis's avatar
Byron Nikolaidis committed
370

371 372 373
					/* OID Options */
					sprintf(ci->fake_oid_index, "%d", IsDlgButtonChecked(hdlg, DS_FAKEOIDINDEX));
					sprintf(ci->show_oid_column, "%d", IsDlgButtonChecked(hdlg, DS_SHOWOIDCOLUMN));
374

375 376
					/* Datasource Connection Settings */
					GetDlgItemText(hdlg, DS_CONNSETTINGS, ci->conn_settings, sizeof(ci->conn_settings));
377

378
					/* fall through */
379

380 381 382 383
				case IDCANCEL:
					EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
					return TRUE;
			}
384 385 386 387 388
	}

	return FALSE;
}

389 390 391 392 393
/*
 *	This function writes any global parameters (that can be manipulated)
 *	to the ODBCINST.INI portion of the registry
 */
static void
394
updateCommons(const ConnInfo *ci)
395
{
396 397 398
	const char *sectionName;
	const char *fileName;
	const GLOBAL_VALUES *comval;
399 400 401 402 403 404 405 406 407 408 409 410 411 412
	char		tmp[128];

	if (ci)
		if (ci->dsn && ci->dsn[0])
		{
			mylog("DSN=%s updating\n", ci->dsn);
			comval = &(ci->drivers);
			sectionName = ci->dsn;
			fileName = ODBC_INI;
		}
		else
		{
			mylog("ci but dsn==NULL\n");
			return;
413
		}
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
	else
	{
		mylog("drivers updating\n");
		comval = &globals;
		sectionName = DBMS_NAME;
		fileName = ODBCINST_INI;
	}
	sprintf(tmp, "%d", comval->fetch_max);
	SQLWritePrivateProfileString(sectionName,
								 INI_FETCH, tmp, fileName);

	sprintf(tmp, "%d", comval->commlog);
	SQLWritePrivateProfileString(sectionName,
								 INI_COMMLOG, tmp, fileName);

	sprintf(tmp, "%d", comval->debug);
	SQLWritePrivateProfileString(sectionName,
								 INI_DEBUG, tmp, fileName);

	sprintf(tmp, "%d", comval->disable_optimizer);
	SQLWritePrivateProfileString(sectionName,
								 INI_OPTIMIZER, tmp, fileName);

	sprintf(tmp, "%d", comval->ksqo);
	SQLWritePrivateProfileString(sectionName,
								 INI_KSQO, tmp, fileName);

441
	/*
442
	 * Never update the onlyread, unique_index from this module.
443
	 */
444 445 446 447
	if (!ci)
	{
		sprintf(tmp, "%d", comval->unique_index);
		SQLWritePrivateProfileString(sectionName, INI_UNIQUEINDEX, tmp,
448
									 fileName);
449

450 451 452
		sprintf(tmp, "%d", comval->onlyread);
		SQLWritePrivateProfileString(sectionName, INI_READONLY, tmp,
									 fileName);
453
	}
454 455 456 457 458 459 460 461 462 463 464

	sprintf(tmp, "%d", comval->use_declarefetch);
	SQLWritePrivateProfileString(sectionName,
								 INI_USEDECLAREFETCH, tmp, fileName);

	sprintf(tmp, "%d", comval->unknown_sizes);
	SQLWritePrivateProfileString(sectionName,
								 INI_UNKNOWNSIZES, tmp, fileName);

	sprintf(tmp, "%d", comval->text_as_longvarchar);
	SQLWritePrivateProfileString(sectionName,
465
								 INI_TEXTASLONGVARCHAR, tmp, fileName);
466 467 468

	sprintf(tmp, "%d", comval->unknowns_as_longvarchar);
	SQLWritePrivateProfileString(sectionName,
469
							   INI_UNKNOWNSASLONGVARCHAR, tmp, fileName);
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488

	sprintf(tmp, "%d", comval->bools_as_char);
	SQLWritePrivateProfileString(sectionName,
								 INI_BOOLSASCHAR, tmp, fileName);

	sprintf(tmp, "%d", comval->parse);
	SQLWritePrivateProfileString(sectionName,
								 INI_PARSE, tmp, fileName);

	sprintf(tmp, "%d", comval->cancel_as_freestmt);
	SQLWritePrivateProfileString(sectionName,
								 INI_CANCELASFREESTMT, tmp, fileName);

	sprintf(tmp, "%d", comval->max_varchar_size);
	SQLWritePrivateProfileString(sectionName,
								 INI_MAXVARCHARSIZE, tmp, fileName);

	sprintf(tmp, "%d", comval->max_longvarchar_size);
	SQLWritePrivateProfileString(sectionName,
489
								 INI_MAXLONGVARCHARSIZE, tmp, fileName);
490 491

	SQLWritePrivateProfileString(sectionName,
492
	INI_EXTRASYSTABLEPREFIXES, comval->extra_systable_prefixes, fileName);
493

494 495 496 497 498
	/*
	 * Never update the conn_setting from this module
	 * SQLWritePrivateProfileString(sectionName, INI_CONNSETTINGS,
	 * comval->conn_settings, fileName);
	 */
499
}
500
#endif   /* WIN32 */
Byron Nikolaidis's avatar
Byron Nikolaidis committed
501

502

503
void
504
makeConnectString(char *connect_string, const ConnInfo *ci, UWORD len)
505
{
506 507
	char		got_dsn = (ci->dsn[0] != '\0');
	char		encoded_conn_settings[LARGE_REGISTRY_LEN];
508
	UWORD		hlen;
509 510
	/*BOOL		abbrev = (len <= 400);*/
	BOOL		abbrev = (len < 1024);
511

512
	/* fundamental info */
Byron Nikolaidis's avatar
Byron Nikolaidis committed
513
	sprintf(connect_string, "%s=%s;DATABASE=%s;SERVER=%s;PORT=%s;UID=%s;PWD=%s",
514 515 516 517 518 519 520
			got_dsn ? "DSN" : "DRIVER",
			got_dsn ? ci->dsn : ci->driver,
			ci->database,
			ci->server,
			ci->port,
			ci->username,
			ci->password);
Byron Nikolaidis's avatar
Byron Nikolaidis committed
521 522 523

	encode(ci->conn_settings, encoded_conn_settings);

524
	/* extra info */
525 526 527
	hlen = strlen(connect_string);
	if (!abbrev)
		sprintf(&connect_string[hlen],
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
				";READONLY=%s;PROTOCOL=%s;FAKEOIDINDEX=%s;SHOWOIDCOLUMN=%s;ROWVERSIONING=%s;SHOWSYSTEMTABLES=%s;CONNSETTINGS=%s;FETCH=%d;SOCKET=%d;UNKNOWNSIZES=%d;MAXVARCHARSIZE=%d;MAXLONGVARCHARSIZE=%d;DEBUG=%d;COMMLOG=%d;OPTIMIZER=%d;KSQO=%d;USEDECLAREFETCH=%d;TEXTASLONGVARCHAR=%d;UNKNOWNSASLONGVARCHAR=%d;BOOLSASCHAR=%d;PARSE=%d;CANCELASFREESTMT=%d;EXTRASYSTABLEPREFIXES=%s",
				ci->onlyread,
				ci->protocol,
				ci->fake_oid_index,
				ci->show_oid_column,
				ci->row_versioning,
				ci->show_system_tables,
				encoded_conn_settings,
				ci->drivers.fetch_max,
				ci->drivers.socket_buffersize,
				ci->drivers.unknown_sizes,
				ci->drivers.max_varchar_size,
				ci->drivers.max_longvarchar_size,
				ci->drivers.debug,
				ci->drivers.commlog,
				ci->drivers.disable_optimizer,
				ci->drivers.ksqo,
				ci->drivers.use_declarefetch,
				ci->drivers.text_as_longvarchar,
				ci->drivers.unknowns_as_longvarchar,
				ci->drivers.bools_as_char,
				ci->drivers.parse,
				ci->drivers.cancel_as_freestmt,
				ci->drivers.extra_systable_prefixes);
552
	/* Abbrebiation is needed ? */
553
	if (abbrev || strlen(connect_string) >= len)
554
		sprintf(&connect_string[hlen],
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
				";A0=%s;A1=%s;A2=%s;A3=%s;A4=%s;A5=%s;A6=%s;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",
				ci->onlyread,
				ci->protocol,
				ci->fake_oid_index,
				ci->show_oid_column,
				ci->row_versioning,
				ci->show_system_tables,
				encoded_conn_settings,
				ci->drivers.fetch_max,
				ci->drivers.socket_buffersize,
				ci->drivers.unknown_sizes,
				ci->drivers.max_varchar_size,
				ci->drivers.max_longvarchar_size,
				ci->drivers.debug,
				ci->drivers.commlog,
				ci->drivers.disable_optimizer,
				ci->drivers.ksqo,
				ci->drivers.use_declarefetch,
				ci->drivers.text_as_longvarchar,
				ci->drivers.unknowns_as_longvarchar,
				ci->drivers.bools_as_char,
				ci->drivers.parse,
				ci->drivers.cancel_as_freestmt,
				ci->drivers.extra_systable_prefixes);
579 580
}

581

582
void
583
copyAttributes(ConnInfo *ci, const char *attribute, const char *value)
584
{
585
	if (stricmp(attribute, "DSN") == 0)
586 587
		strcpy(ci->dsn, value);

588
	else if (stricmp(attribute, "driver") == 0)
589 590
		strcpy(ci->driver, value);

591
	else if (stricmp(attribute, INI_DATABASE) == 0)
592 593
		strcpy(ci->database, value);

594
	else if (stricmp(attribute, INI_SERVER) == 0 || stricmp(attribute, "server") == 0)
595 596
		strcpy(ci->server, value);

597
	else if (stricmp(attribute, INI_USER) == 0 || stricmp(attribute, "uid") == 0)
598 599
		strcpy(ci->username, value);

600
	else if (stricmp(attribute, INI_PASSWORD) == 0 || stricmp(attribute, "pwd") == 0)
601 602
		strcpy(ci->password, value);

603
	else if (stricmp(attribute, INI_PORT) == 0)
604 605
		strcpy(ci->port, value);

606
	else if (stricmp(attribute, INI_READONLY) == 0 || stricmp(attribute, "A0") == 0)
607
		strcpy(ci->onlyread, value);
608

609
	else if (stricmp(attribute, INI_PROTOCOL) == 0 || stricmp(attribute, "A1") == 0)
610 611
		strcpy(ci->protocol, value);

612
	else if (stricmp(attribute, INI_SHOWOIDCOLUMN) == 0 || stricmp(attribute, "A3") == 0)
613 614
		strcpy(ci->show_oid_column, value);

615
	else if (stricmp(attribute, INI_FAKEOIDINDEX) == 0 || stricmp(attribute, "A2") == 0)
616 617
		strcpy(ci->fake_oid_index, value);

618
	else if (stricmp(attribute, INI_ROWVERSIONING) == 0 || stricmp(attribute, "A4") == 0)
Byron Nikolaidis's avatar
Byron Nikolaidis committed
619 620
		strcpy(ci->row_versioning, value);

621
	else if (stricmp(attribute, INI_SHOWSYSTEMTABLES) == 0 || stricmp(attribute, "A5") == 0)
622 623
		strcpy(ci->show_system_tables, value);

624
	else if (stricmp(attribute, INI_CONNSETTINGS) == 0 || stricmp(attribute, "A6") == 0)
625
	{
Byron Nikolaidis's avatar
Byron Nikolaidis committed
626
		decode(value, ci->conn_settings);
627
		/* strcpy(ci->conn_settings, value); */
Byron Nikolaidis's avatar
Byron Nikolaidis committed
628
	}
629 630
	else if (stricmp(attribute, INI_DISALLOWPREMATURE) == 0 || stricmp(attribute, "C3") == 0)
		ci->disallow_premature = atoi(value);
631 632
	else if (stricmp(attribute, INI_UPDATABLECURSORS) == 0 || stricmp(attribute, "C4") == 0)
		ci->updatable_cursors = atoi(value);
633

634
	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, ci->port, ci->onlyread, ci->protocol, ci->conn_settings, ci->disallow_premature);
635 636
}

637
void
638
copyCommonAttributes(ConnInfo *ci, const char *attribute, const char *value)
639 640 641 642 643 644 645 646 647 648 649 650 651
{
	if (stricmp(attribute, INI_FETCH) == 0 || stricmp(attribute, "A7") == 0)
		ci->drivers.fetch_max = atoi(value);
	else if (stricmp(attribute, INI_SOCKET) == 0 || stricmp(attribute, "A8") == 0)
		ci->drivers.socket_buffersize = atoi(value);
	else if (stricmp(attribute, INI_DEBUG) == 0 || stricmp(attribute, "B2") == 0)
		ci->drivers.debug = atoi(value);
	else if (stricmp(attribute, INI_COMMLOG) == 0 || stricmp(attribute, "B3") == 0)
		ci->drivers.commlog = atoi(value);
	else if (stricmp(attribute, INI_OPTIMIZER) == 0 || stricmp(attribute, "B4") == 0)
		ci->drivers.disable_optimizer = atoi(value);
	else if (stricmp(attribute, INI_KSQO) == 0 || stricmp(attribute, "B5") == 0)
		ci->drivers.ksqo = atoi(value);
652

653
	/*
654 655 656 657
	 * else if (stricmp(attribute, INI_UNIQUEINDEX) == 0 ||
	 * stricmp(attribute, "UIX") == 0) ci->drivers.unique_index =
	 * atoi(value);
	 */
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
	else if (stricmp(attribute, INI_UNKNOWNSIZES) == 0 || stricmp(attribute, "A9") == 0)
		ci->drivers.unknown_sizes = atoi(value);
	else if (stricmp(attribute, INI_LIE) == 0)
		ci->drivers.lie = atoi(value);
	else if (stricmp(attribute, INI_PARSE) == 0 || stricmp(attribute, "C0") == 0)
		ci->drivers.parse = atoi(value);
	else if (stricmp(attribute, INI_CANCELASFREESTMT) == 0 || stricmp(attribute, "C1") == 0)
		ci->drivers.cancel_as_freestmt = atoi(value);
	else if (stricmp(attribute, INI_USEDECLAREFETCH) == 0 || stricmp(attribute, "B6") == 0)
		ci->drivers.use_declarefetch = atoi(value);
	else if (stricmp(attribute, INI_MAXVARCHARSIZE) == 0 || stricmp(attribute, "B0") == 0)
		ci->drivers.max_varchar_size = atoi(value);
	else if (stricmp(attribute, INI_MAXLONGVARCHARSIZE) == 0 || stricmp(attribute, "B1") == 0)
		ci->drivers.max_longvarchar_size = atoi(value);
	else if (stricmp(attribute, INI_TEXTASLONGVARCHAR) == 0 || stricmp(attribute, "B7") == 0)
		ci->drivers.text_as_longvarchar = atoi(value);
	else if (stricmp(attribute, INI_UNKNOWNSASLONGVARCHAR) == 0 || stricmp(attribute, "B8") == 0)
		ci->drivers.unknowns_as_longvarchar = atoi(value);
	else if (stricmp(attribute, INI_BOOLSASCHAR) == 0 || stricmp(attribute, "B9") == 0)
		ci->drivers.bools_as_char = atoi(value);
	else if (stricmp(attribute, INI_EXTRASYSTABLEPREFIXES) == 0 || stricmp(attribute, "C2") == 0)
		strcpy(ci->drivers.extra_systable_prefixes, value);
	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",
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
		  ci->drivers.fetch_max,
		  ci->drivers.socket_buffersize,
		  ci->drivers.unknown_sizes,
		  ci->drivers.max_varchar_size,
		  ci->drivers.max_longvarchar_size,
		  ci->drivers.debug,
		  ci->drivers.commlog,
		  ci->drivers.disable_optimizer,
		  ci->drivers.ksqo,
		  ci->drivers.use_declarefetch,
		  ci->drivers.text_as_longvarchar,
		  ci->drivers.unknowns_as_longvarchar,
		  ci->drivers.bools_as_char,
		  ci->drivers.parse,
		  ci->drivers.cancel_as_freestmt,
		  ci->drivers.extra_systable_prefixes);
697 698
}

699

700
void
701
getDSNdefaults(ConnInfo *ci)
702 703 704 705
{
	if (ci->port[0] == '\0')
		strcpy(ci->port, DEFAULT_PORT);

706 707
	if (ci->onlyread[0] == '\0')
		sprintf(ci->onlyread, "%d", globals.onlyread);
708

Byron Nikolaidis's avatar
Byron Nikolaidis committed
709 710 711
	if (ci->protocol[0] == '\0')
		strcpy(ci->protocol, globals.protocol);

712 713 714 715 716 717 718 719 720
	if (ci->fake_oid_index[0] == '\0')
		sprintf(ci->fake_oid_index, "%d", DEFAULT_FAKEOIDINDEX);

	if (ci->show_oid_column[0] == '\0')
		sprintf(ci->show_oid_column, "%d", DEFAULT_SHOWOIDCOLUMN);

	if (ci->show_system_tables[0] == '\0')
		sprintf(ci->show_system_tables, "%d", DEFAULT_SHOWSYSTEMTABLES);

Byron Nikolaidis's avatar
Byron Nikolaidis committed
721 722
	if (ci->row_versioning[0] == '\0')
		sprintf(ci->row_versioning, "%d", DEFAULT_ROWVERSIONING);
723 724 725
}


726
void
727
getDSNinfo(ConnInfo *ci, char overwrite)
728
{
729
	char	   *DSN = ci->dsn;
730
	char		encoded_conn_settings[LARGE_REGISTRY_LEN],
731
				temp[SMALL_REGISTRY_LEN];
732

733 734 735 736
/*
 *	If a driver keyword was present, then dont use a DSN and return.
 *	If DSN is null and no driver, then use the default datasource.
 */
737
	memcpy(&ci->drivers, &globals, sizeof(globals));
738 739 740
	if (DSN[0] == '\0')
	{
		if (ci->driver[0] != '\0')
741 742 743 744 745
			return;
		else
			strcpy(DSN, INI_DSN);
	}

746
	/* brute-force chop off trailing blanks... */
747 748
	while (*(DSN + strlen(DSN) - 1) == ' ')
		*(DSN + strlen(DSN) - 1) = '\0';
749

750
	/* Proceed with getting info for the given DSN. */
751

752
	if (ci->desc[0] == '\0' || overwrite)
753 754
		SQLGetPrivateProfileString(DSN, INI_KDESC, "", ci->desc, sizeof(ci->desc), ODBC_INI);

755
	if (ci->server[0] == '\0' || overwrite)
756 757
		SQLGetPrivateProfileString(DSN, INI_SERVER, "", ci->server, sizeof(ci->server), ODBC_INI);

758 759
	if (ci->database[0] == '\0' || overwrite)
		SQLGetPrivateProfileString(DSN, INI_DATABASE, "", ci->database, sizeof(ci->database), ODBC_INI);
760

761
	if (ci->username[0] == '\0' || overwrite)
762 763
		SQLGetPrivateProfileString(DSN, INI_USER, "", ci->username, sizeof(ci->username), ODBC_INI);

764
	if (ci->password[0] == '\0' || overwrite)
765 766
		SQLGetPrivateProfileString(DSN, INI_PASSWORD, "", ci->password, sizeof(ci->password), ODBC_INI);

767
	if (ci->port[0] == '\0' || overwrite)
768 769
		SQLGetPrivateProfileString(DSN, INI_PORT, "", ci->port, sizeof(ci->port), ODBC_INI);

770
	if (ci->onlyread[0] == '\0' || overwrite)
771
		SQLGetPrivateProfileString(DSN, INI_READONLY, "", ci->onlyread, sizeof(ci->onlyread), ODBC_INI);
772

773
	if (ci->show_oid_column[0] == '\0' || overwrite)
774 775
		SQLGetPrivateProfileString(DSN, INI_SHOWOIDCOLUMN, "", ci->show_oid_column, sizeof(ci->show_oid_column), ODBC_INI);

776
	if (ci->fake_oid_index[0] == '\0' || overwrite)
777 778
		SQLGetPrivateProfileString(DSN, INI_FAKEOIDINDEX, "", ci->fake_oid_index, sizeof(ci->fake_oid_index), ODBC_INI);

779
	if (ci->row_versioning[0] == '\0' || overwrite)
Byron Nikolaidis's avatar
Byron Nikolaidis committed
780 781
		SQLGetPrivateProfileString(DSN, INI_ROWVERSIONING, "", ci->row_versioning, sizeof(ci->row_versioning), ODBC_INI);

782
	if (ci->show_system_tables[0] == '\0' || overwrite)
783 784
		SQLGetPrivateProfileString(DSN, INI_SHOWSYSTEMTABLES, "", ci->show_system_tables, sizeof(ci->show_system_tables), ODBC_INI);

785
	if (ci->protocol[0] == '\0' || overwrite)
786 787
		SQLGetPrivateProfileString(DSN, INI_PROTOCOL, "", ci->protocol, sizeof(ci->protocol), ODBC_INI);

788 789
	if (ci->conn_settings[0] == '\0' || overwrite)
	{
Byron Nikolaidis's avatar
Byron Nikolaidis committed
790 791 792 793
		SQLGetPrivateProfileString(DSN, INI_CONNSETTINGS, "", encoded_conn_settings, sizeof(encoded_conn_settings), ODBC_INI);
		decode(encoded_conn_settings, ci->conn_settings);
	}

794
	if (ci->translation_dll[0] == '\0' || overwrite)
Byron Nikolaidis's avatar
Byron Nikolaidis committed
795 796
		SQLGetPrivateProfileString(DSN, INI_TRANSLATIONDLL, "", ci->translation_dll, sizeof(ci->translation_dll), ODBC_INI);

797
	if (ci->translation_option[0] == '\0' || overwrite)
Byron Nikolaidis's avatar
Byron Nikolaidis committed
798
		SQLGetPrivateProfileString(DSN, INI_TRANSLATIONOPTION, "", ci->translation_option, sizeof(ci->translation_option), ODBC_INI);
799

800 801 802 803 804 805
	if (ci->disallow_premature == 0 || overwrite)
	{
		SQLGetPrivateProfileString(DSN, INI_DISALLOWPREMATURE, "", temp, sizeof(temp), ODBC_INI);
		ci->disallow_premature = atoi(temp);
	}

806 807 808 809 810 811
	if (ci->updatable_cursors == 0 || overwrite)
	{
		SQLGetPrivateProfileString(DSN, INI_UPDATABLECURSORS, "", temp, sizeof(temp), ODBC_INI);
		ci->updatable_cursors = atoi(temp);
	}

812
	/* Allow override of odbcinst.ini parameters here */
813
	getCommonDefaults(DSN, ODBC_INI, ci);
814

815 816 817 818 819 820 821
	qlog("DSN info: DSN='%s',server='%s',port='%s',dbase='%s',user='%s',passwd='%s'\n",
		 DSN,
		 ci->server,
		 ci->port,
		 ci->database,
		 ci->username,
		 ci->password);
822
	qlog("          onlyread='%s',protocol='%s',showoid='%s',fakeoidindex='%s',showsystable='%s'\n",
823 824 825 826 827
		 ci->onlyread,
		 ci->protocol,
		 ci->show_oid_column,
		 ci->fake_oid_index,
		 ci->show_system_tables);
Hiroshi Inoue's avatar
Hiroshi Inoue committed
828 829 830 831

#ifdef MULTIBYTE
	check_client_encoding(ci->conn_settings);
	qlog("          conn_settings='%s',conn_encoding='%s'\n",
832 833
		 ci->conn_settings,
		 check_client_encoding(ci->conn_settings));
Hiroshi Inoue's avatar
Hiroshi Inoue committed
834
#else
835
	qlog("          conn_settings='%s'\n",
836
		 ci->conn_settings);
Hiroshi Inoue's avatar
Hiroshi Inoue committed
837 838
#endif

Byron Nikolaidis's avatar
Byron Nikolaidis committed
839
	qlog("          translation_dll='%s',translation_option='%s'\n",
840 841
		 ci->translation_dll,
		 ci->translation_option);
842 843 844 845 846
}


/*	This is for datasource based options only */
void
847
writeDSNinfo(const ConnInfo *ci)
848
{
849
	const char *DSN = ci->dsn;
850
	char		encoded_conn_settings[LARGE_REGISTRY_LEN],
851
				temp[SMALL_REGISTRY_LEN];
852

853
	encode(ci->conn_settings, encoded_conn_settings);
854

855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918
	SQLWritePrivateProfileString(DSN,
								 INI_KDESC,
								 ci->desc,
								 ODBC_INI);

	SQLWritePrivateProfileString(DSN,
								 INI_DATABASE,
								 ci->database,
								 ODBC_INI);

	SQLWritePrivateProfileString(DSN,
								 INI_SERVER,
								 ci->server,
								 ODBC_INI);

	SQLWritePrivateProfileString(DSN,
								 INI_PORT,
								 ci->port,
								 ODBC_INI);

	SQLWritePrivateProfileString(DSN,
								 INI_USER,
								 ci->username,
								 ODBC_INI);

	SQLWritePrivateProfileString(DSN,
								 INI_PASSWORD,
								 ci->password,
								 ODBC_INI);

	SQLWritePrivateProfileString(DSN,
								 INI_READONLY,
								 ci->onlyread,
								 ODBC_INI);

	SQLWritePrivateProfileString(DSN,
								 INI_SHOWOIDCOLUMN,
								 ci->show_oid_column,
								 ODBC_INI);

	SQLWritePrivateProfileString(DSN,
								 INI_FAKEOIDINDEX,
								 ci->fake_oid_index,
								 ODBC_INI);

	SQLWritePrivateProfileString(DSN,
								 INI_ROWVERSIONING,
								 ci->row_versioning,
								 ODBC_INI);

	SQLWritePrivateProfileString(DSN,
								 INI_SHOWSYSTEMTABLES,
								 ci->show_system_tables,
								 ODBC_INI);

	SQLWritePrivateProfileString(DSN,
								 INI_PROTOCOL,
								 ci->protocol,
								 ODBC_INI);

	SQLWritePrivateProfileString(DSN,
								 INI_CONNSETTINGS,
								 encoded_conn_settings,
								 ODBC_INI);
919

920
	sprintf(temp, "%d", ci->disallow_premature);
921 922 923 924
	SQLWritePrivateProfileString(DSN,
								 INI_DISALLOWPREMATURE,
								 temp,
								 ODBC_INI);
925
	sprintf(temp, "%d", ci->updatable_cursors);
926 927 928 929
	SQLWritePrivateProfileString(DSN,
								 INI_UPDATABLECURSORS,
								 temp,
								 ODBC_INI);
930 931 932
}


933 934 935 936
/*
 *	This function reads the ODBCINST.INI portion of
 *	the registry and gets any driver defaults.
 */
937
void
938
getCommonDefaults(const char *section, const char *filename, ConnInfo *ci)
939
{
940
	char		temp[256];
941
	GLOBAL_VALUES *comval;
942

943 944 945 946
	if (ci)
		comval = &(ci->drivers);
	else
		comval = &globals;
947 948 949 950 951
	/* Fetch Count is stored in driver section */
	SQLGetPrivateProfileString(section, INI_FETCH, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
	{
952
		comval->fetch_max = atoi(temp);
953
		/* sanity check if using cursors */
954 955
		if (comval->fetch_max <= 0)
			comval->fetch_max = FETCH_MAX;
956
	}
957 958
	else if (!ci)
		comval->fetch_max = FETCH_MAX;
959

960 961 962 963
	/* Socket Buffersize is stored in driver section */
	SQLGetPrivateProfileString(section, INI_SOCKET, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
964 965 966
		comval->socket_buffersize = atoi(temp);
	else if (!ci)
		comval->socket_buffersize = SOCK_BUFFER_SIZE;
967

968 969 970 971
	/* Debug is stored in the driver section */
	SQLGetPrivateProfileString(section, INI_DEBUG, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
972 973 974
		comval->debug = atoi(temp);
	else if (!ci)
		comval->debug = DEFAULT_DEBUG;
975

976 977 978 979
	/* CommLog is stored in the driver section */
	SQLGetPrivateProfileString(section, INI_COMMLOG, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
980 981 982
		comval->commlog = atoi(temp);
	else if (!ci)
		comval->commlog = DEFAULT_COMMLOG;
983

984 985
	if (!ci)
		logs_on_off(0, 0, 0);
986 987 988 989
	/* Optimizer is stored in the driver section only */
	SQLGetPrivateProfileString(section, INI_OPTIMIZER, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
990 991 992
		comval->disable_optimizer = atoi(temp);
	else if (!ci)
		comval->disable_optimizer = DEFAULT_OPTIMIZER;
993

994 995 996 997
	/* KSQO is stored in the driver section only */
	SQLGetPrivateProfileString(section, INI_KSQO, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
998 999 1000
		comval->ksqo = atoi(temp);
	else if (!ci)
		comval->ksqo = DEFAULT_KSQO;
1001

1002 1003 1004 1005
	/* Recognize Unique Index is stored in the driver section only */
	SQLGetPrivateProfileString(section, INI_UNIQUEINDEX, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
1006 1007 1008
		comval->unique_index = atoi(temp);
	else if (!ci)
		comval->unique_index = DEFAULT_UNIQUEINDEX;
1009 1010


1011 1012 1013 1014
	/* Unknown Sizes is stored in the driver section only */
	SQLGetPrivateProfileString(section, INI_UNKNOWNSIZES, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
1015 1016 1017
		comval->unknown_sizes = atoi(temp);
	else if (!ci)
		comval->unknown_sizes = DEFAULT_UNKNOWNSIZES;
1018 1019


1020 1021 1022 1023
	/* Lie about supported functions? */
	SQLGetPrivateProfileString(section, INI_LIE, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
1024 1025 1026
		comval->lie = atoi(temp);
	else if (!ci)
		comval->lie = DEFAULT_LIE;
1027

1028 1029 1030 1031
	/* Parse statements */
	SQLGetPrivateProfileString(section, INI_PARSE, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
1032 1033 1034
		comval->parse = atoi(temp);
	else if (!ci)
		comval->parse = DEFAULT_PARSE;
1035

1036 1037 1038 1039
	/* SQLCancel calls SQLFreeStmt in Driver Manager */
	SQLGetPrivateProfileString(section, INI_CANCELASFREESTMT, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
1040 1041 1042
		comval->cancel_as_freestmt = atoi(temp);
	else if (!ci)
		comval->cancel_as_freestmt = DEFAULT_CANCELASFREESTMT;
1043

1044 1045 1046 1047
	/* UseDeclareFetch is stored in the driver section only */
	SQLGetPrivateProfileString(section, INI_USEDECLAREFETCH, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
1048 1049 1050
		comval->use_declarefetch = atoi(temp);
	else if (!ci)
		comval->use_declarefetch = DEFAULT_USEDECLAREFETCH;
1051

1052 1053 1054 1055
	/* Max Varchar Size */
	SQLGetPrivateProfileString(section, INI_MAXVARCHARSIZE, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
1056 1057 1058
		comval->max_varchar_size = atoi(temp);
	else if (!ci)
		comval->max_varchar_size = MAX_VARCHAR_SIZE;
1059

1060 1061 1062 1063
	/* Max TextField Size */
	SQLGetPrivateProfileString(section, INI_MAXLONGVARCHARSIZE, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
1064 1065 1066
		comval->max_longvarchar_size = atoi(temp);
	else if (!ci)
		comval->max_longvarchar_size = TEXT_FIELD_SIZE;
1067

1068 1069 1070 1071
	/* Text As LongVarchar	*/
	SQLGetPrivateProfileString(section, INI_TEXTASLONGVARCHAR, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
1072 1073 1074
		comval->text_as_longvarchar = atoi(temp);
	else if (!ci)
		comval->text_as_longvarchar = DEFAULT_TEXTASLONGVARCHAR;
1075

1076 1077 1078 1079
	/* Unknowns As LongVarchar	*/
	SQLGetPrivateProfileString(section, INI_UNKNOWNSASLONGVARCHAR, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
1080 1081 1082
		comval->unknowns_as_longvarchar = atoi(temp);
	else if (!ci)
		comval->unknowns_as_longvarchar = DEFAULT_UNKNOWNSASLONGVARCHAR;
1083

1084 1085 1086 1087
	/* Bools As Char */
	SQLGetPrivateProfileString(section, INI_BOOLSASCHAR, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
1088 1089 1090
		comval->bools_as_char = atoi(temp);
	else if (!ci)
		comval->bools_as_char = DEFAULT_BOOLSASCHAR;
1091

1092 1093 1094 1095 1096 1097 1098 1099 1100
	/* Extra Systable prefixes */

	/*
	 * Use @@@ to distinguish between blank extra prefixes and no key
	 * entry
	 */
	SQLGetPrivateProfileString(section, INI_EXTRASYSTABLEPREFIXES, "@@@",
							   temp, sizeof(temp), filename);
	if (strcmp(temp, "@@@"))
1101 1102 1103
		strcpy(comval->extra_systable_prefixes, temp);
	else if (!ci)
		strcpy(comval->extra_systable_prefixes, DEFAULT_EXTRASYSTABLEPREFIXES);
1104

1105
	mylog("globals.extra_systable_prefixes = '%s'\n", comval->extra_systable_prefixes);
1106 1107


1108
	/* Dont allow override of an override! */
1109
	if (!ci)
1110 1111 1112 1113 1114 1115
	{
		/*
		 * ConnSettings is stored in the driver section and per datasource
		 * for override
		 */
		SQLGetPrivateProfileString(section, INI_CONNSETTINGS, "",
1116
		 comval->conn_settings, sizeof(comval->conn_settings), filename);
1117

1118 1119 1120 1121
		/* Default state for future DSN's Readonly attribute */
		SQLGetPrivateProfileString(section, INI_READONLY, "",
								   temp, sizeof(temp), filename);
		if (temp[0])
1122
			comval->onlyread = atoi(temp);
Byron Nikolaidis's avatar
Byron Nikolaidis committed
1123
		else
1124
			comval->onlyread = DEFAULT_READONLY;
Byron Nikolaidis's avatar
Byron Nikolaidis committed
1125

1126 1127 1128 1129 1130 1131 1132 1133
		/*
		 * Default state for future DSN's protocol attribute This isn't a
		 * real driver option YET.	This is more intended for
		 * customization from the install.
		 */
		SQLGetPrivateProfileString(section, INI_PROTOCOL, "@@@",
								   temp, sizeof(temp), filename);
		if (strcmp(temp, "@@@"))
1134
			strcpy(comval->protocol, temp);
1135
		else
1136
			strcpy(comval->protocol, DEFAULT_PROTOCOL);
1137
	}
1138
}