Skip to content

Commit 7ba5f00

Browse files
committedJul 15, 2013
spatialite: fix handling of empty geometry column (fixes #8299)
1 parent 02ae90f commit 7ba5f00

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed
 

‎src/providers/spatialite/qgsspatialiteprovider.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ QgsSpatiaLiteProvider::QgsSpatiaLiteProvider( QString const &uri )
446446
gaiaVectorLayersListPtr list = NULL;
447447
gaiaVectorLayerPtr lyr = NULL;
448448
bool specialCase = false;
449-
if ( mGeometryColumn.isNull() )
449+
if ( mGeometryColumn.isEmpty() )
450450
specialCase = true; // non-spatial table
451451
if ( mQuery.startsWith( "(" ) && mQuery.endsWith( ")" ) )
452452
specialCase = true;
@@ -493,7 +493,8 @@ QgsSpatiaLiteProvider::QgsSpatiaLiteProvider( QString const &uri )
493493
{
494494
// enabling editing only for Tables [excluding Views and VirtualShapes]
495495
enabledCapabilities |= QgsVectorDataProvider::DeleteFeatures;
496-
enabledCapabilities |= QgsVectorDataProvider::ChangeGeometries;
496+
if ( !mGeometryColumn.isEmpty() )
497+
enabledCapabilities |= QgsVectorDataProvider::ChangeGeometries;
497498
enabledCapabilities |= QgsVectorDataProvider::ChangeAttributeValues;
498499
enabledCapabilities |= QgsVectorDataProvider::AddFeatures;
499500
enabledCapabilities |= QgsVectorDataProvider::AddAttributes;
@@ -3523,7 +3524,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
35233524
values = QString( ") VALUES (" );
35243525
separator = "";
35253526

3526-
if ( !mGeometryColumn.isNull() )
3527+
if ( !mGeometryColumn.isEmpty() )
35273528
{
35283529
sql += separator + quotedIdentifier( mGeometryColumn );
35293530
values += separator + geomParam();
@@ -3570,7 +3571,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
35703571
// initializing the column counter
35713572
ia = 0;
35723573

3573-
if ( !mGeometryColumn.isNull() )
3574+
if ( !mGeometryColumn.isEmpty() )
35743575
{
35753576
// binding GEOMETRY to Prepared Statement
35763577
if ( !features->geometry() )
@@ -4202,7 +4203,7 @@ bool QgsSpatiaLiteProvider::checkLayerType()
42024203

42034204
QString sql;
42044205

4205-
if ( mGeometryColumn.isNull() )
4206+
if ( mGeometryColumn.isEmpty() )
42064207
{
42074208
// checking if is a non-spatial table
42084209
sql = QString( "SELECT type FROM sqlite_master "
@@ -4479,7 +4480,7 @@ void QgsSpatiaLiteProvider::getViewSpatialIndexName()
44794480
bool QgsSpatiaLiteProvider::getGeometryDetails()
44804481
{
44814482
bool ret = false;
4482-
if ( mGeometryColumn.isNull() )
4483+
if ( mGeometryColumn.isEmpty() )
44834484
{
44844485
geomType = QGis::WKBNoGeometry;
44854486
return true;
@@ -4936,9 +4937,8 @@ bool QgsSpatiaLiteProvider::getTableSummary()
49364937
int columns;
49374938
char *errMsg = NULL;
49384939

4939-
QString sql = QString( "SELECT Min(MbrMinX(%1)), Min(MbrMinY(%1)), "
4940-
"Max(MbrMaxX(%1)), Max(MbrMaxY(%1)), Count(*) " "FROM %2" )
4941-
.arg( quotedIdentifier( mGeometryColumn ) )
4940+
QString sql = QString( "SELECT Count(*)%1 FROM %2" )
4941+
.arg( mGeometryColumn.isEmpty() ? "" : QString( ",Min(MbrMinX(%1)),Min(MbrMinY(%1)),Max(MbrMaxX(%1)),Max(MbrMaxY(%1))" ).arg( quotedIdentifier( mGeometryColumn ) ) )
49424942
.arg( mQuery );
49434943

49444944
if ( !mSubsetString.isEmpty() )
@@ -4955,14 +4955,22 @@ bool QgsSpatiaLiteProvider::getTableSummary()
49554955
{
49564956
for ( i = 1; i <= rows; i++ )
49574957
{
4958-
QString minX = results[( i * columns ) + 0];
4959-
QString minY = results[( i * columns ) + 1];
4960-
QString maxX = results[( i * columns ) + 2];
4961-
QString maxY = results[( i * columns ) + 3];
4962-
QString count = results[( i * columns ) + 4];
4963-
4964-
layerExtent.set( minX.toDouble(), minY.toDouble(), maxX.toDouble(), maxY.toDouble() );
4958+
QString count = results[( i * columns ) + 0];
49654959
numberFeatures = count.toLong();
4960+
4961+
if ( mGeometryColumn.isEmpty() )
4962+
{
4963+
layerExtent.setMinimal();
4964+
}
4965+
else
4966+
{
4967+
QString minX = results[( i * columns ) + 1];
4968+
QString minY = results[( i * columns ) + 2];
4969+
QString maxX = results[( i * columns ) + 3];
4970+
QString maxY = results[( i * columns ) + 4];
4971+
4972+
layerExtent.set( minX.toDouble(), minY.toDouble(), maxX.toDouble(), maxY.toDouble() );
4973+
}
49664974
}
49674975
}
49684976
sqlite3_free_table( results );

0 commit comments

Comments
 (0)
Please sign in to comment.