From: richard Date: Tue, 24 Sep 2002 01:59:28 +0000 (+0000) Subject: added missing stringFind to sql backends X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b26c9f5fc07cc74a2fb20b53c742b285e1dd8299;p=roundup.git added missing stringFind to sql backends git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1219 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/roundup/backends/back_anydbm.py b/roundup/backends/back_anydbm.py index a039f15..1348798 100644 --- a/roundup/backends/back_anydbm.py +++ b/roundup/backends/back_anydbm.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_anydbm.py,v 1.84 2002-09-23 00:50:32 richard Exp $ +#$Id: back_anydbm.py,v 1.85 2002-09-24 01:59:28 richard Exp $ ''' This module defines a backend that saves the hyperdatabase in a database chosen by anydbm. It is guaranteed to always be available in python @@ -980,7 +980,6 @@ class Class(hyperdb.Class): creation = None if d.has_key('activity'): del d['activity'] - self.db.addjournal(self.classname, newid, 'create', d, creator, creation) return newid diff --git a/roundup/backends/back_gadfly.py b/roundup/backends/back_gadfly.py index 1896c62..e14a12c 100644 --- a/roundup/backends/back_gadfly.py +++ b/roundup/backends/back_gadfly.py @@ -1,4 +1,4 @@ -# $Id: back_gadfly.py,v 1.25 2002-09-23 06:48:34 richard Exp $ +# $Id: back_gadfly.py,v 1.26 2002-09-24 01:59:28 richard Exp $ __doc__ = ''' About Gadfly ============ @@ -95,6 +95,16 @@ class Database(Database): return None raise + def sql_fetchall(self): + ''' Fetch a single row. If there's nothing to fetch, return []. + ''' + try: + return self.cursor.fetchall() + except gadfly.database.error, message: + if message == 'no more results': + return [] + raise + def save_dbschema(self, schema): ''' Save the schema definition that the database currently implements ''' diff --git a/roundup/backends/back_sqlite.py b/roundup/backends/back_sqlite.py index e5f64b0..2265db6 100644 --- a/roundup/backends/back_sqlite.py +++ b/roundup/backends/back_sqlite.py @@ -1,4 +1,4 @@ -# $Id: back_sqlite.py,v 1.4 2002-09-23 06:48:35 richard Exp $ +# $Id: back_sqlite.py,v 1.5 2002-09-24 01:59:28 richard Exp $ __doc__ = ''' See https://pysqlite.sourceforge.net/ for pysqlite info ''' @@ -33,6 +33,11 @@ class Database(Database): ''' return self.cursor.fetchone() + def sql_fetchall(self): + ''' Fetch a single row. If there's nothing to fetch, return []. + ''' + return self.cursor.fetchall() + def sql_commit(self): ''' Actually commit to the database. diff --git a/roundup/backends/rdbms_common.py b/roundup/backends/rdbms_common.py index f6fe029..b0eb498 100644 --- a/roundup/backends/rdbms_common.py +++ b/roundup/backends/rdbms_common.py @@ -1,4 +1,4 @@ -# $Id: rdbms_common.py,v 1.14 2002-09-23 08:24:51 richard Exp $ +# $Id: rdbms_common.py,v 1.15 2002-09-24 01:59:28 richard Exp $ # standard python modules import sys, os, time, re, errno, weakref, copy @@ -1612,12 +1612,33 @@ class Class(hyperdb.Class): self.classname, prop, ','.join([a for x in values.keys()]))) sql = '\nintersect\n'.join(tables) self.db.sql(sql, allvalues) - try: - l = [x[0] for x in self.db.cursor.fetchall()] - except gadfly.database.error, message: - if message == 'no more results': - l = [] - raise + l = [x[0] for x in self.db.sql_fetchall()] + if __debug__: + print >>hyperdb.DEBUG, 'find ... ', l + return l + + def stringFind(self, **requirements): + '''Locate a particular node by matching a set of its String + properties in a caseless search. + + If the property is not a String property, a TypeError is raised. + + The return is a list of the id of all nodes that match. + ''' + where = [] + args = [] + for propname in requirements.keys(): + prop = self.properties[propname] + if isinstance(not prop, String): + raise TypeError, "'%s' not a String property"%propname + where.append(propname) + args.append(requirements[propname].lower()) + + # generate the where clause + s = ' and '.join(['_%s=%s'%(col, self.db.arg) for col in where]) + sql = 'select id from _%s where %s'%(self.classname, s) + self.db.sql(sql, tuple(args)) + l = [x[0] for x in self.db.sql_fetchall()] if __debug__: print >>hyperdb.DEBUG, 'find ... ', l return l