Merge branch 'master' of github.com:mapnik/mapnik

This commit is contained in:
Blake Thompson 2015-03-06 17:24:34 -06:00
commit 95f98e5311
2 changed files with 30 additions and 11 deletions

View file

@ -58,7 +58,7 @@ public:
{ {
std::string err_msg = "Postgis Plugin: "; std::string err_msg = "Postgis Plugin: ";
err_msg += status(); err_msg += status();
err_msg += "\nConnection string: '"; err_msg += "Connection string: '";
err_msg += connection_str; err_msg += connection_str;
err_msg += "'\n"; err_msg += "'\n";
MAPNIK_LOG_DEBUG(postgis) << "postgis_connection: creation failed, closing connection - " << this; MAPNIK_LOG_DEBUG(postgis) << "postgis_connection: creation failed, closing connection - " << this;
@ -71,7 +71,7 @@ public:
if ( ! ok ) { if ( ! ok ) {
std::string err_msg = "Postgis Plugin: "; std::string err_msg = "Postgis Plugin: ";
err_msg += status(); err_msg += status();
err_msg += "\nConnection string: '"; err_msg += "Connection string: '";
err_msg += connection_str; err_msg += connection_str;
err_msg += "'\n"; err_msg += "'\n";
close(); close();
@ -127,7 +127,7 @@ public:
{ {
std::string err_msg = "Postgis Plugin: "; std::string err_msg = "Postgis Plugin: ";
err_msg += status(); err_msg += status();
err_msg += "\nin executeQuery Full sql was: '"; err_msg += "in executeQuery Full sql was: '";
err_msg += sql; err_msg += sql;
err_msg += "'\n"; err_msg += "'\n";
if ( result ) PQclear(result); if ( result ) PQclear(result);
@ -142,12 +142,19 @@ public:
std::string status; std::string status;
if (conn_) if (conn_)
{ {
if ( isOK() ) return PQerrorMessage(conn_); char * err_msg = PQerrorMessage(conn_);
else return "Bad connection"; if (err_msg == nullptr)
{
status = "Bad connection\n";
}
else
{
status = std::string(err_msg);
}
} }
else else
{ {
status = "Uninitialized connection"; status = "Uninitialized connection\n";
} }
return status; return status;
} }
@ -167,7 +174,7 @@ public:
{ {
std::string err_msg = "Postgis Plugin: "; std::string err_msg = "Postgis Plugin: ";
err_msg += status(); err_msg += status();
err_msg += "\nin executeAsyncQuery Full sql was: '"; err_msg += "in executeAsyncQuery Full sql was: '";
err_msg += sql; err_msg += sql;
err_msg += "'\n"; err_msg += "'\n";
clearAsyncResult(PQgetResult(conn_)); clearAsyncResult(PQgetResult(conn_));
@ -191,7 +198,7 @@ public:
{ {
std::string err_msg = "Postgis Plugin: "; std::string err_msg = "Postgis Plugin: ";
err_msg += status(); err_msg += status();
err_msg += "\nin getNextAsyncResult"; err_msg += "in getNextAsyncResult";
clearAsyncResult(result); clearAsyncResult(result);
// We need to guarde against losing the connection // We need to guarde against losing the connection
// (i.e db restart) so here we invalidate the full connection // (i.e db restart) so here we invalidate the full connection
@ -208,7 +215,7 @@ public:
{ {
std::string err_msg = "Postgis Plugin: "; std::string err_msg = "Postgis Plugin: ";
err_msg += status(); err_msg += status();
err_msg += "\nin getAsyncResult"; err_msg += "in getAsyncResult";
clearAsyncResult(result); clearAsyncResult(result);
// We need to be guarded against losing the connection // We need to be guarded against losing the connection
// (i.e db restart), we invalidate the full connection // (i.e db restart), we invalidate the full connection

View file

@ -283,6 +283,16 @@ if 'postgis' in mapnik.DatasourceCache.plugin_names() \
eq_(meta['encoding'],u'UTF8') eq_(meta['encoding'],u'UTF8')
eq_(meta['geometry_type'],mapnik.DataGeometryType.Polygon) eq_(meta['geometry_type'],mapnik.DataGeometryType.Polygon)
def test_bad_connection():
try:
ds = mapnik.PostGIS(dbname=MAPNIK_TEST_DBNAME,
table='test',
max_size=20,
geometry_field='geom',
user="rolethatdoesnotexist")
except Exception, e:
assert 'role "rolethatdoesnotexist" does not exist' in str(e)
def test_empty_db(): def test_empty_db():
ds = mapnik.PostGIS(dbname=MAPNIK_TEST_DBNAME,table='empty') ds = mapnik.PostGIS(dbname=MAPNIK_TEST_DBNAME,table='empty')
fs = ds.featureset() fs = ds.featureset()
@ -844,7 +854,8 @@ if 'postgis' in mapnik.DatasourceCache.plugin_names() \
fs = ds_bad.featureset() fs = ds_bad.featureset()
for feature in fs: for feature in fs:
pass pass
except RuntimeError: except RuntimeError, e:
assert 'invalid input syntax for integer' in str(e)
failed = True failed = True
eq_(failed,True) eq_(failed,True)
@ -907,7 +918,8 @@ if 'postgis' in mapnik.DatasourceCache.plugin_names() \
mapnik.render_to_file(map1,'/tmp/mapnik-postgis-test-map1.png', 'png') mapnik.render_to_file(map1,'/tmp/mapnik-postgis-test-map1.png', 'png')
# Test must fail if error was not raised just above # Test must fail if error was not raised just above
eq_(False,True) eq_(False,True)
except RuntimeError: except RuntimeError, e:
assert 'invalid input syntax for integer' in str(e)
pass pass
# This used to raise an exception before correction of issue 2042 # This used to raise an exception before correction of issue 2042
mapnik.render_to_file(map2,'/tmp/mapnik-postgis-test-map2.png', 'png') mapnik.render_to_file(map2,'/tmp/mapnik-postgis-test-map2.png', 'png')