mirror of
https://github.com/postgres/postgres.git
synced 2025-11-24 00:23:06 +03:00
pgindent run. Make it all clean.
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
|
||||
/* Module: drvconn.c
|
||||
/* Module: drvconn.c
|
||||
*
|
||||
* Description: This module contains only routines related to
|
||||
* implementing SQLDriverConnect.
|
||||
* Description: This module contains only routines related to
|
||||
* implementing SQLDriverConnect.
|
||||
*
|
||||
* Classes: n/a
|
||||
* Classes: n/a
|
||||
*
|
||||
* API functions: SQLDriverConnect
|
||||
* API functions: SQLDriverConnect
|
||||
*
|
||||
* Comments: See "notice.txt" for copyright and license information.
|
||||
* Comments: See "notice.txt" for copyright and license information.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -53,45 +53,50 @@
|
||||
#include "dlg_specific.h"
|
||||
|
||||
/* prototypes */
|
||||
void dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci);
|
||||
void dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci);
|
||||
|
||||
#ifdef WIN32
|
||||
BOOL FAR PASCAL dconn_FDriverConnectProc(HWND hdlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
|
||||
RETCODE dconn_DoDialog(HWND hwnd, ConnInfo *ci);
|
||||
RETCODE dconn_DoDialog(HWND hwnd, ConnInfo *ci);
|
||||
|
||||
extern HINSTANCE NEAR s_hModule;/* Saved module handle. */
|
||||
|
||||
extern HINSTANCE NEAR s_hModule; /* Saved module handle. */
|
||||
#endif
|
||||
|
||||
extern GLOBAL_VALUES globals;
|
||||
|
||||
|
||||
RETCODE SQL_API SQLDriverConnect(
|
||||
HDBC hdbc,
|
||||
HWND hwnd,
|
||||
UCHAR FAR *szConnStrIn,
|
||||
SWORD cbConnStrIn,
|
||||
UCHAR FAR *szConnStrOut,
|
||||
SWORD cbConnStrOutMax,
|
||||
SWORD FAR *pcbConnStrOut,
|
||||
UWORD fDriverCompletion)
|
||||
RETCODE SQL_API
|
||||
SQLDriverConnect(
|
||||
HDBC hdbc,
|
||||
HWND hwnd,
|
||||
UCHAR FAR *szConnStrIn,
|
||||
SWORD cbConnStrIn,
|
||||
UCHAR FAR *szConnStrOut,
|
||||
SWORD cbConnStrOutMax,
|
||||
SWORD FAR *pcbConnStrOut,
|
||||
UWORD fDriverCompletion)
|
||||
{
|
||||
static char *func = "SQLDriverConnect";
|
||||
ConnectionClass *conn = (ConnectionClass *) hdbc;
|
||||
ConnInfo *ci;
|
||||
static char *func = "SQLDriverConnect";
|
||||
ConnectionClass *conn = (ConnectionClass *) hdbc;
|
||||
ConnInfo *ci;
|
||||
|
||||
#ifdef WIN32
|
||||
RETCODE dialog_result;
|
||||
RETCODE dialog_result;
|
||||
|
||||
#endif
|
||||
RETCODE result;
|
||||
char connStrIn[MAX_CONNECT_STRING];
|
||||
char connStrOut[MAX_CONNECT_STRING];
|
||||
int retval;
|
||||
char password_required = FALSE;
|
||||
int len = 0;
|
||||
RETCODE result;
|
||||
char connStrIn[MAX_CONNECT_STRING];
|
||||
char connStrOut[MAX_CONNECT_STRING];
|
||||
int retval;
|
||||
char password_required = FALSE;
|
||||
int len = 0;
|
||||
|
||||
|
||||
mylog("%s: entering...\n", func);
|
||||
|
||||
if ( ! conn) {
|
||||
if (!conn)
|
||||
{
|
||||
CC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
@@ -103,17 +108,17 @@ int len = 0;
|
||||
|
||||
ci = &(conn->connInfo);
|
||||
|
||||
/* Parse the connect string and fill in conninfo for this hdbc. */
|
||||
/* Parse the connect string and fill in conninfo for this hdbc. */
|
||||
dconn_get_connect_attributes(connStrIn, ci);
|
||||
|
||||
/* If the ConnInfo in the hdbc is missing anything, */
|
||||
/* this function will fill them in from the registry (assuming */
|
||||
/* of course there is a DSN given -- if not, it does nothing!) */
|
||||
/* If the ConnInfo in the hdbc is missing anything, */
|
||||
/* this function will fill them in from the registry (assuming */
|
||||
/* of course there is a DSN given -- if not, it does nothing!) */
|
||||
getDSNinfo(ci, CONN_DONT_OVERWRITE);
|
||||
|
||||
/* Fill in any default parameters if they are not there. */
|
||||
/* Fill in any default parameters if they are not there. */
|
||||
getDSNdefaults(ci);
|
||||
/* initialize pg_version */
|
||||
/* initialize pg_version */
|
||||
CC_initialize_pg_version(conn);
|
||||
|
||||
#ifdef WIN32
|
||||
@@ -121,51 +126,54 @@ dialog:
|
||||
#endif
|
||||
ci->focus_password = password_required;
|
||||
|
||||
switch(fDriverCompletion) {
|
||||
switch (fDriverCompletion)
|
||||
{
|
||||
#ifdef WIN32
|
||||
case SQL_DRIVER_PROMPT:
|
||||
dialog_result = dconn_DoDialog(hwnd, ci);
|
||||
if(dialog_result != SQL_SUCCESS) {
|
||||
return dialog_result;
|
||||
}
|
||||
break;
|
||||
|
||||
case SQL_DRIVER_COMPLETE_REQUIRED:
|
||||
|
||||
/* Fall through */
|
||||
|
||||
case SQL_DRIVER_COMPLETE:
|
||||
|
||||
/* Password is not a required parameter. */
|
||||
if( ci->username[0] == '\0' ||
|
||||
ci->server[0] == '\0' ||
|
||||
ci->database[0] == '\0' ||
|
||||
ci->port[0] == '\0' ||
|
||||
password_required) {
|
||||
|
||||
case SQL_DRIVER_PROMPT:
|
||||
dialog_result = dconn_DoDialog(hwnd, ci);
|
||||
if(dialog_result != SQL_SUCCESS) {
|
||||
if (dialog_result != SQL_SUCCESS)
|
||||
return dialog_result;
|
||||
break;
|
||||
|
||||
case SQL_DRIVER_COMPLETE_REQUIRED:
|
||||
|
||||
/* Fall through */
|
||||
|
||||
case SQL_DRIVER_COMPLETE:
|
||||
|
||||
/* Password is not a required parameter. */
|
||||
if (ci->username[0] == '\0' ||
|
||||
ci->server[0] == '\0' ||
|
||||
ci->database[0] == '\0' ||
|
||||
ci->port[0] == '\0' ||
|
||||
password_required)
|
||||
{
|
||||
|
||||
dialog_result = dconn_DoDialog(hwnd, ci);
|
||||
if (dialog_result != SQL_SUCCESS)
|
||||
return dialog_result;
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
#else
|
||||
case SQL_DRIVER_PROMPT:
|
||||
case SQL_DRIVER_COMPLETE:
|
||||
case SQL_DRIVER_COMPLETE_REQUIRED:
|
||||
case SQL_DRIVER_PROMPT:
|
||||
case SQL_DRIVER_COMPLETE:
|
||||
case SQL_DRIVER_COMPLETE_REQUIRED:
|
||||
#endif
|
||||
case SQL_DRIVER_NOPROMPT:
|
||||
break;
|
||||
case SQL_DRIVER_NOPROMPT:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Password is not a required parameter unless authentication asks for it.
|
||||
For now, I think it's better to just let the application ask over and over until
|
||||
a password is entered (the user can always hit Cancel to get out)
|
||||
*/
|
||||
if( ci->username[0] == '\0' ||
|
||||
/*
|
||||
* Password is not a required parameter unless authentication asks for
|
||||
* it. For now, I think it's better to just let the application ask
|
||||
* over and over until a password is entered (the user can always hit
|
||||
* Cancel to get out)
|
||||
*/
|
||||
if (ci->username[0] == '\0' ||
|
||||
ci->server[0] == '\0' ||
|
||||
ci->database[0] == '\0' ||
|
||||
ci->port[0] == '\0') {
|
||||
ci->database[0] == '\0' ||
|
||||
ci->port[0] == '\0')
|
||||
{
|
||||
/* (password_required && ci->password[0] == '\0')) */
|
||||
|
||||
return SQL_NO_DATA_FOUND;
|
||||
@@ -174,12 +182,16 @@ dialog:
|
||||
|
||||
/* do the actual connect */
|
||||
retval = CC_connect(conn, password_required);
|
||||
if (retval < 0) { /* need a password */
|
||||
if (fDriverCompletion == SQL_DRIVER_NOPROMPT) {
|
||||
if (retval < 0)
|
||||
{ /* need a password */
|
||||
if (fDriverCompletion == SQL_DRIVER_NOPROMPT)
|
||||
{
|
||||
CC_log_error(func, "Need password but Driver_NoPrompt", conn);
|
||||
return SQL_ERROR; /* need a password but not allowed to prompt so error */
|
||||
return SQL_ERROR; /* need a password but not allowed to
|
||||
* prompt so error */
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
#ifdef WIN32
|
||||
password_required = TRUE;
|
||||
goto dialog;
|
||||
@@ -188,39 +200,44 @@ dialog:
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (retval == 0) {
|
||||
/* error msg filled in above */
|
||||
else if (retval == 0)
|
||||
{
|
||||
/* error msg filled in above */
|
||||
CC_log_error(func, "Error from CC_Connect", conn);
|
||||
return SQL_ERROR;
|
||||
}
|
||||
|
||||
/*********************************************/
|
||||
/* Create the Output Connection String */
|
||||
/* Create the Output Connection String */
|
||||
/*********************************************/
|
||||
result = SQL_SUCCESS;
|
||||
|
||||
makeConnectString(connStrOut, ci);
|
||||
len = strlen(connStrOut);
|
||||
|
||||
if(szConnStrOut) {
|
||||
if (szConnStrOut)
|
||||
{
|
||||
|
||||
/* Return the completed string to the caller. The correct method is to
|
||||
only construct the connect string if a dialog was put up, otherwise,
|
||||
it should just copy the connection input string to the output.
|
||||
However, it seems ok to just always construct an output string. There
|
||||
are possible bad side effects on working applications (Access) by
|
||||
implementing the correct behavior, anyway.
|
||||
*/
|
||||
/*
|
||||
* Return the completed string to the caller. The correct method
|
||||
* is to only construct the connect string if a dialog was put up,
|
||||
* otherwise, it should just copy the connection input string to
|
||||
* the output. However, it seems ok to just always construct an
|
||||
* output string. There are possible bad side effects on working
|
||||
* applications (Access) by implementing the correct behavior,
|
||||
* anyway.
|
||||
*/
|
||||
strncpy_null(szConnStrOut, connStrOut, cbConnStrOutMax);
|
||||
|
||||
if (len >= cbConnStrOutMax) {
|
||||
if (len >= cbConnStrOutMax)
|
||||
{
|
||||
result = SQL_SUCCESS_WITH_INFO;
|
||||
conn->errornumber = CONN_TRUNCATED;
|
||||
conn->errormsg = "The buffer was too small for the result.";
|
||||
}
|
||||
}
|
||||
|
||||
if(pcbConnStrOut)
|
||||
if (pcbConnStrOut)
|
||||
*pcbConnStrOut = len;
|
||||
|
||||
mylog("szConnStrOut = '%s'\n", szConnStrOut);
|
||||
@@ -232,108 +249,117 @@ dialog:
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
RETCODE dconn_DoDialog(HWND hwnd, ConnInfo *ci)
|
||||
RETCODE
|
||||
dconn_DoDialog(HWND hwnd, ConnInfo *ci)
|
||||
{
|
||||
int dialog_result;
|
||||
int dialog_result;
|
||||
|
||||
mylog("dconn_DoDialog: ci = %u\n", ci);
|
||||
mylog("dconn_DoDialog: ci = %u\n", ci);
|
||||
|
||||
if(hwnd) {
|
||||
if (hwnd)
|
||||
{
|
||||
dialog_result = DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_CONFIG),
|
||||
hwnd, dconn_FDriverConnectProc, (LPARAM) ci);
|
||||
if(!dialog_result || (dialog_result == -1)) {
|
||||
hwnd, dconn_FDriverConnectProc, (LPARAM) ci);
|
||||
if (!dialog_result || (dialog_result == -1))
|
||||
return SQL_NO_DATA_FOUND;
|
||||
} else {
|
||||
else
|
||||
return SQL_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return SQL_ERROR;
|
||||
}
|
||||
|
||||
|
||||
BOOL FAR PASCAL dconn_FDriverConnectProc(
|
||||
HWND hdlg,
|
||||
UINT wMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
BOOL FAR PASCAL
|
||||
dconn_FDriverConnectProc(
|
||||
HWND hdlg,
|
||||
UINT wMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
ConnInfo *ci;
|
||||
ConnInfo *ci;
|
||||
|
||||
switch (wMsg) {
|
||||
case WM_INITDIALOG:
|
||||
ci = (ConnInfo *) lParam;
|
||||
switch (wMsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
ci = (ConnInfo *) lParam;
|
||||
|
||||
/* Change the caption for the setup dialog */
|
||||
SetWindowText(hdlg, "PostgreSQL Connection");
|
||||
/* Change the caption for the setup dialog */
|
||||
SetWindowText(hdlg, "PostgreSQL Connection");
|
||||
|
||||
SetWindowText(GetDlgItem(hdlg, IDC_DATASOURCE), "Connection");
|
||||
SetWindowText(GetDlgItem(hdlg, IDC_DATASOURCE), "Connection");
|
||||
|
||||
/* Hide the DSN and description fields */
|
||||
ShowWindow(GetDlgItem(hdlg, IDC_DSNAMETEXT), SW_HIDE);
|
||||
ShowWindow(GetDlgItem(hdlg, IDC_DSNAME), SW_HIDE);
|
||||
ShowWindow(GetDlgItem(hdlg, IDC_DESCTEXT), SW_HIDE);
|
||||
ShowWindow(GetDlgItem(hdlg, IDC_DESC), SW_HIDE);
|
||||
/* Hide the DSN and description fields */
|
||||
ShowWindow(GetDlgItem(hdlg, IDC_DSNAMETEXT), SW_HIDE);
|
||||
ShowWindow(GetDlgItem(hdlg, IDC_DSNAME), SW_HIDE);
|
||||
ShowWindow(GetDlgItem(hdlg, IDC_DESCTEXT), SW_HIDE);
|
||||
ShowWindow(GetDlgItem(hdlg, IDC_DESC), SW_HIDE);
|
||||
|
||||
SetWindowLong(hdlg, DWL_USER, lParam);/* Save the ConnInfo for the "OK" */
|
||||
SetWindowLong(hdlg, DWL_USER, lParam); /* Save the ConnInfo for
|
||||
* the "OK" */
|
||||
|
||||
SetDlgStuff(hdlg, ci);
|
||||
SetDlgStuff(hdlg, ci);
|
||||
|
||||
if (ci->database[0] == '\0')
|
||||
; /* default focus */
|
||||
else if (ci->server[0] == '\0')
|
||||
SetFocus(GetDlgItem(hdlg, IDC_SERVER));
|
||||
else if (ci->port[0] == '\0')
|
||||
SetFocus(GetDlgItem(hdlg, IDC_PORT));
|
||||
else if (ci->username[0] == '\0')
|
||||
SetFocus(GetDlgItem(hdlg, IDC_USER));
|
||||
else if (ci->focus_password)
|
||||
SetFocus(GetDlgItem(hdlg, IDC_PASSWORD));
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case WM_COMMAND:
|
||||
switch (GET_WM_COMMAND_ID(wParam, lParam)) {
|
||||
case IDOK:
|
||||
|
||||
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
|
||||
|
||||
GetDlgStuff(hdlg, ci);
|
||||
|
||||
|
||||
case IDCANCEL:
|
||||
EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
|
||||
return TRUE;
|
||||
|
||||
case IDC_DRIVER:
|
||||
|
||||
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DRV),
|
||||
hdlg, driver_optionsProc, (LPARAM) NULL);
|
||||
if (ci->database[0] == '\0')
|
||||
; /* default focus */
|
||||
else if (ci->server[0] == '\0')
|
||||
SetFocus(GetDlgItem(hdlg, IDC_SERVER));
|
||||
else if (ci->port[0] == '\0')
|
||||
SetFocus(GetDlgItem(hdlg, IDC_PORT));
|
||||
else if (ci->username[0] == '\0')
|
||||
SetFocus(GetDlgItem(hdlg, IDC_USER));
|
||||
else if (ci->focus_password)
|
||||
SetFocus(GetDlgItem(hdlg, IDC_PASSWORD));
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case IDC_DATASOURCE:
|
||||
case WM_COMMAND:
|
||||
switch (GET_WM_COMMAND_ID(wParam, lParam))
|
||||
{
|
||||
case IDOK:
|
||||
|
||||
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
|
||||
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DS),
|
||||
hdlg, ds_optionsProc, (LPARAM) ci);
|
||||
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
|
||||
|
||||
break;
|
||||
}
|
||||
GetDlgStuff(hdlg, ci);
|
||||
|
||||
|
||||
case IDCANCEL:
|
||||
EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
|
||||
return TRUE;
|
||||
|
||||
case IDC_DRIVER:
|
||||
|
||||
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DRV),
|
||||
hdlg, driver_optionsProc, (LPARAM) NULL);
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case IDC_DATASOURCE:
|
||||
|
||||
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
|
||||
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DS),
|
||||
hdlg, ds_optionsProc, (LPARAM) ci);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#endif /* WIN32 */
|
||||
#endif /* WIN32 */
|
||||
|
||||
void dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci)
|
||||
void
|
||||
dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci)
|
||||
{
|
||||
char *our_connect_string;
|
||||
char *pair, *attribute, *value, *equals;
|
||||
char *strtok_arg;
|
||||
char *our_connect_string;
|
||||
char *pair,
|
||||
*attribute,
|
||||
*value,
|
||||
*equals;
|
||||
char *strtok_arg;
|
||||
|
||||
memset(ci, 0, sizeof(ConnInfo));
|
||||
|
||||
@@ -342,29 +368,28 @@ char *strtok_arg;
|
||||
|
||||
mylog("our_connect_string = '%s'\n", our_connect_string);
|
||||
|
||||
while(1) {
|
||||
while (1)
|
||||
{
|
||||
pair = strtok(strtok_arg, ";");
|
||||
if(strtok_arg) {
|
||||
if (strtok_arg)
|
||||
strtok_arg = 0;
|
||||
}
|
||||
if(!pair) {
|
||||
if (!pair)
|
||||
break;
|
||||
}
|
||||
|
||||
equals = strchr(pair, '=');
|
||||
if ( ! equals)
|
||||
if (!equals)
|
||||
continue;
|
||||
|
||||
*equals = '\0';
|
||||
attribute = pair; /* ex. DSN */
|
||||
value = equals + 1; /* ex. 'CEO co1' */
|
||||
attribute = pair; /* ex. DSN */
|
||||
value = equals + 1; /* ex. 'CEO co1' */
|
||||
|
||||
mylog("attribute = '%s', value = '%s'\n", attribute, value);
|
||||
|
||||
if( !attribute || !value)
|
||||
continue;
|
||||
if (!attribute || !value)
|
||||
continue;
|
||||
|
||||
/* Copy the appropriate value to the conninfo */
|
||||
/* Copy the appropriate value to the conninfo */
|
||||
copyAttributes(ci, attribute, value);
|
||||
|
||||
}
|
||||
@@ -372,4 +397,3 @@ char *strtok_arg;
|
||||
|
||||
free(our_connect_string);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user