Revision 1893
Added by Aaron Marcuse-Kubitza over 12 years ago
sql.py | ||
---|---|---|
6 | 6 |
import warnings |
7 | 7 |
|
8 | 8 |
import exc |
9 |
import iters |
|
9 | 10 |
from Proxy import Proxy |
10 | 11 |
import rand |
11 | 12 |
import strings |
... | ... | |
180 | 181 |
|
181 | 182 |
def rows(cur): return iter(lambda: cur.fetchone(), None) |
182 | 183 |
|
183 |
def row(cur): return rows(cur).next() |
|
184 |
def next_row(cur): return rows(cur).next()
|
|
184 | 185 |
|
186 |
def row(cur): |
|
187 |
row_iter = rows(cur) |
|
188 |
row_ = row_iter.next() |
|
189 |
iters.consume_iter(row_iter) # fetch all rows so result will be cached |
|
190 |
return row_ |
|
191 |
|
|
192 |
def next_value(cur): return next_row(cur)[0] |
|
193 |
|
|
185 | 194 |
def value(cur): return row(cur)[0] |
186 | 195 |
|
187 |
def values(cur): return iter(lambda: value(cur), None)
|
|
196 |
def values(cur): return iters.func_iter(lambda: next_value(cur))
|
|
188 | 197 |
|
189 | 198 |
def value_or_none(cur): |
190 | 199 |
try: return value(cur) |
Also available in: Unified diff
sql.py: Made row() and value() cache the result by fetching all rows before returning the first row