Skip to content

Commit 8d91c39

Browse files
author
g_j_m
committed
- Fix a couple of crashes when trying to load a postgres layer that contains
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
1 parent d43e582 commit 8d91c39

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

src/gui/qgsmaplayer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ QgsMapLayer::QgsMapLayer(int type,
5050
// can be used) until we learn otherwise
5151
dataSource(source),
5252
internalName(lyrname),
53+
popMenu(0),
5354
mShowInOverviewAction(0),
5455
mShowInOverview(false),
5556
mCoordinateTransform(0),

src/gui/qgsvectorlayer.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,23 @@ QgsVectorLayer::QgsVectorLayer(QString vectorLayerPath,
126126
if(valid)
127127
{
128128
setCoordinateSystem();
129-
}
130129

131-
// Default for the popup menu
132-
popMenu = 0;
130+
// Default for the popup menu
131+
popMenu = 0;
133132

134-
// Get the update threshold from user settings. We
135-
// do this only on construction to avoid the penality of
136-
// fetching this each time the layer is drawn. If the user
137-
// changes the threshold from the preferences dialog, it will
138-
// have no effect on existing layers
139-
QSettings settings;
140-
updateThreshold = settings.readNumEntry("Map/updateThreshold", 1000);
141-
//editing is now enabled by default
142-
if(dataProvider->capabilities()&QgsVectorDataProvider::AddFeatures)
133+
// Get the update threshold from user settings. We
134+
// do this only on construction to avoid the penality of
135+
// fetching this each time the layer is drawn. If the user
136+
// changes the threshold from the preferences dialog, it will
137+
// have no effect on existing layers
138+
QSettings settings;
139+
updateThreshold = settings.readNumEntry("Map/updateThreshold", 1000);
140+
//editing is now enabled by default
141+
if(dataProvider->capabilities()&QgsVectorDataProvider::AddFeatures)
143142
{
144143
startEditing();
145144
}
145+
}
146146
} // QgsVectorLayer ctor
147147

148148

src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const QString POSTGRES_DESCRIPTION = "PostgreSQL/PostGIS data provider";
6464

6565

6666
QgsPostgresProvider::QgsPostgresProvider(QString const & uri)
67-
: QgsVectorDataProvider(uri)
67+
: QgsVectorDataProvider(uri), geomType(QGis::WKBUnknown)
6868
{
6969
// assume this is a valid layer until we determine otherwise
7070
valid = true;
@@ -345,6 +345,10 @@ QgsPostgresProvider::QgsPostgresProvider(QString const & uri)
345345
{
346346
valid = false;
347347
}
348+
349+
// Close the database connection if the layer isn't going to be loaded.
350+
if (!valid)
351+
PQfinish(connection);
348352
}
349353

350354
QgsPostgresProvider::~QgsPostgresProvider()
@@ -2500,8 +2504,7 @@ bool QgsPostgresProvider::getGeometryDetails()
25002504
showMessageBox(tr("Unknown geometry type"),
25012505
tr("Column ") + geometryColumn + tr(" in ") +
25022506
mSchemaTableName + tr(" has a geometry type of ") +
2503-
QString::number(geomType) +
2504-
tr(", which Qgis does not currently support."));
2507+
fType + tr(", which Qgis does not currently support."));
25052508
valid = false;
25062509
}
25072510
}
@@ -2515,11 +2518,15 @@ bool QgsPostgresProvider::getGeometryDetails()
25152518
}
25162519

25172520
#ifdef QGISDEBUG
2518-
std::cout << "SRID is " << srid.toLocal8Bit().data() << '\n'
2519-
<< "type is " << fType.toLocal8Bit().data() << '\n'
2520-
<< "Feature type is " << geomType << '\n'
2521-
<< "Feature type name is "
2522-
<< QGis::qgisFeatureTypes[geomType] << std::endl;
2521+
if (valid)
2522+
std::cout << "SRID is " << srid.toLocal8Bit().data() << '\n'
2523+
<< "type is " << fType.toLocal8Bit().data() << '\n'
2524+
<< "Feature type is " << geomType << '\n'
2525+
<< "Feature type name is "
2526+
<< QGis::qgisFeatureTypes[geomType] << std::endl;
2527+
else
2528+
std::cout << "Failed to get geometry details for Postgres layer."
2529+
<< std::endl;
25232530
#endif
25242531

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

0 commit comments

Comments
 (0)