Hi,

On 04/26/2011 12:46 PM, Piotr Czekalski wrote:
> [...]
> I'd would appreciate such feature, because working over GSM modem, which
> is common to the administrators novadays (I think) is a nightmare ;-).
> 

Got a patch that works. See the attachment. If the query fails, it
checks if it's because of a bad connection. If connection is bad, it
resets it, and executes once again the query. If it still fails, you
have the usual error message. If it succeeds, you won't even notice that
it had to reset the connection.

I don't see any issue with this patch, but would like others to get a
look. It's wxThread and that kind of stuff is not really my thing
(threading... eeks).

And one more question, we're really early in beta stage. Usually, it
would have to wait a few months to get commited in next dev cycle. But
it is so early in this stage (actually, beta 1 is not even announced
yet), and it would be a so much welcomed patch that I think it could be
commited for this release (ie, 1.14).

Any opinions, objections, ideas?


-- 
Guillaume
 http://www.postgresql.fr
 http://dalibo.com
diff --git a/pgadmin/db/pgQueryThread.cpp b/pgadmin/db/pgQueryThread.cpp
index 010e48d..e69ee9c 100644
--- a/pgadmin/db/pgQueryThread.cpp
+++ b/pgadmin/db/pgQueryThread.cpp
@@ -44,6 +44,7 @@ pgQueryThread::pgQueryThread(pgConn *_conn, const wxString &qry, int _resultToRe
 	caller = _caller;
 	eventId = _eventId;
 	data = _data;
+    alreadyResetOnce = false;
 
 	wxLogSql(wxT("Thread query (%s:%d): %s"), conn->GetHost().c_str(), conn->GetPort(), qry.c_str());
 
@@ -192,8 +193,18 @@ int pgQueryThread::execute()
 
 int pgQueryThread::raiseEvent(int retval)
 {
-	if (caller)
+    wxLogSql(wxT("raiseEvent: %d"), retval);
+    // check if connection still there
+    if (PQstatus(conn->conn) != CONNECTION_OK && !alreadyResetOnce)
+    {
+        wxLogSql(wxT("raiseEvent: oops, trying to reset connection"));
+        PQreset(conn->conn);
+        alreadyResetOnce = true;
+        execute();
+    }
+    else if (caller)
 	{
+        wxLogSql(wxT("raiseEvent: connection OK or already resetted, default behaviour"));
 #if !defined(PGSCLI)
 		wxCommandEvent resultEvent(wxEVT_COMMAND_MENU_SELECTED, eventId);
 		resultEvent.SetClientData(data);
diff --git a/pgadmin/include/db/pgQueryThread.h b/pgadmin/include/db/pgQueryThread.h
index 4a5fde1..daa2019 100644
--- a/pgadmin/include/db/pgQueryThread.h
+++ b/pgadmin/include/db/pgQueryThread.h
@@ -56,6 +56,8 @@ private:
 	wxString messages;
 	pgSet *dataSet;
 	wxCriticalSection criticalSection;
+    
+    bool alreadyResetOnce;
 
 	void *data;
 	wxWindow *caller;
-- 
Sent via pgadmin-support mailing list (pgadmin-support@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-support

Reply via email to