Project

General

Profile

« Previous | Next » 

Revision 1912

sql.py: DbConn: Cache query results as a dict subset of the cursor's key attributes, so that additional attributes can easily be cached by adding them to the subset list

View differences:

lib/sql.py
152 152
                or isinstance(self.result, Exception)):
153 153
                
154 154
                assert self.query_lookup != None
155
                self.query_results[self.query_lookup] = (self.query,
156
                    self.result, self.rowcount)
155
                self.query_results[self.query_lookup] = util.dict_subset(
156
                    dicts.AttrsDictView(self), ['query', 'result', 'rowcount'])
157 157
        
158 158
        def _is_insert(self): return self.query.upper().find('INSERT') >= 0
159 159
    
160 160
    class CacheCursor:
161
        def __init__(self, query, result, rowcount):
162
            self.query = query
163
            self.result = result
164
            self.rowcount = rowcount
161
        def __init__(self, cached_result): self.__dict__ = cached_result
165 162
        
166 163
        def execute(self):
167 164
            if isinstance(self.result, Exception): raise self.result
......
187 184
                    _add_cursor_info(e, cur)
188 185
                    raise
189 186
            else:
190
                cur = self.CacheCursor(*cached_result)
187
                cur = self.CacheCursor(cached_result)
191 188
                cur.execute()
192 189
        finally:
193 190
            if self.log_debug != log_debug_none: # only compute msg if needed

Also available in: Unified diff