Python Datastore
objType |
the class of the object to cache |
size: int |
the maximum size allowable for the cache Default value: 0 |
Constructor.
Destructor
newKey: int |
|
newOne |
Add a record to the cache. It must be valid().
Return int value:
key |
Remove a record from the cache
Return bool value:
pos: int |
Remove a record from the cache
Return bool value:
searchKey |
|
fetchIfMissing: bool |
Default value: True |
Locate the cache position (-1 if not found)
Note: Pull into cache if fetchIfNotFound is True
Note: key must be a positive (non-zero) number
Return int value:
searchKey: int |
Check if key exists in list
Return bool value:
key |
Get pointer to data for the key. Check if result is valid().
Note: key must be a positive (non-zero) number
pos: int |
position in cache, from 0+ |
This method allows the class instance to be indexed, e.g. HelloCache[2] to get the second element (not key==2)
Return value: the instance at position
Return the size of the cache when using the len() function
This class abstracts database protocols and allows an app to use this interface to perform database table queries and changes.
This class connects to dbbroker, which actually performs the database manipulation. Note that dbbroker can be configured to connect to a variety of databases; this gets rid of app responsibility for database connection and syntax; an app can simply use the database.
It is safe (and convenient) to create an instance of this class for each table your program uses.
If you have an existing database table and you want to create a class interface to it, consider using genmae like this:
genmae db2h tablename > classname.h
genmae py classname.h > classname.py
Likewise, if you create .h file with the core class variables, you can use genmae to create the SQL code to setup the table, like this:
genmae h2sql classname.h > tablename.sql
Note that database manipulation commands will block program execution until a response from dbbroker is received.
FieldType |
Default value: Enum('FieldType', 'FieldInt', 'FieldTime', 'FieldEnum', 'FieldLogical', 'FieldString', 'FieldFloat', 'FieldDate', 'FieldBinary') |
OK |
DB operation was successful (no error) Default value: 0 |
INVALID_NAME |
DB operation failed - invalid name given Default value: -1 |
OPEN |
DB operation failed - cannot open table Default value: -2 |
INVALID_TYPE |
DB operation failed - invalid field type Default value: -3 |
INVALID_FIELD |
DB operation failed - invalid field name Default value: -4 |
INVALID_REC |
DB operation failed - invalid record id Default value: -5 |
INVALID_ENUM |
DB operation failed - invalid enum Default value: -6 |
INVALID_PARAM |
DB operation failed - invalid parameter Default value: -7 |
LOCKED |
DB operation failed - record locked Default value: -8 |
NOT_SUPPORTED |
DB operation failed - operation not supported Default value: -9 |
FAILED |
DB operation failed - (non-specific) Default value: -10 |
REC_NOT_FOUND |
DB operation failed - record not found Default value: -11 |
ALREADY_EXISTS |
DB operation failed - record already exists Default value: -12 |
INVALID_SCHEMA |
DB operation failed - invalid schema Default value: -13 |
COMM_ERROR |
DB operation failed - communications error Default value: -14 |
CORRUPT_REPLY |
DB operation failed - reply was corrupt (cannot parse) Default value: -15 |
INVALID_CONN |
DB operation failed - invalid connection Default value: -16 |
INVALID_EXPR |
DB operation failed - invalid expression Default value: -17 |
LINEPAYLOADMAX |
Maximum line length to send to dbbroker Default value: 10000 - 100 |
PAYLOADMAX |
Default value: 10000 |
tableName: str |
Default value: |
Constructor to initialize our data structure. This does not yet setup the connection to dbbroker.
Determine status of our connection to database - is it valid?
Return int value: True if connected to db
Get the status of the last request
Return int value: the status of the last request (see codes at top of Datastore.py)
Determine if the status of the last operator was successful.
Return bool value: True if last operation successful, False otherwise.
Determine if the database connection is established and ready.
Return bool value: True if db connection ready
Return human readable status of last request.
Return str value: msg corresponding to last DB request
name: str |
fieldtype |
Return str value:
rcToGetMsgFor: int |
the return code number to look up Default value: 1 |
Get the status message of the specified return code.
Return str value: the text of the error message
tableName: str |
the name of the table to use as the current table. If not successful, check status() for the code or statusMsg() for human readable description. |
Set the currently active table by opening it.
Return int value: the status code of the operation.
tableName: str |
the name of the table to use as the current table. If not successful, check status() for the code or statusMsg() for human readable description. |
Identifical to open(). Set the currently active table by opening it.
Return int value: the status code of the operation.
Check to make sure the database connection is working.
Return bool value: True if db responding to our requests
Pack the database (remove deleted records), if the database supports this.
Otherwise, it is ignored.
Return bool value: True upon success, False upon failure (see statusMsg())
specifiedTable: str |
Signal to close this database table.
@param table name of the table to close; if none, then last table used
Return bool value: True upon success, False upon failure (see statusMsg())
Get the list of defined tables.
Return value: the list of tables in the database
fieldName: str |
name of field for operation |
type |
type of field (string, int, float) |
size: int |
(optional) size of field in bytes |
table: str |
name of table for operation Default value: |
isIndex: bool |
True if this field is an index for the table Default value: False |
Obsolete. Add a field to the named database table.
Return 0 value: field id of new field
fieldName: str |
name of the field for which to get the fieldid |
table: str |
name of table for operation Default value: |
Query field id from field name for the named table.
Return int value: nonzero on success, 0 on failure
fieldName: str |
id of the enum field |
enumName: str |
name/identifier for enum |
enumId: int |
(optional) integer value to use for enum |
table: str |
name of table for operation Default value: |
Obsolete. Add field enumeration to the nanmed table.
Return int value: new enum value
fieldName: str |
id of the enum field |
table: str |
name of table for operation Default value: |
Query a field type (string, float, etc) for the provided field name in the provided table.
Return value: the field type
data |
any data to pre-populate the record |
recno: int |
(optional) id for the record Default value: 0 |
table: str |
name of table for operation Default value: |
Add/Append a new record to the table provided, populated with the data provided.
Return value: new record number added
recno |
number of the record to delete |
table: str |
name of table for operation Default value: |
Delete a record in the named table.
Return bool value: transaction status (see statusMsg())
recno |
number of the record to lock |
table: str |
name of table for operation Default value: |
Lock a record in the named table; prevent other applications from modifying this record until it is unlocked.
Return bool value: transaction status (see statusMsg())
recno |
number of the record to unlock |
table: str |
name of table for operation Default value: |
Unlock a record in the named table, allowing other applications to now modify it.
Return bool value: transaction status (see statusMsg())
recno |
number of the record containing the field |
fieldName: str |
name of the field to clear |
table: str |
name of table for operation Default value: |
clear/empty the value for the field with this field name
Return bool value: transaction status (see statusMsg())
recno |
number of the record in which to set the value |
fieldName: str |
|
value |
the value to set |
table: str |
name of table for operation Default value: |
change a string value identified by field ID
@param field name of the field in which to set the value
Return bool value: transaction status (see statusMsg())
recno |
number of the record in which to set the value |
newValues |
|
table: str |
name of table for operation Default value: |
change several field values at once
@param newValue key/value pairs for new field/value changes
Return bool value: transaction status (see statusMsg())
recno |
number of the record containing the value |
fieldName: str |
name of the field to get |
table: str |
name of table for operation Default value: |
get an int field value identified by field name
Return int value: the int value or -1 if unsuccessful
recno |
number of the record containing the value |
fieldName: str |
name of the field to get |
table: str |
name of table for operation Default value: |
get a string field value identified by field name
Return str value: the string value or zero length string if unsuccessful
recno |
number of the record containing the value |
fieldName: str |
name of the field to get |
table: str |
name of table for operation Default value: |
get a float field value identified by field name
Return float value: the float value or ??? if unsuccessful
recno |
number of the record containing the value |
fieldName: str |
name of the field to get |
table: str |
name of table for operation Default value: |
get an enum value identified by field name
Return str value: the enum value or zero length string if unsuccessful
recno |
number of the record containing the value |
fields |
Default value: [] |
table: str |
name of table for operation Default value: |
get an int field value identified by field name
@param fieldName name of the field to get
Return value: key/value pairs of field/value values from record. Error if empty, check status()/statusMsg().
recno |
number of the record containing the value |
fieldName: str |
name of the field to get |
table: str |
name of table for operation Default value: |
get an enum value as an int identified by field name
Return int value: the enum value or zero length string if unsuccessful
fieldName: str |
name of field to search |
value: str |
enum value to search for |
sortby: str |
Default value: |
table: str |
name of table for operation Default value: |
simple query for enum value by field name
Return list value: list of record numbers matching criteria
fieldName: str |
Name of field to search, paired with the value; alternatively fieldName can be an XMLData object with key/value pairs to search for (if so, value is ignored) |
value: str |
string value to search for Default value: |
sortby: str |
Default value: |
table: str |
name of table for operation Default value: |
simple query for string value by field name
Return list value: list of record numbers matching criteria
criteria |
|
ANDed: bool |
Default value: True |
sortby: str |
Default value: |
table: str |
name of table for operation Default value: |
compound query for a field value
@param list list of field key/value pairs to be searched for
Return list value: list of record numbers matching criteria
expression: str |
using field names, comparison operators, and logic operators, specify which records match the query |
fields: list |
a list of fields to return Default value: 'Id' |
sortby: str |
field name to use to sort the results start with + (default) for ascending sort, - for descending sort Default value: |
table: str |
name of table for operation Default value: |
Using an expression, query records and return the requested fields, sorted if specified.
@param results - (output) a list of records and their fields that matched
Return bool value: True upon success
sortby: str |
Default value: |
table: str |
Default value: |
query for all records in the named (or current) table
Return list value: recList with results which will be empty if unsuccessful
table: str |
the name of the table to query for fields Default value: |
query for all field names and types
Return value: XMLData which will be empty if unsuccessful. Otherwise key is field name, value is field type.
table: str |
the name of the table to query for fields
Default value: |
query for all field names and types
Connect to database server.
In actuality, this only checks to make sure we're connected to the MAE daemon, commhub.
Return bool value: True on success; False on failure
cmd: str |
|
params |
Default value: None |
Send a command for dbbroker that has no parameters. And wait for the reply.
Return bool value: True on success; False on failure
params |
Send data to commhub for DB operation
Return bool value: True if sent; False if failed
Wait for a dbbroker response from commhub.
Return bool value: True if reply received; False if not
text: str |
the text to encode |
commhub wants a comment to have new \n characters, so encode them
text: str |
the text to unencode |
commhub didn't let dbbroker send any \n characters, so unencode them