Skip to content

Commit c283ca9

Browse files
author
Richard Jones
committed
added filter_sql to SQL backends which takes an arbitrary SQL statement...
...and returns a list of item ids
1 parent e9d1f0b commit c283ca9

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Feature:
2020
backends
2121
- sorting, grouping, and searching by transitive properties (e.g.,
2222
messages.author.supervisor) is now supported in all backends
23+
- added filter_sql to SQL backends which takes an arbitrary SQL statement
24+
and returns a list of item ids
2325

2426
Fixed:
2527
- Verbose option for import and export (sf bug 1505645)

doc/customizing.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Customising Roundup
33
===================
44

5-
:Version: $Revision: 1.204 $
5+
:Version: $Revision: 1.205 $
66

77
.. This document borrows from the ZopeBook section on ZPT. The original is at:
88
http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx
@@ -1871,6 +1871,17 @@ filter lists of items from this class, filtered and sorted. Two
18711871
eg. ``issue.filter(filterspec={"priority": "1"},
18721872
sort=('activity', '+'))``
18731873

1874+
filter_sql **Only in SQL backends**
1875+
1876+
Lists the items that match the SQL provided. The SQL is a
1877+
complete "select" statement.
1878+
1879+
The SQL select must include the item id as the first column.
1880+
1881+
This function **does not** filter out retired items, add
1882+
on a where clause "__retired__ <> 1" if you don't want
1883+
retired nodes.
1884+
18741885
classhelp display a link to a javascript popup containing this class'
18751886
"help" template.
18761887

roundup/backends/rdbms_common.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: rdbms_common.py,v 1.178 2006-08-29 04:20:50 richard Exp $
18+
#$Id: rdbms_common.py,v 1.179 2006-08-29 04:32:49 richard Exp $
1919
''' Relational database (SQL) backend common code.
2020
2121
Basics:
@@ -2319,6 +2319,25 @@ def filter(self, search_matches, filterspec, sort=[], group=[]):
23192319
self.db.stats['filtering'] += (time.time() - start_t)
23202320
return l
23212321

2322+
def filter_sql(self, sql):
2323+
'''Return a list of the ids of the items in this class that match
2324+
the SQL provided. The SQL is a complete "select" statement.
2325+
2326+
The SQL select must include the item id as the first column.
2327+
2328+
This function DOES NOT filter out retired items, add on a where
2329+
clause "__retired__ <> 1" if you don't want retired nodes.
2330+
'''
2331+
if __debug__:
2332+
start_t = time.time()
2333+
2334+
self.db.sql(sql)
2335+
l = self.db.sql_fetchall()
2336+
2337+
if __debug__:
2338+
self.db.stats['filtering'] += (time.time() - start_t)
2339+
return l
2340+
23222341
def count(self):
23232342
'''Get the number of nodes in this class.
23242343

0 commit comments

Comments
 (0)