> For the complete documentation index, see [llms.txt](https://tmediadocs.telcobridges.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tmediadocs.telcobridges.com/telecom-references/developer-reference/database/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](/telecom-references/developer-reference/caf/ctbcafservicecmmgmtclient.md) to the application
* Connect to the database using object of type [CTBCAFDb](/telecom-references/developer-reference/caf/ctbcafdb.md) initialized using the DB connection string received on *OnReloadConfig* (see [CTBCAFServiceCmMgmtClient](/telecom-references/developer-reference/caf/ctbcafservicecmmgmtclient.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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://tmediadocs.telcobridges.com/telecom-references/developer-reference/database/accessing-toolpack-db.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
