Skip to content

Commit

Permalink
- Fix a couple of crashes when trying to load a postgres layer that c…
Browse files Browse the repository at this point in the history
…ontains

  geometry types that Qgis doesn't support.

- Properly close the postgres connection if the layer fails to load

- Fix up a missing \n



git-svn-id: http://svn.osgeo.org/qgis/trunk@5278 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed Apr 14, 2006
1 parent eecdb36 commit 0d38805
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/gui/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ QgsMapLayer::QgsMapLayer(int type,
// can be used) until we learn otherwise
dataSource(source),
internalName(lyrname),
popMenu(0),
mShowInOverviewAction(0),
mShowInOverview(false),
mCoordinateTransform(0),
Expand Down
24 changes: 12 additions & 12 deletions src/gui/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,23 @@ QgsVectorLayer::QgsVectorLayer(QString vectorLayerPath,
if(valid)
{
setCoordinateSystem();
}

// Default for the popup menu
popMenu = 0;
// Default for the popup menu
popMenu = 0;

// Get the update threshold from user settings. We
// do this only on construction to avoid the penality of
// fetching this each time the layer is drawn. If the user
// changes the threshold from the preferences dialog, it will
// have no effect on existing layers
QSettings settings;
updateThreshold = settings.readNumEntry("Map/updateThreshold", 1000);
//editing is now enabled by default
if(dataProvider->capabilities()&QgsVectorDataProvider::AddFeatures)
// Get the update threshold from user settings. We
// do this only on construction to avoid the penality of
// fetching this each time the layer is drawn. If the user
// changes the threshold from the preferences dialog, it will
// have no effect on existing layers
QSettings settings;
updateThreshold = settings.readNumEntry("Map/updateThreshold", 1000);
//editing is now enabled by default
if(dataProvider->capabilities()&QgsVectorDataProvider::AddFeatures)
{
startEditing();
}
}
} // QgsVectorLayer ctor


Expand Down
25 changes: 16 additions & 9 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const QString POSTGRES_DESCRIPTION = "PostgreSQL/PostGIS data provider";


QgsPostgresProvider::QgsPostgresProvider(QString const & uri)
: QgsVectorDataProvider(uri)
: QgsVectorDataProvider(uri), geomType(QGis::WKBUnknown)
{
// assume this is a valid layer until we determine otherwise
valid = true;
Expand Down Expand Up @@ -345,6 +345,10 @@ QgsPostgresProvider::QgsPostgresProvider(QString const & uri)
{
valid = false;
}

// Close the database connection if the layer isn't going to be loaded.
if (!valid)
PQfinish(connection);
}

QgsPostgresProvider::~QgsPostgresProvider()
Expand Down Expand Up @@ -2500,8 +2504,7 @@ bool QgsPostgresProvider::getGeometryDetails()
showMessageBox(tr("Unknown geometry type"),
tr("Column ") + geometryColumn + tr(" in ") +
mSchemaTableName + tr(" has a geometry type of ") +
QString::number(geomType) +
tr(", which Qgis does not currently support."));
fType + tr(", which Qgis does not currently support."));
valid = false;
}
}
Expand All @@ -2515,11 +2518,15 @@ bool QgsPostgresProvider::getGeometryDetails()
}

#ifdef QGISDEBUG
std::cout << "SRID is " << srid.toLocal8Bit().data() << '\n'
<< "type is " << fType.toLocal8Bit().data() << '\n'
<< "Feature type is " << geomType << '\n'
<< "Feature type name is "
<< QGis::qgisFeatureTypes[geomType] << std::endl;
if (valid)
std::cout << "SRID is " << srid.toLocal8Bit().data() << '\n'
<< "type is " << fType.toLocal8Bit().data() << '\n'
<< "Feature type is " << geomType << '\n'
<< "Feature type name is "
<< QGis::qgisFeatureTypes[geomType] << std::endl;
else
std::cout << "Failed to get geometry details for Postgres layer."
<< std::endl;
#endif

return valid;
Expand All @@ -2532,7 +2539,7 @@ PGresult* QgsPostgresProvider::executeDbCommand(PGconn* connection,
#ifdef QGISDEBUG
std::cout << "Executed SQL: " << sql.local8Bit().data() << '\n';
if (PQresultStatus(result) == PGRES_TUPLES_OK)
std::cout << "Command was successful.";
std::cout << "Command was successful.\n";
else
std::cout << "Command was unsuccessful. The error message was: "
<< PQresultErrorMessage(result) << ".\n";
Expand Down

0 comments on commit 0d38805

Please sign in to comment.