| |
- object
-
- LazyResultSet
class LazyResultSet(object) |
|
Wrapper around a DB-API cursor providing lazy-loading
The LazyResultSet is intended to allow for interleaved
iterations, and random access of a result set provided by
a DB-API cursor. The LazyResultSet builds a cache of
loaded (and potentially wrapped) objects which are
returned from the cursor.
Performance Considerations:
If your cursor does not support rowcount, then taking
a len( ) of the LazyResultSet will require loading the
entire result set. The same applies to taking negative
indices, as they require calculating length first.
Doing an index or contains with the default rows (the
raw DB-API sequences) will require comparing each row
with the sample row sequentially until the row is found.
Attributes:
cursor -- pointer to the cursor provided at initialization
cursorDescription -- the cursor's description at
initialization
count -- number of records to retrieve in a given block
__loadLock -- reentrant lock protecting the reading functions
_rowCache -- the cache of loaded (and wrapped) rows
length -- length of the result-set (once calculated) |
|
Methods defined here:
- __contains__(self, row)
- Determine whether we contain the given row
Performance Note:
If the row object has an "index" attribute, this
method can short-circuit by checking if that index
is == given row. Otherwise (or if self[row.index]
!= given row), needs to scan sequentially, which
may trigger a full result-set load.
- __delitem__(self, index)
- Delete row at index from the table
raises TypeError
Sub-classes that allow for deleting records may
want to override this method.
- __getattr__(self, key)
- Delegate attribute lookup to our cursor where possible
- __getitem__(self, index)
- Get a particular row in the table
Retrieves a given row in the table. If the row is
not yet in the cache, this will cause all rows up
to and including the row to be retrieved into the
row-cache.
- __getslice__(self, start=0, stop=2147483647, step=1)
- Get slice from the result-set
This returns a new list of records/objects/rows from
the result-set, forcing loading of all objects in the
slice.
start=0, stop= sys.maxint, step=1
- __init__(self, cursor, count=100, *arguments, **named)
- Initialize the LazyResultSet
cursor -- DB-API cursor with the result set to be
wrapped by the LazyResultSet
count -- number of records to retrieve in a single
call to fetchMany
- __iter__(self)
- Iterate through this result-set sequentially
You should be able to use multiple iterators
simultaneously alongside random access operations without
causing any problems.
- __len__(self)
- Return length of the table (number of rows)
Performance Note:
If the cursor object does not support the rowcount
attribute, then __len__ will force a full load of
the result set.
- append(self, row)
- Append a row to the table
raises TypeError
Sub-classes that allow for creating new records may
want to override this method.
- calculateLength(self)
- Calculation of rowset length
Called by the __len__ method and other instances
with the length of the entire result set is required,
see performance note under __len__.
- fetchMany(self, count=None)
- Fetch and return count rows from cursor
Note: these rows are not cached, you should not likely
call this method save in a sub-class from a customized
forceLoad method.
- forceLoad(self, toIndex=None)
- Force loading of all rows up to toIndex
This method is called to load up to the given
index in the result set. The method stops
loading when there are no more results, or the
cache is now long enough to index with toIndex.
- index(self, row)
- Return the index of the given row, uses == checking for rows
Performance Note:
If the row object has an "index" attribute, this
method can short-circuit by checking if that index
is == given row. Otherwise (or if self[row.index]
!= given row), needs to scan sequentially, which
may trigger a full result-set load.
- wrapRow(self, data, index)
- Customization Point: Wrap a single row with our DBRow class
This customization point is intended to allow for use
with customized row classes such as seen in The OPAL
Group's db_row, or pytable's DBRow classes.
index -- index of this row in the result-set/cache
data -- DB-API result-object (a python sequence)
You can get at the cursor via self.cursor, and the
cursor description via self.cursorDescription
Data and other attributes defined here:
- __dict__ = <dictproxy object at 0x01DF3070>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'LazyResultSet' objects>
- list of weak references to the object (if defined)
- length = -1
| |