[QGIS Commit] r13940 - in trunk/qgis: python/core src/core
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Tue Jul 20 05:50:41 EDT 2010
Author: wonder
Date: 2010-07-20 09:50:41 +0000 (Tue, 20 Jul 2010)
New Revision: 13940
Modified:
trunk/qgis/python/core/qgssearchtreenode.sip
trunk/qgis/src/core/qgssearchstringlexer.ll
trunk/qgis/src/core/qgssearchstringparser.yy
trunk/qgis/src/core/qgssearchtreenode.cpp
trunk/qgis/src/core/qgssearchtreenode.h
Log:
Support string concatenation using the standard sql concatenation operator ||
Developed for Faunalia (http://www.faunalia.it) with funding from Regione Toscana - Sistema Informativo per la Gestione del Territorio e dell' Ambiente [RT-SIGTA].
For the project: "Sviluppo di prodotti software GIS open-source basati sui prodotti QuantumGIS e Postgis (CIG 037728516E)"
Modified: trunk/qgis/python/core/qgssearchtreenode.sip
===================================================================
--- trunk/qgis/python/core/qgssearchtreenode.sip 2010-07-19 19:12:11 UTC (rev 13939)
+++ trunk/qgis/python/core/qgssearchtreenode.sip 2010-07-20 09:50:41 UTC (rev 13940)
@@ -36,9 +36,13 @@
opASIN,
opACOS,
opATAN,
+
+ // conversion
opTOINT,
opTOREAL,
opTOSTRING,
+
+ // measuring
opLENGTH,
opAREA,
@@ -50,7 +54,10 @@
opGE, // >=
opLE, // <=
opRegexp, // ~
- opLike // LIKE
+ opLike, // LIKE
+
+ // string handling
+ opCONCAT
};
//! constructors
Modified: trunk/qgis/src/core/qgssearchstringlexer.ll
===================================================================
--- trunk/qgis/src/core/qgssearchstringlexer.ll 2010-07-19 19:12:11 UTC (rev 13939)
+++ trunk/qgis/src/core/qgssearchstringlexer.ll 2010-07-20 09:50:41 UTC (rev 13940)
@@ -92,6 +92,8 @@
"to real" { yylval.op = QgsSearchTreeNode::opTOREAL; return FUNCTION;}
"to string" { yylval.op = QgsSearchTreeNode::opTOSTRING; return FUNCTION;}
+"||" { return CONCAT; }
+
[+-/*^] { return yytext[0]; }
[()] { return yytext[0]; }
Modified: trunk/qgis/src/core/qgssearchstringparser.yy
===================================================================
--- trunk/qgis/src/core/qgssearchstringparser.yy 2010-07-19 19:12:11 UTC (rev 13939)
+++ trunk/qgis/src/core/qgssearchstringparser.yy 2010-07-20 09:50:41 UTC (rev 13940)
@@ -62,6 +62,7 @@
%token <number> NUMBER
%token <op> COMPARISON
%token <op> FUNCTION
+%token CONCAT
%token IS
%token AREA
%token LENGTH
@@ -95,6 +96,8 @@
%left COMPARISON
+%left CONCAT
+
%left '+' '-'
%left '*' '/'
%left '^'
@@ -136,6 +139,7 @@
| '(' scalar_exp ')' { $$ = $2; }
| '+' scalar_exp %prec UMINUS { $$ = $2; }
| '-' scalar_exp %prec UMINUS { $$ = $2; if ($$->type() == QgsSearchTreeNode::tNumber) $$->setNumber(- $$->number()); }
+ | scalar_exp CONCAT scalar_exp { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opCONCAT, $1, $3); joinTmpNodes($$, $1, $3); }
| AREA { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opAREA, 0, 0); addToTmpNodes($$); }
| LENGTH { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opLENGTH, 0, 0); addToTmpNodes($$); }
| NUMBER { $$ = new QgsSearchTreeNode($1); addToTmpNodes($$); }
Modified: trunk/qgis/src/core/qgssearchtreenode.cpp
===================================================================
--- trunk/qgis/src/core/qgssearchtreenode.cpp 2010-07-19 19:12:11 UTC (rev 13939)
+++ trunk/qgis/src/core/qgssearchtreenode.cpp 2010-07-20 09:50:41 UTC (rev 13940)
@@ -214,6 +214,9 @@
case opRegexp: str += " ~ "; break;
case opLike: str += " LIKE "; break;
+ // TODO: other opeators / functions
+ case opCONCAT: str += " || "; break;
+
default: str += " ? ";
}
@@ -548,12 +551,29 @@
//don't convert to numbers in case of string concatenation
if ( mLeft && mRight && !value1.isNumeric() && !value2.isNumeric() )
{
+ // TODO: concatenation using '+' operator should be removed in favor of '||' operator
+ // because it may lead to surprising behavior if numbers are stored in a string
if ( mOp == opPLUS )
{
return QgsSearchTreeValue( value1.string() + value2.string() );
}
}
+ // string concatenation ||
+ if ( mLeft && mRight && mOp == opCONCAT )
+ {
+ if ( value1.isNumeric() && value2.isNumeric() )
+ {
+ return QgsSearchTreeValue( 5, "Operator doesn't match the argument types." );
+ }
+ else
+ {
+ QString arg1 = value1.isNumeric() ? QString::number( value1.number() ) : value1.string();
+ QString arg2 = value2.isNumeric() ? QString::number( value2.number() ) : value2.string();
+ return QgsSearchTreeValue( arg1 + arg2 );
+ }
+ }
+
// for other operators, convert strings to numbers if needed
double val1, val2;
if ( value1.isNumeric() )
Modified: trunk/qgis/src/core/qgssearchtreenode.h
===================================================================
--- trunk/qgis/src/core/qgssearchtreenode.h 2010-07-19 19:12:11 UTC (rev 13939)
+++ trunk/qgis/src/core/qgssearchtreenode.h 2010-07-20 09:50:41 UTC (rev 13940)
@@ -72,9 +72,13 @@
opASIN,
opACOS,
opATAN,
+
+ // conversion
opTOINT,
opTOREAL,
opTOSTRING,
+
+ // measuring
opLENGTH,
opAREA,
@@ -88,7 +92,10 @@
opGE, // >=
opLE, // <=
opRegexp, // ~
- opLike // LIKE
+ opLike, // LIKE
+
+ // string handling
+ opCONCAT
};
//! constructors
More information about the QGIS-commit
mailing list