Class Datastore
#include <Datastore.h >
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.
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 |
const string& name |
a field name as text |
Given a field name, return the field type.
Return value: field type
FieldType type |
a field type |
Given a field type, return the field type label.
Return value: the field name as text
const string& tableName |
current table for various operations Default value: "" |
Constructor. Establish connection with database. Set current table if provided.
Determine status of our connection to database - is it valid?
Return value: true if connected to db
Get the status of the last request
Return value: the status of the last request (see codes in Datastore.h)
Determine if the status of the last operator was successful.
Return value: true if last operation successful, false otherwise.
Determine if the database connection is established and ready.
Return value: true if db connection ready
Return human readable status of last request.
Return value: msg corresponding to last DB request
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
Query the name of the currently active db table.
Return value: the table name
Query the name of the database table.
Return value: the table namne
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())
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())
Get the list of defined tables.
Return value: the list of tables in the database
DbRecNum recno |
record number to check |
Check if record number is valid
Return value: the true if recno is valid
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
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
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
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
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
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
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
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
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
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
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
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())
DbRecNum recno |
number of the record to delete |
Delete a record in the current table.
Return value: transaction status (see statusMsg())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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())
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
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
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
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
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
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
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
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
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
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
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
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
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().
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().
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().
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().
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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.
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.
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.
Check to make sure the database connection is working.
Return value: true if db responding to our requests
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.
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 |
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
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
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
const XMLData& params |
Send data to commhub for DB operation
Return value: true if sent; false if failed
Wait for a dbbroker response from commhub.
Return value: true if reply received; false if not
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
string& text |
the text to encode |
commhub wants a comment to have new \n characters, so encode them
string& text |
the text to unencode |
commhub didn't let dbbroker send any \n characters, so unencode them