27 #include "../common/Translator.h"
39 #include <boost/format.hpp>
48 if(PQresultStatus(result) != PGRES_TUPLES_OK)
50 boost::format errmsg(
TE_TR(
"Could not retrieve the dataset due to the following error: %1%."));
51 errmsg = errmsg % PQerrorMessage(
m_pgconn);
55 throw Exception(errmsg.str());
63 PGresult* result = PQexec(m_pgconn, command.c_str());
65 if((PQresultStatus(result) != PGRES_COMMAND_OK) &&
66 (PQresultStatus(result) != PGRES_TUPLES_OK))
68 boost::format errmsg(
TE_TR(
"Could not execute the sql statement due to the following error: %1%."));
70 errmsg = errmsg % PQerrorMessage(m_pgconn);
74 throw Exception(errmsg.str());
90 m_lastuse(boost::posix_time::second_clock::local_time())
96 m_pgconn = PQconnectdb(conninfo.c_str());
98 ConnStatusType status = PQstatus(
m_pgconn);
100 if(status != CONNECTION_OK)
102 boost::format errmsg(
TE_TR(
"It was not possible to create a connection to the given data source due to the following error: %1%."));
104 errmsg = errmsg % PQerrorMessage(
m_pgconn);
110 throw Exception(errmsg.str());
115 if(cencoding.empty())
118 if(PQsetClientEncoding(
m_pgconn, cencoding.c_str()) == -1)
120 boost::format errmsg(
TE_TR(
"It was not possible to set the client encoding for the PostGIS data source due to the following error: %1%."));
122 errmsg = errmsg % PQerrorMessage(
m_pgconn);
128 throw Exception(errmsg.str());
Connection(ConnectionPool *pool, const std::string &conninfo, const std::string &cencoding, bool inuse=false)
Constructor.
struct pg_result PGresult
#define TE_TR(message)
It marks a string in order to get translated.
void execute(const std::string &command)
It executes the given SQL command and throws away the result.
PGconn * m_pgconn
The PostgreSQL real connection handle.
A class that implements a connection to a PostgreSQL database.
static void PostGISNoticeProcessor(void *, const char *)
This will just close the PostgreSQL notice processor.
An exception class for the PostGIS driver.
This class implements a connection pool for the PostGIS driver.
PGresult * query(const std::string &query)
It queries the database.