New API reference documentation is available for testing at http://thewinecellarbook.com/daboDocTestAlt/. Please report any problems or suggestions on the dabo-users mailing list.

Class dCursorMixin

Dabo's cursor class, representing the lowest tier.

Properties

Application AutoPopulatePK AutoQuoteNames
AutoSQL AuxCursor BackendObject
BaseClass BasePrefKey Class
CurrentSQL DataStructure Encoding
FieldDescription IsAdding IsPrefCursor
KeyField LastSQL LogEvents
Name ParamPlaceholder Parent
PreferenceManager Record RowCount
RowNumber Table UserSQL
VirtualFields

Events


Methods

addField addFrom addGroupBy
addJoin addOrderBy addWhere
afterInit appendDataSet autoBindEvents
beforeInit beginTransaction bindEvent
bindEvents cancel checkPK
clearLastRequeryTime clearSQL cloneRecord
commitTransaction createAssociation createIndexes
createTable createTableAndIndexes cursorToXML
delete escQuote escape
execute executeSQL executeSafe
filter filterByExpression first
flush formatBLOB formatDateTime
formatNone genTempAutoPK getAbsoluteName
getChangedRows getChildFilterClause getCurrentRecord
getDataDiff getDataSet getDataTypes
getFieldClause getFieldInfoFromDescription getFieldVal
getFields getFromClause getGroupByClause
getJoinClause getLastInsertID getLimit
getLimitClause getLimitPosition getLimitWord
getNonUpdateFields getOrderByClause getPK
getProperties getRecordStatus getSQL
getSortCase getSortColumn getSortOrder
getStructureOnlySql getTableRecordCount getTables
getWhereClause getWordMatchFormat hasPK
initEvents initProperties isChanged
last locate lookupPKWithAdd
makePkWhere makeUpdClause mmAddToBoth
mmAssociateValue mmAssociateValues mmDissociateAll
mmDissociateValue mmDissociateValues mmGetAssociatedValues
mmSetFullAssociation moveToPK moveToRowNum
new next oldVal
pkExpression pkFieldExpression pregenPK
prepareWhere prior processFields
raiseEvent removeFilter removeFilters
replace requery rollbackTransaction
save seek setChildFilter
setChildFilterClause setCursorFactory setDataSet
setDefaults setFieldClause setFieldVal
setFieldVals setFromClause setGroupByClause
setJoinClause setLimit setLimitClause
setNewFlag setNonMatchChildFilterClause setNonUpdateFields
setOrderByClause setProperties setPropertiesFromAtts
setValuesByDict setWhereClause sort
unbindEvent




Properties

Application
Read-only object reference to the Dabo Application object.  (dApp).

(inherited from dObject)
AutoPopulatePK
When inserting a new record, does the backend populate the PK field?
AutoQuoteNames
When True (default), table and column names are enclosed with
quotes during SQL creation.  (bool)
AutoSQL
Returns the SQL statement automatically generated by the sql manager.
AuxCursor
Auxiliary cursor object that handles queries that would otherwise
affect the main cursor's data set.  (dCursorMixin subclass)
BackendObject
Returns a reference to the object defining backend-specific behavior (dBackend)
BaseClass
The base Dabo class of the object. Read-only.  (class)

(inherited from dObject)
BasePrefKey
Base key used when saving/restoring preferences  (str)

(inherited from dObject)
Class
The class the object is based on. Read-only.  (class)

(inherited from dObject)
CurrentSQL
Returns the current SQL that will be run, which is one of UserSQL or AutoSQL.
DataStructure
Returns the structure of the cursor in a tuple of 6-tuples.

| 0: field alias (str)
| 1: data type code (str)
| 2: pk field (bool)
| 3: table name (str)
| 4: field name (str)
| 5: field scale (int or None)

This information will try to come from a few places, in order:

1) The explicitly-set DataStructure property
2) The backend table method

Encoding
Encoding type used by the Backend  (string)
FieldDescription
Tuple of field names and types, as returned by the backend  (tuple)
IsAdding
Returns True if the current record is new and unsaved
IsPrefCursor
Returns True if this cursor is used for managing internal
Dabo preferences and settings. Default=False.  (bool)
KeyField
Name of field that is the PK. If multiple fields make up the key,
separate the fields with commas. (str)
LastSQL
Returns the last executed SQL statement.
LogEvents
Specifies which events to log.  (list of strings)

If the first element is 'All', all events except the following listed events
will be logged.
Event logging is resource-intensive, so in addition to setting this LogEvents
property, you also need to make the following call:

	>>> dabo.eventLogging = True


(inherited from dObject)
Name
The name of the object.  (str)

(inherited from dObject)
ParamPlaceholder
The character(s) used to indicate a parameter in an SQL statement.
This can be different for different backend systems. Read-only.  (str)
Parent
The containing object.  (obj)

(inherited from dObject)
PreferenceManager
Reference to the Preference Management object  (dPref)

(inherited from dObject)
Record
Represents a record in the data set. You can address individual
columns by referring to 'self.Record.fieldName' (read-only) (no type)
RowCount
Current number of rows in the recordset. Read-only.
RowNumber
Current row in the recordset.
Table
The name of the table in the database that this cursor is updating.
UserSQL
SQL statement to run. If set, the automatic SQL builder will not be used.
VirtualFields
A dictionary mapping virtual_field_name to a function to call.

The specified function will be called when getFieldVal() is called on
the specified field name.



Events




Methods

addField(self, exp, alias=None)
Add a field to the field clause.
addFrom(self, exp, alias=None)
Add a table to the sql statement. For joins, use
the addJoin() method.
addGroupBy(self, exp)
Add an expression to the group-by clause.
addJoin(self, tbl, joinCondition, joinType=None)
Add a joined table to the sql statement.
addOrderBy(self, exp)
Add an expression to the order-by clause.
addWhere(self, exp, comp='and')
Add an expression to the where clause.
afterInit(self)
Subclass hook. Called after the object's __init__ has run fully.
Subclasses should place their __init__ code here in this hook, instead of
overriding __init__ directly, to avoid conflicting with base Dabo behavior.

(inherited from dObject)
appendDataSet(self, ds, updateInternals=False)
Appends the rows in the passed dataset to this cursor's dataset. No checking
is done on the dataset columns to make sure that they are correct for this cursor;
it is the responsibility of the caller to make sure that they match. If invalid data is
passed, a dException.FieldNotFoundException will be raised.
autoBindEvents(self, force=True)
Automatically bind any on*() methods to the associated event.

User code only needs to define the callback, and Dabo will automatically
set up the event binding. This will satisfy lots of common cases where
you want an object or its parent to respond to the object's events.

To use this feature, just define a method on<EventName>(), or	if you
want a parent container to respond to the event, make a method in the
parent on<EventName>_<object Name or RegID>().

For example::
	
	class MyButton(dabo.ui.dButton):
		def onHit(self, evt):
			print "Hit!"

	class MyPanel(dabo.ui.dPanel):
		def afterInit(self):
			self.addObject(MyButton, RegID="btn1")

		def onHit_btn1(self, evt):
			print "panel: button hit!"

When the button is pressed, you'll see both 'hit' messages because of
auto event binding.

If you want to bind your events explicitly, you can turn off auto event
binding by calling::

	 dabo.autoBindEvents = False

This feature is inspired by PythonCard.

(inherited from EventMixin)
beforeInit(self, *args, **kwargs)
Subclass hook. Called before the object is fully instantiated.
Usually, user code should override afterInit() instead, but there may be
cases where you need to set an attribute before the init stage is fully
underway.

(inherited from dObject)
beginTransaction(self)
Begin a SQL transaction.
bindEvent(self, eventClass, function, _auto=False)
Bind a dEvent to a callback function.

(inherited from EventMixin)
bindEvents(self, bindings)
Bind a sequence of [dEvent, callback] lists.

(inherited from EventMixin)
cancel(self, allRows=False, ignoreNoRecords=None)
Revert any changes to the data set back to the original values.
checkPK(self)
Verify that the field(s) specified in the KeyField prop exist.
clearLastRequeryTime(self)
Clear the last requery time to force the cache to be expired.
clearSQL(self)

			
		
cloneRecord(self)
Creates a copy of the current record and adds it to the dataset.
commitTransaction(self)
Commit a SQL transaction.
createAssociation(self, mmOtherTable, mmOtherPKCol, assocTable, assocPKColThis, assocPKColOther)
Create a many-to-many association.
createIndexes(self, tabledef)
Create indexes based on the table definition.
createTable(self, tabledef)
Create a table based on the table definition.
createTableAndIndexes(self, tabledef)
Create a table and its indexes based on the table definition.
cursorToXML(self)
Returns an XML string containing the information necessary to
re-create this cursor.
delete(self, delRowNum=None)
Delete the specified row, or the currently active row.
escQuote(self, val)
Escape special characters in SQL strings.
escape(self, val)
Provides the proper escaping of values in XML output
execute(self, sql, params=None, _newQuery=False, errorClass=None, convertQMarks=False)
Execute the sql, and populate the DataSet if it is a select statement.
executeSQL(self, *args, **kwargs)

			
		
executeSafe(self, sql, params=None)
Execute the passed SQL using an auxiliary cursor.
This is considered 'safe', because it won't harm the contents
of the main cursor. Returns the temp cursor.
filter(self, fld, expr, op='=')
Apply a filter to the current records.
filterByExpression(self, expr)
Allows you to filter by any valid Python expression.
first(self)
Move the record pointer to the first record of the data set.
flush(self)
Some backends need to be prompted to flush changes
to disk even without starting a transaction. This is the method
to call to accomplish this.
formatBLOB(self, val)
Format BLOB values for the backend
formatDateTime(self, val)
Format DateTime values for the backend
formatNone(self)
Format None values for the backend
genTempAutoPK(self)
Create a temporary PK for a new record. Set the key field to this
value, and also create a temp field to hold it so that when saving the
new record, child records that are linked to this one can be updated
with the actual PK value.
getAbsoluteName(self)
Return the fully qualified name of the object.

(inherited from dObject)
getChangedRows(self, includeNewUnchanged=False)
Returns a list of rows with changes.
getChildFilterClause(self)
Get the child filter part of the sql statement.
getCurrentRecord(self)
Returns the current record (as determined by self.RowNumber)
as a dict, or None if the RowNumber is not a valid record.
getDataDiff(self, allRows=False)
Create a compact representation of all the modified records
for this cursor.
getDataSet(self, flds=(), rowStart=0, rows=None, returnInternals=False)
Get the entire data set encapsulated in a dDataSet object.

If the optional	'flds' parameter is given, the result set will be filtered
to only include the specified fields. rowStart specifies the starting row
to include, and rows is the number of rows to return.
getDataTypes(self)
Returns the internal _types dict.
getFieldClause(self)
Get the field clause of the sql statement.
getFieldInfoFromDescription(self)
Get field information from the cursor description.

Returns a tuple of 3-tuples, where the 3-tuple's elements are:

	| 0: the field name (string)
	| 1: the field type ('I', 'N', 'C', 'M', 'B', 'D', 'T'), or None.
	| 2: boolean specifying whether this is a pk field, or None.

getFieldVal(self, fld, row=None, _rowChangeCallback=None)
Return the value of the specified field in the current or specified row.
getFields(self, tableName=None)
Get field information about the backend table.

Returns a list of 3-tuples, where the 3-tuple's elements are:

	| 0: the field name (string)
	| 1: the field type ('I', 'N', 'C', 'M', 'B', 'D', 'T')
	| 2: boolean specifying whether this is a pk field.

getFromClause(self)
Get the from clause of the sql statement.
getGroupByClause(self)
Get the group-by clause of the sql statement.
getJoinClause(self)
Get the join clause of the sql statement.
getLastInsertID(self)
Return the most recently generated PK
getLimit(self)
Get the limit clause of the sql statement.
getLimitClause(self)
Get the limit clause of the sql statement.
getLimitPosition(self)
Return the position to place the limit clause.

For currently-supported dbapi's, the return values of 'top' or 'bottom'
are sufficient.
getLimitWord(self)
Return the word to use in the db-specific limit clause.
getNonUpdateFields(self)

			
		
getOrderByClause(self)
Get the order-by clause of the sql statement.
getPK(self, row=None)
Returns the value of the PK field in the current or passed record number.
If that record is a new unsaved record, return the temp PK value. If this is a
compound PK, return a tuple containing each field's values.
getProperties(self, propertySequence=(), propsToSkip=(), ignoreErrors=False, *propertyArguments)
Returns a dictionary of property name/value pairs.

If a sequence of properties is passed, just those property values
will be returned. Otherwise, all property values will be returned.
The sequence of properties can be a list, tuple, or plain string
positional arguments. For instance, all of the following are
equivilent::

	print self.getProperties("Caption", "FontInfo", "Form")
	print self.getProperties(["Caption", "FontInfo", "Form"])
	t = ("Caption", "FontInfo", "Form")
	print self.getProperties(t)
	print self.getProperties(\*t)

An exception will be raised if any passed property names don't
exist, aren't actual properties, or are not readable (do not have
getter functions).

However, if an exception is raised from the property getter function,
the exception will get caught and used as the property value in the
returned property dictionary. This allows the property list to be
returned even if some properties can't be evaluated correctly by the
object yet.

(inherited from PropertyHelperMixin)
getRecordStatus(self, row=None, pk=None)
Returns a dictionary containing an element for each changed
field in the specified record (or the current record if none is specified).
The field name is the key for each element; the value is a 2-element
tuple, with the first element being the original value, and the second
being the current value. You can specify the record by either the
row number or the PK.
getSQL(self, ignoreChildFilter=False)
Get the complete SQL statement from all the parts.
getSortCase(self)

			
		
getSortColumn(self)

			
		
getSortOrder(self)

			
		
getStructureOnlySql(self)
Creates a SQL statement that will not return any records.
getTableRecordCount(self, tableName)
Get the number of records in the backend table.
getTables(self, includeSystemTables=False)
Return a tuple of tables in the current database.
getWhereClause(self)
Get the where clause of the sql statement.
getWordMatchFormat(self)

			
		
hasPK(self, pk)
Return True if the passed pk is present in the dataset.
initEvents(self)
Hook for subclasses. User code should do custom event binding
here, such as::
	
	self.bindEvent(dEvents.GotFocus, self.customGotFocusHandler)
	

(inherited from dObject)
initProperties(self)
Hook for subclasses. User subclasses should set properties
here, such as::
	
	self.Name = "MyTextBox"
	self.BackColor = (192,192,192)
	

(inherited from dObject)
isChanged(self, allRows=True, includeNewUnchanged=False)
Return True if there are any changes to the local field values.

If allRows is True (the default), all records in the recordset will be
considered. Otherwise, only the current record will be checked.

If includeNewUnchanged is True, new records that have not been
modified from their default values, which normally are not
considered 'changed', will be counted as 'changed'.
last(self)
Move the record pointer to the last record in the recordset.
locate(self, val, fld=None, caseSensitive=True, movePointer=True)
Find the first row where the field value matches the passed value.

Returns True or False, depending on whether a matching value was located.
If 'fld' is not specified, the current sortColumn is used. If 'caseSensitive' is
set to False, string comparisons are done in a case-insensitive fashion.

This is very similar to the seek() method, with two main differences: there
is no concept of a near-match; either the value is found or it isn't; the return
value is a boolean indicating if the match was found, not the matching RowNumber.
lookupPKWithAdd(self, field, val, tbl=None, pkCol=None)
Runs a lookup in the specified field for the desired value. If
found, returns the PK for that record. If not found, a record is
inserted into the table, with its 'field' column populated with 'val',
and the new PK is returned. None of this affects the current dataset.
makePkWhere(self, row=None)
Create the WHERE clause used for updates, based on the pk field.

Optionally pass in a row number, otherwise use the current record.
makeUpdClause(self, diff)
Create the 'set field=val' section of the Update statement. Return a 2-tuple
containing the sql portion as the first element, and the parameters for the
values as the second.
mmAddToBoth(self, thisField, thisVal, otherField, otherVal)
Creates an association in a M-M relationship. If the relationship
already exists, nothing changes. Otherwise, this will ensure that
both values exist in their respective tables, and will create the 
entry in the association table.
mmAssociateValue(self, otherField, otherVal)
Associates the value in the 'other' table of a M-M relationship with the
current record. If that value doesn't exist in the other table, it is added.
mmAssociateValues(self, otherField, listOfValues)

			
		
mmDissociateAll(self)
Removes all associations between the current record and the associated
M-M table.
mmDissociateValue(self, otherField, otherVal)
Removes the association between the current record and the specified value
in the 'other' table of a M-M relationship. If no such association exists,
nothing happens.
mmDissociateValues(self, otherField, listOfValues)
Removes the association between the current record and every item in 'listOfValues'
in the 'other' table of a M-M relationship. If no such association exists,
nothing happens.
mmGetAssociatedValues(self, listOfFields)
Returns a dataset containing the values for the specified fields
in the records associated with the current record.
mmSetFullAssociation(self, otherField, listOfValues)
Adds and/or removes association records so that the current record
is associated with every item in listOfValues, and none other.
moveToPK(self, pk)
Find the record with the passed primary key, and make it active.

If the record is not found, the position is set to the first record.
moveToRowNum(self, rownum)
Move the record pointer to the specified row number.

If the specified row does not exist, the pointer remains where it is,
and an exception is raised.
new(self)
Add a new record to the data set.
next(self)
Move the record pointer forward one position in the recordset.
oldVal(self, fieldName, row=None)
Returns the value of the field as it existed after the last requery.
pkExpression(self, rec=None)
Returns the PK expression for the passed record.
pkFieldExpression(self)
Returns the field or comma-separated list of field names
for the PK for this cursor's table.
pregenPK(self)
Various backend databases require that you manually
generate new PKs if you need to refer to their values afterward.
This method will call the backend to generate and
retrieve a new PK if the backend supports this. We use the
auxiliary cursor so as not to alter the current data.
prepareWhere(self, clause)
Modifies WHERE clauses as needed for each backend.
prior(self)
Move the record pointer back one position in the recordset.
processFields(self, txt)

			
		
raiseEvent(self, eventClass, uiEvent=None, *args, **kwargs)
Send the event to all registered listeners.

If uiEvent is sent, dEvents.Event will be able to parse it for useful
information to send along to the callback. 

Additional arguments, if any, are sent along to the constructor	of the
event. While this feature exists so that UI-lib event handlers can pass
along information (such as the keystroke information in a key event), user
code may pass along additional arguments as well, which	will exist in the
event.EventData dictionary property.

In most cases, user code should call raiseEvent() with
the event class (dEvents.Hit, for example) as the only parameter.

(inherited from EventMixin)
removeFilter(self)
Remove the most recently applied filter.
removeFilters(self)
Remove all applied filters, going back to the original data set.
replace(self, field, valOrExpr, scope=None)
Replaces the value of the specified field with the given value
or expression. All records matching the scope are affected; if
no scope is specified, all records are affected.

'valOrExpr' will be treated as a literal value, unless it is prefixed
with an equals sign. All expressions will therefore be a string
beginning with '='. Literals can be of any type.

.. note::
	
   This does NOT work with the memento framework for
   determining modified records. It is strongly recommended that
   instead of calling this directly that the bizobj.replace() method
   be used in any programming.
   
requery(self, params=None)

			
		
rollbackTransaction(self)
Roll back (revert) a SQL transaction.
save(self, allRows=False, includeNewUnchanged=False)
Save any changes to the current record back to the data store.
seek(self, val, fld=None, caseSensitive=True, near=False, movePointer=True, sort=True, incremental=False)
Find the first row where the field value matches the passed value.

Returns the row number of the first record that matches the passed
value in the designated field, or -1 if there is no match. If 'near' is
True, a match will happen on the row whose value is the greatest value
that is less than the passed value. If 'caseSensitive' is set to False,
string comparisons are done in a case-insensitive fashion.

If sort is True (the default), then we seek to the first matching value
without sorting first. 

If incremental is True (default is False), then we only compare the first
characters up until the length of val.
setChildFilter(self, fld)
This method sets the appropriate WHERE filter for dependent child queries.
setChildFilterClause(self, clause)
Set the child filter clause of the sql statement.
setCursorFactory(self, func, cls)

			
		
setDataSet(self, ds)
Set the records of the cursor to the passed dDataSet instance.

Obviously, use with care. You can't get the original records back 
and this is really intended for one-off read-only cursors.
setDefaults(self, vals)
Set the default field values for newly added records. The
'vals' parameter is a dictionary of fields and their default values.
If vals is None, the defaults for all but the KeyField will be set to
None, and their values will not be included in the insert statement
when saved unless the user changes them to some non-null
value.
setFieldClause(self, clause)
Set the field clause of the sql statement.
setFieldVal(self, fld, val, row=None, pk=None)
Set the value of the specified field.
setFieldVals(self, valDict, row=None, pk=None)
Set the value for multiple fields with one call by passing a dict containing
the field names as keys, and the new values as values.
setFromClause(self, clause)
Set the from clause of the sql statement.
setGroupByClause(self, clause)
Set the group-by clause of the sql statement.
setJoinClause(self, clause)
Set the join clause of the sql statement.
setLimit(self, clause)
Set the limit clause of the sql statement.
setLimitClause(self, clause)
Set the limit clause of the sql statement.
setNewFlag(self)
Set the current record to be flagged as a new record.

dBizobj will automatically call this method as appropriate, but if you are
using dCursor without a proxy dBizobj, you'll need to manually call this
method after cursor.new(), and (if applicable) after cursor.genTempAutoPK().

For example::
	
	cursor.new()
	cursor.genTempAutoPK()
	cursor.setNewFlag()

setNonMatchChildFilterClause(self)
Called when the parent has no records, which implies that the child
cannot have any, either.
setNonUpdateFields(self, fldList=None)

			
		
setOrderByClause(self, clause)
Set the order-by clause of the sql statement.
setProperties(self, propDict={}, ignoreErrors=False, **propKw)
Sets a group of properties on the object all at once.

You have the following options for sending the properties:
	
	1) Property/Value pair dictionary
	2) Keyword arguments
	3) Both

The following examples all do the same thing::

	self.setProperties(FontBold=True, ForeColor="Red")
	self.setProperties({"FontBold": True, "ForeColor": "Red"})
	self.setProperties({"FontBold": True}, ForeColor="Red")


(inherited from PropertyHelperMixin)
setPropertiesFromAtts(self, propDict={}, ignoreExtra=True, context=None)
Sets a group of properties on the object all at once. This
is different from the regular setProperties() method because
it only accepts a dict containing prop:value pairs, and it
assumes that the value is always a string. It will convert
the value to the correct type for the property, and then set
the property to that converted value. If the value needs to be evaluated
in a specific namespace, pass that as the 'context' parameter.

(inherited from PropertyHelperMixin)
setValuesByDict(self, valDict, row=None, pk=None)
Set the value for multiple fields with one call by passing a dict containing
the field names as keys, and the new values as values.
setWhereClause(self, clause)
Set the where clause of the sql statement.
sort(self, col, ordr=None, caseSensitive=True)
Sort the result set on the specified column in the specified order. If the sort
direction is not specified, default to ascending order. If 'cycle' is specified as the
direction, use the next ordering in the list [None, 'ASC', 'DESC']. The possible
values for 'ordr' are:

	None
	"" (i.e., an empty string)
	ASC
	DESC
	CYCLE

Only the first three characters are significant; case is ignored.
unbindEvent(self, eventClass=None, function=None)
Remove a previously registered event binding.

Removes all registrations that exist for the given binding for this
object. If event is None, all bindings for the passed function are
removed. If function is None, all bindings for the passed event are
removed. If both event and function are None, all event bindings are
removed.

(inherited from EventMixin)

Dabo 0.9.4 (rev. 7089)
9 Feb 2012 23:31:09