|
93 | 93 |
|
94 | 94 | # functions
|
95 | 95 | functions = [
|
96 |
| - # TODO get them from a reference page |
97 |
| - "abs", "changes", "coalesce", "glob", "ifnull", "hex", "last_insert_rowid", |
98 |
| - "length", "like", "lower", "ltrim", "max", "min", "nullif", "quote", "random", |
99 |
| - "randomblob", "replace", "round", "rtrim", "soundex", "total_change", "trim", |
100 |
| - "typeof", "upper", "zeroblob", "date", "datetime", "julianday", "strftime", |
101 |
| - "avg", "count", "group_concat", "sum", "total" |
| 96 | + "coalesce", |
| 97 | + "nullif", "quote", "random", |
| 98 | + "replace", "soundex" |
| 99 | +] |
| 100 | +operators=[ |
| 101 | +' AND ',' OR ','||',' < ',' <= ',' > ',' >= ',' = ',' <> ',' IS ',' IS NOT ',' IN ',' LIKE ',' GLOB ',' MATCH ',' REGEXP ' |
102 | 102 | ]
|
| 103 | + |
| 104 | +math_functions = [ |
| 105 | + # SQL math functions |
| 106 | + "Abs", "ACos", "ASin", "ATan", "Cos", "Cot", "Degrees", "Exp", "Floor", "Log", "Log2", |
| 107 | + "Log10", "Pi", "Radians", "Round", "Sign", "Sin", "Sqrt", "StdDev_Pop", "StdDev_Samp", "Tan", |
| 108 | + "Var_Pop", "Var_Samp" ] |
| 109 | + |
| 110 | +string_functions=["Length", "Lower", "Upper", "Like", "Trim", "LTrim", "RTrim", "Replace", "Substr"] |
| 111 | + |
| 112 | +aggregate_functions=[ |
| 113 | +"Max","Min","Avg","Count","Sum","Group_Concat","Total","Var_Pop","Var_Samp","StdDev_Pop","StdDev_Samp" |
| 114 | +] |
| 115 | + |
103 | 116 | postgis_functions = [ # from http://www.postgis.org/docs/reference.html
|
104 | 117 | # 7.1. PostgreSQL PostGIS Types
|
105 |
| - "box2d", "box3d", "box3d_extent", "geometry", "geometry_dump", "geography", |
| 118 | + "*box2d", "*box3d", "*box3d_extent", "*geometry", "*geometry_dump", "*geography", |
106 | 119 | # 7.2. Management Functions
|
107 |
| - "addgeometrycolumn", "dropgeometrycolumn", "dropgeometrytable", "postgis_full_version", |
108 |
| - "postgis_geos_version", "postgis_libxml_version", "postgis_lib_build_date", |
109 |
| - "postgis_lib_version", "postgis_proj_version", "postgis_scripts_build_date", |
110 |
| - "postgis_scripts_installed", "postgis_scripts_released", "postgis_uses_stats", "postgis_version", |
111 |
| - "populate_geometry_columns", "probe_geometry_columns", "updategeometrysrid", |
| 120 | + "*addgeometrycolumn", "*dropgeometrycolumn", "*dropgeometrytable", "*postgis_full_version", |
| 121 | + "*postgis_geos_version", "*postgis_libxml_version", "*postgis_lib_build_date", |
| 122 | + "*postgis_lib_version", "*postgis_proj_version", "*postgis_scripts_build_date", |
| 123 | + "*postgis_scripts_installed", "*postgis_scripts_released", "*postgis_uses_stats", "*postgis_version", |
| 124 | + "*populate_geometry_columns", "*probe_geometry_columns", "*updategeometrysrid", |
112 | 125 | # 7.3. Geometry Constructors
|
113 |
| - "st_bdpolyfromtext", "st_bdmpolyfromtext", "st_geogfromtext", "st_geographyfromtext", |
114 |
| - "st_geogfromwkb", "st_geomcollfromtext", "st_geomfromewkb", "st_geomfromewkt", |
115 |
| - "st_geometryfromtext", "st_geomfromgml", "st_geomfromkml", "st_gmltosql", "st_geomfromtext", |
116 |
| - "st_geomfromwkb", "st_linefrommultipoint", "st_linefromtext", "st_linefromwkb", |
117 |
| - "st_linestringfromwkb", "st_makebox2d", "st_makebox3d", "st_makeline", "st_makeenvelope", |
118 |
| - "st_makepolygon", "st_makepoint", "st_makepointm", "st_mlinefromtext", "st_mpointfromtext", |
119 |
| - "st_mpolyfromtext", "st_point", "st_pointfromtext", "st_pointfromwkb", "st_polygon", |
120 |
| - "st_polygonfromtext", "st_wkbtosql", "st_wkttosql", |
| 126 | + "*ST_bdpolyfromtext", "*ST_bdmpolyfromtext", "*ST_geogfromtext", "*ST_geographyfromtext", |
| 127 | + "*ST_geogfromwkb", "*ST_geomcollfromtext", "*ST_geomfromewkb", "*ST_geomfromewkt", |
| 128 | + "*ST_geometryfromtext", "*ST_geomfromgml", "*ST_geomfromkml", "*ST_gmltosql", "*ST_geomfromtext", |
| 129 | + "*ST_geomfromwkb", "*ST_linefrommultipoint", "*ST_linefromtext", "*ST_linefromwkb", |
| 130 | + "*ST_linestringfromwkb", "*ST_makebox2d", "*ST_makebox3d", "ST_MakeLine", "*ST_makeenvelope", |
| 131 | + "ST_MakePolygon", "ST_MakePoint", "ST_MakePointM", "*ST_MLinefromtext", "*ST_mpointfromtext", |
| 132 | + "*ST_mpolyfromtext", "ST_Point", "*ST_pointfromtext", "*ST_pointfromwkb", "ST_Polygon", |
| 133 | + "*ST_polygonfromtext", "*ST_wkbtosql", "*ST_wkttosql", |
121 | 134 | # 7.4. Geometry Accessors
|
122 |
| - "geometrytype", "st_boundary", "st_coorddim", "st_dimension", "st_endpoint", "st_envelope", |
123 |
| - "st_exteriorring", "st_geometryn", "st_geometrytype", "st_interiorringn", "st_isclosed", |
124 |
| - "st_isempty", "st_isring", "st_issimple", "st_isvalid", "st_isvalidreason", "st_m", "st_ndims", |
125 |
| - "st_npoints", "st_nrings", "st_numgeometries", "st_numinteriorrings", "st_numinteriorring", |
126 |
| - "st_numpoints", "st_pointn", "st_srid", "st_startpoint", "st_summary", "st_x", "st_y", "st_z", |
127 |
| - "st_zmflag", |
| 135 | + "GeometryType", "ST_Boundary", "*ST_coorddim", "ST_Dimension", "ST_EndPoint", "ST_Envelope", |
| 136 | + "ST_ExteriorRing", "ST_GeometryN", "ST_GeometryType", "ST_InteriorRingN", "ST_isClosed", |
| 137 | + "ST_isEmpty", "ST_isRing", "ST_isSimple", "ST_isValid", "ST_isValidReason", "ST_M", "ST_NDims", |
| 138 | + "ST_NPoints", "ST_NRings", "ST_NumGeometries", "ST_NumInteriorrings", "ST_NumInteriorring", |
| 139 | + "ST_NumPoints", "ST_PointN", "ST_Srid", "ST_StartPoint", "ST_Summary", "ST_X", "ST_Y", "ST_Z", |
| 140 | + "*ST_zmflag", |
128 | 141 | # 7.5. Geometry Editors
|
129 |
| - "st_addpoint", "st_affine", "st_force_2d", "st_force_3d", "st_force_3dz", "st_force_3dm", |
130 |
| - "st_force_4d", "st_force_collection", "st_forcerhr", "st_linemerge", "st_collectionextract", |
131 |
| - "st_multi", "st_removepoint", "st_reverse", "st_rotate", "st_rotatex", "st_rotatey", |
132 |
| - "st_rotatez", "st_scale", "st_segmentize", "st_setpoint", "st_setsrid", "st_snaptogrid", |
133 |
| - "st_transform", "st_translate", "st_transscale", |
| 142 | + "ST_AddPoint", "ST_Affine", "ST_Force2D", "*ST_Force3D", "*ST_Force3dZ", "*ST_Force3DM", |
| 143 | + "*ST_Force_4d", "*ST_force_collection", "*ST_forcerhr", "*ST_linemerge", "*ST_collectionextract", |
| 144 | + "ST_Multi", "*ST_removepoint", "*ST_reverse", "*ST_rotate", "*ST_rotatex", "*ST_rotatey", |
| 145 | + "*ST_rotatez", "*ST_scale", "*ST_segmentize", "*ST_setpoint", "ST_SetSrid", "ST_SnapToGrid", |
| 146 | + "ST_Transform", "ST_Translate", "*ST_transscale", |
134 | 147 | # 7.6. Geometry Outputs
|
135 |
| - "st_asbinary", "st_asewkb", "st_asewkt", "st_asgeojson", "st_asgml", "st_ashexewkb", "st_askml", |
136 |
| - "st_assvg", "st_geohash", "st_astext", |
| 148 | + "*ST_asbinary", "*ST_asewkb", "*ST_asewkt", "*ST_asgeojson", "*ST_asgml", "*ST_ashexewkb", "*ST_askml", |
| 149 | + "*ST_assvg", "*ST_geohash", "ST_Astext", |
137 | 150 | # 7.7. Operators
|
138 | 151 | # 7.8. Spatial Relationships and Measurements
|
139 |
| - "st_area", "st_azimuth", "st_centroid", "st_closestpoint", "st_contains", "st_containsproperly", |
140 |
| - "st_covers", "st_coveredby", "st_crosses", "st_linecrossingdirection", "st_disjoint", |
141 |
| - "st_distance", "st_hausdorffdistance", "st_maxdistance", "st_distance_sphere", |
142 |
| - "st_distance_spheroid", "st_dfullywithin", "st_dwithin", "st_equals", "st_hasarc", |
143 |
| - "st_intersects", "st_length", "st_length2d", "st_length3d", "st_length_spheroid", |
144 |
| - "st_length2d_spheroid", "st_length3d_spheroid", "st_longestline", "st_orderingequals", |
145 |
| - "st_overlaps", "st_perimeter", "st_perimeter2d", "st_perimeter3d", "st_pointonsurface", |
146 |
| - "st_relate", "st_shortestline", "st_touches", "st_within", |
| 152 | + "ST_Area", "ST_Azimuth", "ST_Centroid", "ST_ClosestPoint", "ST_Contains", "ST_ContainsProperly", |
| 153 | + "ST_Covers", "ST_CoveredBy", "ST_Crosses", "*ST_linecrossingdirection", "ST_Cisjoint", |
| 154 | + "ST_Distance", "*ST_hausdorffdistance", "*ST_maxdistance", "ST_Distance_Sphere", |
| 155 | + "ST_Distance_Spheroid", "*ST_DFullyWithin", "ST_DWithin", "ST_Equals", "*ST_hasarc", |
| 156 | + "ST_Intersects", "ST_Length", "*ST_Length2d", "*ST_length3d", "ST_Length_Spheroid", |
| 157 | + "*ST_length2d_spheroid", "*ST_length3d_spheroid", "*ST_longestline", "*ST_orderingequals", |
| 158 | + "ST_Overlaps", "*ST_perimeter", "*ST_perimeter2d", "*ST_perimeter3d", "ST_PointOnSurface", |
| 159 | + "ST_Relate", "ST_ShortestLine", "ST_Touches", "ST_Within", |
147 | 160 | # 7.9. Geometry Processing Functions
|
148 |
| - "st_buffer", "st_buildarea", "st_collect", "st_convexhull", "st_curvetoline", "st_difference", |
149 |
| - "st_dump", "st_dumppoints", "st_dumprings", "st_intersection", "st_linetocurve", "st_memunion", |
150 |
| - "st_minimumboundingcircle", "st_polygonize", "st_shift_longitude", "st_simplify", |
151 |
| - "st_simplifypreservetopology", "st_symdifference", "st_union", |
| 161 | + "ST_Buffer", "ST_BuildArea", "ST_Collect", "ST_ConvexHull", "*ST_curvetoline", "ST_Difference", |
| 162 | + "ST_Dump", "*ST_dumppoints", "*ST_dumprings", "ST_Intersection", "*ST_linetocurve", "*ST_memunion", |
| 163 | + "*ST_minimumboundingcircle", "*ST_polygonize", "*ST_shift_longitude", "ST_Simplify", |
| 164 | + "ST_SimplifyPreserveTopology", "ST_SymDifference", "ST_Union", |
152 | 165 | # 7.10. Linear Referencing
|
153 |
| - "st_line_interpolate_point", "st_line_locate_point", "st_line_substring", |
154 |
| - "st_locate_along_measure", "st_locate_between_measures", "st_locatebetweenelevations", |
155 |
| - "st_addmeasure", |
| 166 | + "ST_Line_Interpolate_Point", "ST_Line_Locate_Point", "ST_Line_Substring", |
| 167 | + "*ST_locate_along_measure", "*ST_locate_between_measures", "*ST_locatebetweenelevations", |
| 168 | + "*ST_addmeasure", |
156 | 169 | # 7.11. Long Transactions Support
|
157 |
| - "addauth", "checkauth", "disablelongtransactions", "enablelongtransactions", "lockrow", |
158 |
| - "unlockrows", |
| 170 | + "*addauth", "*checkauth", "*disablelongtransactions", "*enablelongtransactions", "*lockrow", |
| 171 | + "*unlockrows", |
159 | 172 | # 7.12. Miscellaneous Functions
|
160 |
| - "st_accum", "box2d", "box3d", "st_estimated_extent", "st_expand", "st_extent", "st_extent3d", |
161 |
| - "find_srid", "st_mem_size", "st_point_inside_circle", "st_xmax", "st_xmin", "st_ymax", "st_ymin", |
162 |
| - "st_zmax", "st_zmin", |
| 173 | + "*ST_accum", "*box2d", "*box3d", "*ST_estimated_extent", "*ST_expand", "ST_Extent", "*ST_extent3d", |
| 174 | + "*find_srid", "*ST_mem_size", "*ST_point_inside_circle", "ST_XMax", "ST_XMin", "ST_YMax", "ST_YMin", |
| 175 | + "ST_ZMax", "ST_ZMin", |
163 | 176 | # 7.13. Exceptional Functions
|
164 |
| - "postgis_addbbox", "postgis_dropbbox", "postgis_hasbbox" |
| 177 | + "*postgis_addbbox", "*postgis_dropbbox", "*postgis_hasbbox" |
165 | 178 | ]
|
166 | 179 |
|
167 | 180 | # constants
|
|
170 | 183 |
|
171 | 184 |
|
172 | 185 | def getSqlDictionary(spatial=True):
|
| 186 | + def strip_star(s): |
| 187 | + if s[0] == '*': |
| 188 | + return s.lower()[1:] |
| 189 | + else: |
| 190 | + return s.lower() |
| 191 | + |
173 | 192 | k, c, f = list(keywords), list(constants), list(functions)
|
174 | 193 |
|
175 | 194 | if spatial:
|
176 | 195 | k += postgis_keywords
|
177 | 196 | f += postgis_functions
|
178 | 197 | c += postgis_constants
|
179 | 198 |
|
180 |
| - return {'keyword': k, 'constant': c, 'function': f} |
| 199 | + return {'keyword': map(strip_star,k), 'constant': map(strip_star,c), 'function': map(strip_star,f)} |
| 200 | + |
| 201 | +def getQueryBuilderDictionary(): |
| 202 | + # concat functions |
| 203 | + def ff( l ): |
| 204 | + return filter( lambda s:s[0] != '*', l ) |
| 205 | + def add_paren( l ): |
| 206 | + return map( lambda s:s+"(", l ) |
| 207 | + foo = sorted(add_paren(ff( list(set.union(set(functions), set(postgis_functions))) ))) |
| 208 | + m = sorted(add_paren(ff( math_functions ))) |
| 209 | + agg = sorted(add_paren(ff(aggregate_functions))) |
| 210 | + op = ff(operators) |
| 211 | + s = sorted(add_paren(ff(string_functions))) |
| 212 | + return {'function': foo, 'math' : m, 'aggregate': agg, 'operator': op, 'string': s } |
0 commit comments