Skip to content

Commit

Permalink
Fix #9139 - Don't crash on MSSQL relations
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed May 21, 2014
1 parent a94483e commit 9e67d7a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/providers/mssql/qgsmssqlfeatureiterator.cpp
Expand Up @@ -97,6 +97,7 @@ void QgsMssqlFeatureIterator::BuildStatement( const QgsFeatureRequest& request )
mAttributesToFetch.append( i );
}
}

// get fid col if not yet required
if ( mFidCol == -1 && !mSource->mFidColName.isEmpty() )
{
Expand All @@ -107,7 +108,7 @@ void QgsMssqlFeatureIterator::BuildStatement( const QgsFeatureRequest& request )
++fieldCount;
}
// get geometry col
if ( !( request.flags() & QgsFeatureRequest::NoGeometry ) && !mSource->mGeometryColName.isEmpty() )
if ( !( request.flags() & QgsFeatureRequest::NoGeometry ) && mSource->isSpatial() )
{
if ( fieldCount != 0 )
mStatement += ",";
Expand All @@ -124,7 +125,7 @@ void QgsMssqlFeatureIterator::BuildStatement( const QgsFeatureRequest& request )

bool filterAdded = false;
// set spatial filter
if ( request.filterType() & QgsFeatureRequest::FilterRect )
if ( request.filterType() & QgsFeatureRequest::FilterRect && isSpatial() )
{
// polygons should be CCW for SqlGeography
QString r;
Expand Down Expand Up @@ -162,6 +163,7 @@ void QgsMssqlFeatureIterator::BuildStatement( const QgsFeatureRequest& request )
mStatement += " and (" + mSource->mSqlWhereClause + ")";
}

// QgsDebugMsg( mStatement );
if ( fieldCount == 0 )
{
QgsDebugMsg( "QgsMssqlProvider::select no fields have been requested" );
Expand Down
6 changes: 6 additions & 0 deletions src/providers/mssql/qgsmssqlfeatureiterator.h
Expand Up @@ -62,6 +62,9 @@ class QgsMssqlFeatureSource : public QgsAbstractFeatureSource
// SQL statement used to limit the features retrieved
QString mSqlWhereClause;

// Return True if this feature source has spatial attributes.
bool isSpatial() { return !mGeometryColName.isEmpty() || !mGeometryColType.isEmpty(); }

friend class QgsMssqlFeatureIterator;
};

Expand Down Expand Up @@ -111,6 +114,9 @@ class QgsMssqlFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsM

// for parsing sql geometries
QgsMssqlGeometryParser mParser;

// Return True of the geometry column was found when parsing the columns.
bool isSpatial() { return mGeometryCol > -1; }
};

#endif // QGSMSSQLFEATUREITERATOR_H

0 comments on commit 9e67d7a

Please sign in to comment.