postgis: throw errors if sql queries fail - closes #363

This commit is contained in:
Dane Springmeyer 2009-08-27 03:13:42 +00:00
parent 434c303e83
commit 72f9c5badc
2 changed files with 21 additions and 3 deletions

View file

@ -14,6 +14,8 @@ For a complete change history, see the SVN log.
Mapnik 0.6.2 Release
--------------------
- PostGIS Plugin: Throw and report errors if SQL execution fails (r1291) (#363)
- PostGIS Plugin: Added missing support for BigInt(int8) postgres datatypes (r1250) (#384)

View file

@ -72,10 +72,26 @@ class Connection
PGresult *result=0;
if (type==1)
{
result=PQexecParams(conn_,sql.c_str(),0,0,0,0,0,1);
return boost::shared_ptr<ResultSet>(new ResultSet(result));
result=PQexecParams(conn_,sql.c_str(),0,0,0,0,0,1);
}
result=PQexec(conn_,sql.c_str());
else
{
result=PQexec(conn_,sql.c_str());
}
if(!result || PQresultStatus(result) != PGRES_TUPLES_OK)
{
std::string s("PSQL error");
if (conn_ )
{
std::string msg = PQerrorMessage( conn_ );
if ( ! msg.empty() )
{
s += ":\n" + msg.substr( 0, msg.size() - 1 );
}
}
throw mapnik::datasource_exception( s );
}
return boost::shared_ptr<ResultSet>(new ResultSet(result));
}