Skip to content

Commit b0bfa5f

Browse files
author
Hugo Mercier
committed
Merge pull request #2662 from mhugo/vlayer_expr
Support for expression functions in virtual layers
2 parents c69afc9 + 1c44122 commit b0bfa5f

File tree

7 files changed

+418
-155
lines changed

7 files changed

+418
-155
lines changed

python/plugins/db_manager/db_plugins/vlayers/sql_dictionary.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@
123123
"*filtermbrwithin", "*filtermbrcontains", "*filtermbrintersects", "*buildmbrfilter"
124124
]
125125

126+
qgis_functions = [
127+
"atan2", "round", "rand", "randf", "clamp", "scale_linear", "scale_exp", "_pi", "to_int", "toint", "to_real", "toreal",
128+
"to_string", "tostring", "to_datetime", "todatetime", "to_date", "todate", "to_time", "totime", "to_interval", "tointerval",
129+
"regexp_match", "now", "_now", "age", "year", "month", "week", "day", "hour", "minute", "second", "day_of_week", "title",
130+
"levenshtein", "longest_common_substring", "hamming_distance", "wordwrap", "regexp_replace", "regexp_substr", "concat",
131+
"strpos", "_left", "_right", "rpad", "lpad", "format", "format_number", "format_date", "color_rgb", "color_rgba", "ramp_color",
132+
"color_hsl", "color_hsla", "color_hsv", "color_hsva", "color_cmyk", "color_cmyka", "color_part", "darker", "lighter",
133+
"set_color_part", "point_n", "start_point", "end_point", "nodes_to_points", "segments_to_lines", "make_point",
134+
"make_point_m", "make_line", "make_polygon", "x_min", "xmin", "x_max", "xmax", "y_min", "ymin", "y_max", "ymax", "geom_from_wkt",
135+
"geomFromWKT", "geom_from_gml", "relate", "intersects_bbox", "bbox", "translate", "buffer", "point_on_surface", "reverse",
136+
"exterior_ring", "interior_ring_n", "geometry_n", "bounds", "num_points", "num_interior_rings", "num_rings", "num_geometries",
137+
"bounds_width", "bounds_height", "is_closed", "convex_hull", "sym_difference", "combine", "_union", "geom_to_wkt", "geomToWKT",
138+
"transform", "uuid", "_uuid", "layer_property", "var", "_specialcol_", "project_color"]
139+
140+
126141
# constants
127142
constants = ["null", "false", "true"]
128143
spatialite_constants = []
@@ -140,6 +155,7 @@ def strip_star(s):
140155
if spatial:
141156
k += spatialite_keywords
142157
f += spatialite_functions
158+
f += qgis_functions
143159
c += spatialite_constants
144160

145161
return {'keyword': map(strip_star, k), 'constant': map(strip_star, c), 'function': map(strip_star, f)}
@@ -152,7 +168,7 @@ def ff(l):
152168

153169
def add_paren(l):
154170
return map(lambda s: s + "(", l)
155-
foo = sorted(add_paren(ff(list(set.union(set(functions), set(spatialite_functions))))))
171+
foo = sorted(add_paren(ff(list(set.union(set(functions), set(spatialite_functions), set(qgis_functions))))))
156172
m = sorted(add_paren(ff(math_functions)))
157173
agg = sorted(add_paren(ff(aggregate_functions)))
158174
op = ff(operators)

src/providers/virtual/qgsvirtuallayersqlfunctions.txt

+114-1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,117 @@ ST_SymDifference
5757
ST_Buffer
5858
ST_ConvexHull
5959
ST_Transform
60-
60+
atan2
61+
round
62+
rand
63+
randf
64+
clamp
65+
scale_linear
66+
scale_exp
67+
_pi
68+
to_int
69+
toint
70+
to_real
71+
toreal
72+
to_string
73+
tostring
74+
to_datetime
75+
todatetime
76+
to_date
77+
todate
78+
to_time
79+
totime
80+
to_interval
81+
tointerval
82+
regexp_match
83+
now
84+
_now
85+
age
86+
year
87+
month
88+
week
89+
day
90+
hour
91+
minute
92+
second
93+
day_of_week
94+
title
95+
levenshtein
96+
longest_common_substring
97+
hamming_distance
98+
wordwrap
99+
regexp_replace
100+
regexp_substr
101+
concat
102+
strpos
103+
_left
104+
_right
105+
rpad
106+
lpad
107+
format
108+
format_number
109+
format_date
110+
color_rgb
111+
color_rgba
112+
ramp_color
113+
color_hsl
114+
color_hsla
115+
color_hsv
116+
color_hsva
117+
color_cmyk
118+
color_cmyka
119+
color_part
120+
darker
121+
lighter
122+
set_color_part
123+
point_n
124+
start_point
125+
end_point
126+
nodes_to_points
127+
segments_to_lines
128+
make_point
129+
make_point_m
130+
make_line
131+
make_polygon
132+
x_min
133+
xmin
134+
x_max
135+
xmax
136+
y_min
137+
ymin
138+
y_max
139+
ymax
140+
geom_from_wkt
141+
geomFromWKT
142+
geom_from_gml
143+
relate
144+
intersects_bbox
145+
bbox
146+
translate
147+
buffer
148+
point_on_surface
149+
reverse
150+
exterior_ring
151+
interior_ring_n
152+
geometry_n
153+
bounds
154+
num_points
155+
num_interior_rings
156+
num_rings
157+
num_geometries
158+
bounds_width
159+
bounds_height
160+
is_closed
161+
convex_hull
162+
sym_difference
163+
combine
164+
_union
165+
geom_to_wkt
166+
geomToWKT
167+
transform
168+
uuid
169+
_uuid
170+
layer_property
171+
var
172+
_specialcol_
173+
project_color

src/providers/virtual/qgsvirtuallayersqlitehelper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ QgsScopedSqlite::QgsScopedSqlite( const QString& path, bool withExtension )
2727
{
2828
// register a statically-linked function as extension
2929
// for all future database connection
30-
sqlite3_auto_extension( reinterpret_cast < void( * )() > ( qgsvlayer_module_init ) );
30+
sqlite3_auto_extension( reinterpret_cast < void( * )() > ( qgsvlayerModuleInit ) );
3131
}
3232
int r;
3333
r = sqlite3_open( path.toLocal8Bit().constData(), &db_ );

src/providers/virtual/qgsvirtuallayersqlitehelper.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ extern "C"
2121
{
2222
#include <sqlite3.h>
2323

24-
int qgsvlayer_module_init( sqlite3 *db,
25-
char **pzErrMsg,
26-
void * unused /*const sqlite3_api_routines *pApi*/ );
24+
int qgsvlayerModuleInit( sqlite3 *db,
25+
char **pzErrMsg,
26+
void * unused /*const sqlite3_api_routines *pApi*/ );
2727

2828
}
2929

0 commit comments

Comments
 (0)