> For the complete documentation index, see [llms.txt](https://prosbcdocs.telcobridges.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://prosbcdocs.telcobridges.com/telecom-references/apis-and-integration/accessing-toolpack-db.md).

# Accessing Toolpack DB

The CAF library provides DAOs (Data Access Objects) for all tables in the Toolpack configuration database.

### Where to find these DAOs

These DAO objects are defined in the "tbcmc" source packages, for example tbcmc\_2.5.89\_common.tgz, under:

* tb/inc/tbcaf/dao/oam

### Prerequisites to use the DAOs

To access the Toolpack database, an application needs to:

* Attach to Toolpack OAM "CM" (configuration management), by binding an object of type [CTBCAFServiceCmMgmtClient](https://github.com/telcobridges-main/tmedia-wiki/tree/main/reference/api/ctbcafservicecmmgmtclient/README.md) to the application
* Connect to the database using object of type [CTBCAFDb](https://github.com/telcobridges-main/tmedia-wiki/tree/main/reference/api/ctbcafdb/README.md) initialized using the DB connection string received on *OnReloadConfig* (see [CTBCAFServiceCmMgmtClient](https://github.com/telcobridges-main/tmedia-wiki/tree/main/reference/api/ctbcafservicecmmgmtclient/README.md))
* Use appropriate DAO access object to query the desired table
* Optionally use a custom SQL query string to query specific elements from a table

### How to use the DAOs

* Initialize the DAO access object that corresponds to the table you want to read from (*CTBCAFOam\_virtual\_adapters\_db\_acc* for example) CTBCAFOam\_virtual\_adapters\_db\_acc AccessVirtualAdapters; AccessVirtualAdapters.Init( pConfigDb );
* Use one of the DAO functions to retrieve one or multiple entries: CTBCAFOam\_virtual\_adapters VirtualAdapter = AccessVirtualAdapters.GetById( un32MyVirtualAdapterId ); std::vector\<CTBCAFOam\_virtual\_adapters> AllVirtualAdapters = AccessVirtualAdapters.GetAllBy\_configuration\_id( un32ConfigurationId );
* Access the information from returned classes VirtualAdapter.str\_serial VirtualAdapter.un32\_last\_upgrade\_time ...

### Example code

The following code shows how to use the DAO objects, taken from the "simple\_call" sample application:

```
TBX_RESULT CTBS2GWSimpleCall::ExampleDbAccess()
{
TBX_RESULT								Result;
TBX_UINT32								un32Index;

CTBCAFOam_configurations_db_acc			ConfigurationsAdapters;
CTBCAFOam_configurations				CurrentConfiguration;

CTBCAFOam_virtual_adapters_db_acc		AccessVirtualAdapters;
std::vector<CTBCAFOam_virtual_adapters>	AllVirtualAdapters;

CTBCAFOam_line_services_db_acc			AccessLineServices;

/*---------------------------------------------------------------------------------------------------------------------------
|  Code section
```

* \--------------------------------------------------------------------------------------------------------------------------\*/ CAFCODE( CTBS2GWSimpleCall::ExampleDbAccess ) { // Initialize the DAO access objects Result = ConfigurationsAdapters.Init( mpConfigDb ); TBCAF\_EXIT\_ON\_ERROR( Result, "Cannot init ConfigurationsAdapters" );

  Result = AccessVirtualAdapters.Init( mpConfigDb ); TBCAF\_EXIT\_ON\_ERROR( Result, "Cannot init AccessVirtualAdapters" );

  Result = AccessLineServices.Init( mpConfigDb ); TBCAF\_EXIT\_ON\_ERROR( Result, "Cannot init AccessVirtualAdapters" );

  // Implementation note: // Database queries below should be done "in background" using a background thread of this application, outside // the lock of mMutex, in order to avoid blocking the whole application in case the database is // temporarily unavailable (backup database about to be activated, for example). // In this simple example, we do it inline, however...

  // Example get the name of current configuration (this function will 'throw' if not found) CurrentConfiguration = ConfigurationsAdapters.GetById( mun32ConfigurationId );

  // Example: Get all virtual adapters from current configuration AllVirtualAdapters = AccessVirtualAdapters.GetAllBy\_configuration\_id( mun32ConfigurationId );

  // Example: Print the serial number of all adapters of current configuration LogTrace ( TBCAF\_TRACE\_LEVEL\_ALWAYS, "Adapters from current configuration %s", CurrentConfiguration.str\_name.c\_str() ); for( un32Index = 0; un32Index < AllVirtualAdapters.size(); un32Index++ ) { CTBCAFString strQuery; std::vector\<CTBCAFOam\_line\_services> AllE1LineServices; std::vector\<CTBCAFOam\_line\_services> AllT1LineServices;

  // Example custom SQL query to get E1 line services in current configuration strQuery.Format ( "SELECT \* FROM %s WHERE %s="E1LineService"", TBTBL\_LINE\_SERVICES, TBCOL\_LINE\_SERVICES\_COMMON\_LINE\_SERVICE\_TYPE ); AllE1LineServices = AccessLineServices.GetAll( strQuery );

  // Example custom SQL query to get T1 line services in current configuration strQuery.Format ( "SELECT \* FROM %s WHERE %s="T1LineService"", TBTBL\_LINE\_SERVICES, TBCOL\_LINE\_SERVICES\_COMMON\_LINE\_SERVICE\_TYPE ); AllT1LineServices = AccessLineServices.GetAll( strQuery );

  LogTrace ( TBCAF\_TRACE\_LEVEL\_ALWAYS, " %s (%u E1, %u T1 line services)", AllVirtualAdapters\[ un32Index ].str\_serial.c\_str(), AllE1LineServices.size(), AllT1LineServices.size() ); }

  ExampleDbQuery();

  TBX\_EXIT\_SUCCESS( TBX\_RESULT\_OK ); }

  /\*--------------------------------------------------------------------------------------------------------------------------- | Exception handling section
* \--------------------------------------------------------------------------------------------------------------------------\*/ CAF\_EXCEPTION\_HANDLING

  /\*--------------------------------------------------------------------------------------------------------------------------- | Error handling section
* \--------------------------------------------------------------------------------------------------------------------------\*/ CAF\_ERROR\_HANDLING( CAF\_VERBOSE ) { }

  /\*--------------------------------------------------------------------------------------------------------------------------- | Cleanup section
* \--------------------------------------------------------------------------------------------------------------------------\*/ CAF\_CLEANUP { AccessLineServices.Uninit(); AccessVirtualAdapters.Uninit(); ConfigurationsAdapters.Uninit(); }

  RETURN; }


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://prosbcdocs.telcobridges.com/telecom-references/apis-and-integration/accessing-toolpack-db.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
