RETCODE SQL_API PGAPI_FreeEnv(HENV henv) { CSTR func = "PGAPI_FreeEnv"; SQLRETURN ret = SQL_SUCCESS; EnvironmentClass *env = (EnvironmentClass *) henv; mylog("**** in PGAPI_FreeEnv: env = %p ** \n", env); if (env && EN_Destructor(env)) { #ifdef _HANDLE_ENLIST_IN_DTC_ CALL_DtcOnRelease(); #endif /* _HANDLE_ENLIST_IN_DTC_ */ mylog(" ok\n"); goto cleanup; } mylog(" error\n"); ret = SQL_ERROR; EN_log_error(func, "Error freeing environment", env); cleanup: return ret; }
/*------- * ConfigDlgProc * Description: Manage add data source name dialog * Input : hdlg --- Dialog window handle * wMsg --- Message * wParam - Message parameter * lParam - Message parameter * Output : TRUE if message processed, FALSE otherwise *------- */ LRESULT CALLBACK ConfigDlgProc(HWND hdlg, UINT wMsg, WPARAM wParam, LPARAM lParam) { LPSETUPDLG lpsetupdlg; ConnInfo *ci; DWORD cmd; char strbuf[64]; switch (wMsg) { /* Initialize the dialog */ case WM_INITDIALOG: lpsetupdlg = (LPSETUPDLG) lParam; ci = &lpsetupdlg->ci; /* Hide the driver connect message */ ShowWindow(GetDlgItem(hdlg, DRV_MSG_LABEL), SW_HIDE); LoadString(s_hModule, IDS_ADVANCE_SAVE, strbuf, sizeof(strbuf)); SetWindowText(GetDlgItem(hdlg, IDOK), strbuf); SetWindowLongPtr(hdlg, DWLP_USER, lParam); CenterDialog(hdlg); /* Center dialog */ /* * NOTE: Values supplied in the attribute string will always */ /* override settings in ODBC.INI */ memcpy(&ci->drivers, &globals, sizeof(globals)); /* Get the rest of the common attributes */ getDSNinfo(ci, CONN_DONT_OVERWRITE); /* Fill in any defaults */ getDSNdefaults(ci); /* Initialize dialog fields */ SetDlgStuff(hdlg, ci); if (lpsetupdlg->fNewDSN || !ci->dsn[0]) ShowWindow(GetDlgItem(hdlg, IDC_MANAGEDSN), SW_HIDE); if (lpsetupdlg->fDefault) { EnableWindow(GetDlgItem(hdlg, IDC_DSNAME), FALSE); EnableWindow(GetDlgItem(hdlg, IDC_DSNAMETEXT), FALSE); } else SendDlgItemMessage(hdlg, IDC_DSNAME, EM_LIMITTEXT, (WPARAM) (MAXDSNAME - 1), 0L); SendDlgItemMessage(hdlg, IDC_DESC, EM_LIMITTEXT, (WPARAM) (MAXDESC - 1), 0L); return TRUE; /* Focus was not set */ /* Process buttons */ case WM_COMMAND: switch (cmd = GET_WM_COMMAND_ID(wParam, lParam)) { /* * Ensure the OK button is enabled only when a data * source name */ /* is entered */ case IDC_DSNAME: if (GET_WM_COMMAND_CMD(wParam, lParam) == EN_CHANGE) { char szItem[MAXDSNAME]; /* Edit control text */ /* Enable/disable the OK button */ EnableWindow(GetDlgItem(hdlg, IDOK), GetDlgItemText(hdlg, IDC_DSNAME, szItem, sizeof(szItem))); return TRUE; } break; /* Accept results */ case IDOK: case IDAPPLY: lpsetupdlg = (LPSETUPDLG) GetWindowLong(hdlg, DWLP_USER); /* Retrieve dialog values */ if (!lpsetupdlg->fDefault) GetDlgItemText(hdlg, IDC_DSNAME, lpsetupdlg->ci.dsn, sizeof(lpsetupdlg->ci.dsn)); /* Get Dialog Values */ GetDlgStuff(hdlg, &lpsetupdlg->ci); /* Update ODBC.INI */ SetDSNAttributes(hdlg, lpsetupdlg, NULL); if (IDAPPLY == cmd) break; /* Return to caller */ case IDCANCEL: EndDialog(hdlg, wParam); return TRUE; case IDC_TEST: { lpsetupdlg = (LPSETUPDLG) GetWindowLong(hdlg, DWLP_USER); if (NULL != lpsetupdlg) { EnvironmentClass *env = EN_Constructor(); ConnectionClass *conn = NULL; char szMsg[SQL_MAX_MESSAGE_LENGTH]; /* Get Dialog Values */ GetDlgStuff(hdlg, &lpsetupdlg->ci); if (env) conn = CC_Constructor(); if (conn) { char *emsg; int errnum; EN_add_connection(env, conn); memcpy(&conn->connInfo, &lpsetupdlg->ci, sizeof(ConnInfo)); CC_initialize_pg_version(conn); if (CC_connect(conn, AUTH_REQ_OK, NULL) > 0) { if (CC_get_errornumber(conn) != 0) { CC_get_error(conn, &errnum, &emsg); snprintf(szMsg, sizeof(szMsg), "Warning: %s", emsg); } else strncpy(szMsg, "Connection successful", sizeof(szMsg)); emsg = szMsg; } else { CC_get_error(conn, &errnum, &emsg); } MessageBox(lpsetupdlg->hwndParent, emsg, "Connection Test", MB_ICONEXCLAMATION | MB_OK); EN_remove_connection(env, conn); CC_Destructor(conn); } if (env) EN_Destructor(env); return TRUE; } break; } case IDC_DATASOURCE: lpsetupdlg = (LPSETUPDLG) GetWindowLong(hdlg, DWLP_USER); DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DRV), hdlg, ds_options1Proc, (LPARAM) &lpsetupdlg->ci); return TRUE; case IDC_DRIVER: lpsetupdlg = (LPSETUPDLG) GetWindowLong(hdlg, DWLP_USER); DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_GLOBAL), hdlg, global_optionsProc, (LPARAM) &lpsetupdlg->ci); return TRUE; case IDC_MANAGEDSN: lpsetupdlg = (LPSETUPDLG) GetWindowLong(hdlg, DWLP_USER); if (DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_DRIVER_CHANGE), hdlg, manage_dsnProc, (LPARAM) lpsetupdlg) > 0) EndDialog(hdlg, 0); return TRUE; } break; case WM_CTLCOLORSTATIC: if (lParam == (LPARAM)GetDlgItem(hdlg, IDC_NOTICE_USER)) { HBRUSH hBrush = (HBRUSH)GetStockObject(LTGRAY_BRUSH); SetTextColor((HDC)wParam, RGB(255, 0, 0)); return (long)hBrush; } break; } /* Message not processed */ return FALSE; }