Connection test button
am 11.10.2006 16:16:25 von Andreas PflugThis is a multi-part message in MIME format.
--------------000405030304010405040407
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Attached a patch that adds a test button to the config dialog to execute
a quick connection test based on the current parameters.
Please note that the patch bases on REL-08_01_0200.
Regards,
Andreas
--------------000405030304010405040407
Content-Type: text/plain;
name="psqlodbc-test.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="psqlodbc-test.diff"
Index: dlg_specific.h
============================================================ =======
RCS file: /cvsroot/psqlodbc/psqlodbc/dlg_specific.h,v
retrieving revision 1.46
diff -u -w -b -r1.46 dlg_specific.h
--- dlg_specific.h 26 Jan 2006 18:44:27 -0000 1.46
+++ dlg_specific.h 11 Oct 2006 11:55:58 -0000
@@ -179,6 +179,10 @@
UINT wMsg,
WPARAM wParam,
LPARAM lParam);
+int CALLBACK testProc(HWND hdlg,
+ UINT wMsg,
+ WPARAM wParam,
+ LPARAM lParam);
int CALLBACK ds_options1Proc(HWND hdlg,
UINT wMsg,
WPARAM wParam,
Index: dlg_wingui.c
============================================================ =======
RCS file: /cvsroot/psqlodbc/psqlodbc/dlg_wingui.c,v
retrieving revision 1.12
diff -u -w -b -r1.12 dlg_wingui.c
--- dlg_wingui.c 26 Jan 2006 18:44:27 -0000 1.12
+++ dlg_wingui.c 11 Oct 2006 13:58:46 -0000
@@ -264,6 +264,100 @@
return 0;
}
+
+
+#define TM_TEST 42 // what else...
+
+int CALLBACK testProc(HWND hdlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (wMsg)
+ {
+ case WM_INITDIALOG:
+ {
+ char buffer[2048]="";
+ ConnectionClass *conn=(ConnectionClass*)lParam;
+ ConnInfo *ci=&conn->connInfo;
+
+ SetWindowLong(hdlg, DWL_USER, lParam); /* save for OK etc */
+
+ if (ci->server[0])
+ sprintf(buffer+strlen(buffer), "Server=%s\r\n", ci->server);
+ if (ci->port[0])
+ sprintf(buffer+strlen(buffer), "Port=%s\r\n", ci->port);
+ if (ci->sslmode[0])
+ sprintf(buffer+strlen(buffer), "SSL-Mode=%s\r\n", ci->sslmode);
+ if (ci->database[0])
+ sprintf(buffer+strlen(buffer), "Database=%s\r\n", ci->database);
+ if (ci->username[0])
+ sprintf(buffer+strlen(buffer), "User=%s\r\n", ci->username);
+
+ strcat(buffer, "Testing connection... ");
+
+ SetDlgItemText(hdlg, IDC_TESTOUTPUT, buffer);
+ EnableWindow(GetDlgItem(hdlg, IDOK), FALSE);
+
+ sprintf(buffer, "Test connection %s", ci->dsn);
+ SetWindowText(hdlg, buffer);
+
+ SetTimer(hdlg, TM_TEST, 10, 0);
+
+ break;
+ }
+ case WM_TIMER:
+ {
+ ConnectionClass *conn=(ConnectionClass*)GetWindowLong(hdlg, DWL_USER);
+ if (conn)
+ {
+ char buffer[2048]="";
+ int rc;
+
+ SetWindowLong(hdlg, DWL_USER, 0);
+ KillTimer(hdlg, TM_TEST);
+ GetDlgItemText(hdlg, IDC_TESTOUTPUT, buffer, sizeof(buffer));
+
+ rc=LIBPQ_connect(conn);
+ if (rc)
+ strcat(buffer, " succeeded.");
+ else
+ {
+ char *src=conn->__error_message;
+ char *dst;
+ strcat(buffer, "failed. libpq reported:\r\n");
+ dst=buffer+strlen(buffer);
+
+ while (*src)
+ {
+ if (*src =='\n')
+ *dst++ = '\r';
+ *dst++ = *src++;
+ }
+ *dst=0;
+ }
+ SetDlgItemText(hdlg, IDC_TESTOUTPUT, buffer);
+
+ CC_Destructor(conn);
+
+ EnableWindow(GetDlgItem(hdlg, IDOK), TRUE);
+ }
+ return TRUE;
+ }
+ case WM_COMMAND:
+ {
+ switch (GET_WM_COMMAND_ID(wParam, lParam))
+ {
+ case IDOK:
+ case IDCANCEL:
+ EndDialog(hdlg, 0);
+ return TRUE;
+ }
+ break;
+ }
+ }
+
+ return FALSE;
+}
+
+
int CALLBACK
driver_optionsProc(HWND hdlg,
UINT wMsg,
Index: psqlodbc.rc
============================================================ =======
RCS file: /cvsroot/psqlodbc/psqlodbc/psqlodbc.rc,v
retrieving revision 1.75
diff -u -w -b -r1.75 psqlodbc.rc
--- psqlodbc.rc 31 Jan 2006 13:21:26 -0000 1.75
+++ psqlodbc.rc 11 Oct 2006 13:56:36 -0000
@@ -212,6 +212,15 @@
LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
END
+DLG_TEST DIALOG DISCARDABLE 0, 0, 278, 146
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Test connection"
+FONT 8, "MS Sans Serif"
+BEGIN
+ DEFPUSHBUTTON "OK",IDOK,221,125,50,14
+ EDITTEXT IDC_TESTOUTPUT,7,7,264,114,ES_MULTILINE | ES_AUTOHSCROLL |
+ ES_READONLY | WS_GROUP | NOT WS_TABSTOP
+END
//////////////////////////////////////////////////////////// /////////////////
//
@@ -400,14 +409,17 @@
EDITTEXT IDC_USER,57,69,72,12,ES_AUTOHSCROLL
RTEXT "Pass&word",IDC_STATIC,156,72,34,9
EDITTEXT IDC_PASSWORD,192,70,72,12,ES_PASSWORD | ES_AUTOHSCROLL
- DEFPUSHBUTTON "OK",IDOK,12,100,44,15,WS_GROUP
- PUSHBUTTON "Cancel",IDCANCEL,66,100,44,15
- GROUPBOX "Options",IDC_OPTIONS,121,87,177,35,BS_LEFT
- PUSHBUTTON "Datasource",IDC_DATASOURCE,128,101,50,14
- PUSHBUTTON "Global",IDC_DRIVER,184,101,50,14
LTEXT "Please supply any missing information required to connect.",
DRV_MSG_LABEL,12,5,249,10
- PUSHBUTTON "Manage DSN",IDC_MANAGEDSN,240,101,52,14
+
+ GROUPBOX "Options",IDC_OPTIONS,5,86,177,35,BS_LEFT
+ PUSHBUTTON "Datasource",IDC_DATASOURCE,12,100,50,14
+ PUSHBUTTON "Global",IDC_DRIVER,67,100,50,14
+ PUSHBUTTON "Manage DSN",IDC_MANAGEDSN,122,100,52,14
+
+ PUSHBUTTON "Test",IDC_TEST,254,89,44,15
+ DEFPUSHBUTTON "OK",IDOK,203,107,44,15,WS_GROUP
+ PUSHBUTTON "Cancel",IDCANCEL,254,107,44,15
END
DLG_OPTIONS_DRV DIALOGEX 0, 0, 303, 228
Index: resource.h
============================================================ =======
RCS file: /cvsroot/psqlodbc/psqlodbc/resource.h,v
retrieving revision 1.36
diff -u -w -b -r1.36 resource.h
--- resource.h 26 Jan 2006 18:44:29 -0000 1.36
+++ resource.h 11 Oct 2006 13:11:34 -0000
@@ -5,7 +5,7 @@
#define IDS_BADDSN 1
#define IDS_MSGTITLE 2
#define IDS_ADVANCE_OPTION_DEF 3
-#define IDOK2 3
+#define IDC_TEST 3
#define IDS_ADVANCE_SAVE 4
#define IDCANCEL2 4
#define IDS_ADVANCE_OPTION_DSN1 5
@@ -20,6 +20,8 @@
#define DLG_OPTIONS_DRV 102
#define DLG_OPTIONS_DS 103
#define DLG_OPTIONS_GLOBAL 104
+#define IDD_DIALOG1 109
+#define DLG_TEST 109
#define IDC_DSNAME 400
#define IDC_DSNAMETEXT 401
#define IDC_DESC 404
@@ -83,14 +85,15 @@
#define IDC_MANAGEDSN 1077
#define IDC_DRIVER_LIST 1078
#define IDC_SSLMODE 1079
+#define IDC_TESTOUTPUT 1082
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 109
+#define _APS_NEXT_RESOURCE_VALUE 110
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1082
+#define _APS_NEXT_CONTROL_VALUE 1083
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
Index: setup.c
============================================================ =======
RCS file: /cvsroot/psqlodbc/psqlodbc/setup.c,v
retrieving revision 1.38
diff -u -w -b -r1.38 setup.c
--- setup.c 17 Dec 2005 21:05:44 -0000 1.38
+++ setup.c 11 Oct 2006 14:00:45 -0000
@@ -283,6 +283,19 @@
EndDialog(hdlg, wParam);
return TRUE;
+ case IDC_TEST:
+ {
+ ConnectionClass *conn=CC_Constructor();
+ if (conn)
+ {
+ GetDlgStuff(hdlg, &conn->connInfo);
+ GetDlgItemText(hdlg, IDC_DSNAME, (char*)&conn->connInfo.dsn, sizeof(conn->connInfo.dsn));
+ DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_TEST), hdlg, testProc, (LPARAM)conn);
+
+ return TRUE;
+ }
+ break;
+ }
case IDC_DATASOURCE:
lpsetupdlg = (LPSETUPDLG) GetWindowLong(hdlg, DWL_USER);
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DRV),
--------------000405030304010405040407
Content-Type: text/plain
Content-Disposition: inline
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly
--------------000405030304010405040407--