Propsed pgagent patch: pgAgent reports failure upon success - For Review - Mailing list pgadmin-hackers

From Martin French
Subject Propsed pgagent patch: pgAgent reports failure upon success - For Review
Date
Msg-id OF1A71C687.E0A5A19F-ON80257A3D.004B2F8F-80257A3D.004BB29F@LocalDomain
Whole thread Raw
Responses Re: Propsed pgagent patch: pgAgent reports failure upon success - For Review
List pgadmin-hackers
<p><tt><font size="2">Hi, </font></tt><br /><br /><tt><font size="2">I have attempted a patch for an issue where
pgAgentincorrectly reports failure on a plain SQL job. Please see below.</font></tt><br /><br /><tt><font
size="2">Feedback/commentswelcome.</font></tt><br /><br /><tt><font size="2">Thanks</font></tt><br /><br /><tt><font
size="2">MartinFrench.</font></tt><br /><br /><br /><tt><font size="2">diff --git a/connection.cpp b/connection.cpp<br
/>index5e10078..6103c00 100644<br />--- a/connection.cpp<br />+++ b/connection.cpp<br />@@ -336,6 +336,7 @@
DBresult::DBresult(DBconn*conn, const wxString &query)<br /> if (result)<br /> {<br /> int rc =
PQresultStatus(result);<br/>+ conn->SetLastResult(rc);<br /> if (rc == PGRES_TUPLES_OK)<br /> maxRows =
PQntuples(result);<br/> else if (rc != PGRES_COMMAND_OK)<br />diff --git a/include/connection.h
b/include/connection.h<br/>index 04087db..3cd1c0d 100644<br />--- a/include/connection.h<br />+++
b/include/connection.h<br/>@@ -51,7 +51,33 @@ public:<br /> {<br /> return conn != 0;<br /> }<br />-<br />+        bool
LastCommandOk()<br/>+        {<br />+                return IsCommandOk((ExecStatusType)lastResult);<br />+        }<br
/>+       bool IsCommandOk(ExecStatusType ret)<br />+        {<br />+                switch (ret)<br />+              
 {<br/>+                        case PGRES_COMMAND_OK:<br />+                        case PGRES_TUPLES_OK:<br />+      
                case PGRES_COPY_OUT:<br />+                        case PGRES_COPY_IN:<br />+                      
 casePGRES_COPY_BOTH:<br />+                                return true;<br />+                        default:<br />+
                              return false;<br />+                };<br />+        }<br />+        void
SetLastResult(intres)<br />+        {<br />+                lastResult = res;<br />+        }<br />+        int
GetLastResult()<br/>+        {<br />+                return lastResult;<br />+        }<br />+ <br /> DBresult
*Execute(constwxString &query);<br /> wxString ExecuteScalar(const wxString &query);<br /> int
ExecuteVoid(constwxString &query);<br />@@ -70,7 +96,7 @@ protected:<br /> PGconn *conn;<br /> DBconn *next,
*prev;<br/> bool inUse;<br />-<br />+ int lastResult;<br /> friend class DBresult;<br /><br /> };<br />diff --git
a/job.cppb/job.cpp<br />index 9a5bb08..ba270be 100644<br />--- a/job.cpp<br />+++ b/job.cpp<br />@@ -80,6 +80,7 @@
Job::~Job()<br/> int Job::Execute()<br /> {<br /> int rc = 0;<br />+ bool succeeded = false;<br /> DBresult *steps =
threadConn->Execute(<br/>                       wxT("SELECT * ")<br />                       wxT("  FROM
pgagent.pga_jobstep")<br />@@ -138,13 +139,14 @@ int Job::Execute()<br /> {<br />
LogMessage(wxString::Format(_("ExecutingSQL step %s (part of job %s)"), stepid.c_str(), jobid.c_str()), LOG_DEBUG);<br
/>rc = stepConn->ExecuteVoid(steps->GetString(wxT("jstcode")));<br />+ succeeded =
stepConn->LastCommandOk();<br/> output = stepConn->GetLastError();<br /> stepConn->Return();<br /> }<br />
else<br/> {<br /> output = _("Couldn't get a connection to the database!");<br />- rc = -1;<br />+ succeeded =
false;<br/> }<br /><br /><br />@@ -292,6 +294,9 @@ int Job::Execute()<br /> rc = WEXITSTATUS(rc);<br /> else<br /> rc =
-1;<br/>+ // set success status for batch runs, be pessimistic bt default<br />+ if (rc == 0)<br />+ succeeded =
true;<br/> #endif<br /><br /> // Delete the file/directory. If we fail, don't overwrite the script output in the log,
justthrow warnings.<br />@@ -319,7 +324,7 @@ int Job::Execute()<br /> }<br /><br /> wxString stepstatus;<br />- if (rc
==0)<br />+ if (succeeded)<br /> stepstatus = wxT("s");<br /> else<br /> stepstatus =
steps->GetString(wxT("jstonerror"));<br/></font></tt><font
face="sans-serif">=============================================Romax Technology Limited Rutherford House Nottingham
Science& Technology Park Nottingham, NG7 2PZ England Telephone numbers: +44 (0)115 951 88 00 (main) For other
officelocations see: http://www.romaxtech.com/Contact ================================= =============== E-mail:
info@romaxtech.comWebsite: www.romaxtech.com ================================= ================ Confidentiality
StatementThis transmission is for the addressee only and contains information that is confidential and privileged.
Unlessyou are the named addressee, or authorised to receive it on behalf of the addressee you may not copy or use it,
ordisclose it to anyone else. If you have received this transmission in error please delete from your system and
contactthe sender. Thank you for your cooperation. =================================================</font> 

pgadmin-hackers by date:

Previous
From: Akshay Joshi
Date:
Subject: Fixed pgAdmin3 folder hierarchy
Next
From: Dave Page
Date:
Subject: Re: Propsed pgagent patch: pgAgent reports failure upon success - For Review