Allow the change of database for the lock report on the server status window.
authorguillaume <guillaume@a7884b65-44f6-0310-8a51-81a127f17b15>
Mon, 28 Sep 2009 19:38:57 +0000 (19:38 +0000)
committerguillaume <guillaume@a7884b65-44f6-0310-8a51-81a127f17b15>
Mon, 28 Sep 2009 19:38:57 +0000 (19:38 +0000)
Fixes #78.

git-svn-id: svn://svn.pgadmin.org/trunk/pgadmin3@8045 a7884b65-44f6-0310-8a51-81a127f17b15

CHANGELOG
pgadmin/frm/frmStatus.cpp
pgadmin/include/frm/frmStatus.h

index 5f25ba56a5b725dde1bf31f3f3fa1ab374f1cf5f..41b2c9a6296278c4317d1213ff6a7eb950255190 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -36,6 +36,8 @@ Changes
 
 Date       Dev Ver     Change details
 ---------- --- ------  --------------
+2009-09-28 GL  1.12.0  Allow the change of database for the lock report on the
+                       server status window.
 2009-09-25 GL  1.12.0  Highlight processes according to their activity.
 2009-09-24 GL  1.10.1  Reverse engineer function defaults values correctly.
 2009-09-18 DP  1.10.1  Fix a potential crash in the edit grid.
index fed6eaf94e1f7fced65194538af58c8258c5af2c..864568bd8050fc91bca37486fa16f83c9253cc01 100644 (file)
@@ -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"
 #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 @@ BEGIN_EVENT_TABLE(frmStatus, pgFrame)
     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 @@ frmStatus::frmStatus(frmMain *form, const wxString& _title, pgConn *conn) : pgFr
 
     mainForm = form;
     connection = conn;
+    locks_connection = conn;
 
     statusTimer = 0;
     locksTimer = 0;
@@ -239,6 +249,9 @@ frmStatus::frmStatus(frmMain *form, const wxString& _title, pgConn *conn) : pgFr
     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 @@ frmStatus::frmStatus(frmMain *form, const wxString& _title, pgConn *conn) : pgFr
     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 @@ frmStatus::frmStatus(frmMain *form, const wxString& _title, pgConn *conn) : pgFr
     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 @@ frmStatus::~frmStatus()
     }
 
     // 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::OnExit(wxCommandEvent& event)
 }
 
 
+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 @@ void frmStatus::AddLockPane()
     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 @@ void frmStatus::OnRefreshLocksTimer(wxTimerEvent &event)
     if (! viewMenu->IsChecked(MNU_LOCKPAGE))
         return;
 
-    if (!connection)
+    if (!locks_connection)
     {
         statusTimer->Stop();
         locksTimer->Stop();
@@ -1172,16 +1208,16 @@ void frmStatus::OnRefreshLocksTimer(wxTimerEvent &event)
     }
 
     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 @@ void frmStatus::OnRefreshLocksTimer(wxTimerEvent &event)
               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 @@ void frmStatus::OnRefreshLocksTimer(wxTimerEvent &event)
               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 @@ void frmStatus::OnRefreshLocksTimer(wxTimerEvent &event)
                 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 @@ void frmStatus::OnRefreshLocksTimer(wxTimerEvent &event)
 
                 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 @@ void frmStatus::checkConnection()
             logTimer->Stop();
         statusBar->SetStatusText(_("Connection broken."));
     }
+    if (!locks_connection->IsAlive())
+    {
+        locks_connection = connection;
+    }
 }
 
 
index cd68761415fdda68f3bac33876778a16b9c32617..0f65dabb9e6c31d54d08c9888c2d816fffc244ea 100644 (file)
@@ -69,12 +69,13 @@ enum
 #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 @@ private:
     wxAuiManager manager;
     
     frmMain *mainForm;
-    pgConn *connection;
+    pgConn *connection, *locks_connection;
 
     wxString logFormat;
     bool logHasTimestamp, logFormatKnown;
@@ -118,6 +119,7 @@ private:
     ctlComboBoxFix    *cbRate;
     wxComboBox    *cbLogfiles;
     wxButton      *btnRotateLog;
+    ctlComboBoxFix *cbDatabase;
     
     wxTimer *refreshUITimer;
     wxTimer *statusTimer, *locksTimer, *xactTimer, *logTimer;
@@ -177,6 +179,8 @@ private:
     void OnCommit(wxCommandEvent &event);
     void OnRollback(wxCommandEvent &event);
 
+    void OnChangeDatabase(wxCommandEvent &ev);
+
     int fillLogfileCombo();
     void emptyLogfileCombo();