Skip to content
Permalink
Browse files

Fix subset in ogr provider for ODBC driver

  • Loading branch information
mhugent committed Aug 23, 2013
1 parent 8aa7795 commit f68af8c7fc1b51811cd8103c3c1641e40b4d80a8
Showing with 24 additions and 2 deletions.
  1. +12 −1 src/providers/ogr/qgsogrfeatureiterator.cpp
  2. +12 −1 src/providers/ogr/qgsogrprovider.cpp
@@ -54,7 +54,18 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrProvider* p, const QgsFeatur

if ( !P->subsetString().isEmpty() )
{
QByteArray sql = "SELECT * FROM " + P->quotedIdentifier( OGR_FD_GetName( OGR_L_GetLayerDefn( ogrLayer ) ) );
QByteArray layerName = OGR_FD_GetName( OGR_L_GetLayerDefn( ogrLayer ) );
if ( P->ogrDriverName == "ODBC" ) //the odbc driver does not like schema names for subset
{
QString layerNameString = P->mEncoding->toUnicode( layerName );
int dotIndex = layerNameString.indexOf( "." );
if ( dotIndex > 1 )
{
QString modifiedLayerName = layerNameString.right( layerNameString.size() - dotIndex - 1 );
layerName = P->mEncoding->fromUnicode( modifiedLayerName );
}
}
QByteArray sql = "SELECT * FROM " + P->quotedIdentifier( layerName );
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 );
@@ -398,7 +398,18 @@ bool QgsOgrProvider::setSubsetString( QString theSQL, bool updateFeatureCount )

if ( !mSubsetString.isEmpty() )
{
QByteArray sql = "SELECT * FROM " + quotedIdentifier( OGR_FD_GetName( OGR_L_GetLayerDefn( ogrOrigLayer ) ) );
QByteArray layerName = OGR_FD_GetName( OGR_L_GetLayerDefn( ogrOrigLayer ) );
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 ) ) );

0 comments on commit f68af8c

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