Merge branch 'master' of github.com:mapnik/mapnik
This commit is contained in:
commit
95f98e5311
2 changed files with 30 additions and 11 deletions
|
@ -58,7 +58,7 @@ public:
|
|||
{
|
||||
std::string err_msg = "Postgis Plugin: ";
|
||||
err_msg += status();
|
||||
err_msg += "\nConnection string: '";
|
||||
err_msg += "Connection string: '";
|
||||
err_msg += connection_str;
|
||||
err_msg += "'\n";
|
||||
MAPNIK_LOG_DEBUG(postgis) << "postgis_connection: creation failed, closing connection - " << this;
|
||||
|
@ -71,7 +71,7 @@ public:
|
|||
if ( ! ok ) {
|
||||
std::string err_msg = "Postgis Plugin: ";
|
||||
err_msg += status();
|
||||
err_msg += "\nConnection string: '";
|
||||
err_msg += "Connection string: '";
|
||||
err_msg += connection_str;
|
||||
err_msg += "'\n";
|
||||
close();
|
||||
|
@ -127,7 +127,7 @@ public:
|
|||
{
|
||||
std::string err_msg = "Postgis Plugin: ";
|
||||
err_msg += status();
|
||||
err_msg += "\nin executeQuery Full sql was: '";
|
||||
err_msg += "in executeQuery Full sql was: '";
|
||||
err_msg += sql;
|
||||
err_msg += "'\n";
|
||||
if ( result ) PQclear(result);
|
||||
|
@ -142,12 +142,19 @@ public:
|
|||
std::string status;
|
||||
if (conn_)
|
||||
{
|
||||
if ( isOK() ) return PQerrorMessage(conn_);
|
||||
else return "Bad connection";
|
||||
char * err_msg = PQerrorMessage(conn_);
|
||||
if (err_msg == nullptr)
|
||||
{
|
||||
status = "Bad connection\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
status = std::string(err_msg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = "Uninitialized connection";
|
||||
status = "Uninitialized connection\n";
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
@ -167,7 +174,7 @@ public:
|
|||
{
|
||||
std::string err_msg = "Postgis Plugin: ";
|
||||
err_msg += status();
|
||||
err_msg += "\nin executeAsyncQuery Full sql was: '";
|
||||
err_msg += "in executeAsyncQuery Full sql was: '";
|
||||
err_msg += sql;
|
||||
err_msg += "'\n";
|
||||
clearAsyncResult(PQgetResult(conn_));
|
||||
|
@ -191,7 +198,7 @@ public:
|
|||
{
|
||||
std::string err_msg = "Postgis Plugin: ";
|
||||
err_msg += status();
|
||||
err_msg += "\nin getNextAsyncResult";
|
||||
err_msg += "in getNextAsyncResult";
|
||||
clearAsyncResult(result);
|
||||
// We need to guarde against losing the connection
|
||||
// (i.e db restart) so here we invalidate the full connection
|
||||
|
@ -208,7 +215,7 @@ public:
|
|||
{
|
||||
std::string err_msg = "Postgis Plugin: ";
|
||||
err_msg += status();
|
||||
err_msg += "\nin getAsyncResult";
|
||||
err_msg += "in getAsyncResult";
|
||||
clearAsyncResult(result);
|
||||
// We need to be guarded against losing the connection
|
||||
// (i.e db restart), we invalidate the full connection
|
||||
|
|
|
@ -283,6 +283,16 @@ if 'postgis' in mapnik.DatasourceCache.plugin_names() \
|
|||
eq_(meta['encoding'],u'UTF8')
|
||||
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():
|
||||
ds = mapnik.PostGIS(dbname=MAPNIK_TEST_DBNAME,table='empty')
|
||||
fs = ds.featureset()
|
||||
|
@ -844,7 +854,8 @@ if 'postgis' in mapnik.DatasourceCache.plugin_names() \
|
|||
fs = ds_bad.featureset()
|
||||
for feature in fs:
|
||||
pass
|
||||
except RuntimeError:
|
||||
except RuntimeError, e:
|
||||
assert 'invalid input syntax for integer' in str(e)
|
||||
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')
|
||||
# Test must fail if error was not raised just above
|
||||
eq_(False,True)
|
||||
except RuntimeError:
|
||||
except RuntimeError, e:
|
||||
assert 'invalid input syntax for integer' in str(e)
|
||||
pass
|
||||
# This used to raise an exception before correction of issue 2042
|
||||
mapnik.render_to_file(map2,'/tmp/mapnik-postgis-test-map2.png', 'png')
|
||||
|
|
Loading…
Reference in a new issue