Hi,

Someone, on a french PostgreSQL forum, ask me for a statement timeout UI in 
the query tool. Here is what I've done so far:

 * add a config in the Query tab of the Options window;
 * add a textbox in the toolbar of the query tool;
 * each query executed will first get the old statement_timeout value, set
   statement_timeout to the text box one (which is initialized with the config
   value), execute the real query, and then get back to the old value

I checked the UI on Windows, Mac OS X, and Linux.

The patch is attached.

Comments?


-- 
Guillaume.
 http://www.postgresqlfr.org
 http://dalibo.com
diff --git a/pgadmin/frm/frmOptions.cpp b/pgadmin/frm/frmOptions.cpp
index 3c33df2..24b6d12 100644
--- a/pgadmin/frm/frmOptions.cpp
+++ b/pgadmin/frm/frmOptions.cpp
@@ -1,7 +1,7 @@
 //////////////////////////////////////////////////////////////////////////
 //
 // pgAdmin III - PostgreSQL Tools
-// RCS-ID:      $Id$
+// RCS-ID:      $Id: frmOptions.cpp 8084 2009-11-20 01:42:32Z dpage $
 // Copyright (C) 2002 - 2009, The pgAdmin Development Team
 // This software is released under the BSD Licence
 //
@@ -76,6 +76,7 @@
 #define btnSlowProcessColour        CTRL_BUTTON("btnSlowProcessColour")
 #define txtBlockedProcessColour     CTRL_TEXT("txtBlockedProcessColour")
 #define btnBlockedProcessColour     CTRL_BUTTON("btnBlockedProcessColour")
+#define txtStatementTimeout         CTRL_TEXT("txtStatementTimeout")
 
 BEGIN_EVENT_TABLE(frmOptions, pgDialog)
     EVT_MENU(MNU_HELP,                           frmOptions::OnHelp)
@@ -203,6 +204,7 @@ frmOptions::frmOptions(frmMain *parent)
     chkSpacesForTabs->SetValue(settings->GetSpacesForTabs());
     cbCopyQuote->SetSelection(settings->GetCopyQuoting());
     cbCopyQuoteChar->SetValue(settings->GetCopyQuoteChar());
+    txtStatementTimeout->SetValue(settings->GetStatementTimeout());
 
     wxString copySeparator = settings->GetCopyColSeparator();
     if (copySeparator == wxT("\t"))
@@ -475,6 +477,7 @@ void frmOptions::OnOK(wxCommandEvent &ev)
     settings->SetSpacesForTabs(chkSpacesForTabs->GetValue());
     settings->SetCopyQuoting(cbCopyQuote->GetCurrentSelection());
     settings->SetCopyQuoteChar(cbCopyQuoteChar->GetValue());
+    settings->SetStatementTimeout(txtStatementTimeout->GetValue());
     
     wxString copySeparator = cbCopySeparator->GetValue();
     if (copySeparator == _("Tab"))
diff --git a/pgadmin/frm/frmQuery.cpp b/pgadmin/frm/frmQuery.cpp
index 93fe8f8..7fbc1f4 100644
--- a/pgadmin/frm/frmQuery.cpp
+++ b/pgadmin/frm/frmQuery.cpp
@@ -1,7 +1,7 @@
 //////////////////////////////////////////////////////////////////////////
 //
 // pgAdmin III - PostgreSQL Tools
-// RCS-ID:      $Id$
+// RCS-ID:      $Id: frmQuery.cpp 8102 2009-12-03 08:54:54Z guillaume $
 // Copyright (C) 2002 - 2009, The pgAdmin Development Team
 // This software is released under the BSD Licence
 //
@@ -77,6 +77,7 @@
 
 #define CTRLID_CONNECTION       4200
 #define CTRLID_DATABASELABEL    4201
+#define CTL_TXTSTTIMEOUT        4202
 
 // Initialize execution 'mutex'. As this will always run in the
 // main thread, there aren't any real concurrency issues, so
@@ -384,6 +385,15 @@ pgsTimer(new pgScriptTimer(this))
     toolBar->AddTool(MNU_CANCEL, _("Cancel"), wxBitmap(query_cancel_xpm), _("Cancel query"), wxITEM_NORMAL);
     toolBar->AddSeparator();
 
+    toolBar->AddTool(MNU_CANCEL, _("Cancel"), wxBitmap(query_cancel_xpm), _("Cancel query"), wxITEM_NORMAL);
+    toolBar->AddSeparator();
+
+    txtStatementTimeout = new wxTextCtrl(toolBar, CTL_TXTSTTIMEOUT, wxT(""));
+	txtStatementTimeout->SetToolTip(wxT("Set statement timeout"));
+    txtStatementTimeout->SetValue(settings->GetStatementTimeout());
+    toolBar->AddControl(txtStatementTimeout);
+    toolBar->AddSeparator();
+
     toolBar->AddTool(MNU_HELP, _("Help"), wxBitmap(help_xpm), _("Display help on SQL commands."), wxITEM_NORMAL);
     toolBar->Realize();
 
@@ -2116,6 +2126,16 @@ void frmQuery::execQuery(const wxString &query, int resultToRetrieve, bool singl
 
     aborted=false;
 
+    if (txtStatementTimeout->GetValue() != wxT(""))
+    {
+        pgSet *set = conn->ExecuteSet(wxT("SHOW statement_timeout"));
+        if (set)
+            statement_timeout = set->GetVal(wxT("statement_timeout"));
+        else
+            statement_timeout = wxT("");
+        conn->ExecuteVoid(wxT("SET statement_timeout TO ") + conn->qtDbString(txtStatementTimeout->GetValue()));
+    }
+
     QueryExecInfo *qi = new QueryExecInfo();
     qi->queryOffset = queryOffset;
     qi->toFile = toFile;
@@ -2146,6 +2166,12 @@ void frmQuery::execQuery(const wxString &query, int resultToRetrieve, bool singl
         return;
     }
 
+    if (txtStatementTimeout->GetValue() != wxT("") && statement_timeout != wxT(""))
+    {
+        conn->ExecuteVoid(wxT("SET statement_timeout TO ") + conn->qtDbString(statement_timeout));
+        statement_timeout = wxT("");
+    }
+
     completeQuery(false, false, false);
 }
 
@@ -2313,6 +2339,12 @@ void frmQuery::OnQueryComplete(wxCommandEvent &ev)
         }
     }
 
+    if (txtStatementTimeout->GetValue() != wxT("") && statement_timeout != wxT(""))
+    {
+        conn->ExecuteVoid(wxT("SET statement_timeout TO ") + conn->qtDbString(statement_timeout));
+        statement_timeout = wxT("");
+    }
+
     completeQuery(done, qi->explain, qi->verbose);
 }
 
diff --git a/pgadmin/include/frm/frmQuery.h b/pgadmin/include/frm/frmQuery.h
index 5a70f82..c0fefd3 100644
--- a/pgadmin/include/frm/frmQuery.h
+++ b/pgadmin/include/frm/frmQuery.h
@@ -1,7 +1,7 @@
 //////////////////////////////////////////////////////////////////////////
 //
 // pgAdmin III - PostgreSQL Tools
-// RCS-ID:      $Id$
+// RCS-ID:      $Id: frmQuery.h 8080 2009-11-19 07:12:08Z guillaume $
 // Copyright (C) 2002 - 2009, The pgAdmin Development Team
 // This software is released under the BSD Licence
 //
@@ -28,15 +28,15 @@
 #include <wx/dcbuffer.h>
 #include <wx/timer.h>
 
-#define FRMQUERY_PERPSECTIVE_VER wxT("$Rev$")
+#define FRMQUERY_PERPSECTIVE_VER wxT("$Rev: 8080 $")
 
 #ifdef __WXMAC__
-#define FRMQUERY_DEFAULT_PERSPECTIVE wxT("layout2|name=toolBar;caption=Tool bar;state=16788208;dir=1;layer=10;row=0;pos=0;prop=100000;bestw=415;besth=23;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=databaseBar;caption=Database bar;state=16788208;dir=1;layer=10;row=0;pos=396;prop=100000;bestw=250;besth=21;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=sqlQuery;caption=SQL query;state=17404;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=350;besth=200;minw=200;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=outputPane;caption=Output pane;state=16779260;dir=3;layer=0;row=0;pos=0;prop=100000;bestw=550;besth=300;minw=200;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=scratchPad;caption=Scratch pad;state=16779260;dir=2;layer=0;row=0;pos=0;prop=100000;bestw=250;besth=200;minw=100;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(1,10,0)=25|dock_size(5,0,0)=200|dock_size(3,0,0)=290|dock_size(2,0,0)=255|")
+#define FRMQUERY_DEFAULT_PERSPECTIVE wxT("layout2|name=toolBar;caption=Tool bar;state=16788208;dir=1;layer=10;row=0;pos=0;prop=100000;bestw=565;besth=30;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=databaseBar;caption=Database bar;state=16788208;dir=1;layer=10;row=0;pos=396;prop=100000;bestw=250;besth=21;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=sqlQuery;caption=SQL query;state=17404;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=350;besth=200;minw=200;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=outputPane;caption=Output pane;state=16779260;dir=3;layer=0;row=0;pos=0;prop=100000;bestw=550;besth=300;minw=200;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=scratchPad;caption=Scratch pad;state=16779260;dir=2;layer=0;row=0;pos=0;prop=100000;bestw=250;besth=200;minw=100;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(1,10,0)=25|dock_size(5,0,0)=200|dock_size(3,0,0)=290|dock_size(2,0,0)=255|")
 #else
 #ifdef __WXGTK__
-#define FRMQUERY_DEFAULT_PERSPECTIVE wxT("layout2|name=toolBar;caption=Tool bar;state=16788208;dir=1;layer=10;row=0;pos=0;prop=100000;bestw=525;besth=30;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=databaseBar;caption=Database bar;state=16788208;dir=1;layer=10;row=0;pos=396;prop=100000;bestw=250;besth=30;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=sqlQuery;caption=SQL query;state=17404;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=350;besth=200;minw=200;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=outputPane;caption=Output pane;state=16779260;dir=3;layer=0;row=0;pos=0;prop=100000;bestw=550;besth=300;minw=200;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=scratchPad;caption=Scratch pad;state=16779260;dir=2;layer=0;row=0;pos=0;prop=100000;bestw=250;besth=200;minw=100;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(1,10,0)=25|dock_size(5,0,0)=200|dock_size(3,0,0)=290|dock_size(2,0,0)=255|")
+#define FRMQUERY_DEFAULT_PERSPECTIVE wxT("layout2|name=toolBar;caption=Tool bar;state=16788208;dir=1;layer=10;row=0;pos=0;prop=100000;bestw=625;besth=30;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=databaseBar;caption=Database bar;state=16788208;dir=1;layer=10;row=0;pos=396;prop=100000;bestw=250;besth=30;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=sqlQuery;caption=SQL query;state=17404;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=350;besth=200;minw=200;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=outputPane;caption=Output pane;state=16779260;dir=3;layer=0;row=0;pos=0;prop=100000;bestw=550;besth=300;minw=200;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=scratchPad;caption=Scratch pad;state=16779260;dir=2;layer=0;row=0;pos=0;prop=100000;bestw=250;besth=200;minw=100;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(1,10,0)=25|dock_size(5,0,0)=200|dock_size(3,0,0)=290|dock_size(2,0,0)=255|")
 #else
-#define FRMQUERY_DEFAULT_PERSPECTIVE wxT("layout2|name=toolBar;caption=Tool bar;state=16788208;dir=1;layer=10;row=0;pos=0;prop=100000;bestw=415;besth=23;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=databaseBar;caption=Database bar;state=16788208;dir=1;layer=10;row=0;pos=396;prop=100000;bestw=250;besth=21;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=sqlQuery;caption=SQL query;state=17404;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=350;besth=200;minw=200;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=outputPane;caption=Output pane;state=16779260;dir=3;layer=0;row=0;pos=0;prop=100000;bestw=550;besth=300;minw=200;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=scratchPad;caption=Scratch pad;state=16779260;dir=2;layer=0;row=0;pos=0;prop=100000;bestw=250;besth=200;minw=100;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(1,10,0)=25|dock_size(5,0,0)=200|dock_size(3,0,0)=290|dock_size(2,0,0)=255|")
+#define FRMQUERY_DEFAULT_PERSPECTIVE wxT("layout2|name=toolBar;caption=Tool bar;state=16788208;dir=1;layer=10;row=0;pos=0;prop=100000;bestw=565;besth=23;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=databaseBar;caption=Database bar;state=16788208;dir=1;layer=10;row=0;pos=396;prop=100000;bestw=250;besth=21;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=sqlQuery;caption=SQL query;state=17404;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=350;besth=200;minw=200;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=outputPane;caption=Output pane;state=16779260;dir=3;layer=0;row=0;pos=0;prop=100000;bestw=550;besth=300;minw=200;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=scratchPad;caption=Scratch pad;state=16779260;dir=2;layer=0;row=0;pos=0;prop=100000;bestw=250;besth=200;minw=100;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(1,10,0)=25|dock_size(5,0,0)=200|dock_size(3,0,0)=290|dock_size(2,0,0)=255|")
 #endif
 #endif
 
@@ -82,10 +82,14 @@ private:
     wxTextCtrl *msgResult, *msgHistory;
     ctlComboBoxFix *cbConnection;
     wxTextCtrl *scratchPad;
+    wxTextCtrl *txtStatementTimeout;
 
 	// Query timing/status update
     wxTimer timer;
     wxLongLong elapsedQuery, startTimeQuery;
+
+    // Query timeout
+    wxString statement_timeout;
     
     // pgScript interface
     pgsApplication * pgScript;
diff --git a/pgadmin/include/utils/sysSettings.h b/pgadmin/include/utils/sysSettings.h
index 05cf68b..7ac3710 100644
--- a/pgadmin/include/utils/sysSettings.h
+++ b/pgadmin/include/utils/sysSettings.h
@@ -1,7 +1,7 @@
 //////////////////////////////////////////////////////////////////////////
 //
 // pgAdmin III - PostgreSQL Tools
-// RCS-ID:      $Id$
+// RCS-ID:      $Id: sysSettings.h 8044 2009-09-25 14:51:52Z guillaume $
 // Copyright (C) 2002 - 2009, The pgAdmin Development Team
 // This software is released under the BSD Licence
 //
@@ -120,6 +120,8 @@ public:
     void SetSQLFont(const wxFont &font);
     int GetLineEndingType() const { int i; Read(wxT("LineEndingType"), &i, 2); return i; }
 	void SetLineEndingType(const int newval) { Write(wxT("LineEndingType"), newval); }
+    wxString GetStatementTimeout() const { wxString s; Read(wxT("StatementTimeout"), &s, wxT("")); return s; }
+	void SetStatementTimeout(const wxString &newval) { Write(wxT("StatementTimeout"), newval); }
 
     // Status Colours options
     wxString GetIdleProcessColour() const { wxString s; Read(wxT("IdleProcessColour"), &s, wxT("#5fa4d9")); return s; }
diff --git a/pgadmin/ui/frmOptions.xrc b/pgadmin/ui/frmOptions.xrc
index 6197890..9dc1a44 100644
--- a/pgadmin/ui/frmOptions.xrc
+++ b/pgadmin/ui/frmOptions.xrc
@@ -3,7 +3,7 @@
   <object class="wxDialog" name="frmOptions">
     <title>Options</title>
     <pos>0,0d</pos>
-    <size>246,235d</size>
+    <size>246,255d</size>
     <style>wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxCAPTION|wxSYSTEM_MENU</style>
     <object class="wxNotebook" name="nbOptions">
       <object class="notebookpage">
@@ -318,6 +318,14 @@
             <pos>175,172d</pos>
             <size>226,12d</size>
           </object>
+          <object class="wxStaticText" name="stStatementTimeout">
+            <label>Statement Timeout</label>
+            <pos>5,187d</pos>
+          </object>
+          <object class="wxTextCtrl" name="txtStatementTimeout">
+            <pos>175,185d</pos>
+            <size>55,-1d</size>
+          </object>
         </object>
       </object>
       <object class="notebookpage">
@@ -414,7 +422,7 @@
         </object>
       </object>
       <pos>2,3d</pos>
-      <size>240,210d</size>
+      <size>240,230d</size>
       <object class="notebookpage">
         <label>Display</label>
         <object class="wxPanel" name="pnlDisplay">
@@ -442,18 +450,18 @@
     </object>
     <object class="wxButton" name="wxID_HELP">
       <label>&amp;Help</label>
-      <pos>2,216d</pos>
+      <pos>2,236d</pos>
     </object>
     <object class="wxButton" name="wxID_OK">
       <label>&amp;OK</label>
       <default>1</default>
-      <pos>140,216d</pos>
+      <pos>140,236d</pos>
       <tooltip>Accept the current settings and close the dialogue.</tooltip>
     </object>
     <object class="wxButton" name="wxID_CANCEL">
       <label>&amp;Cancel</label>
       <default>0</default>
-      <pos>193,216d</pos>
+      <pos>193,236d</pos>
       <tooltip>Cancel any changes and close the dialogue.</tooltip>
     </object>
   </object>
-- 
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