| |
- Propertied(object)
-
- SQLQuery
-
- SQLMultiQuery
class SQLMultiQuery(SQLQuery) |
|
Multiple-execution version of an SQLQuery object
SQLMultiQuery overrides the "do" method of the SQLQuery
to use the cursor's executemany method, which allows for
efficient execution of identical queries against multiple
data set values. It requires a named argument "dataSet"
to be passed to the __call__ method which will provide
the set of data to be passed to the executemany method. |
|
- Method resolution order:
- SQLMultiQuery
- SQLQuery
- Propertied
- object
Methods defined here:
- 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:
- __call__(self, cursor, **namedarguments)
- Execute with cursor
cursor -- the pytable.dbcursor object to be
used for executing the query. Note that the
query will attempt to automatically coerce a
dbdriver or dbconnection object to a cursor
using that driver/connection. A log warning
will be returned if passing a driver (which
is not recommended, as it will result in
significant setup overhead (connections are
expensive to create for a single execution)).
namedarguments -- will be substituted using
python string substitution into the template
query string in order to create the final
query string. For single-execution queries
(SQLQuery), the namedarguments also represent
the row from which query arguments will be
taken. For multiple-execution queries
(SQLMultiQuery), the namedargument "dataSet"
is used as the executemany argument.
The "do" method takes care of the actual execution
of the query after cursor-coercion and query
substitution.
The "processResults" method takes the cursor and
returns the final result-set for the query which
will be the value returned from this function.
By default, this is simply a pointer to the cursor
used to execute the query.
- __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 = ''
- sql = ''
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 0x01E9DD10>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'Propertied' objects>
- list of weak references to the object (if defined)
|
class SQLQuery(Propertied) |
|
An SQL query to be run against a cursor
This is a callable object which is primarily
defined by an SQL query-string. Currently only
supports pyformat-style query arguments.
Attributes of note:
sql -- SQL query string template, see the
__call__ method for details, basically the
template uses Python extended-string
substitution on the query %(name)s, so you
will need to escape % signs in the query.
debug -- per-query debugging flag. If true, then
this particular query will log to the
"wxoo.sql" debug-module Log. |
|
- Method resolution order:
- SQLQuery
- Propertied
- object
Methods defined here:
- __call__(self, cursor, **namedarguments)
- Execute with cursor
cursor -- the pytable.dbcursor object to be
used for executing the query. Note that the
query will attempt to automatically coerce a
dbdriver or dbconnection object to a cursor
using that driver/connection. A log warning
will be returned if passing a driver (which
is not recommended, as it will result in
significant setup overhead (connections are
expensive to create for a single execution)).
namedarguments -- will be substituted using
python string substitution into the template
query string in order to create the final
query string. For single-execution queries
(SQLQuery), the namedarguments also represent
the row from which query arguments will be
taken. For multiple-execution queries
(SQLMultiQuery), the namedargument "dataSet"
is used as the executemany argument.
The "do" method takes care of the actual execution
of the query after cursor-coercion and query
substitution.
The "processResults" method takes the cursor and
returns the final result-set for the query which
will be the value returned from this function.
By default, this is simply a pointer to the cursor
used to execute the query.
- __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
- do(self, cursor, query, **namedarguments)
- Do the actual processing of the query (execute)
cursor -- a dbcursor object
query -- a final SQL query string, must be fully
substituted so that decree will operate properly
with the given cursor.
namedarguments -- for the single-query version,
(SQLQuery, this version), used as the dictionary
source for named and pyformat query arguments.
These are the same arguments passed to the
__call__ method.
returns the result of the cursor's execute method,
which is currently ignored by the __call__ method.
- 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 defined here:
- debug = 0
- name = ''
- sql = ''
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 0x01E9DE30>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'Propertied' objects>
- list of weak references to the object (if defined)
| |