Mercurial > p > roundup > code
comparison roundup/backends/back_sqlite.py @ 1170:af104fa52746
Added some words to the installation doc about choosing backends.
Added hyperdb Class.filter unit tests - gadfly currently fails
substring searching, but I knew it would :(
Lots of fixes to the RDBMS backend - it works a treat now!
A couple of other cleanups in CGI land...
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 19 Sep 2002 02:37:41 +0000 |
| parents | 94620e088e3a |
| children | 08a13a84ed43 |
comparison
equal
deleted
inserted
replaced
| 1169:7b448a2425fd | 1170:af104fa52746 |
|---|---|
| 1 # $Id: back_sqlite.py,v 1.2 2002-09-18 07:04:37 richard Exp $ | 1 # $Id: back_sqlite.py,v 1.3 2002-09-19 02:37:41 richard Exp $ |
| 2 __doc__ = ''' | 2 __doc__ = ''' |
| 3 See https://pysqlite.sourceforge.net/ for pysqlite info | 3 See https://pysqlite.sourceforge.net/ for pysqlite info |
| 4 ''' | 4 ''' |
| 5 import base64, marshal | 5 import base64, marshal |
| 6 from roundup.backends.rdbms_common import * | 6 from roundup.backends.rdbms_common import * |
| 126 d[k] = float(v) | 126 d[k] = float(v) |
| 127 else: | 127 else: |
| 128 d[k] = v | 128 d[k] = v |
| 129 return d | 129 return d |
| 130 | 130 |
| 131 class Class(Class): | |
| 132 _marker = [] | |
| 133 def get(self, nodeid, propname, default=_marker, cache=1): | |
| 134 '''Get the value of a property on an existing node of this class. | |
| 135 | |
| 136 'nodeid' must be the id of an existing node of this class or an | |
| 137 IndexError is raised. 'propname' must be the name of a property | |
| 138 of this class or a KeyError is raised. | |
| 139 | |
| 140 'cache' indicates whether the transaction cache should be queried | |
| 141 for the node. If the node has been modified and you need to | |
| 142 determine what its values prior to modification are, you need to | |
| 143 set cache=0. | |
| 144 ''' | |
| 145 if propname == 'id': | |
| 146 return nodeid | |
| 147 | |
| 148 if propname == 'creation': | |
| 149 if not self.do_journal: | |
| 150 raise ValueError, 'Journalling is disabled for this class' | |
| 151 journal = self.db.getjournal(self.classname, nodeid) | |
| 152 if journal: | |
| 153 return self.db.getjournal(self.classname, nodeid)[0][1] | |
| 154 else: | |
| 155 # on the strange chance that there's no journal | |
| 156 return date.Date() | |
| 157 if propname == 'activity': | |
| 158 if not self.do_journal: | |
| 159 raise ValueError, 'Journalling is disabled for this class' | |
| 160 journal = self.db.getjournal(self.classname, nodeid) | |
| 161 if journal: | |
| 162 return self.db.getjournal(self.classname, nodeid)[-1][1] | |
| 163 else: | |
| 164 # on the strange chance that there's no journal | |
| 165 return date.Date() | |
| 166 if propname == 'creator': | |
| 167 if not self.do_journal: | |
| 168 raise ValueError, 'Journalling is disabled for this class' | |
| 169 journal = self.db.getjournal(self.classname, nodeid) | |
| 170 if journal: | |
| 171 name = self.db.getjournal(self.classname, nodeid)[0][2] | |
| 172 else: | |
| 173 return None | |
| 174 try: | |
| 175 return self.db.user.lookup(name) | |
| 176 except KeyError: | |
| 177 # the journaltag user doesn't exist any more | |
| 178 return None | |
| 179 | |
| 180 # get the property (raises KeyErorr if invalid) | |
| 181 prop = self.properties[propname] | |
| 182 | |
| 183 # get the node's dict | |
| 184 d = self.db.getnode(self.classname, nodeid) #, cache=cache) | |
| 185 | |
| 186 if not d.has_key(propname): | |
| 187 if default is self._marker: | |
| 188 if isinstance(prop, Multilink): | |
| 189 return [] | |
| 190 else: | |
| 191 return None | |
| 192 else: | |
| 193 return default | |
| 194 | |
| 195 # special handling for some types | |
| 196 if isinstance(prop, Multilink): | |
| 197 # don't pass our list to other code | |
| 198 return d[propname][:] | |
| 199 elif d[propname] is None: | |
| 200 # always return None right now, no conversion | |
| 201 return None | |
| 202 elif isinstance(prop, Boolean) or isinstance(prop, Number): | |
| 203 # turn Booleans and Numbers into integers | |
| 204 return int(d[propname]) | |
| 205 | |
| 206 return d[propname] | |
| 207 |
