Skip to content

Commit

Permalink
[OGR provider] Use QgsSQLiteExpressionCompiler for SQLite and GPKG dr…
Browse files Browse the repository at this point in the history
…ivers
  • Loading branch information
rouault committed Apr 26, 2016
1 parent 5ed41e3 commit 328eaad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 0 additions & 4 deletions src/providers/ogr/qgsogrexpressioncompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,12 @@ QgsSqlExpressionCompiler::Result QgsOgrExpressionCompiler::compile( const QgsExp
return Fail;
else if ( mSource->mDriverName == "OCI" )
return Fail;
else if ( mSource->mDriverName == "SQLite" )
return Fail;
else if ( mSource->mDriverName == "ODBC" )
return Fail;
else if ( mSource->mDriverName == "PGeo" )
return Fail;
else if ( mSource->mDriverName == "MSSQLSpatial" )
return Fail;
else if ( mSource->mDriverName == "GPKG" )
return Fail;

return QgsSqlExpressionCompiler::compile( exp );
}
Expand Down
18 changes: 14 additions & 4 deletions src/providers/ogr/qgsogrfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "qgsogrprovider.h"
#include "qgsogrgeometrysimplifier.h"
#include "qgsogrexpressioncompiler.h"
#include "qgssqliteexpressioncompiler.h"

#include "qgsogrutils.h"
#include "qgsapplication.h"
Expand Down Expand Up @@ -100,13 +101,20 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource* source, bool
if ( request.filterType() == QgsFeatureRequest::FilterExpression
&& QSettings().value( "/qgis/compileExpressions", true ).toBool() )
{
QgsOgrExpressionCompiler compiler = QgsOgrExpressionCompiler( source );

QgsSqlExpressionCompiler::Result result = compiler.compile( request.filterExpression() );
QgsSqlExpressionCompiler* compiler;
if ( source->mDriverName == "SQLite" || source->mDriverName == "GPKG" )
{
compiler = new QgsSQLiteExpressionCompiler( source->mFields );
}
else
{
compiler = new QgsOgrExpressionCompiler( source );
}

QgsSqlExpressionCompiler::Result result = compiler->compile( request.filterExpression() );
if ( result == QgsSqlExpressionCompiler::Complete || result == QgsSqlExpressionCompiler::Partial )
{
QString whereClause = compiler.result();
QString whereClause = compiler->result();
if ( OGR_L_SetAttributeFilter( ogrLayer, mSource->mEncoding->fromUnicode( whereClause ).constData() ) == OGRERR_NONE )
{
//if only partial success when compiling expression, we need to double-check results using QGIS' expressions
Expand All @@ -118,6 +126,8 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource* source, bool
{
OGR_L_SetAttributeFilter( ogrLayer, nullptr );
}

delete compiler;
}
else
{
Expand Down

0 comments on commit 328eaad

Please sign in to comment.