| |
- LazyResultSet(object)
-
- DBResultSet(LazyResultSet, Propertied)
- Propertied(object)
-
- DBResultSet(LazyResultSet, Propertied)
- SQLMultiQuery(SQLQuery)
-
- SimpleTableUpdate
class DBResultSet(LazyResultSet, Propertied) |
|
A pseudo-sequence with read/write lazy-result-set semantics
The DBResultSet wraps a pytable cursor which has a
retrieved result-set to provide access to a controlling
schema (a table or view schema) and to provide automated
commit/abort of changes to the generated dbrow objects.
Via the lazyresultset base-class provides lazy loading
of the results from the set. |
|
- Method resolution order:
- DBResultSet
- LazyResultSet
- Propertied
- object
Methods defined here:
- __getattr__(self, key)
- Delegate attribute lookup to our schema if it exists
- abort(self, rows=None)
- Abort changes to rows, or all changed rows
- commit(self, rows=None)
- Commit changes to rows, or all changed rows
- getProperties(self)
- Retrieve the properties for this particular result-set
- wrapRow(self, data, index)
- Wrap a single row in our DBRow class
Data and other attributes defined here:
- autoCommit = <BooleanProperty 'autoCommit'>
- Override schema's autoCommit value
autoCommit cause a database update to be done on every
property __set__. TableSchemas normally do *not* define an
autoCommit attribute, so the result-set's autoCommit
value is normally derived from the defaultFunction of this
property (which defaults to false)
- cursor = <BasicProperty 'cursor'>
- Pointer to our database cursor (a pytable dbcursor instance)
- cursorDescription = <BasicProperty 'cursorDescription'>
- The db-api-style cursor description for data-rows
This is used to unify result-set fields with the
controlling schema, as the order of fields may
not match that within the database.
- length = <IntegerProperty 'length'>
- Length of the table if calculated yet, otherwise -1
You should use len( self ), not self.length for any
code you write. Length is just part of the
lazyresultset base-class's API.
Note: this property shadows the lazyresultset's
attribute to provide documentation.
- schema = <BasicProperty 'schema'>
- The controlling schema for this result-set
Methods inherited from LazyResultSet:
- __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.
- __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.
Data and other attributes inherited from LazyResultSet:
- __dict__ = <dictproxy object at 0x01DF3890>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'LazyResultSet' objects>
- list of weak references to the object (if defined)
Methods inherited from Propertied:
- __str__(self)
- Get a friendly representation of the object
- clone(self, **newValues)
- Clone this object, with optional new property values
This method calls the __init__ method of your class with
the current property values of your class. Providing newValues
(a dictionary) overrides property settings with new values.
- getCloneProperties(self)
- Get properties dictionary (key:value) for use in cloning of the instance
By default you get getProperties()' values, with an
attempt made to use the property's name, then the property's
direct "__get__" method.
- toString(self, indentation='', alreadyDone=None, indentString=' ')
- Get a nicely formatted representation of this object
This version assumes that getProperties returns
the list of properties which should be presented,
it recursively calls it's children with greater
indents to get their representations.
indentation -- current string indentation level
alreadyDone -- set of object ids which are already finished
XXX Needs a far better API, likely a stand-alone class
without the automatic inheritance problems here :(
|
class SimpleTableUpdate(SQLMultiQuery) |
|
Query to do an update in a single table for a set of rows
Note:
This really is the "simple" update query. DBRow instances,
which are far more commonly used, have their own far more
involved update/insert/delete queries.
XXX Should likely eliminate this code? It's only use is
for doing updates of large numbers of rows
simultaneously with the same fields for each update. |
|
- Method resolution order:
- SimpleTableUpdate
- SQLMultiQuery
- SQLQuery
- Propertied
- object
Methods defined here:
- __call__(self, cursor, tableName, keySet, columnSet, rows, **named)
- Build the sql query up from given values and then execute it
cursor -- DBCursor or DBConnection object
tableName -- string tableName into which to update
keySet -- list of key field names (WHERE clause)
columnSet -- list of fields to update
rows -- list of objects/dictionaries used as data-source(s)
named -- passed to the underlying query
Data and other attributes defined here:
- sql = 'UPDATE\n\t\t%(tableName)s\n\tSET\n\t\t%(columnFragment)s\n\tWHERE\n\t\t%(keySetFragment)s\n\t;'
Methods inherited from SQLMultiQuery:
- do(self, cursor, query, dataSet, **namedarguments)
- Do the actual processing of the query (executemany)
cursor -- a dbcursor object
query -- a final SQL query string, must be fully
substituted so that decree will operate properly
with the given cursor.
dataSet -- must have been passed to the __call__ method
as a named argument. Should be a sequence of
objects suitable for use as argument-sources for the
cursor's executemany method.
namedarguments -- unused in this version, these are the
same arguments passed to the __call__ method.
returns the result of the cursor's executemany method,
which is currently ignored by the __call__ method.
Methods inherited from SQLQuery:
- __init__(self, sql=None, debug=None, **named)
- Initialise the SQLQuery
sql -- sql string or None to use class' sql value
debug -- if provided (not None), override class' debug flag
- encodeQuery(self, query, cursor=None)
- Encode query for use by the given cursor
- processResults(self, cursor, **namedarguments)
- Convert the query results to desired format
cursor -- a dbcursor object which has just executed
this query. Note that the query may have
returned an empty or null resultset, so this code
should deal with that eventuality.
namedarguments -- These are the same arguments
passed to the __call__ method.
This method provides post-processing of the query
results into application-specific data formats.
By default, simply returns the cursor.
Data and other attributes inherited from SQLQuery:
- debug = 0
- name = ''
Methods inherited from Propertied:
- __str__(self)
- Get a friendly representation of the object
- clone(self, **newValues)
- Clone this object, with optional new property values
This method calls the __init__ method of your class with
the current property values of your class. Providing newValues
(a dictionary) overrides property settings with new values.
- getCloneProperties(self)
- Get properties dictionary (key:value) for use in cloning of the instance
By default you get getProperties()' values, with an
attempt made to use the property's name, then the property's
direct "__get__" method.
- toString(self, indentation='', alreadyDone=None, indentString=' ')
- Get a nicely formatted representation of this object
This version assumes that getProperties returns
the list of properties which should be presented,
it recursively calls it's children with greater
indents to get their representations.
indentation -- current string indentation level
alreadyDone -- set of object ids which are already finished
XXX Needs a far better API, likely a stand-alone class
without the automatic inheritance problems here :(
Class methods inherited from Propertied:
- getProperties(cls) from type
- Get the BasicProperty properties for a particular object's class
Data and other attributes inherited from Propertied:
- __dict__ = <dictproxy object at 0x01DF3950>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'Propertied' objects>
- list of weak references to the object (if defined)
| |