[GRASS-SVN] r58385 - grass/trunk/lib/python/pygrass/vector
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Dec 4 07:19:34 PST 2013
Author: lucadelu
Date: 2013-12-04 07:19:34 -0800 (Wed, 04 Dec 2013)
New Revision: 58385
Modified:
grass/trunk/lib/python/pygrass/vector/table.py
Log:
add group by option in the Filters class
Modified: grass/trunk/lib/python/pygrass/vector/table.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/table.py 2013-12-04 14:14:26 UTC (rev 58384)
+++ grass/trunk/lib/python/pygrass/vector/table.py 2013-12-04 15:19:34 UTC (rev 58385)
@@ -72,6 +72,7 @@
self._where = None
self._orderby = None
self._limit = None
+ self._groupby = None
def __repr__(self):
return "Filters(%r)" % self.get_sql()
@@ -103,6 +104,13 @@
self._limit = 'LIMIT {number}'.format(number=number)
return self
+ def group_by(self, groupby):
+ """Create the group by condition"""
+ if not isinstance(groupby, str):
+ groupby = ', '.join(groupby)
+ self._groupby = 'GROUP BY {groupby}'.format(groupby=groupby)
+ return self
+
def get_sql(self):
"""Return the SQL query"""
sql_list = list()
@@ -112,6 +120,8 @@
if self._where is not None:
sql_list.append(self._where)
+ if self._groupby is not None:
+ sql_list.append(self._groupby)
if self._orderby is not None:
sql_list.append(self._orderby)
if self._limit is not None:
@@ -124,6 +134,7 @@
self._where = None
self._orderby = None
self._limit = None
+ self._groupby = None
class Columns(object):
More information about the grass-commit
mailing list