--- pgAgent-NG/connection.h	2013-09-11 11:34:17.570562475 +0200
+++ pgagent/include/connection.h	2013-09-11 12:02:08.412191487 +0200
@@ -9,85 +9,116 @@
 //
 //////////////////////////////////////////////////////////////////////////
 
+
 #ifndef CONNECTION_H
 #define CONNECTION_H
 
-#include <pgsql/libpq-fe.h>
+#include <libpq-fe.h>
 
 class DBresult;
-class connInfo;
+
 
 class DBconn
 {
-public:
-    DBconn(connInfo *cInfo);
+protected:
+	DBconn(const wxString &, const wxString &);
 	~DBconn();
 
-
-    std::string qtDbString(const std::string &value);
+public:
+	wxString qtDbString(const wxString &value);
 
 	bool BackendMinimumVersion(int major, int minor);
 
-    static DBconn *Get(const std::string &connStr, const std::string &db);
-    static DBconn *InitConnection(const std::string &connectString);
+	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 std::string &bcs)
+	static void SetBasicConnectString(const wxString &bcs)
 	{
 		basicConnectString = bcs;
 	}
-    static const std::string &GetBasicConnectString()
+	static const wxString &GetBasicConnectString()
 	{
 		return basicConnectString;
 	}
 
-    std::string GetLastError();
-    std::string GetDBname()
+	wxString GetLastError();
+	wxString GetDBname()
 	{
 		return dbname;
 	}
+
 	bool IsValid()
 	{
 		return conn != 0;
 	}
 
-    DBresult *Execute(const std::string &query);
-    std::string ExecuteScalar(const std::string &query);
-    int ExecuteVoid(const std::string &query);
+        bool LastCommandOk()
+        {
+                return IsCommandOk((ExecStatusType)lastResult);
+        }
+
+        bool IsCommandOk(ExecStatusType ret)
+        {
+                switch (ret)
+                {
+                        case PGRES_COMMAND_OK:
+                        case PGRES_TUPLES_OK:
+                        case PGRES_COPY_OUT:
+                        case PGRES_COPY_IN:
+#if (PG_VERSION_NUM >= 90100)
+                        case PGRES_COPY_BOTH:
+#endif
+                                return true;
+                        default:
+                                return false;
+                };
+        }
+
+        void SetLastResult(int res)
+        {
+                lastResult = res;
+        }
+
+        int GetLastResult()
+        {
+                return lastResult;
+        }
+	
+	DBresult *Execute(const wxString &query);
+	wxString ExecuteScalar(const wxString &query);
+	int ExecuteVoid(const wxString &query);
 	void Return();
 
-    connInfo* getConnInfo();
-
 private:
-    bool Connect(const std::string &connectString);
+	bool Connect(const wxString &connectString);
 
 	int minorVersion, majorVersion;
 
 protected:
-    static std::string basicConnectString;
+	static wxString basicConnectString;
 	static DBconn *primaryConn;
 
-    connInfo* cnInfo;
-
-    std::string dbname, lastError, connStr;
+	wxString dbname, lastError, connStr;
 	PGconn *conn;
 	DBconn *next, *prev;
 	bool inUse;
-
+	int lastResult;
 	friend class DBresult;
 
 };
 
+
 class DBresult
 {
 protected:
-    DBresult(DBconn *conn, const std::string &query);
+	DBresult(DBconn *conn, const wxString &query);
 
 public:
 	~DBresult();
 
-    std::string GetString(int col) const;
-    std::string GetString(const std::string &colname) const;
+	wxString GetString(int col) const;
+	wxString GetString(const wxString &colname) const;
 
 	bool IsValid() const
 	{
@@ -95,27 +126,16 @@
 	}
 	bool HasData() const
 	{
-        //std::ostringstream oss;
-        //oss << "HasData: " << " currentRow: " << currentRow << " maxRow: " << maxRows;
-        //LogMessage(oss.str(), LOG_DEBUG);
-        return currentRow < maxRows;
+		return currentRow < maxRows;
 	}
-
 	void MoveNext()
 	{
-        //std::ostringstream oss;
-        //oss << "MoveNext: " << " currentRow: " << currentRow << " maxRow: " << maxRows;
-        //LogMessage(oss.str(), LOG_DEBUG);
-        if (currentRow < maxRows) currentRow++;
+		if (currentRow < maxRows) currentRow++;
 	}
 
 	long RowsAffected() const
 	{
-        long n;
-        std::istringstream in(PQcmdTuples(result));
-        in >> n;
-        //return atol(PQcmdTuples(result));
-        return n;
+		return atol(PQcmdTuples(result));
 	}
 
 protected:
@@ -132,45 +152,21 @@
 	connInfo()
 	{
 		isValid = false;
-        connection_timeout = "0";
-        port = "5432";
+		connection_timeout = 0;
+		port = 0;
 	}
 
-    //copy constructor
-    connInfo(connInfo* preInfo)
-    {
-        isValid = false;
-
-        user = preInfo->user;
-        port = preInfo->port;
-        host = preInfo->host;
-        hostaddr = preInfo->hostaddr;
-        dbname = preInfo->dbname;
-        connection_timeout = preInfo->connection_timeout;
-        password = preInfo->password;
-        if(connection_timeout.empty()) connection_timeout = "0";
-        if(port.empty() || port == "0") port = "5432";
-
-
-    }
-//private:
-    std::string      user;
-    std::string      port;
-    std::string      host;
-    std::string      hostaddr;
-    std::string      dbname;
-    std::string      connection_timeout;
-    std::string      password;
-    bool             isValid;
-
-    std::string backendPid;
-
-    std::string getConnectionString();
-
-    connInfo getConnectionInfo();
+private:
+	wxString      user;
+	unsigned long port;
+	wxString      host;
+	wxString      dbname;
+	unsigned long connection_timeout;
+	wxString      password;
+	bool          isValid;
 
-    bool setConnectionString(std::string str_conn);
-    bool setKeyValue(std::string key, std::string val);
+	wxString getConnectionString();
+	static connInfo getConnectionInfo(wxString connStr);
 
 protected:
 	bool IsValidIP();
