Skip to content
Permalink
Browse files
Fix #9139 - Don't crash on MSSQL relations
  • Loading branch information
NathanW2 committed May 21, 2014
1 parent a94483e commit 9e67d7a6340616b7ab8719f621d54bf3d0bf02a3
Showing with 10 additions and 2 deletions.
  1. +4 −2 src/providers/mssql/qgsmssqlfeatureiterator.cpp
  2. +6 −0 src/providers/mssql/qgsmssqlfeatureiterator.h
@@ -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() )
{
@@ -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 += ",";
@@ -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;
@@ -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" );
@@ -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;
};

@@ -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.