Skip to content
Permalink
Browse files

Compile some supported functions for spatialite provider

  • Loading branch information
nyalldawson committed Jan 3, 2017
1 parent 9615ac4 commit 30f498f006397b35494e1621f54ac6f6feb0ac21
@@ -84,6 +84,25 @@ QString QgsSQLiteExpressionCompiler::quotedValue( const QVariant& value, bool& o
}
}

static const QMap<QString, QString>& functionNamesSqlFunctionsMap()
{
static QMap<QString, QString> fnNames;
if ( fnNames.isEmpty() )
{
fnNames =
{
{ "abs", "abs" },
{ "round", "round" }
};
}
return fnNames;
}

QString QgsSQLiteExpressionCompiler::sqlFunctionFromFunctionName( const QString& fnName ) const
{
return functionNamesSqlFunctionsMap().value( fnName, QString() );
}

QString QgsSQLiteExpressionCompiler::castToReal( const QString& value ) const
{
return QStringLiteral( "CAST((%1) AS REAL)" ).arg( value );
@@ -44,6 +44,7 @@ class CORE_EXPORT QgsSQLiteExpressionCompiler : public QgsSqlExpressionCompiler
virtual Result compileNode( const QgsExpression::Node* node, QString& str ) override;
virtual QString quotedIdentifier( const QString& identifier ) override;
virtual QString quotedValue( const QVariant& value, bool& ok ) override;
virtual QString sqlFunctionFromFunctionName( const QString& fnName ) const override;
virtual QString castToReal( const QString& value ) const override;
virtual QString castToInt( const QString& value ) const override;

@@ -243,6 +243,7 @@ def runGetFeatureTests(self, provider):
self.assert_query(provider, 'log(3, pk) <= 1', [1, 2, 3])
self.assert_query(provider, 'log10(pk) < 0.5', [1, 2, 3])
self.assert_query(provider, 'round(3.14) <= pk', [3, 4, 5])
self.assert_query(provider, 'round(0.314,1) * 10 = pk', [3])
self.assert_query(provider, 'floor(3.14) <= pk', [3, 4, 5])
self.assert_query(provider, 'ceil(3.14) <= pk', [4, 5])
self.assert_query(provider, 'pk < pi()', [1, 2, 3])
@@ -147,6 +147,7 @@ def uncompiledFilters(self):
'log(3, pk) <= 1',
'log10(pk) < 0.5',
'round(3.14) <= pk',
'round(0.314,1) * 10 = pk',
'floor(3.14) <= pk',
'ceil(3.14) <= pk',
'pk < pi()',
@@ -197,7 +197,6 @@ def uncompiledFilters(self):
'sqrt(pk) >= 2',
'radians(cnt) < 2',
'degrees(pk) <= 200',
'abs(cnt) <= 200',
'cos(pk) < 0',
'sin(pk) < 0',
'tan(pk) < 0',
@@ -209,11 +208,9 @@ def uncompiledFilters(self):
'ln(pk) <= 1',
'log(3, pk) <= 1',
'log10(pk) < 0.5',
'round(3.14) <= pk',
'floor(3.14) <= pk',
'ceil(3.14) <= pk',
'pk < pi()',
'round(cnt / 66.67) <= 2',
'floor(cnt / 66.67) <= 2',
'ceil(cnt / 66.67) <= 2',
'pk < pi() / 2',

0 comments on commit 30f498f

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