cvs server: Diffing src/db
Index: src/db/pgConn.cpp
===================================================================
RCS file: /disk1/cvsroot/pgadmin3/src/db/pgConn.cpp,v
retrieving revision 1.38
diff -c -r1.38 pgConn.cpp
*** src/db/pgConn.cpp	6 Oct 2003 21:42:53 -0000	1.38
--- src/db/pgConn.cpp	9 Oct 2003 20:27:57 -0000
***************
*** 30,45 ****
  #include "pgSet.h"
  #include "sysLogger.h"
  
  
  extern double libpqVersion;
  
  static void pgNoticeProcessor(void *arg, const char *message)
  {
      ((pgConn*)arg)->Notice(message);
  }
  
  
! pgConn::pgConn(const wxString& server, const wxString& database, const wxString& username, const wxString& password, int port, int sslmode)
  : conv(wxConvLibc)
  {
      wxLogInfo(wxT("Creating pgConn object"));
--- 30,64 ----
  #include "pgSet.h"
  #include "sysLogger.h"
  
+ #define TIMER_ID 333
  
  extern double libpqVersion;
  
+ BEGIN_EVENT_TABLE(pgConn, wxFrame)
+     EVT_TIMER(TIMER_ID, pgConn::OnTimer)
+ END_EVENT_TABLE()
+ 
+ 
  static void pgNoticeProcessor(void *arg, const char *message)
  {
      ((pgConn*)arg)->Notice(message);
  }
  
  
! void pgConn::OnTimer(wxTimerEvent& event)
! {
! 	if (timer->IsRunning()) timer->Stop();
! 	heartBeat = FALSE;
! 
! 	if(ExecuteScalar(wxT("SELECT 1")) != wxT("1"))
! 		wxLogError(__("Invalid heartbeat response from server: %s@%s:%d"), GetUser().c_str(), GetHost().c_str(), GetPort());
! 
! 	heartBeat = TRUE;
!     timer->Start(5000);
! }
! 
! 
! pgConn::pgConn(const wxString& server, const wxString& database, const wxString& username, const wxString& password, int port, int sslmode, bool heartbeat)
  : conv(wxConvLibc)
  {
      wxLogInfo(wxT("Creating pgConn object"));
***************
*** 47,52 ****
--- 66,75 ----
      
      needColQuoting = false;
  
+ 	// Setup the heartbeat timer.
+ 	heartBeat = heartbeat;
+ 	timer = new wxTimer(this, TIMER_ID);
+ 
      // Check the hostname/ipaddress
      struct hostent *host;
      unsigned long addr;
***************
*** 167,172 ****
--- 190,199 ----
              
              delete set;
          }
+ 
+ 		// Start the timer.
+ 		PQsetnonblocking(conn, 1);
+ 		if (heartBeat) timer->Start(5000);
      }
  }
  
***************
*** 216,221 ****
--- 243,249 ----
  
  bool pgConn::ExecuteVoid(const wxString& sql)
  {
+ 
      // Execute the query and get the status.
      PGresult *qryRes;
  
***************
*** 235,252 ****
      return res == PGRES_TUPLES_OK || res == PGRES_COMMAND_OK;
  }
  
- 
- bool pgConn::HasPrivilege(const wxString &objTyp, const wxString &objName, const wxString &priv)
- {
-     wxString res=ExecuteScalar(
-         wxT("SELECT has_") + objTyp.Lower() 
-         + wxT("_privilege(") + qtString(objName)
-         + wxT(", ") + qtString(priv) + wxT(")"));
- 
-     return StrToBool(res);
- }
- 
- 
  wxString pgConn::ExecuteScalar(const wxString& sql)
  {
      // Execute the query and get the status.
--- 263,268 ----
***************
*** 322,327 ****
--- 338,352 ----
      }
  }
  
+ bool pgConn::HasPrivilege(const wxString &objTyp, const wxString &objName, const wxString &priv)
+ {
+     wxString res=ExecuteScalar(
+         wxT("SELECT has_") + objTyp.Lower() 
+         + wxT("_privilege(") + qtString(objName)
+         + wxT(", ") + qtString(priv) + wxT(")"));
+ 
+     return StrToBool(res);
+ }
  
  wxString pgConn::GetVersionString()
  {
cvs server: Diffing src/include
Index: src/include/pgConn.h
===================================================================
RCS file: /disk1/cvsroot/pgadmin3/src/include/pgConn.h,v
retrieving revision 1.18
diff -c -r1.18 pgConn.h
*** src/include/pgConn.h	6 Oct 2003 21:42:53 -0000	1.18
--- src/include/pgConn.h	9 Oct 2003 20:27:57 -0000
***************
*** 45,59 ****
  };
  
  // Class declarations
! class pgConn
  {
  public:
!     pgConn(const wxString& server = wxT(""), const wxString& database = wxT(""), const wxString& username = wxT(""), const wxString& password = wxT(""), int port = 5432, int sslmode=0);
      ~pgConn();
      bool HasPrivilege(const wxString &objTyp, const wxString &objName, const wxString &priv);
      bool ExecuteVoid(const wxString& sql);
      wxString ExecuteScalar(const wxString& sql);
      pgSet *ExecuteSet(const wxString& sql);
      wxString GetUser() const { return wxString(PQuser(conn), wxConvUTF8); }
      wxString GetPassword() const { return wxString(PQpass(conn), wxConvUTF8); }
      wxString GetHost() const { return dbHost; }
--- 45,60 ----
  };
  
  // Class declarations
! class pgConn : wxFrame
  {
  public:
!     pgConn(const wxString& server = wxT(""), const wxString& database = wxT(""), const wxString& username = wxT(""), const wxString& password = wxT(""), int port = 5432, int sslmode=0, bool heartbeat=false);
      ~pgConn();
      bool HasPrivilege(const wxString &objTyp, const wxString &objName, const wxString &priv);
      bool ExecuteVoid(const wxString& sql);
      wxString ExecuteScalar(const wxString& sql);
      pgSet *ExecuteSet(const wxString& sql);
+ 	wxString GetDatabase() const { return wxString(PQdb(conn), wxConvUTF8); }
      wxString GetUser() const { return wxString(PQuser(conn), wxConvUTF8); }
      wxString GetPassword() const { return wxString(PQpass(conn), wxConvUTF8); }
      wxString GetHost() const { return dbHost; }
***************
*** 74,90 ****
--- 75,96 ----
      void Notice(const char *msg);
  
  private:
+ 	void OnTimer(wxTimerEvent& event);
+ 	bool heartBeat;
      PGconn *conn;
      int minorVersion, majorVersion;
      wxMBConv &conv;
      bool resolvedIP, needColQuoting;
      wxString dbHost;
      OID lastSystemOID;
+ 	wxTimer *timer;
  
      void *noticeArg;
      PQnoticeProcessor noticeProc;
  
      friend class pgQueryThread;
+ 
+ 	DECLARE_EVENT_TABLE()
  };
  
  #endif
Index: src/include/pgServer.h
===================================================================
RCS file: /disk1/cvsroot/pgadmin3/src/include/pgServer.h,v
retrieving revision 1.23
diff -c -r1.23 pgServer.h
*** src/include/pgServer.h	3 Oct 2003 22:29:15 -0000	1.23
--- src/include/pgServer.h	9 Oct 2003 20:27:57 -0000
***************
*** 28,34 ****
      ~pgServer();
      int GetType() const { return PG_SERVER; }
      wxString GetTypeName() const { return wxT("Server"); }
!     int Connect(wxFrame *form, bool lockFields = FALSE);
      bool Disconnect();
  
      wxString GetIdentifier() const;
--- 28,34 ----
      ~pgServer();
      int GetType() const { return PG_SERVER; }
      wxString GetTypeName() const { return wxT("Server"); }
!     int Connect(wxFrame *form, bool lockFields = FALSE, bool heartBeat = FALSE);
      bool Disconnect();
  
      wxString GetIdentifier() const;
cvs server: Diffing src/include/images
cvs server: Diffing src/include/nodes
cvs server: Diffing src/include/parser
cvs server: Diffing src/schema
Index: src/schema/pgServer.cpp
===================================================================
RCS file: /disk1/cvsroot/pgadmin3/src/schema/pgServer.cpp,v
retrieving revision 1.34
diff -c -r1.34 pgServer.cpp
*** src/schema/pgServer.cpp	3 Oct 2003 22:29:15 -0000	1.34
--- src/schema/pgServer.cpp	9 Oct 2003 20:27:57 -0000
***************
*** 73,79 ****
  }
  
  
! int pgServer::Connect(wxFrame *form, bool lockFields) 
  {
      wxLogInfo(wxT("Attempting to create a connection object..."));
  
--- 73,79 ----
  }
  
  
! int pgServer::Connect(wxFrame *form, bool lockFields, bool heartBeat) 
  {
      wxLogInfo(wxT("Attempting to create a connection object..."));
  
***************
*** 120,126 ****
          else
              StartMsg(wxT("Connecting to database"));
          if (conn) delete conn;
!         conn = new pgConn(GetName(), database, username, password, port, ssl);   
          EndMsg();
          if (!conn)
          {
--- 120,126 ----
          else
              StartMsg(wxT("Connecting to database"));
          if (conn) delete conn;
!         conn = new pgConn(GetName(), database, username, password, port, ssl, heartBeat);   
          EndMsg();
          if (!conn)
          {
cvs server: Diffing src/ui
Index: src/ui/frmMain.cpp
===================================================================
RCS file: /disk1/cvsroot/pgadmin3/src/ui/frmMain.cpp,v
retrieving revision 1.73
diff -c -r1.73 frmMain.cpp
*** src/ui/frmMain.cpp	3 Oct 2003 22:29:15 -0000	1.73
--- src/ui/frmMain.cpp	9 Oct 2003 20:27:57 -0000
***************
*** 492,498 ****
  int frmMain::ReconnectServer(pgServer *server)
  {
      // Create a server object and connect it.
!     int res = server->Connect(this, TRUE);
  
      // Check the result, and handle it as appropriate
      wxTreeItemId item;
--- 492,498 ----
  int frmMain::ReconnectServer(pgServer *server)
  {
      // Create a server object and connect it.
!     int res = server->Connect(this, TRUE, TRUE);
  
      // Check the result, and handle it as appropriate
      wxTreeItemId item;