CTBCAFDb
This class is used to connect to a MySql database.
The CAF library contains DAOs (Database Access Objects) for each table found in the Toolpack configuration database. These DAOs include a class to retrieve the table rows, and a class that represents the content of one database row.
To initialize the DAOs, it's mandatory that the application uses the class CTBCAFDb to access the MySql database.
For more information on using the DAOs, please refer to the following page: Accessing_Toolpack_DB
Contents |
Initializing CTBCAFDb
The constructor of CTBCAFDb (as well as function SetConnectString) receive a "connection string" as an argument. This connection string is of the form:
ODBC:SERVER=10.3.2.240/10.3.6.240;PORT=3306;UID=root;PWD=root;DATABASE=toolpack_0
The application should use the connection string provided by Toolpack OAM system through class CTBCAFServiceCmMgmtClient (see CTBCAFServiceCmMgmtClient: for more information).
Connecting to the database
To connect to the database using the previously provided connection string, use the Open function.
Querying the database
To query the database:
- Create a new query using function CreateQuery
- Use the query object's Exec function to start the query
- Get query result using functions NextRow, ColCount, ColName, and ColValue, etc.
- Delete the query object
Warning: Opening the database and executing queries are synchronous operations, and will block if the database is not available. It is thus recommended to call that function using a background thread in the application that will not prevent the application from properly running while the database is attempted to be accessed. Among other things, the application shall continue to respond to Toolpack OAM Heart-beat (see CTBCAFServiceAlmMgmt) even while waiting for database operation to complete, to avoid the application from being killed during that time.