Skip to content
Permalink
Browse files

- Fix a couple of crashes when trying to load a postgres layer that c…

…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/qgis@5278 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m
g_j_m committed Apr 14, 2006
1 parent d43e582 commit 8d91c393262fd57ef281ce6ff2c2df127fe0b0aa
Showing with 29 additions and 21 deletions.
  1. +1 −0 src/gui/qgsmaplayer.cpp
  2. +12 −12 src/gui/qgsvectorlayer.cpp
  3. +16 −9 src/providers/postgres/qgspostgresprovider.cpp
@@ -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),
@@ -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


@@ -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;
@@ -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()
@@ -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;
}
}
@@ -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;
@@ -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";

0 comments on commit 8d91c39

Please sign in to comment.
You can’t perform that action at this time.