Skip to content

Commit 30f498f

Browse files
committed
Compile some supported functions for spatialite provider
1 parent 9615ac4 commit 30f498f

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

src/core/qgssqliteexpressioncompiler.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,25 @@ QString QgsSQLiteExpressionCompiler::quotedValue( const QVariant& value, bool& o
8484
}
8585
}
8686

87+
static const QMap<QString, QString>& functionNamesSqlFunctionsMap()
88+
{
89+
static QMap<QString, QString> fnNames;
90+
if ( fnNames.isEmpty() )
91+
{
92+
fnNames =
93+
{
94+
{ "abs", "abs" },
95+
{ "round", "round" }
96+
};
97+
}
98+
return fnNames;
99+
}
100+
101+
QString QgsSQLiteExpressionCompiler::sqlFunctionFromFunctionName( const QString& fnName ) const
102+
{
103+
return functionNamesSqlFunctionsMap().value( fnName, QString() );
104+
}
105+
87106
QString QgsSQLiteExpressionCompiler::castToReal( const QString& value ) const
88107
{
89108
return QStringLiteral( "CAST((%1) AS REAL)" ).arg( value );

src/core/qgssqliteexpressioncompiler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class CORE_EXPORT QgsSQLiteExpressionCompiler : public QgsSqlExpressionCompiler
4444
virtual Result compileNode( const QgsExpression::Node* node, QString& str ) override;
4545
virtual QString quotedIdentifier( const QString& identifier ) override;
4646
virtual QString quotedValue( const QVariant& value, bool& ok ) override;
47+
virtual QString sqlFunctionFromFunctionName( const QString& fnName ) const override;
4748
virtual QString castToReal( const QString& value ) const override;
4849
virtual QString castToInt( const QString& value ) const override;
4950

tests/src/python/providertestbase.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def runGetFeatureTests(self, provider):
243243
self.assert_query(provider, 'log(3, pk) <= 1', [1, 2, 3])
244244
self.assert_query(provider, 'log10(pk) < 0.5', [1, 2, 3])
245245
self.assert_query(provider, 'round(3.14) <= pk', [3, 4, 5])
246+
self.assert_query(provider, 'round(0.314,1) * 10 = pk', [3])
246247
self.assert_query(provider, 'floor(3.14) <= pk', [3, 4, 5])
247248
self.assert_query(provider, 'ceil(3.14) <= pk', [4, 5])
248249
self.assert_query(provider, 'pk < pi()', [1, 2, 3])

tests/src/python/test_provider_shapefile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def uncompiledFilters(self):
147147
'log(3, pk) <= 1',
148148
'log10(pk) < 0.5',
149149
'round(3.14) <= pk',
150+
'round(0.314,1) * 10 = pk',
150151
'floor(3.14) <= pk',
151152
'ceil(3.14) <= pk',
152153
'pk < pi()',

tests/src/python/test_provider_spatialite.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ def uncompiledFilters(self):
197197
'sqrt(pk) >= 2',
198198
'radians(cnt) < 2',
199199
'degrees(pk) <= 200',
200-
'abs(cnt) <= 200',
201200
'cos(pk) < 0',
202201
'sin(pk) < 0',
203202
'tan(pk) < 0',
@@ -209,11 +208,9 @@ def uncompiledFilters(self):
209208
'ln(pk) <= 1',
210209
'log(3, pk) <= 1',
211210
'log10(pk) < 0.5',
212-
'round(3.14) <= pk',
213211
'floor(3.14) <= pk',
214212
'ceil(3.14) <= pk',
215213
'pk < pi()',
216-
'round(cnt / 66.67) <= 2',
217214
'floor(cnt / 66.67) <= 2',
218215
'ceil(cnt / 66.67) <= 2',
219216
'pk < pi() / 2',

0 commit comments

Comments
 (0)