Skip to content
Permalink
Browse files
[OGR provider] Use QgsSQLiteExpressionCompiler for SQLite and GPKG dr…
…ivers
  • Loading branch information
rouault committed Apr 26, 2016
1 parent 5ed41e3 commit 328eaade33fddbb12e2d8d1c8fd76438d36d3ac9
Showing with 14 additions and 8 deletions.
  1. +0 −4 src/providers/ogr/qgsogrexpressioncompiler.cpp
  2. +14 −4 src/providers/ogr/qgsogrfeatureiterator.cpp
@@ -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 );
}
@@ -17,6 +17,7 @@
#include "qgsogrprovider.h"
#include "qgsogrgeometrysimplifier.h"
#include "qgsogrexpressioncompiler.h"
#include "qgssqliteexpressioncompiler.h"

#include "qgsogrutils.h"
#include "qgsapplication.h"
@@ -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
@@ -118,6 +126,8 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource* source, bool
{
OGR_L_SetAttributeFilter( ogrLayer, nullptr );
}

delete compiler;
}
else
{

0 comments on commit 328eaad

Please sign in to comment.