Index: connection.cpp
===================================================================
--- connection.cpp	(revision 7524)
+++ connection.cpp	(working copy)
@@ -11,31 +11,34 @@
 
 #include "pgAgent.h"
 
-DBconn *DBconn::primaryConn;
+#include <wx/regex.h>
+#include <wx/tokenzr.h>
+
+DBconn *DBconn::primaryConn = NULL;
 wxString DBconn::basicConnectString;
 static wxMutex s_PoolLock;
 
-DBconn::DBconn(const wxString &db)
-{
-    dbname = db;
-    inUse = false;
-    next=0;
-    prev=0;
-    majorVersion=0;
-    minorVersion=0;
-    Connect(basicConnectString  + wxT(" dbname=") + dbname);
-}
 
-
 DBconn::DBconn(const wxString &connectString, const wxString &db)
 {
-    dbname = db;
     inUse = false;
     next=0;
     prev=0;
     majorVersion=0;
     minorVersion=0;
-    Connect(connectString);
+    dbname = db;
+    connStr = connectString;
+
+    if (connectString.IsEmpty())
+    {
+        // This is a sql call to a local database. 
+        // No connection string found. Use basicConnectString.
+        Connect(basicConnectString  + wxT(" dbname=") + dbname);
+    }
+    else
+    {
+        Connect(connectString);
+    }
 }
 
 
@@ -44,11 +47,8 @@
     LogMessage(wxString::Format(_("Creating DB connection: %s"), connectString.c_str()), LOG_DEBUG);
     wxCharBuffer cstrUTF=connectString.mb_str(wxConvUTF8);
     conn=PQconnectdb(cstrUTF);
-    if (PQstatus(conn) == CONNECTION_OK)
+    if (PQstatus(conn) != CONNECTION_OK)
     {
-    }
-    else
-    {
         lastError = wxString::FromAscii(PQerrorMessage(conn));
         PQfinish(conn);
         conn=0;
@@ -56,6 +56,7 @@
     return IsValid();
 }
 
+
 DBconn::~DBconn()
 {
     // clear a single connection
@@ -66,6 +67,7 @@
     }
 }
 
+
 wxString DBconn::qtDbString(const wxString& value)
 {
     wxString result = value;	
@@ -87,16 +89,18 @@
     return result;
 }
 
+
 bool DBconn::BackendMinimumVersion(int major, int minor)
 {
     if (!majorVersion)
     {
         wxString version=ExecuteScalar(wxT("SELECT version();")) ;
-	    sscanf(version.ToAscii(), "%*s %d.%d", &majorVersion, &minorVersion);
+        sscanf(version.ToAscii(), "%*s %d.%d", &majorVersion, &minorVersion);
     }
-	return majorVersion > major || (majorVersion == major && minorVersion >= minor);
+    return majorVersion > major || (majorVersion == major && minorVersion >= minor);
 }
 
+
 DBconn *DBconn::InitConnection(const wxString &connectString)
 {
     wxMutexLocker lock(s_PoolLock);
@@ -104,80 +108,84 @@
     basicConnectString=connectString;
     wxString dbname;
 
-    int pos=basicConnectString.find(wxT("dbname="));
-    if (pos == -1)
-        dbname = wxT("postgres");
+    connInfo cnInfo = connInfo::getConnectionInfo(connectString);
+    if (cnInfo.isValid)
+    {
+        dbname = cnInfo.dbname;
+        basicConnectString = cnInfo.getConnectionString();
+        primaryConn = new DBconn(cnInfo.getConnectionString(), dbname);
+        
+        if (!primaryConn)
+            LogMessage(_("Failed to create primary connection!"), LOG_ERROR);
+        primaryConn->dbname = dbname;
+        primaryConn->inUse = true;
+    }
     else
     {
-        dbname = basicConnectString.substr(pos+7);
-        basicConnectString = basicConnectString.substr(0, pos);
-        pos = dbname.find(wxT(" "));
-        if (pos != -1)
-        {
-            if (basicConnectString.length())
-                basicConnectString += wxT(" ");
-            basicConnectString += dbname.substr(pos+1);
-            dbname = dbname.substr(0, pos);
-        }
+        primaryConn = NULL;
+        LogMessage(wxT("Primary connection string is not valid!!!"), LOG_ERROR);
     }
-    primaryConn = new DBconn(connectString, dbname);
 
-    if (!primaryConn)
-        LogMessage(_("Failed to create primary connection!"), LOG_ERROR);
-
-    primaryConn->inUse = true;
-
     return primaryConn;
 }
 
 
-DBconn *DBconn::Get(const wxString &db)
+DBconn *DBconn::Get(const wxString &connStr, const wxString &db)
 {
-    if (db.IsEmpty())
+    if (db.IsEmpty() && connStr.IsEmpty())
     {
-        LogMessage(_("Cannot allocate connection - no database specified!"), LOG_WARNING);
+        LogMessage(_("Cannot allocate connection - no database or connection string specified!"), LOG_WARNING);
         return NULL;
     }
 
     wxMutexLocker lock(s_PoolLock);
 
-    DBconn *thisConn = primaryConn, *testConn;
+    DBconn *thisConn = primaryConn, *lastConn;
 
     // find an existing connection
     do
     {
-        if (db == thisConn->dbname && !thisConn->inUse)
+        if (thisConn && ((!db.IsEmpty() && db == thisConn->dbname && connStr.IsEmpty()) || (!connStr.IsEmpty() && connStr == thisConn->connStr)) && !thisConn->inUse)
         {
             LogMessage(wxString::Format(_("Allocating existing connection to database %s"), thisConn->dbname.c_str()), LOG_DEBUG);
             thisConn->inUse = true;
             return thisConn;
         }
 
-        testConn = thisConn;
-        if (thisConn->next != 0)
-            thisConn = thisConn->next;
+        lastConn = thisConn;
+        thisConn = thisConn->next;
 
-    } while (testConn->next != 0);
+    } while (thisConn != 0);
 
 
     // No suitable connection was found, so create a new one.
-    DBconn *newConn=new DBconn(db);
+    DBconn *newConn = NULL;
+    newConn = new DBconn(connStr, db);
+
     if (newConn->conn)
     {
         LogMessage(wxString::Format(_("Allocating new connection to database %s"), newConn->dbname.c_str()), LOG_DEBUG);
         newConn->inUse = true;
-        newConn->prev = thisConn;
-        thisConn->next = newConn;
+        newConn->prev = lastConn;
+        lastConn->next = newConn;
     }
-    else
+    else if (connStr.IsEmpty())
     {
         LogMessage(wxString::Format(_("Failed to create new connection to database %s"), db.c_str()), LOG_WARNING);
+        LogMessage(wxString::Format(_("\tError message from connection : (%s)"), newConn->GetLastError().c_str()), LOG_WARNING);
         return NULL;
     }
+    else
+    {
+        LogMessage(wxString::Format(_("Failed to create new connection for connection string: %s"), connStr.c_str()), LOG_WARNING);
+        LogMessage(wxString::Format(_("\tError message from connection : (%s)"), newConn->GetLastError().c_str()), LOG_WARNING);
+        return NULL;
+    }
 
     return newConn;
 }
 
+
 void DBconn::Return()
 {
     wxMutexLocker lock(s_PoolLock);
@@ -190,6 +198,7 @@
     inUse = false;
 }
 
+
 void DBconn::ClearConnections(bool all)
 {
     wxMutexLocker lock(s_PoolLock);
@@ -271,6 +280,7 @@
     return res;
 }
 
+
 wxString DBconn::ExecuteScalar(const wxString& query)
 {
     int rows=-1;
@@ -286,6 +296,7 @@
     return wxEmptyString;
 }
 
+
 int DBconn::ExecuteVoid(const wxString &query)
 {
     int rows=-1;
@@ -298,6 +309,7 @@
     return rows;
 }
 
+
 wxString DBconn::GetLastError()
 {
     // Return the last error message, minus any trailing line ends
@@ -313,8 +325,6 @@
 
 ///////////////////////////////////////////////////////7
 
-
-
 DBresult::DBresult(DBconn *conn, const wxString &query)
 {
     wxCharBuffer cstrUTF=query.mb_str(wxConvUTF8);
@@ -372,3 +382,172 @@
     return GetString(col);
 }
 
+///////////////////////////////////////////////////////7
+
+bool connInfo::IsValidIP()
+{
+    if (host.IsEmpty())
+        return false;
+
+    // check for IPv4 format
+    wxStringTokenizer tkip4(host, wxT("."));
+    int count = 0;
+    
+    while (tkip4.HasMoreTokens())
+    {
+        unsigned long val = 0;
+        if (!tkip4.GetNextToken().ToULong(&val))
+            break;
+        if (count == 0 || count == 3)
+            if (val > 0 && val < 255)
+                count++;
+            else
+                break;
+        else if (val >= 0 && val < 255)
+            count++;
+        else
+            break;
+    }
+
+    if (count == 4)
+        return true;
+
+    // check for IPv6 format
+    wxStringTokenizer tkip6(host, wxT(":"));
+    count = 0;
+    
+    while (tkip6.HasMoreTokens())
+    {
+        unsigned long val = 0;
+        wxString strVal = tkip6.GetNextToken();
+        if (strVal.Length() > 4 || !strVal.ToULong(&val, 16))
+            return false;
+        count++;
+    }
+    if (count <= 8)
+        return true;
+    
+    // TODO:: We're not supporting mix mode (x:x:x:x:x:x:d.d.d.d)
+    //        i.e. ::ffff:12.34.56.78
+    return false;
+}
+
+
+wxString connInfo::getConnectionString()
+{
+    wxString connStr;
+    
+    // Check if it has valid connection info
+    if (!isValid)
+        return connStr;
+
+    // User
+    connStr = wxT("user=") + user;
+
+    // Port
+    if (port != 0)
+    {
+        wxString portStr;
+        portStr.Printf(wxT("%ld"), port);
+        connStr += wxT(" port=") + portStr;
+    }
+
+    // host or hostaddr
+    if (!host.IsEmpty())
+        if (IsValidIP())
+           connStr += wxT(" hostaddr=") + host;
+        else
+           connStr += wxT(" host=") + host;
+
+    // connection timeout
+    if (connection_timeout != 0)
+    {
+        wxString val;
+        val.Printf(wxT("%ld"), connection_timeout);
+        connStr += wxT(" connection_timeout=") + val;
+    }
+
+    // password
+    if (!password.IsEmpty())
+        connStr += wxT(" password=") + password;
+
+    if (!dbname.IsEmpty())
+        connStr += wxT(" dbname=") + dbname;
+
+    LogMessage(wxString::Format(_("Connection Information:")), LOG_DEBUG);
+    LogMessage(wxString::Format(_("     user         : %s"), user.c_str()), LOG_DEBUG);
+    LogMessage(wxString::Format(_("     port         : %ld"), port), LOG_DEBUG);
+    LogMessage(wxString::Format(_("     host         : %s"), host.c_str()), LOG_DEBUG);
+    LogMessage(wxString::Format(_("     dbname       : %s"), dbname.c_str()), LOG_DEBUG);
+    LogMessage(wxString::Format(_("     password     : %s"), password.c_str()), LOG_DEBUG);
+    LogMessage(wxString::Format(_("     conn timeout : %ld"), connection_timeout), LOG_DEBUG);
+
+    return connStr;
+}
+
+
+connInfo connInfo::getConnectionInfo(wxString connStr)
+{
+    connInfo cnInfo;
+
+    wxRegEx propertyExp;
+
+    // Remove the white-space(s) to match the following format
+    // i.e. prop=value
+    bool res = propertyExp.Compile(wxT("(([ ]*[\t]*)+)="));
+
+    propertyExp.ReplaceAll(&connStr, wxT("="));
+
+    res = propertyExp.Compile(wxT("=(([ ]*[\t]*)+)"));
+    propertyExp.ReplaceAll(&connStr, wxT("="));
+
+    // Seperate all the prop=value patterns
+    wxArrayString tokens = wxStringTokenize(connStr, wxT("\t \n\r"));
+    
+    unsigned int index = 0;
+    while (index < tokens.Count())
+    {
+        wxString prop, value;
+
+        wxArrayString pairs = wxStringTokenize(tokens[index++], wxT("="));
+
+        if (pairs.GetCount()!= 2)
+            return cnInfo;
+
+        prop=pairs[0];
+        value=pairs[1];
+
+        if (prop.CmpNoCase(wxT("user")) == 0)
+            cnInfo.user = value;
+        else if (prop.CmpNoCase(wxT("host")) == 0 || prop.CmpNoCase(wxT("hostAddr")) == 0)
+            cnInfo.host = value;
+        else if (prop.CmpNoCase(wxT("port")) == 0)
+        {
+            if (!value.ToULong(&cnInfo.port))
+                // port must be an unsigned integer
+                return cnInfo;
+        }
+        else if (prop.CmpNoCase(wxT("password")) == 0)
+            cnInfo.password = value;
+        else if (prop.CmpNoCase(wxT("connection_timeout")) == 0)
+        {
+            if (!value.ToULong(&cnInfo.connection_timeout))
+                // connection timeout must be an unsigned interger
+                return cnInfo;
+        }
+        else if (prop.CmpNoCase(wxT("dbname")) == 0)
+            cnInfo.dbname = value;
+        else
+            // Not valid property found
+            return cnInfo;
+    }
+
+    // If user, dbname & host all are blank than we will consider this an invalid connection string
+    if (cnInfo.user.IsEmpty() && cnInfo.dbname.IsEmpty() && cnInfo.host.IsEmpty())
+        cnInfo.isValid = false;
+    else
+        cnInfo.isValid = true;
+
+    return cnInfo;
+}
+
Index: pgagent.sql
===================================================================
--- pgagent.sql	(revision 7524)
+++ pgagent.sql	(working copy)
@@ -67,7 +67,8 @@
 jstenabled           bool                 NOT NULL DEFAULT true,
 jstkind              char                 NOT NULL CHECK (jstkind IN ('b', 's')), -- batch, sql
 jstcode              text                 NOT NULL,
-jstdbname            name                 NOT NULL DEFAULT '' CHECK ((jstdbname != '' AND jstkind = 's') OR (jstdbname = '' AND jstkind = 'b')),
+jstconnstr           text                 NOT NULL DEFAULT '' CHECK ((jstconnstr != '' AND jstkind = 's' ) OR (jstconnstr = '' AND (jstkind = 'b' OR jstdbname != ''))),
+jstdbname            name                 NOT NULL DEFAULT '' CHECK ((jstdbname != '' AND jstkind = 's' ) OR (jstdbname = '' AND (jstkind = 'b' OR jstconnstr != ''))),
 jstonerror           char                 NOT NULL CHECK (jstonerror IN ('f', 's', 'i')) DEFAULT 'f', -- fail, success, ignore
 jscnextrun           timestamptz          NULL
 ) WITHOUT OIDS;
@@ -143,6 +144,13 @@
 COMMENT ON COLUMN pgagent.pga_jobsteplog.jslstatus IS 'Status of job step: r=running, s=successfully finished,  f=failed stopping job, i=ignored failure, d=aborted';
 COMMENT ON COLUMN pgagent.pga_jobsteplog.jslresult IS 'Return code of job step';
 
+CREATE FUNCTION pgagent.pgagent_schema_version() RETURNS int2 AS '
+BEGIN
+    -- RETURNS PGAGENT MAJOR VERSION
+    -- WE WILL CHANGE THE MAJOR VERSION, ONLY IF THERE IS A SCHEMA CHANGE
+    RETURN 3;
+END;
+' LANGUAGE 'plpgsql' VOLATILE;
 
 
 CREATE OR REPLACE FUNCTION pgagent.pga_next_schedule(int4, timestamptz, timestamptz, _bool, _bool, _bool, _bool, _bool) RETURNS timestamptz AS '
Index: include/misc.h
===================================================================
--- include/misc.h	(revision 7524)
+++ include/misc.h	(working copy)
@@ -18,6 +18,7 @@
 void setOptions(int argc, char **argv, const wxString& executable);
 wxString getArg(int &argc, char** &argv);
 wxString NumToStr(const long l);
+wxString getPgAgentSchemaVersion();
 
 #endif // MISC_H
 
Index: include/connection.h
===================================================================
--- include/connection.h	(revision 7524)
+++ include/connection.h	(working copy)
@@ -21,8 +21,7 @@
 class DBconn
 {
 protected:
-    DBconn(const wxString &db);
-    DBconn(const wxString &connectString, const wxString &db);
+    DBconn(const wxString &, const wxString&);
     ~DBconn();
 
 public:
@@ -30,11 +29,12 @@
 
     bool BackendMinimumVersion(int major, int minor);
 
-    static DBconn *Get(const wxString &db);
+    static DBconn *Get(const wxString &connStr, const wxString &db);
     static DBconn *InitConnection(const wxString &connectString);
 
     static void ClearConnections(bool allIncludingPrimary=false);
     static void SetBasicConnectString(const wxString &bcs) { basicConnectString = bcs; }
+    static const wxString& GetBasicConnectString() { return basicConnectString; }
 
     wxString GetLastError();
     wxString GetDBname() { return dbname; }
@@ -43,7 +43,7 @@
     DBresult *Execute(const wxString &query);
     wxString ExecuteScalar(const wxString &query);
     int ExecuteVoid(const wxString &query);
-	void Return();
+    void Return();
 
 private:
     bool Connect(const wxString &connectString);
@@ -54,9 +54,9 @@
     static wxString basicConnectString;
 	static DBconn *primaryConn;
 
-    wxString dbname, lastError;
+    wxString dbname, lastError, connStr;
     PGconn *conn;
-	DBconn *next, *prev;
+    DBconn *next, *prev;
     bool inUse;
 
     friend class DBresult;
@@ -88,5 +88,28 @@
     friend class DBconn;
 };
 
+
+class connInfo
+{
+public:
+    connInfo() { isValid = false; connection_timeout = 0; port = 0; }
+
+private:
+    wxString      user;
+    unsigned long port;
+    wxString      host;
+    wxString      dbname;
+    unsigned long connection_timeout;
+    wxString      password;
+    bool          isValid;
+
+    wxString getConnectionString();
+    static connInfo getConnectionInfo(wxString connStr);
+
+protected:
+    bool IsValidIP();
+    friend class DBconn;
+};
+
 #endif // CONNECTION_H
 
Index: pgagent_update.sql
===================================================================
--- pgagent_update.sql	(revision 0)
+++ pgagent_update.sql	(revision 0)
@@ -0,0 +1,12 @@
+CREATE OR REPLACE FUNCTION pgagent.pgagent_schema_version() RETURNS int2 AS '
+BEGIN
+    -- RETURNS PGAGENT MAJOR VERSION
+    -- WE WILL CHANGE THE MAJOR VERSION, ONLY IF THERE IS A SCHEMA CHANGE
+    RETURN 3;
+END;
+' LANGUAGE 'plpgsql' VOLATILE;
+
+ALTER TABLE pgagent.pga_jobstep ADD COLUMN jstconnstr text NOT NULL DEFAULT '' CONSTRAINT pga_jobstep_connstr_check CHECK ((jstconnstr != '' AND jstkind = 's' ) OR (jstconnstr = '' AND (jstkind = 'b' OR jstdbname != '')));
+ALTER TABLE pgagent.pga_jobstep DROP CONSTRAINT pga_jobstep_check;
+
+ALTER TABLE pgagent.pga_jobstep ADD CONSTRAINT pga_jobstep_dbname_check CHECK ((jstdbname != '' AND jstkind = 's' ) OR (jstdbname = '' AND (jstkind = 'b' OR jstconnstr != '')));
Index: job.cpp
===================================================================
--- job.cpp	(revision 7524)
+++ job.cpp	(working copy)
@@ -78,7 +78,7 @@
 {
     int rc=0;
     DBresult *steps=threadConn->Execute(
-        wxT("SELECT jstid, jstkind, jstdbname, jstcode, jstonerror ")
+        wxT("SELECT * ")
         wxT("  FROM pgagent.pga_jobstep ")
         wxT(" WHERE jstenabled ")
         wxT("   AND jstjobid=") + jobid +
@@ -127,7 +127,10 @@
         {
             case 's':
             {
-                stepConn=DBconn::Get(steps->GetString(wxT("jstdbname")));
+                wxString jstdbname = steps->GetString(wxT("jstdbname"));
+                wxString jstconnstr = steps->GetString(wxT("jstconnstr"));
+                
+                stepConn=DBconn::Get(jstconnstr, jstdbname);
                 if (stepConn)
                 {
                     LogMessage(wxString::Format(_("Executing SQL step %s (part of job %s)"), stepid.c_str(), jobid.c_str()), LOG_DEBUG);
@@ -344,7 +347,7 @@
     runnable = false;
     jobid = jid;
 
-    DBconn *threadConn=DBconn::Get(serviceDBname);
+    DBconn *threadConn=DBconn::Get(DBconn::GetBasicConnectString(), serviceDBname);
     job = new Job(threadConn, jobid);
 
     if (job->Runnable())
Index: pgAgent.cpp
===================================================================
--- pgAgent.cpp	(revision 7524)
+++ pgAgent.cpp	(working copy)
@@ -146,8 +146,53 @@
                     LogMessage(_("Could not find the table 'pgagent.pga_job'. Have you run pgagent.sql on this database?"), LOG_ERROR);
 
                 backendPid=res->GetString(wxT("pid"));
+ 
+                delete res;
+                res = NULL;
             }
 
+            // Check for particular version
+
+            bool hasSchemaVerFunc = false;
+            wxString sqlCheckSchemaVersion
+                = wxT("SELECT COUNT(*)                                            ")\
+                  wxT("FROM pg_proc                                               ")\
+                  wxT("WHERE proname = 'pgagent_schema_version' AND               ")\
+                  wxT("      pronamespace = (SELECT oid                           ")\
+                  wxT("                      FROM pg_namespace                    ")\
+                  wxT("                      WHERE nspname = 'pgagent') AND       ")\
+                  wxT("      prorettype = (SELECT oid                             ")\
+                  wxT("                    FROM pg_type                           ")\
+                  wxT("                    WHERE typname = 'int2') AND            ")\
+                  wxT("      proargtypes = ''                                     ");
+
+            res = serviceConn->Execute(sqlCheckSchemaVersion);
+
+            if (res)
+            {
+                if (res->IsValid() && res->GetString(0) == wxT("1"))
+                    hasSchemaVerFunc = true;
+                delete res;
+                res = NULL;
+            }
+  
+            if (!hasSchemaVerFunc) 
+            {
+                wxString strSchemaVerFuncNotFound;
+                strSchemaVerFuncNotFound.Printf(_("\tCouldn't find the function 'pgagent_schema_version'.\n\tPlease upgrade pgagent schema to PgAgent-%s.\n\tUse pgagent_upgrade.sql to upgrade."), getPgAgentSchemaVersion().c_str());
+                LogMessage(strSchemaVerFuncNotFound, LOG_ERROR);
+            }
+
+            wxString strPgAgentSchemaVer= serviceConn->ExecuteScalar(wxT("SELECT pgagent.pgagent_schema_version()"));
+            wxString currentPgAgentVersion;
+            currentPgAgentVersion.Printf(_("%d"), PGAGENT_VERSION_MAJOR);
+            if (strPgAgentSchemaVer != currentPgAgentVersion)
+            {
+                wxString strSchemaVerMisMatch;
+                strSchemaVerMisMatch.Printf(_("\tSchema version does not match with the current version of pgagent\n\tCurrently supported schema version: %s.x.x\n\tCurrent pgagent version : %s"), strPgAgentSchemaVer.c_str(), getPgAgentSchemaVersion().c_str());
+                LogMessage(strSchemaVerMisMatch, LOG_ERROR);
+            }
+
             MainRestartLoop(serviceConn);
         }
 
@@ -157,3 +202,11 @@
     }
     while (1);
 }
+
+wxString getPgAgentSchemaVersion()
+{
+    wxString ver;
+    ver.Printf(_("%d.%d.%d"), PGAGENT_VERSION_MAJOR, PGAGENT_VERSION_MINOR, PGAGENT_VERSION_PATCH);
+    return ver;
+}
+
Index: misc.cpp
===================================================================
--- misc.cpp	(revision 7524)
+++ misc.cpp	(working copy)
@@ -10,6 +10,7 @@
 //////////////////////////////////////////////////////////////////////////
 
 #include "pgAgent.h"
+#include "connection.h"
 
 #ifndef __WXMSW__
 #include <unistd.h>
@@ -131,4 +132,3 @@
     return buf;
 }
 
-
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 7524)
+++ CMakeLists.txt	(working copy)
@@ -52,10 +52,10 @@
 ################################################################################
 PROJECT(pgagent)
 
-SET(VERSION 2.0.1)
+SET(VERSION 3.0.1)
 
 # CPack stuff
-SET(CPACK_PACKAGE_VERSION_MAJOR 2)
+SET(CPACK_PACKAGE_VERSION_MAJOR 3)
 SET(CPACK_PACKAGE_VERSION_MINOR 0)
 SET(CPACK_PACKAGE_VERSION_PATCH 1)
 SET(CPACK_PACKAGE_NAME "pgAgent")
@@ -69,6 +69,10 @@
 SET(CPACK_SOURCE_GENERATOR TGZ)
 SET(CPACK_SOURCE_IGNORE_FILES "\\\\.DS_Store;/CVS/;/\\\\.svn/;\\\\.swp$;\\\\.#;/#;.*~;cscope.*")
 
+ADD_DEFINITIONS(-DPGAGENT_VERSION_MAJOR=${CPACK_PACKAGE_VERSION_MAJOR})
+ADD_DEFINITIONS(-DPGAGENT_VERSION_MINOR=${CPACK_PACKAGE_VERSION_MINOR})
+ADD_DEFINITIONS(-DPGAGENT_VERSION_PATCH=${CPACK_PACKAGE_VERSION_PATCH})
+
 # This must come after we set the CPACK variables!!
 INCLUDE(CPack)
 
