27 #include "../core/translator/Translator.h" 39 #include <boost/format.hpp> 46 PGresult* result = PQexecParams(
m_pgconn, query.c_str(), 0,
nullptr,
nullptr,
nullptr,
nullptr, 1);
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);
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);
72 std::string msg = errmsg.str();
74 std::size_t idx = msg.find(
"invalid SRID");
76 if(idx != std::string::npos)
77 msg+=
" PostGIS doens't recognize this projection. " 78 "Please, reproject your data to a correct one. " 79 "Or save your result as Vector File, and afterwards use Exchange to put the result " 80 "in PGIS changing the USER SRID to a valid one.";
101 m_lastuse(boost::posix_time::second_clock::local_time())
103 static int newId = 0;
107 m_pgconn = PQconnectdb(conninfo.c_str());
109 ConnStatusType status = PQstatus(
m_pgconn);
111 if(status != CONNECTION_OK)
113 boost::format errmsg(
TE_TR(
"It was not possible to create a connection to the given data source due to the following error: %1%."));
115 errmsg = errmsg % PQerrorMessage(
m_pgconn);
126 if(cencoding.empty())
129 if(PQsetClientEncoding(
m_pgconn, cencoding.c_str()) == -1)
131 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%."));
133 errmsg = errmsg % PQerrorMessage(
m_pgconn);
Base exception class for plugin module.
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.
An exception class for the PostGIS driver.
boost::posix_time::ptime m_lastuse
It marks the last time this connection was used.
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.
int m_id
The connection Id.
This class implements a connection pool for the PostGIS driver.
PGresult * query(const std::string &query)
It queries the database.
ConnectionPool * m_pool
The connection pool associated to the connection.
bool m_inuse
Tells if the connection is in use or not.