Skip to content

Commit de791aa

Browse files
author
Richard Jones
committed
added missing stringFind to sql backends
1 parent 84f38e6 commit de791aa

File tree

4 files changed

+46
-11
lines changed

4 files changed

+46
-11
lines changed

roundup/backends/back_anydbm.py

Lines changed: 1 addition & 2 deletions
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: back_anydbm.py,v 1.84 2002-09-23 00:50:32 richard Exp $
18+
#$Id: back_anydbm.py,v 1.85 2002-09-24 01:59:28 richard Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in a database
2121
chosen by anydbm. It is guaranteed to always be available in python
@@ -980,7 +980,6 @@ def import_list(self, propnames, proplist):
980980
creation = None
981981
if d.has_key('activity'):
982982
del d['activity']
983-
984983
self.db.addjournal(self.classname, newid, 'create', d, creator,
985984
creation)
986985
return newid

roundup/backends/back_gadfly.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_gadfly.py,v 1.25 2002-09-23 06:48:34 richard Exp $
1+
# $Id: back_gadfly.py,v 1.26 2002-09-24 01:59:28 richard Exp $
22
__doc__ = '''
33
About Gadfly
44
============
@@ -95,6 +95,16 @@ def sql_fetchone(self):
9595
return None
9696
raise
9797

98+
def sql_fetchall(self):
99+
''' Fetch a single row. If there's nothing to fetch, return [].
100+
'''
101+
try:
102+
return self.cursor.fetchall()
103+
except gadfly.database.error, message:
104+
if message == 'no more results':
105+
return []
106+
raise
107+
98108
def save_dbschema(self, schema):
99109
''' Save the schema definition that the database currently implements
100110
'''

roundup/backends/back_sqlite.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_sqlite.py,v 1.4 2002-09-23 06:48:35 richard Exp $
1+
# $Id: back_sqlite.py,v 1.5 2002-09-24 01:59:28 richard Exp $
22
__doc__ = '''
33
See https://pysqlite.sourceforge.net/ for pysqlite info
44
'''
@@ -33,6 +33,11 @@ def sql_fetchone(self):
3333
'''
3434
return self.cursor.fetchone()
3535

36+
def sql_fetchall(self):
37+
''' Fetch a single row. If there's nothing to fetch, return [].
38+
'''
39+
return self.cursor.fetchall()
40+
3641
def sql_commit(self):
3742
''' Actually commit to the database.
3843

roundup/backends/rdbms_common.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.14 2002-09-23 08:24:51 richard Exp $
1+
# $Id: rdbms_common.py,v 1.15 2002-09-24 01:59:28 richard Exp $
22

33
# standard python modules
44
import sys, os, time, re, errno, weakref, copy
@@ -1612,12 +1612,33 @@ def find(self, **propspec):
16121612
self.classname, prop, ','.join([a for x in values.keys()])))
16131613
sql = '\nintersect\n'.join(tables)
16141614
self.db.sql(sql, allvalues)
1615-
try:
1616-
l = [x[0] for x in self.db.cursor.fetchall()]
1617-
except gadfly.database.error, message:
1618-
if message == 'no more results':
1619-
l = []
1620-
raise
1615+
l = [x[0] for x in self.db.sql_fetchall()]
1616+
if __debug__:
1617+
print >>hyperdb.DEBUG, 'find ... ', l
1618+
return l
1619+
1620+
def stringFind(self, **requirements):
1621+
'''Locate a particular node by matching a set of its String
1622+
properties in a caseless search.
1623+
1624+
If the property is not a String property, a TypeError is raised.
1625+
1626+
The return is a list of the id of all nodes that match.
1627+
'''
1628+
where = []
1629+
args = []
1630+
for propname in requirements.keys():
1631+
prop = self.properties[propname]
1632+
if isinstance(not prop, String):
1633+
raise TypeError, "'%s' not a String property"%propname
1634+
where.append(propname)
1635+
args.append(requirements[propname].lower())
1636+
1637+
# generate the where clause
1638+
s = ' and '.join(['_%s=%s'%(col, self.db.arg) for col in where])
1639+
sql = 'select id from _%s where %s'%(self.classname, s)
1640+
self.db.sql(sql, tuple(args))
1641+
l = [x[0] for x in self.db.sql_fetchall()]
16211642
if __debug__:
16221643
print >>hyperdb.DEBUG, 'find ... ', l
16231644
return l

0 commit comments

Comments
 (0)