Hi Dave,

Please find the patch for the same.

*--**
**Thanks & Regards,**

**Ashesh Vashi**
**EnterpriseDB INDIA:* Enterprise Postgres Company<http://www.enterprisedb.com>


On Mon, Jul 12, 2010 at 12:58 PM, Dave Page <dp...@pgadmin.org> wrote:

> Please look at this.
>
> Thanks.
>
>
> ---------- Forwarded message ----------
> From: pgAdmin Trac <t...@code.pgadmin.org>
> Date: Mon, Jul 12, 2010 at 1:50 AM
> Subject: [pgadmin-hackers] [pgAdmin III] #209: "Connect to Server" dialog
> buggy
> To:
> Cc: pgadmin-hackers@postgresql.org
>
>
> #209: "Connect to Server" dialog buggy
>
> ------------------------+---------------------------------------------------
>  Reporter:  brsa        |       Owner:  dpage
>     Type:  bug         |      Status:  new
>  Priority:  major       |   Milestone:  1.12
> Component:  pgadmin     |     Version:
>  Keywords:  SQL editor  |    Platform:  windows
>
> ------------------------+---------------------------------------------------
>  Testing v1.12beta3 (rev. 8448) on Windows XP Pro. Server = pg 8.4.4 on
>  Debian Lenny.
>
>  In the SQL editor try to connect to another server by choosing "new
>  connection" from the connection combobox.
>
>  - Selecting a different server triggers an immediate attempt to connect.
>  (happens sometimes)
>
>  The "Username" combobox behaves differently from the 2 other comboboxes:
>  - The first user shown is the alphabetically first in the list, but it
>  should be the user of the same name as in the current connection - if such
>  a user exists. (happens always)
>  - A click into the field does not open the list. (happens always)
>  - Typed text is not completed, not even after moving the focus to another
>  control. Only after clicking on the down arrow. (happens always)
>  - This way I can enter non-existing users and try to connect with these.
>  - pgAdmin randomly crashes when I try to use the feature. (happens
>  sometimes)
>
>  I had to try like 6 times, 3 times of which pgadmin crashed completely
>  until I managed to open another connection.
>
>  Wishlist item: a way to close a connection without closing the SQL editor
>  window.
>
> --
> Ticket URL: <http://code.pgadmin.org/trac/ticket/209>
> pgAdmin III <http://code.pgadmin.org/trac/>
> pgAdmin III
>
> --
> Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgadmin-hackers
>
>
>
> --
> Dave Page
> EnterpriseDB UK: http://www.enterprisedb.com
> The Enterprise Postgres Company
>
Index: pgAdmin3.cpp
===================================================================
--- pgAdmin3.cpp	(revision 8461)
+++ pgAdmin3.cpp	(working copy)
@@ -448,7 +448,8 @@
                 int rc=dlg.Go(conn, NULL);
                 if (rc != wxID_OK)
                     return false;
-                conn = dlg.CreateConn(applicationname);
+                bool dummyRes;
+                conn = dlg.CreateConn(applicationname, dummyRes);
             }
             else if (cmdParser.Found(wxT("Sc"), &connstr))
             {
@@ -539,7 +540,8 @@
                 int rc=dlg.Go(conn, NULL);
                 if (rc != wxID_OK)
                     return false;
-                conn = dlg.CreateConn(applicationname);
+                bool dummyRes;
+                conn = dlg.CreateConn(applicationname, dummyRes);
             }
             else if (cmdParser.Found(wxT("qc"), &connstr))
             {
Index: include/dlg/dlgSelectConnection.h
===================================================================
--- include/dlg/dlgSelectConnection.h	(revision 8461)
+++ include/dlg/dlgSelectConnection.h	(working copy)
@@ -24,7 +24,7 @@
     ~dlgSelectConnection();
     wxString GetHelpPage() const;
     pgServer *GetServer() { return remoteServer; }
-	pgConn *CreateConn(wxString& applicationame);
+	pgConn *CreateConn(wxString& applicationame, bool& createdNew);
 	pgConn *CreateConn(wxString& server, wxString& dbname, wxString& username, int port, int sslmode, wxString& applicationame, bool writeMRU = false);
 	wxString GetServerName();
     wxString GetDatabase();
Index: frm/frmQuery.cpp
===================================================================
--- frm/frmQuery.cpp	(revision 8461)
+++ frm/frmQuery.cpp	(working copy)
@@ -981,9 +981,10 @@
         int rc=dlg.Go(conn, cbConnection);
         if (rc == wxID_OK)
         {
+            bool createdNewConn;
             wxString applicationname = _("pgAdmin - Query Tool");
-            conn = dlg.CreateConn(applicationname);
-            if (conn)
+            conn = dlg.CreateConn(applicationname, createdNewConn);
+            if (conn && createdNewConn)
             {
                 cbConnection->Insert(conn->GetName(), CreateBitmap(GetServerColour()), sel, (void*)conn);
                 cbConnection->SetSelection(sel);
Index: dlg/dlgSelectConnection.cpp
===================================================================
--- dlg/dlgSelectConnection.cpp	(revision 8461)
+++ dlg/dlgSelectConnection.cpp	(working copy)
@@ -84,6 +84,7 @@
 		return;
 
     cbDatabase->Clear();
+    cbUsername->Clear();
 
     int sel=cbServer->GetCurrentSelection();
     if (sel >= 0)
@@ -169,12 +170,14 @@
     EndModal(wxID_CANCEL);
 }
 
-pgConn *dlgSelectConnection::CreateConn(wxString& applicationname)
+pgConn *dlgSelectConnection::CreateConn(wxString& applicationname, bool& createdNew)
 {
     /* gcc requires that we store this in temporary variables for some reason... */
     wxString serv = cbServer->GetValue();
     wxString db = cbDatabase->GetValue();
 
+    createdNew = true;
+
 	long port = 0;
 	if (serv.Find(':') > 0)
 	{
@@ -188,6 +191,24 @@
 
     wxString user = cbUsername->GetValue();
 
+    if (cbConnection)
+    {
+        /* Check if selected combination already exists */
+        for (unsigned int index = 0; index < cbConnection->GetCount() - 1; index++)
+        {
+            pgConn* conn = (pgConn*)cbConnection->GetClientData(index);
+            if (conn &&
+                conn->GetHost() == serv &&
+                conn->GetPort() == port &&
+                conn->GetUser() == user &&
+                conn->GetDbname() == db)
+            {
+                createdNew = false;
+                return conn;
+            }
+        }
+    }
+
 	return CreateConn(serv, db, user, port, 0, applicationname, true);
 }
 
@@ -240,13 +261,15 @@
         pgObject *object;
         pgServer *server;
 
+        bool foundServer = false;
+
         folderitem = browser->GetFirstChild(browser->GetRootItem(), foldercookie);
-        while (folderitem)
+        while (folderitem && !foundServer)
         {
             if (browser->ItemHasChildren(folderitem))
             {
                 serveritem = browser->GetFirstChild(folderitem, servercookie);
-                while (serveritem)
+                while (serveritem && !foundServer)
                 {
                     object = browser->GetObject(serveritem);
                     if (object->IsCreatedBy(serverFactory))
@@ -259,6 +282,8 @@
 			            {
 			            	 cbServer->SetSelection(cbServer->GetCount()-1);
 			            	 remoteServer = server;
+                             // We found the server, stop iteration
+                             foundServer = true;
 			            }
                     }
                     serveritem = browser->GetNextChild(folderitem, servercookie);
@@ -266,12 +291,34 @@
             }
             folderitem = browser->GetNextChild(browser->GetRootItem(), foldercookie);
         }
-		cbServer->SetFocus();
+        cbServer->SetFocus();
+
+        wxCommandEvent ev;
+        OnChangeServer(ev);
+
+        if (foundServer)
+        {
+
+            unsigned int index = 0;
+            for (;index < cbDatabase->GetCount(); index++)
+            {
+                if (cbDatabase->GetString(index) == conn->GetDbname())
+                {
+                    cbDatabase->SetSelection(index);
+                    break;
+                }
+            }
+            for (index = 0;index < cbUsername->GetCount(); index++)
+            {
+                if (cbUsername->GetString(index) == conn->GetUser())
+                {
+                    cbUsername->SetSelection(index);
+                    break;
+                }
+            }
+        }
 	}
 
-    wxCommandEvent ev;
-    OnChangeServer(ev);
-
     return ShowModal();
 }
 
-- 
Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to