#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)
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();
mainForm = form;
connection = conn;
+ locks_connection = conn;
statusTimer = 0;
locksTimer = 0;
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
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();
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();
}
// If connection is still available, delete it
+ if (locks_connection && locks_connection != connection)
+ delete locks_connection;
if (connection)
delete connection;
}
}
+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
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);
if (! viewMenu->IsChecked(MNU_LOCKPAGE))
return;
- if (!connection)
+ if (!locks_connection)
{
statusTimer->Stop();
locksTimer->Stop();
}
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, ")
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, ")
wxT("ORDER BY pid;");
}
- pgSet *dataSet2=connection->ExecuteSet(sql);
+ pgSet *dataSet2=locks_connection->ExecuteSet(sql);
if (dataSet2)
{
statusBar->SetStatusText(_("Refreshing locks list."));
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")));
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);
logTimer->Stop();
statusBar->SetStatusText(_("Connection broken."));
}
+ if (!locks_connection->IsAlive())
+ {
+ locks_connection = connection;
+ }
}
#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
wxAuiManager manager;
frmMain *mainForm;
- pgConn *connection;
+ pgConn *connection, *locks_connection;
wxString logFormat;
bool logHasTimestamp, logFormatKnown;
ctlComboBoxFix *cbRate;
wxComboBox *cbLogfiles;
wxButton *btnRotateLog;
+ ctlComboBoxFix *cbDatabase;
wxTimer *refreshUITimer;
wxTimer *statusTimer, *locksTimer, *xactTimer, *logTimer;
void OnCommit(wxCommandEvent &event);
void OnRollback(wxCommandEvent &event);
+ void OnChangeDatabase(wxCommandEvent &ev);
+
int fillLogfileCombo();
void emptyLogfileCombo();