-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Expression compiler for SpatiaLite provider
- Loading branch information
1 parent
5f65f87
commit 35d0dd3
Showing
10 changed files
with
182 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/providers/spatialite/qgsspatialiteexpressioncompiler.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/*************************************************************************** | ||
qgsspatialiteexpressioncompiler.cpp | ||
----------------------------------- | ||
begin : November 2015 | ||
copyright : (C) 2015 Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsspatialiteexpressioncompiler.h" | ||
#include "qgssqlexpressioncompiler.h" | ||
#include "qgsspatialiteprovider.h" | ||
|
||
QgsSpatiaLiteExpressionCompiler::QgsSpatiaLiteExpressionCompiler( QgsSpatiaLiteFeatureSource* source ) | ||
: QgsSqlExpressionCompiler( source->mFields, QgsSqlExpressionCompiler::LikeIsCaseInsensitive ) | ||
{ | ||
} | ||
|
||
QgsSqlExpressionCompiler::Result QgsSpatiaLiteExpressionCompiler::compileNode( const QgsExpression::Node* node, QString& result ) | ||
{ | ||
switch ( node->nodeType() ) | ||
{ | ||
case QgsExpression::ntBinaryOperator: | ||
{ | ||
switch ( static_cast<const QgsExpression::NodeBinaryOperator*>( node )->op() ) | ||
{ | ||
case QgsExpression::boPow: | ||
case QgsExpression::boRegexp: | ||
return Fail; //not supported by SQLite | ||
|
||
default: | ||
//fallback to default handling | ||
return QgsSqlExpressionCompiler::compileNode( node, result ); | ||
} | ||
} | ||
|
||
default: | ||
return QgsSqlExpressionCompiler::compileNode( node, result ); | ||
} | ||
|
||
return QgsSqlExpressionCompiler::compileNode( node, result ); | ||
} | ||
|
||
QString QgsSpatiaLiteExpressionCompiler::quotedIdentifier( const QString& identifier ) | ||
{ | ||
return QgsSpatiaLiteProvider::quotedIdentifier( identifier ); | ||
} | ||
|
||
QString QgsSpatiaLiteExpressionCompiler::quotedValue( const QVariant& value ) | ||
{ | ||
if ( value.isNull() ) | ||
return "NULL"; | ||
|
||
switch ( value.type() ) | ||
{ | ||
case QVariant::Int: | ||
case QVariant::LongLong: | ||
case QVariant::Double: | ||
return value.toString(); | ||
|
||
case QVariant::Bool: | ||
//SQLite has no boolean literals | ||
return value.toBool() ? "1" : "0"; | ||
|
||
default: | ||
case QVariant::String: | ||
QString v = value.toString(); | ||
v.replace( '\'', "''" ); | ||
if ( v.contains( '\\' ) ) | ||
return v.replace( '\\', "\\\\" ).prepend( "E'" ).append( '\'' ); | ||
else | ||
return v.prepend( '\'' ).append( '\'' ); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/providers/spatialite/qgsspatialiteexpressioncompiler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/*************************************************************************** | ||
qgsspatialiteexpressioncompiler.h | ||
--------------------------------- | ||
begin : November 2015 | ||
copyright : (C) 2015 Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSSPATIALITEEXPRESSIONCOMPILER_H | ||
#define QGSSPATIALITEEXPRESSIONCOMPILER_H | ||
|
||
#include "qgssqlexpressioncompiler.h" | ||
#include "qgsexpression.h" | ||
#include "qgsspatialitefeatureiterator.h" | ||
|
||
class QgsSpatiaLiteExpressionCompiler : public QgsSqlExpressionCompiler | ||
{ | ||
public: | ||
|
||
explicit QgsSpatiaLiteExpressionCompiler( QgsSpatiaLiteFeatureSource* source ); | ||
|
||
protected: | ||
|
||
virtual Result compileNode( const QgsExpression::Node* node, QString& str ) override; | ||
virtual QString quotedIdentifier( const QString& identifier ) override; | ||
virtual QString quotedValue( const QVariant& value ) override; | ||
|
||
}; | ||
|
||
#endif // QGSSPATIALITEEXPRESSIONCOMPILER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters