Skip to content

Commit 328eaad

Browse files
committedApr 26, 2016
[OGR provider] Use QgsSQLiteExpressionCompiler for SQLite and GPKG drivers
1 parent 5ed41e3 commit 328eaad

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed
 

‎src/providers/ogr/qgsogrexpressioncompiler.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,12 @@ QgsSqlExpressionCompiler::Result QgsOgrExpressionCompiler::compile( const QgsExp
3535
return Fail;
3636
else if ( mSource->mDriverName == "OCI" )
3737
return Fail;
38-
else if ( mSource->mDriverName == "SQLite" )
39-
return Fail;
4038
else if ( mSource->mDriverName == "ODBC" )
4139
return Fail;
4240
else if ( mSource->mDriverName == "PGeo" )
4341
return Fail;
4442
else if ( mSource->mDriverName == "MSSQLSpatial" )
4543
return Fail;
46-
else if ( mSource->mDriverName == "GPKG" )
47-
return Fail;
4844

4945
return QgsSqlExpressionCompiler::compile( exp );
5046
}

‎src/providers/ogr/qgsogrfeatureiterator.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "qgsogrprovider.h"
1818
#include "qgsogrgeometrysimplifier.h"
1919
#include "qgsogrexpressioncompiler.h"
20+
#include "qgssqliteexpressioncompiler.h"
2021

2122
#include "qgsogrutils.h"
2223
#include "qgsapplication.h"
@@ -100,13 +101,20 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource* source, bool
100101
if ( request.filterType() == QgsFeatureRequest::FilterExpression
101102
&& QSettings().value( "/qgis/compileExpressions", true ).toBool() )
102103
{
103-
QgsOgrExpressionCompiler compiler = QgsOgrExpressionCompiler( source );
104-
105-
QgsSqlExpressionCompiler::Result result = compiler.compile( request.filterExpression() );
104+
QgsSqlExpressionCompiler* compiler;
105+
if ( source->mDriverName == "SQLite" || source->mDriverName == "GPKG" )
106+
{
107+
compiler = new QgsSQLiteExpressionCompiler( source->mFields );
108+
}
109+
else
110+
{
111+
compiler = new QgsOgrExpressionCompiler( source );
112+
}
106113

114+
QgsSqlExpressionCompiler::Result result = compiler->compile( request.filterExpression() );
107115
if ( result == QgsSqlExpressionCompiler::Complete || result == QgsSqlExpressionCompiler::Partial )
108116
{
109-
QString whereClause = compiler.result();
117+
QString whereClause = compiler->result();
110118
if ( OGR_L_SetAttributeFilter( ogrLayer, mSource->mEncoding->fromUnicode( whereClause ).constData() ) == OGRERR_NONE )
111119
{
112120
//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
118126
{
119127
OGR_L_SetAttributeFilter( ogrLayer, nullptr );
120128
}
129+
130+
delete compiler;
121131
}
122132
else
123133
{

0 commit comments

Comments
 (0)
Please sign in to comment.