Skip to content
Permalink
Browse files

Merge pull request #829 from mhugent/ogr_odbc_subset

Fix subset for ODBC ogr layers
  • Loading branch information
mhugent committed Aug 25, 2013
2 parents bb798b4 + 8e43791 commit 7f2d84cdc51f20912b9f3ebe06c8b17a86b7e749
@@ -54,10 +54,7 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrProvider* p, const QgsFeatur

if ( !P->subsetString().isEmpty() )
{
QByteArray sql = "SELECT * FROM " + P->quotedIdentifier( OGR_FD_GetName( OGR_L_GetLayerDefn( ogrLayer ) ) );
sql += " WHERE " + P->textEncoding()->fromUnicode( P->subsetString() );
QgsDebugMsg( QString( "SQL: %1" ).arg( P->textEncoding()->toUnicode( sql ) ) );
ogrLayer = OGR_DS_ExecuteSQL( ogrDataSource, sql.constData(), NULL, NULL );
ogrLayer = P->setSubsetString( ogrLayer, ogrDataSource );
mSubsetStringSet = true;
}

@@ -398,12 +398,8 @@ bool QgsOgrProvider::setSubsetString( QString theSQL, bool updateFeatureCount )

if ( !mSubsetString.isEmpty() )
{
QByteArray sql = "SELECT * FROM " + quotedIdentifier( OGR_FD_GetName( OGR_L_GetLayerDefn( ogrOrigLayer ) ) );
sql += " WHERE " + mEncoding->fromUnicode( mSubsetString );

QgsDebugMsg( QString( "SQL: %1" ).arg( mEncoding->toUnicode( sql ) ) );
ogrLayer = OGR_DS_ExecuteSQL( ogrDataSource, sql.constData(), NULL, NULL );

ogrLayer = setSubsetString( ogrOrigLayer, ogrDataSource );
if ( !ogrLayer )
{
pushError( tr( "OGR[%1] error %2: %3" ).arg( CPLGetLastErrorType() ).arg( CPLGetLastErrorNo() ).arg( CPLGetLastErrorMsg() ) );
@@ -2415,6 +2411,26 @@ OGRwkbGeometryType QgsOgrProvider::ogrWkbSingleFlatten( OGRwkbGeometryType type
}
}

OGRLayerH QgsOgrProvider::setSubsetString( OGRLayerH layer, OGRDataSourceH ds )
{
QByteArray layerName = OGR_FD_GetName( OGR_L_GetLayerDefn( layer ) );
if ( ogrDriverName == "ODBC" ) //the odbc driver does not like schema names for subset
{
QString layerNameString = mEncoding->toUnicode( layerName );
int dotIndex = layerNameString.indexOf( "." );
if ( dotIndex > 1 )
{
QString modifiedLayerName = layerNameString.right( layerNameString.size() - dotIndex - 1 );
layerName = mEncoding->fromUnicode( modifiedLayerName );
}
}
QByteArray sql = "SELECT * FROM " + quotedIdentifier( layerName );
sql += " WHERE " + mEncoding->fromUnicode( mSubsetString );

QgsDebugMsg( QString( "SQL: %1" ).arg( mEncoding->toUnicode( sql ) ) );
return OGR_DS_ExecuteSQL( ds, sql.constData(), NULL, NULL );
}

// ---------------------------------------------------------------------------

QGISEXTERN QgsVectorLayerImport::ImportError createEmptyLayer(
@@ -341,6 +341,8 @@ class QgsOgrProvider : public QgsVectorDataProvider
/**Calls OGR_L_SyncToDisk and recreates the spatial index if present*/
bool syncToDisc();

OGRLayerH setSubsetString( OGRLayerH layer, OGRDataSourceH ds );

friend class QgsOgrFeatureIterator;
QSet< QgsOgrFeatureIterator* > mActiveIterators;
};

0 comments on commit 7f2d84c

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