Project

General

Profile

« Previous | Next » 

Revision 1899

sql.py: DbConn: DbCursor: Fixed bug where caching was always turned on, by passing the cacheable setting to it from run_query(). Turned caching back on (uncommented it) since it's now working.

View differences:

lib/sql.py
119 119
        return self.__db
120 120
    
121 121
    class DbCursor(Proxy):
122
        def __init__(self, outer):
122
        def __init__(self, outer, cache_results):
123 123
            Proxy.__init__(self, outer.db.cursor())
124
            self.outer = outer
124
            if cache_results: self.query_results = outer.query_results
125
            else: self.query_results = None
125 126
            self.query_lookup = None
126 127
            self.result = []
127 128
        
......
133 134
        
134 135
        def fetchone(self):
135 136
            row = self.inner.fetchone()
136
            if row == None: # fetched all rows
137
            if row != None: self.result.append(row)
138
            # otherwise, fetched all rows
139
            elif self.query_results != None: # is caching
137 140
                assert self.query_lookup != None
138
                pass #self.outer.query_results[self.query_lookup] = (self.query,
139
                    #self.result)
140
            else: self.result.append(row)
141
                self.query_results[self.query_lookup] = (self.query,
142
                    self.result)
141 143
            return row
142 144
    
143 145
    class CacheCursor:
......
154 156
        query_lookup = _query_lookup(query, params)
155 157
        try: actual_query, result = self.query_results[query_lookup]
156 158
        except KeyError:
157
            cur = self.DbCursor(self)
159
            cur = self.DbCursor(self, cacheable)
158 160
            try: cur.execute(query, params)
159 161
            except Exception, e:
160 162
                _add_cursor_info(e, cur)

Also available in: Unified diff