Le lundi 21 septembre 2009 à 10:04:28, Dave Page a écrit :
> On Sun, Sep 20, 2009 at 10:17 AM, Guillaume Lelarge
> <[email protected]> wrote:
> > [...]
> > This patch adds a connection toolbar to the frmStatus window. It allows
> > one to change the connection used byt the various reports. It is mostly
> > important for the locks report because it's the only way to get the name
> > of locked relations.
> >
> > One thing that bugs me is the log report. It needs to keep the connection
> > to the maintenance database because it's the only database where we
> > require to have the adminpack functions. Should we keep two connections
> > (one on the maintenance database and the one selected in the combobox)?
> > or should we allow the change of connection for the locks report only?
> 
> I think we should use the maintenance DB as much as possible, and just
> use the user-selectable connection where needed.

OK. This patch now uses only two connections: one to the maintenance DB, one 
to a user selected one. They are the same at the beginning but can change if 
the user selects another database. If he tries various databases, each 
previous connection is closed before opening the new one unless the previous 
one is the connection to the maintenance DB.

> BTW - it looks like
> the patch as-is doesn't prevent the user from selecting an entirely
> different server. If the user does that (which doesn't seem entirely
> unreasonable), we need to switch the maintenance DB to the new server
> too.
> 

There's no more a connection toolbar. There is now a database combobox 
available on the "standard" toolbar. It is filled at startup. Which means a 
user cannot change his connection to an entirely different server.

Patch attached.


-- 
Guillaume.
 http://www.postgresqlfr.org
 http://dalibo.com
Index: pgadmin/include/frm/frmStatus.h
===================================================================
--- pgadmin/include/frm/frmStatus.h	(révision 8044)
+++ pgadmin/include/frm/frmStatus.h	(copie de travail)
@@ -69,12 +69,13 @@
 #define FRMSTATUS_PERSPECTIVE_VER wxT("$Rev$")
 
 #ifdef __WXMAC__
-#define FRMSTATUS_DEFAULT_PERSPECTIVE wxT("layout2|name=Activity;caption=Activity;state=6293500;dir=4;layer=0;row=0;pos=0;prop=100000;bestw=321;besth=244;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=462;floaty=165;floatw=595;floath=282|name=Locks;caption=Locks;state=6293500;dir=4;layer=0;row=0;pos=1;prop=100000;bestw=321;besth=244;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-231;floaty=235;floatw=595;floath=282|name=Transactions;caption=Transactions;state=6293500;dir=4;layer=0;row=0;pos=2;prop=100000;bestw=0;besth=0;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=461;floaty=527;floatw=595;floath=282|name=Logfile;caption=Logfile;state=6293500;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=0;besth=0;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-103;floaty=351;floatw=595;floath=282|name=toolBar;caption=Tool bar;state=2124528;dir=1;layer=10;row=0;pos=0;prop=100000;bestw=608;besth=33;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=888;floaty=829;floatw=558;floath=49|dock_size(4,0,0)=583|dock_size(5,0,0)=10|dock_size(1,10,0)=35|")
+#define FRMSTATUS_DEFAULT_PERSPECTIVE wxT("layout2|name=Activity;caption=Activity;state=6293500;dir=4;layer=0;row=0;pos=0;prop=100000;bestw=321;besth=244;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=462;floaty=165;floatw=595;floath=282|name=Locks;caption=Locks;state=6293500;dir=4;layer=0;row=0;pos=1;prop=100000;bestw=321;besth=244;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-231;floaty=235;floatw=595;floath=282|name=Transactions;caption=Transactions;state=6293500;dir=4;layer=0;row=0;pos=2;prop=100000;bestw=0;besth=0;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=461;floaty=527;floatw=595;floath=282|name=Logfile;caption=Logfile;state=6293500;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=0;besth=0;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-103;floaty=351;floatw=595;floath=282|name=toolBar;caption=Tool bar;state=2124528;dir=1;layer=10;row=0;pos=0;prop=100000;bestw=808;besth=33;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=888;floaty=829;floatw=558;floath=49|dock_size(4,0,0)=583|dock_size(5,0,0)=10|dock_size(1,10,0)=35|")
 #else
 #ifdef __WXGTK__
-#define FRMSTATUS_DEFAULT_PERSPECTIVE wxT("layout2|name=Activity;caption=Activity;state=6293500;dir=4;layer=0;row=0;pos=2;prop=100000;bestw=20;besth=20;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=Locks;caption=Locks;state=6293500;dir=4;layer=0;row=0;pos=1;prop=100000;bestw=20;besth=20;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=Transactions;caption=Transactions;state=6293500;dir=4;layer=0;row=0;pos=0;prop=100000;bestw=20;besth=20;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=Logfile;caption=Logfile;state=6293500;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=20;besth=20;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=toolBar;caption=Tool bar;state=2108144;dir=1;layer=10;row=0;pos=0;prop=100000;bestw=720;besth=31;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(4,0,0)=549|dock_size(5,0,0)=22|dock_size(1,10,0)=33|")
+#define FRMSTATUS_DEFAULT_PERSPECTIVE
+wxT("layout2|name=Activity;caption=Activity;state=6293500;dir=4;layer=0;row=0;pos=2;prop=100000;bestw=20;besth=20;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=Locks;caption=Locks;state=6293500;dir=4;layer=0;row=0;pos=1;prop=100000;bestw=20;besth=20;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=Transactions;caption=Transactions;state=6293500;dir=4;layer=0;row=0;pos=0;prop=100000;bestw=20;besth=20;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=Logfile;caption=Logfile;state=6293500;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=20;besth=20;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=toolBar;caption=Tool bar;state=2108144;dir=1;layer=10;row=0;pos=0;prop=100000;bestw=1020;besth=31;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(4,0,0)=549|dock_size(5,0,0)=22|dock_size(1,10,0)=33|")
 #else
-#define FRMSTATUS_DEFAULT_PERSPECTIVE wxT("layout2|name=Activity;caption=Activity;state=6309884;dir=4;layer=0;row=1;pos=0;prop=100000;bestw=20;besth=20;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=174;floaty=216;floatw=578;floath=282|name=Locks;caption=Locks;state=6293500;dir=4;layer=0;row=1;pos=1;prop=100000;bestw=20;besth=20;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=136;floaty=339;floatw=576;floath=283|name=Transactions;caption=Transactions;state=6293500;dir=4;layer=0;row=1;pos=2;prop=100000;bestw=20;besth=20;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=133;floaty=645;floatw=577;floath=283|name=Logfile;caption=Logfile;state=6293500;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=20;besth=20;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=toolBar;caption=Tool bar;state=2108144;dir=1;layer=10;row=0;pos=0;prop=100000;bestw=516;besth=23;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=586;floaty=525;floatw=483;floath=49|dock_size(5,0,0)=22|dock_size(1,10,0)=25|dock_size(4,0,1)=627|")
+#define FRMSTATUS_DEFAULT_PERSPECTIVE wxT("layout2|name=Activity;caption=Activity;state=6309884;dir=4;layer=0;row=1;pos=0;prop=100000;bestw=20;besth=20;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=174;floaty=216;floatw=578;floath=282|name=Locks;caption=Locks;state=6293500;dir=4;layer=0;row=1;pos=1;prop=100000;bestw=20;besth=20;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=136;floaty=339;floatw=576;floath=283|name=Transactions;caption=Transactions;state=6293500;dir=4;layer=0;row=1;pos=2;prop=100000;bestw=20;besth=20;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=133;floaty=645;floatw=577;floath=283|name=Logfile;caption=Logfile;state=6293500;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=20;besth=20;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=toolBar;caption=Tool bar;state=2108144;dir=1;layer=10;row=0;pos=0;prop=100000;bestw=716;besth=23;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=586;floaty=525;floatw=483;floath=49|dock_size(5,0,0)=22|dock_size(1,10,0)=25|dock_size(4,0,1)=627|")
 #endif
 #endif
 
@@ -95,7 +96,7 @@
     wxAuiManager manager;
     
     frmMain *mainForm;
-    pgConn *connection;
+    pgConn *connection, *locks_connection;
 
     wxString logFormat;
     bool logHasTimestamp, logFormatKnown;
@@ -118,6 +119,7 @@
     ctlComboBoxFix    *cbRate;
     wxComboBox    *cbLogfiles;
     wxButton      *btnRotateLog;
+    ctlComboBoxFix *cbDatabase;
     
     wxTimer *refreshUITimer;
     wxTimer *statusTimer, *locksTimer, *xactTimer, *logTimer;
@@ -177,6 +179,8 @@
     void OnCommit(wxCommandEvent &event);
     void OnRollback(wxCommandEvent &event);
 
+    void OnChangeDatabase(wxCommandEvent &ev);
+
     int fillLogfileCombo();
     void emptyLogfileCombo();
 
Index: pgadmin/frm/frmStatus.cpp
===================================================================
--- pgadmin/frm/frmStatus.cpp	(révision 8044)
+++ pgadmin/frm/frmStatus.cpp	(copie de travail)
@@ -26,6 +26,7 @@
 #include "frm/frmStatus.h"
 #include "frm/frmHint.h"
 #include "frm/frmMain.h"
+#include "db/pgConn.h"
 #include "frm/frmQuery.h"
 #include "utils/pgfeatures.h"
 #include "schema/pgServer.h"
@@ -41,6 +42,12 @@
 #include "images/storedata.xpm"
 
 
+#include "db/pgConn.h"
+
+
+#define CTRLID_DATABASE         4200
+
+
 BEGIN_EVENT_TABLE(frmStatus, pgFrame)
     EVT_MENU(MNU_EXIT,                               frmStatus::OnExit)
     
@@ -85,6 +92,8 @@
     EVT_LIST_ITEM_SELECTED(CTL_LOGLIST,                frmStatus::OnSelLogItem)
     EVT_LIST_ITEM_DESELECTED(CTL_LOGLIST,            frmStatus::OnSelLogItem)
 
+    EVT_COMBOBOX(CTRLID_DATABASE,                   frmStatus::OnChangeDatabase)
+
     EVT_CLOSE(                                        frmStatus::OnClose)
 END_EVENT_TABLE();
 
@@ -157,6 +166,7 @@
 
     mainForm = form;
     connection = conn;
+    locks_connection = conn;
 
     statusTimer = 0;
     locksTimer = 0;
@@ -239,6 +249,9 @@
     toolBar->AddSeparator();
     cbRate = new ctlComboBoxFix(toolBar, CTL_RATECBO, wxDefaultPosition, wxSize(-1, -1), wxCB_READONLY|wxCB_DROPDOWN);
     toolBar->AddControl(cbRate);
+    toolBar->AddSeparator();
+    cbDatabase = new ctlComboBoxFix(toolBar, CTRLID_DATABASE, wxDefaultPosition, wxSize(-1, -1), wxCB_READONLY|wxCB_DROPDOWN);
+    toolBar->AddControl(cbDatabase);
     toolBar->Realize();
 
     // Append items to cbo
@@ -260,6 +273,15 @@
     toolBar->EnableTool(MNU_ROLLBACK, false);
     cbLogfiles->Enable(false);
     btnRotateLog->Enable(false);
+
+    // Add the database combobox
+    pgSet *dataSet1=connection->ExecuteSet(wxT("SELECT datname FROM pg_database WHERE datallowconn ORDER BY datname"));
+    while (!dataSet1->Eof())
+    {
+        cbDatabase->Append(dataSet1->GetVal(wxT("datname")));
+        dataSet1->MoveNext();
+    }
+    delete dataSet1;
     
     // Create panel
     AddStatusPane();
@@ -290,9 +312,9 @@
     viewMenu->Check(MNU_LOGPAGE, manager.GetPane(wxT("Logfile")).IsShown());
     viewMenu->Check(MNU_TOOLBAR, manager.GetPane(wxT("toolBar")).IsShown());
 		
-		// Read the highlight status checkbox
+    // Read the highlight status checkbox
     settings->Read(wxT("frmStatus/HighlightStatus"), &highlight, true);
-		viewMenu->Check(MNU_HIGHLIGHTSTATUS, highlight);
+    viewMenu->Check(MNU_HIGHLIGHTSTATUS, highlight);
 
     // Get our PID
     backend_pid = connection->GetBackendPID();
@@ -351,6 +373,8 @@
     }
 
     // If connection is still available, delete it
+    if (locks_connection && locks_connection != connection)
+        delete locks_connection;
     if (connection)
         delete connection;
 }
@@ -406,6 +430,18 @@
 }
 
 
+void frmStatus::OnChangeDatabase(wxCommandEvent &ev)
+{
+    if (locks_connection != connection)
+    {
+        delete locks_connection;
+    }
+
+    locks_connection = new pgConn(connection->GetHostAddress(), cbDatabase->GetValue(),
+      connection->GetUser(), connection->GetPassword(), connection->GetPort(), connection->GetSslMode());
+}
+
+
 void frmStatus::AddStatusPane()
 {
     // Create panel
@@ -487,12 +523,12 @@
     lockList->AddColumn(_("Database"), 50);
     lockList->AddColumn(_("Relation"), 50);
     lockList->AddColumn(_("User"), 50);
-    if (connection->BackendMinimumVersion(8, 3))
+    if (locks_connection->BackendMinimumVersion(8, 3))
         lockList->AddColumn(_("XID"), 50);
     lockList->AddColumn(_("TX"), 50);
     lockList->AddColumn(_("Mode"), 50);
     lockList->AddColumn(_("Granted"), 50);
-    if (connection->BackendMinimumVersion(7, 4))
+    if (locks_connection->BackendMinimumVersion(7, 4))
         lockList->AddColumn(_("Start"), 50);
     lockList->AddColumn(_("Query"), 500);
 
@@ -1159,7 +1195,7 @@
     if (! viewMenu->IsChecked(MNU_LOCKPAGE))
         return;
 
-    if (!connection)
+    if (!locks_connection)
     {
         statusTimer->Stop();
         locksTimer->Stop();
@@ -1172,16 +1208,16 @@
     }
 
     checkConnection();
-    if (!connection)
+    if (!locks_connection)
         return;
     
     wxCriticalSectionLocker lock(gs_critsect);
 
-    connection->ExecuteVoid(wxT("SET log_statement='none';SET log_duration='off';"),false);
+    locks_connection->ExecuteVoid(wxT("SET log_statement='none';SET log_duration='off';"),false);
 
     long row=0;
     wxString sql;
-    if (connection->BackendMinimumVersion(8, 3)) 
+    if (locks_connection->BackendMinimumVersion(8, 3)) 
     {
         sql = wxT("SELECT ")
               wxT("(SELECT datname FROM pg_database WHERE oid = pgl.database) AS dbname, ")
@@ -1194,7 +1230,7 @@
               wxT("WHERE pgl.pid = pg_stat_get_backend_pid(svrid) ")
               wxT("ORDER BY pid;");
     } 
-    else if (connection->BackendMinimumVersion(7, 4)) 
+    else if (locks_connection->BackendMinimumVersion(7, 4)) 
     {
            sql = wxT("SELECT ")
               wxT("(SELECT datname FROM pg_database WHERE oid = pgl.database) AS dbname, ")
@@ -1220,7 +1256,7 @@
               wxT("ORDER BY pid;");
     }
 
-    pgSet *dataSet2=connection->ExecuteSet(sql);
+    pgSet *dataSet2=locks_connection->ExecuteSet(sql);
     if (dataSet2)
     {
         statusBar->SetStatusText(_("Refreshing locks list."));
@@ -1252,7 +1288,7 @@
                 lockList->SetItem(row, colpos++, dataSet2->GetVal(wxT("dbname")));
                 lockList->SetItem(row, colpos++, dataSet2->GetVal(wxT("class")));
                 lockList->SetItem(row, colpos++, dataSet2->GetVal(wxT("user")));
-                if (connection->BackendMinimumVersion(8, 3)) 
+                if (locks_connection->BackendMinimumVersion(8, 3)) 
                     lockList->SetItem(row, colpos++, dataSet2->GetVal(wxT("virtualxid")));
                 lockList->SetItem(row, colpos++, dataSet2->GetVal(wxT("transaction")));
                 lockList->SetItem(row, colpos++, dataSet2->GetVal(wxT("mode")));
@@ -1264,7 +1300,7 @@
 
                 wxString qry=dataSet2->GetVal(wxT("current_query"));
 
-                if (connection->BackendMinimumVersion(7, 4))
+                if (locks_connection->BackendMinimumVersion(7, 4))
                 {
                     if (qry.IsEmpty() || qry == wxT("<IDLE>"))
                         lockList->SetItem(row, colpos++, wxEmptyString);
@@ -1548,6 +1584,10 @@
             logTimer->Stop();
         statusBar->SetStatusText(_("Connection broken."));
     }
+    if (!locks_connection->IsAlive())
+    {
+        locks_connection = connection;
+    }
 }
 
 
-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to