Class Datastore

Index Home MAE > MAE Architecture > MAE Data Types > Class Index > Class Datastore

Summary
Public Properties
Public Methods
static FieldType fieldNameToType(name)
static string fieldTypeToName(type)
Datastore(tableName)
int valid() const
inline int status() const
inline bool statusOK() const
inline bool isOpen() const
inline string statusMsg() const
string errorMsg(status_code)
inline string getTableName() const
inline string getDbName() const
bool pack()
bool close(table)
StringSet getTableList()
inline int validRecno(recno)
DbFieldId addField(table, fieldName, type, size, isIndex)
inline DbFieldId addField(fieldName, type, size, isIndex)
DbFieldId getFieldId(table, fieldName)
inline DbFieldId getFieldId(fieldName)
int addFieldEnum(table, fieldName, enumName, enumId)
inline int addFieldEnum(fieldName, enumName, enumId)
FieldType getFieldType(table, fieldName)
inline FieldType getFieldType(field)
DbRecNum addRecord(table, data, recno)
inline DbRecNum addRecord(data, recno)
inline DbRecNum addRecord(recno)
bool deleteRecord(table, recno)
inline int deleteRecord(recno)
bool lockRecord(table, recno)
inline bool lockRecord(recno)
bool unlockRecord(table, recno)
inline int unlockRecord(recno)
bool setValue(table, recno, field, value)
inline bool setValue(recno, field, value)
bool setValue(table, recno, field, value)
inline bool setValue(recno, field, value)
bool setValue(table, recno, field, value)
inline bool setValue(recno, field, value)
inline bool setValue(table, recno, field, value)
inline bool setValue(recno, field, value)
bool setValue(table, recno, field, value)
inline bool setValue(recno, field, value)
bool setValue(table, recno, field, value)
inline bool setValue(recno, field, value)
bool setValueEnum(table, recno, field, value)
inline bool setValueEnum(recno, field, value)
bool setValueEnum(table, recno, field, value)
inline bool setValueEnum(recno, field, value)
bool setRecord(table, recno, newValues)
inline bool setRecord(recno, newValues)
bool clearField(table, recno, fieldName)
inline bool clearField(recno, fieldName)
long getFieldInt(table, recno, fieldName)
inline long getFieldInt(recno, fieldName)
string getFieldString(table, recno, fieldName)
inline string getFieldString(recno, fieldName)
float getFieldFloat(table, recno, fieldName)
inline float getFieldFloat(recno, fieldName)
Logical getFieldLogical(table, recno, fieldName)
inline Logical getFieldLogical(recno, fieldName)
string getFieldEnumValue(table, recno, fieldName)
inline string getFieldEnumValue(recno, fieldName)
long getFieldEnumValueAsInt(table, recno, fieldName)
inline long getFieldEnumValueAsInt(recno, fieldName)
XMLData getRecord(table, recno, fieldNames)
inline XMLData getRecord(table, recno)
inline XMLData getRecord(recno)
inline XMLData operator[](recno)
DbRecList queryRecords(tableName, fieldName, value, sortby)
inline DbRecList queryRecords(fieldName, value, sortby)
DbRecList queryRecords(table, fieldName, value, sortby)
inline DbRecList queryRecords(fieldName, value, sortby)
DbRecList queryRecords(table, fieldName, value, sortby)
inline DbRecList queryRecords(fieldName, value, sortby)
DbRecList queryRecords(table, fieldName, value, sortby)
inline DbRecList queryRecords(fieldName, value, sortby)
DbRecList queryRecords(table, fieldName, value, sortby)
inline DbRecList queryRecords(fieldName, value, sortby)
DbRecList queryRecordsEnum(table, fieldName, value, sortby)
inline DbRecList queryRecordsEnum(fieldName, value, sortby)
DbRecList queryRecordsEnum(table, fieldName, value, sortby)
inline DbRecList queryRecordsEnum(fieldName, value, sortby)
DbRecList queryRecords(table, criteria, ANDed, sortby)
inline DbRecList queryRecords(criteria, ANDed, sortby)
bool query(table, expression, fields, results, sortby)
inline bool query(expression, fields, results, sortby)
DbRecList queryAllRecords(table, sortby)
XMLData queryFieldNames(table)
XMLData queryFieldIds(table)
int open(tableName)
bool connected()
int select(tableName)
Private Properties
Private Methods
bool connect()
bool doCommand(cmd)
bool doCommand(cmd, params)
bool send(params)
bool receive()
inline string getTableName(newTable)
static void encodeNewline(text)
static void unencodeNewline(text)

#include <Datastore.h >

Summary

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 db2cpp tablename > classname.cpp

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.

Public Properties

static const int OK

DB operation was successful (no error)

static const int INVALID_NAME

DB operation failed - invalid name given

static const int OPEN

DB operation failed - cannot open table

static const int INVALID_TYPE

DB operation failed - invalid field type

static const int INVALID_FIELD

DB operation failed - invalid field name

static const int INVALID_REC

DB operation failed - invalid record id

static const int INVALID_ENUM

DB operation failed - invalid enum

static const int INVALID_PARAM

DB operation failed - invalid parameter

static const int LOCKED

DB operation failed - record locked

static const int NOT_SUPPORTED

DB operation failed - operation not supported

static const int FAILED

DB operation failed - (non-specific)

static const int REC_NOT_FOUND

DB operation failed - record not found

static const int ALREADY_EXISTS

DB operation failed - record already exists

static const int INVALID_SCHEMA

DB operation failed - invalid schema

static const int COMM_ERROR

DB operation failed - communications error

static const int CORRUPT_REPLY

DB operation failed - reply was corrupt (cannot parse)

static const int INVALID_CONN

DB operation failed - invalid connection

static const int INVALID_EXPR

DB operation failed - invalid expression


Public Methods

static FieldType fieldNameToType(name)

const string& name

a field name as text


Given a field name, return the field type.

Return value: field type

static string fieldTypeToName(type)

FieldType type

a field type


Given a field type, return the field type label.

Return value: the field name as text

Datastore(tableName)

const string& tableName

current table for various operations

Default value: ""


Constructor. Establish connection with database. Set current table if provided.

int valid() const

Determine status of our connection to database - is it valid?

Return value: true if connected to db

inline int status() const

Get the status of the last request

Return value: the status of the last request (see codes in Datastore.h)

inline bool statusOK() const

Determine if the status of the last operator was successful.

Return value: true if last operation successful, false otherwise.

inline bool isOpen() const

Determine if the database connection is established and ready.

Return value: true if db connection ready

inline string statusMsg() const

Return human readable status of last request.

Return value: msg corresponding to last DB request

string errorMsg(status_code)

int status_code

a Datastore status code

Default value: 1


Given a status code, return a human readable status.

Return value: a string with human readable text

inline string getTableName() const

Query the name of the currently active db table.

Return value: the table name

inline string getDbName() const

Query the name of the database table.

Return value: the table namne

bool pack()

Pack the database (remove deleted records), if the database supports this.

Otherwise, it is ignored.

Return value: true upon success, false upon failure (see statusMsg())

bool close(table)

const string& table

name of the table to close; if none, then last table used

Default value: ""


Signal to close this database table.

Return value: true upon success, false upon failure (see statusMsg())

StringSet getTableList()

Get the list of defined tables.

Return value: the list of tables in the database

inline int validRecno(recno)

DbRecNum recno

record number to check


Check if record number is valid

Return value: the true if recno is valid

DbFieldId addField(table, fieldName, type, size, isIndex)

const string& table

name of table for operation

const string& fieldName

name of field for operation

FieldType type

type of field (string, int, float)

int size

(optional) size of field in bytes

bool isIndex

true if this field is an index for the table

Default value: false


Obsolete. Add a field to the named database table.

Return value: field id of new field

inline DbFieldId addField(fieldName, type, size, isIndex)

const string& fieldName

name of field for operation

FieldType type

type of field (string, int, float)

int size

(optional) size of field in bytes

bool isIndex

true if this field is an index for the table

Default value: false


Obsolete. Add a field to the current database table.

Return value: field id of new field

DbFieldId getFieldId(table, fieldName)

const string& table

name of table for operation

const string& fieldName

name of the field for which to get the fieldid


Query field id from field name for the named table.

Return value: nonzero on success, 0 on failure

inline DbFieldId getFieldId(fieldName)

const string& fieldName

name of the field for which to get the fieldid


Query field id from field name in the current table.

Return value: nonzero on success, 0 on failure

int addFieldEnum(table, fieldName, enumName, enumId)

const string& table

name of table for operation

const string& fieldName

id of the enum field

const string& enumName

name/identifier for enum

int enumId

(optional) integer value to use for enum

Default value: 0


Obsolete.  Add field enumeration to the nanmed table.

Return value: new enum value

inline int addFieldEnum(fieldName, enumName, enumId)

const string& fieldName

id of the enum field

const string& enumName

name/identifier for enum

int enumId

(optional) integer value to use for enum

Default value: 0


Obsolete.  Add field enumeration to the current table.

Return value: new enum value

FieldType getFieldType(table, fieldName)

const string& table

name of table for operation

const string& fieldName

id of the enum field


Query a field type (string, float, etc) for the provided field name in the provided table.

Return value: the field type

inline FieldType getFieldType(field)

const string& field

Name id of the enum field


Query a field type (string, float, etc) for the provided field name in the current table.

Return value: the field type

DbRecNum addRecord(table, data, recno)

const string& table

name of table for operation

const XMLData& data

any data to pre-populate the record

DbRecNum recno

(optional) id for the record

Default value: 0


Add/Append a new record to the table provided, populated with the data provided.

Return value: new record number added

inline DbRecNum addRecord(data, recno)

const XMLData& data

any data to pre-populate the record

DbRecNum recno

(optional) id for the record

Default value: 0


Add/Append a new record to the current table, populated with the data provided.

Return value: new record number added

inline DbRecNum addRecord(recno)

DbRecNum recno

(optional) id for the record

Default value: 0


Add/Append a new record to the current table with a blank record.

Return value: new record number added

bool deleteRecord(table, recno)

const string& table

name of table for operation

DbRecNum recno

number of the record to delete


Delete a record in the named table.

Return value: transaction status (see statusMsg())

inline int deleteRecord(recno)

DbRecNum recno

number of the record to delete


Delete a record in the current table.

Return value: transaction status (see statusMsg())

bool lockRecord(table, recno)

const string& table

name of table for operation

DbRecNum recno

number of the record to lock


Lock a record in the named table; prevent other applications from modifying this record until it is unlocked.

Return value: transaction status (see statusMsg())

inline bool lockRecord(recno)

DbRecNum recno

number of the record to lock


Lock a record in the current table; prevent other applications from modifying this record until it is unlocked.

Return value: transaction status (see statusMsg())

bool unlockRecord(table, recno)

const string& table

name of table for operation

DbRecNum recno

number of the record to unlock


Unlock a record in the named table, allowing other applications to now modify it.

Return value: transaction status (see statusMsg())

inline int unlockRecord(recno)

DbRecNum recno

number of the record to unlock


Unlock a record in the current table, allowing other applications to now modify it.

Return value: transaction status (see statusMsg())

bool setValue(table, recno, field, value)

const string& table

name of table for operation

DbRecNum recno

number of the record in which to set the value

const string& field

name of the field in which to set the value

const string& value

the value to set


Change a string value identified by field name in the named table.

Return value: transaction status (see statusMsg())

inline bool setValue(recno, field, value)

DbRecNum recno

number of the record in which to set the value

const string& field

name of the field in which to set the value

const string& value

the value to set


Change a string value identified by field name in the current table.

Return value: transaction status (see statusMsg())

bool setValue(table, recno, field, value)

const string& table

name of table for operation

DbRecNum recno

number of the record in which to set the value

const string& field

name of the field in which to set the value

Logical value

the value to set


Change a Logical value identified by field name in the named table.

Return value: transaction status (see statusMsg())

inline bool setValue(recno, field, value)

DbRecNum recno

number of the record in which to set the value

const string& field

name of the field in which to set the value

Logical value

the value to set


Change a Logical value identified by field name in the current table.

Return value: transaction status (see statusMsg())

bool setValue(table, recno, field, value)

const string& table

name of table for operation

DbRecNum recno

number of the record in which to set the value

const string& field

name of the field in which to set the value

float value

the value to set


Change a float value identified by field name in the named table.

Return value: transaction status (see statusMsg())

inline bool setValue(recno, field, value)

DbRecNum recno

number of the record in which to set the value

const string& field

name of the field in which to set the value

float value

the value to set


Change a float value identified by field name in the current table.

Return value: transaction status (see statusMsg())

inline bool setValue(table, recno, field, value)

const string& table

name of table for operation

DbRecNum recno

number of the record in which to set the value

const string& field

name of the field in which to set the value

int value

the value to set


Change an int value identified by field name in the named table.

Return value: transaction status (see statusMsg())

inline bool setValue(recno, field, value)

DbRecNum recno

number of the record in which to set the value

const string& field

name of the field in which to set the value

int value

the value to set


Change an int value identified by field name in the current table.

Return value: transaction status (see statusMsg())

bool setValue(table, recno, field, value)

const string& table

name of table for operation

DbRecNum recno

number of the record in which to set the value

const string& field

name of the field in which to set the value

long value

the value to set


Change an long value identified by field name in the named table.

Return value: transaction status (see statusMsg())

inline bool setValue(recno, field, value)

DbRecNum recno

number of the record in which to set the value

const string& field

name of the field in which to set the value

long value

the value to set


Change an long value identified by field name in the current table.

Return value: transaction status (see statusMsg())

bool setValue(table, recno, field, value)

const string& table

name of table for operation

DbRecNum recno

number of the record in which to set the value

const string& field

name of the field in which to set the value

unsigned long value

the value to set


Change an unsigned long value identified by field name in the named table.

Return value: transaction status (see statusMsg())

inline bool setValue(recno, field, value)

DbRecNum recno

number of the record in which to set the value

const string& field

name of the field in which to set the value

unsigned long value

the value to set


Change an unsigned long value identified by field name in the current table.

Return value: transaction status (see statusMsg())

bool setValueEnum(table, recno, field, value)

const string& table

name of table for operation

DbRecNum recno

number of the record in which to set the value

const string& field

name of the field in which to set the value

const string& value

the string representation of the enum value to set


Change an enum value identified by field name in the named table.

Return value: transaction status (see statusMsg())

inline bool setValueEnum(recno, field, value)

DbRecNum recno

number of the record in which to set the value

const string& field

name of the field in which to set the value

const string& value

the string representation of the enum value to set


Change an enum value identified by field name in the current table.

Return value: transaction status (see statusMsg())

bool setValueEnum(table, recno, field, value)

const string& table

name of table for operation

DbRecNum recno

number of the record in which to set the value

const string& field

name of the field in which to set the value

int value

the int representation of the enum value to set


Change an enum value identified by field name in the named table.

Return value: transaction status (see statusMsg())

inline bool setValueEnum(recno, field, value)

DbRecNum recno

number of the record in which to set the value

const string& field

name of the field in which to set the value

int value

the int representation of the enum value to set


Change an enum value identified by field name in the current table.

Return value: transaction status (see statusMsg())

bool setRecord(table, recno, newValues)

const string& table

name of table for operation

DbRecNum recno

number of the record in which to set the value

const XMLData& newValues

key/value pairs for new field/value changes


Change several field values at once in the named table.

Return value: transaction status (see statusMsg())

inline bool setRecord(recno, newValues)

DbRecNum recno

number of the record in which to set the value

const XMLData& newValues

key/value pairs for new field/value changes


Change several field values at once in the current table.

Return value: transaction status (see statusMsg())

bool clearField(table, recno, fieldName)

const string& table

name of table for operation

DbRecNum recno

number of the record containing the field

const string& fieldName

name of the field to clear


Clear/Empty the value for the field with this field name in the named table.

Return value: transaction status (see statusMsg())

inline bool clearField(recno, fieldName)

DbRecNum recno

number of the record containing the field

const string& fieldName

name of the field to clear


Clear/Empty the value for the field with this field name in the current table.

Return value: transaction status (see statusMsg())

long getFieldInt(table, recno, fieldName)

const string& table

name of table for operation

DbRecNum recno

number of the record containing the value

const string& fieldName

name of the field to get


Get an int field value identified by field name from the named table.

Return value: the int value or -1 if unsuccessful

inline long getFieldInt(recno, fieldName)

DbRecNum recno

number of the record containing the value

const string& fieldName

name of the field to get


Get an int field value identified by field name from the current table.

Return value: the int value or -1 if unsuccessful

string getFieldString(table, recno, fieldName)

const string& table

name of table for operation

DbRecNum recno

number of the record containing the value

const string& fieldName

name of the field to get


Get a string field value identified by field name from the named table.

Return value: the string value or zero length string if unsuccessful

inline string getFieldString(recno, fieldName)

DbRecNum recno

number of the record containing the value

const string& fieldName

name of the field to get


Get a string field value identified by field name from the current table.

Return value: the string value or zero length string if unsuccessful

float getFieldFloat(table, recno, fieldName)

const string& table

name of table for operation

DbRecNum recno

number of the record containing the value

const string& fieldName

name of the field to get


Get a float field value identified by field name from the named table.

Return value: the float value or ??? if unsuccessful

inline float getFieldFloat(recno, fieldName)

DbRecNum recno

number of the record containing the value

const string& fieldName

name of the field to get


Get a float field value identified by field name from the current table.

Return value: the float value or ??? if unsuccessful

Logical getFieldLogical(table, recno, fieldName)

const string& table

name of table for operation

DbRecNum recno

number of the record containing the value

const string& fieldName

name of the field to get


Get a logical/boolean field value identified by field name from the named table.

Return value: the logical value or Unknown if unsuccessful

inline Logical getFieldLogical(recno, fieldName)

DbRecNum recno

number of the record containing the value

const string& fieldName

name of the field to get


Get a logical/boolean field value identified by field name from the current table.

Return value: the logical value or Unknown if unsuccessful

string getFieldEnumValue(table, recno, fieldName)

const string& table

name of table for operation

DbRecNum recno

number of the record containing the value

const string& fieldName

name of the field to get


Get an enum value identified by field name from the named table.

Return value: the enum value or zero length string if unsuccessful

inline string getFieldEnumValue(recno, fieldName)

DbRecNum recno

number of the record containing the value

const string& fieldName

name of the field to get


Get an enum value identified by field name from the current table.

Return value: the enum value or zero length string if unsuccessful

long getFieldEnumValueAsInt(table, recno, fieldName)

const string& table

name of table for operation

DbRecNum recno

number of the record containing the value

const string& fieldName

name of the field to get


Get an enum value as an int identified by field name from the named table.

Return value: the enum value or zero length string if unsuccessful

inline long getFieldEnumValueAsInt(recno, fieldName)

DbRecNum recno

number of the record containing the value

const string& fieldName

name of the field to get


Get an enum value as an int identified by field name from the named table.

Return value: the enum value or zero length string if unsuccessful

XMLData getRecord(table, recno, fieldNames)

const string& table

name of table for operation

DbRecNum recno

number of the record containing the values

const StringSet& fieldNames

names of the fields to get (an empty list means all fields)


Get multiple fields from the named table for a record.

Return value: key/value pairs of field/value values from record.  Error if empty, check status()/statusMsg().

inline XMLData getRecord(table, recno)

const string& table

name of table for operation

DbRecNum recno

number of the record containing the values


Get all record fields from the named table for a record.

Return value: key/value pairs of field/value values from record.  Error if empty, check status()/statusMsg().

inline XMLData getRecord(recno)

DbRecNum recno

number of the record containing the values


Get all record fields from the current table for a record.

Return value: key/value pairs of field/value values from record.  Error if empty, check status()/statusMsg().

inline XMLData operator[](recno)

DbRecNum recno

number of the record containing the values


Get all record fields from the current table for a record.

Return value: key/value pairs of field/value values from record.  Error if empty, check status()/statusMsg().

DbRecList queryRecords(tableName, fieldName, value, sortby)

const string& tableName

name of table for operation

const string& fieldName

Name of field to search

const string& value

string value to search for

const string& sortby

field name to use to sort the results; start with + (default) for ascending sort, - for descending sort

Default value: ""


Simple query for ids where string value equal to a value by field name for the named table.

Return value: list of record numbers matching criteria for field=value

inline DbRecList queryRecords(fieldName, value, sortby)

const string& fieldName

Name of field to search

const string& value

string value to search for

const string& sortby

field name to use to sort the results; start with + (default) for ascending sort, - for descending sort

Default value: ""


Simple query for ids where string value equal to a value by field name for the current table.

Return value: list of record numbers matching criteria for field=value

DbRecList queryRecords(table, fieldName, value, sortby)

const string& table

name of table for operation

const string& fieldName

name of field to search

long value

int value to search for

const string& sortby

field name to use to sort the results; start with + (default) for ascending sort, - for descending sort

Default value: ""


Simple query for ids where int value equal to a value by field name for the named table.

Return value: list of record numbers matching criteria for field=value

inline DbRecList queryRecords(fieldName, value, sortby)

const string& fieldName

name of field to search

long value

int value to search for

const string& sortby

field name to use to sort the results; start with + (default) for ascending sort, - for descending sort

Default value: ""


Simple query for ids where int value equal to a value by field name for the current table.

Return value: list of record numbers matching criteria for field=value

DbRecList queryRecords(table, fieldName, value, sortby)

const string& table

name of table for operation

const string& fieldName

name of field to search

unsigned long value

int value to search for

const string& sortby

field name to use to sort the results; start with + (default) for ascending sort, - for descending sort

Default value: ""


Simple query for ids where int value equal to a value by field name for the named table.

Return value: list of record numbers matching criteria for field=value

inline DbRecList queryRecords(fieldName, value, sortby)

const string& fieldName

name of field to search

unsigned long value

int value to search for

const string& sortby

field name to use to sort the results; start with + (default) for ascending sort, - for descending sort

Default value: ""


Simple query for ids where int value equal to a value by field name for the current table.

Return value: list of record numbers matching criteria for field=value

DbRecList queryRecords(table, fieldName, value, sortby)

const string& table

name of table for operation

const string& fieldName

name of field to search

float value

int value to search for

const string& sortby

field name to use to sort the results; start with + (default) for ascending sort, - for descending sort

Default value: ""


Simple query for ids where float value equal to a value by field name for the named table.

Return value: list of record numbers matching criteria for field=value

inline DbRecList queryRecords(fieldName, value, sortby)

const string& fieldName

name of field to search

float value

int value to search for

const string& sortby

field name to use to sort the results; start with + (default) for ascending sort, - for descending sort

Default value: ""


Simple query for ids where float value equal to a value by field name for the current table.

Return value: list of record numbers matching criteria for field=value

DbRecList queryRecords(table, fieldName, value, sortby)

const string& table

name of table for operation

const string& fieldName

name of field to search

Logical value

int value to search for

const string& sortby

field name to use to sort the results; start with + (default) for ascending sort, - for descending sort

Default value: ""


Simple query for ids where logical value equal to a value by field name for the named table.

Return value: list of record numbers matching criteria for field=value

inline DbRecList queryRecords(fieldName, value, sortby)

const string& fieldName

name of field to search

Logical value

int value to search for

const string& sortby

Default value: ""


Simple query for ids where logical value equal to a value by field name for the current table.

Return value: list of record numbers matching criteria for field=value

DbRecList queryRecordsEnum(table, fieldName, value, sortby)

const string& table

name of table for operation

const string& fieldName

name of field to search

const string& value

int value to search for

const string& sortby

field name to use to sort the results; start with + (default) for ascending sort, - for descending sort

Default value: ""


Simple query for ids where enum value equal to a string value by field name for the named table.

Return value: list of record numbers matching criteria for field=value

inline DbRecList queryRecordsEnum(fieldName, value, sortby)

const string& fieldName

name of field to search

const string& value

int value to search for

const string& sortby

field name to use to sort the results; start with + (default) for ascending sort, - for descending sort

Default value: ""


Simple query for ids where enum value equal to a string value by field name for the current table.

Return value: list of record numbers matching criteria for field=value

DbRecList queryRecordsEnum(table, fieldName, value, sortby)

const string& table

name of table for operation

const string& fieldName

name of field to search

int value

int value to search for

const string& sortby

field name to use to sort the results; start with + (default) for ascending sort, - for descending sort

Default value: ""


Simple query for ids where enum value equal to an int value by field name for the named table.

Return value: list of record numbers matching criteria for field=value

inline DbRecList queryRecordsEnum(fieldName, value, sortby)

const string& fieldName

name of field to search

int value

int value to search for

const string& sortby

field name to use to sort the results; start with + (default) for ascending sort, - for descending sort

Default value: ""


Simple query for ids where enum value equal to an int value by field name for the current table.

Return value: list of record numbers matching criteria for field=value

DbRecList queryRecords(table, criteria, ANDed, sortby)

const string& table

name of table for operation

const XMLData& criteria

a collection of key-value paires (field name-value pairs) to search for

bool ANDed

how to trie the list of key-value pairs - make sure every record matches all criteria (true) or any record that matches at least one of the criteria

Default value: true

const string& sortby

Default value: ""


Compound query for ids where each field value equal to a value by field name for the named table.

Return value: list of record numbers matching criteria specified

inline DbRecList queryRecords(criteria, ANDed, sortby)

const XMLData& criteria

a collection of key-value paires (field name-value pairs) to search for

bool ANDed

how to trie the list of key-value pairs - make sure every record matches all criteria (true) or any record that matches at least one of the criteria

Default value: true

const string& sortby

field name to use to sort the results; start with + (default) for ascending sort, - for descending sort

Default value: ""


Compound query for ids where a field value equal to a value by field name for the current table.

Return value: list of record numbers matching criteria specified

bool query(table, expression, fields, results, sortby)

const string& table

name of table for operation

const string& expression

using field names, comparison operators ( <, >, <=, >=, !=, =), parenthesis and logic operators (AND, OR), specify which records match the query

const StringList& fields

a list of fields to return

XMLData& results

(output) a list of records and their fields that matched

const string& sortby

field name to use to sort the results; start with + (default) for ascending sort, - for descending sort

Default value: ""


Using an expression, query records and return the requested fields, sorted if specified.

Return value: true upon success

inline bool query(expression, fields, results, sortby)

const string& expression

using field names, comparison operators ( <, >, <=, >=, !=, =), parenthesis and logic operators (AND, OR), specify which records match the query

const StringList& fields

a list of fields to return

XMLData& results

(output) a list of records and their fields that matched

const string& sortby

field name to use to sort the results; start with + (default) for ascending sort, - for descending sort

Default value: ""


Using an expression, query records and return the requested fields, sorted if specified.

Return value: true upon success

DbRecList queryAllRecords(table, sortby)

const string& table

name of table for operation (default: current table)

Default value: ""

const string& sortby

field name to use to sort the results; start with + (default) for ascending sort, - for descending sort

Default value: ""


Query all record ids in the named (or current) table.

Return value: recList with results which will be empty if unsuccessful

XMLData queryFieldNames(table)

const string& table

the name of the table to query for fields (default: current table)

Default value: ""


Query all field names and types in the named (or current) table.

Return value: XMLData which will be empty if unsuccessful. Otherwise key is field name, value is field type.

XMLData queryFieldIds(table)

const string& table

the name of the table to query for fields (default: current table)

Default value: ""


Query for all field names and ids in the named (or current) table.

Return value: XMLData which will be empty if unsuccessful. Otherwise key is field name, value is field id.

int open(tableName)

const string& tableName

the name of the table to use as the current table.


Set the currently active table by opening it.

Return value: the status code of the operation.

bool connected()

Check to make sure the database connection is working.

Return value: true if db responding to our requests

int select(tableName)

const string& tableName

the name of the table to use as the current table.


Identifical to open().  Set the currently active table by opening it.

Return value: the status code of the operation.

Private Properties

int fd

file descriptor - connection to db

string table

last table used (current table)

DbRecNum recno

last record number refernced

string cmd

last db command sent

int rc_

last return code received

bool openOK

flag: true if the last table open worked

bool lastStatus

flag: last command succeeded?

string lastMessage

last status message received from db

XMLData reply

last reply received from db


Private Methods

bool connect()

Connect to database server.

In actuality, this only checks to make sure we're connected to the MAE daemon, commhub.

Return value: true on success; false on failure

bool doCommand(cmd)

const string& cmd


Send a command for dbbroker that has no parameters. And wait for the reply.

Return value: true on success; false on failure

bool doCommand(cmd, params)

const string& cmd

XMLData& params


Given a command for dbbroker and parameters, send it and wait for the reply.

Return value: true on success; false on failure

bool send(params)

const XMLData& params


Send data to commhub for DB operation

Return value: true if sent; false if failed

bool receive()

Wait for a dbbroker response from commhub.

Return value: true if reply received; false if not

inline string getTableName(newTable)

const string& newTable

(optional) if not empty, switch to this table


Get a table name - either the one already set or this new one (if not empty())

Return value: table name

static void encodeNewline(text)

string& text

the text to encode


commhub wants a comment to have new \n characters, so encode them

static void unencodeNewline(text)

string& text

the text to unencode


commhub didn't let dbbroker send any \n characters, so unencode them