ImagingTools Core SDK
Public Member Functions | List of all members
imtdb::IDatabaseConnectorabstract

Manages database connection lifecycle for remote database servers. More...

#include <IDatabaseConnector.h>

Inherits istd::IPolymorphic.

Inherited by imtdb::CDatabaseConnectorComp [virtual].

Public Member Functions

virtual bool ConnectToDatabase (const IDatabaseLoginSettings &loginSettings) const =0
 Establishes a connection to a database server.
 
virtual bool DisconnectFromDatabase (const QString &connectionName) const =0
 Closes an existing database connection.
 

Detailed Description

Manages database connection lifecycle for remote database servers.

IDatabaseConnector handles the establishment and termination of connections to database servers. It abstracts the connection process and supports various database backends through the IDatabaseLoginSettings interface.

Typical usage pattern:

auto connector = acf::CreateComponent<imtdb::CDatabaseConnectorComp>();
// Create login settings
imtdb::CDatabaseAccessSettings settings;
settings.SetHost("localhost");
settings.SetPort(5432);
settings.SetDatabaseName("myapp");
settings.SetUserName("dbuser");
settings.SetPassword("secure_password");
// Connect
if (connector->ConnectToDatabase(settings)) {
// Connection successful, can now execute queries
}
// Later, disconnect
connector->DisconnectFromDatabase(settings.GetConnectionName());
Note
Connection names allow multiple simultaneous connections to different databases
See also
IDatabaseLoginSettings for connection configuration
CDatabaseConnectorComp for the implementation

Definition at line 49 of file IDatabaseConnector.h.

Member Function Documentation

◆ ConnectToDatabase()

virtual bool imtdb::IDatabaseConnector::ConnectToDatabase ( const IDatabaseLoginSettings loginSettings) const
pure virtual

Establishes a connection to a database server.

Creates and opens a database connection using the provided login credentials. The connection is registered with Qt's SQL system and can be used for query execution.

Parameters
loginSettingsConfiguration containing host, port, database name, credentials
Returns
true if connection established successfully, false on failure
Note
Connection failures may be due to:
  • Invalid credentials
  • Network connectivity issues
  • Database server not running
  • Insufficient permissions
The connection name from loginSettings determines the connection identifier. Use unique connection names for multiple simultaneous database connections.
See also
DisconnectFromDatabase()
IDatabaseLoginSettings

◆ DisconnectFromDatabase()

virtual bool imtdb::IDatabaseConnector::DisconnectFromDatabase ( const QString &  connectionName) const
pure virtual

Closes an existing database connection.

Terminates the connection identified by the given connection name and releases associated resources.

Parameters
connectionNameThe name of the connection to close (from IDatabaseLoginSettings)
Returns
true if disconnection successful, false if connection not found or error occurred
Note
Always disconnect when done to free resources
Disconnecting closes all open transactions (may cause rollback)
Safe to call even if connection is already closed
See also
ConnectToDatabase()