| digiKam Developer Documentation Professional Photo Management with the Power of Open Source

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
Digikam::CoreDbAccess Class Reference

The CoreDbAccess provides access to the database: Create an instance of this class on the stack to retrieve a pointer to the database. More...

## Public Types
enum | ApplicationStatus { MainApplication , DatabaseSlave }

## Public Member Functions
| CoreDbAccess ()
| Create a CoreDbAccess object for the default database.
CoreDbBackend * | backend () const
| Retrieve a pointer to the database backend.
CoreDB * | db () const
| Retrieve a pointer to the album database.
QString | lastError ()
| Returns the error message for the last error that occurred, or a null QString of no error occurred.
void | setLastError (const QString &error)
| Set the "last error" message.

## Static Public Member Functions
static bool | checkReadyForUse (InitializationObserver *const observer=nullptr)
| Method to one-time initialize a database when new parameters have been set: Make sure that the database is open, that the schema has properly been initialized.
static void | cleanUpDatabase ()
| Clean up the database access.
static CoreDbWatch * | databaseWatch ()
| Return the CoreDbWatch.
static void | initDbEngineErrorHandler (DbEngineErrorHandler *const errorhandler)
| Setup the errors handler instance.
static DbEngineParameters | parameters ()
| Return the default parameters.
static void | setParameters (const DbEngineParameters &parameters)
| Set the default parameters.
static void | setParameters (const DbEngineParameters &parameters, ApplicationStatus status)

## Friends
class | CoreDbAccessUnlock

## Detailed Description

While you hold an instance of CoreDbAccess, the database access is locked for other threads, but not for other processes. This is due to the fact that while databases allow concurrent access (of course), their client libs may not be thread-safe.

When initializing your application, you need to call two methods:

- in a not-yet-multithreaded context, you need to call setParameters
- to make sure that the database is available and the schema is properly initialized, call checkReadyForUse()

## Constructor & Destructor Documentation

## ◆ CoreDbAccess()

Digikam::CoreDbAccess::CoreDbAccess | ( |  | ) |

Note that when initializing your app, setParameters need to be called (in a not-yet-multithreaded context) for this to work. If the database is not yet opened, it will be opened. The schema will not be checked, use checkReadyForUse() for a full opening process including schema update and error messages.

## Member Function Documentation

## ◆ checkReadyForUse()

bool Digikam::CoreDbAccess::checkReadyForUse | ( | InitializationObserver *const | observer = `nullptr` | ) |
| static

If the parameters were not changed, this method has no effect.

Returns
  if the database is ready for use

## ◆ cleanUpDatabase()

void Digikam::CoreDbAccess::cleanUpDatabase | ( |  | ) |
| static

When this function has been called, the access can be restored by calling setParameters. Construction a database access object otherwise after calling this method will crash.

## ◆ setLastError()

void Digikam::CoreDbAccess::setLastError | ( | const QString & | error | ) |

This method is not for public use.

## ◆ setParameters()

void Digikam::CoreDbAccess::setParameters | ( | const DbEngineParameters & | parameters | ) |
| static

Call this function at least once in the starting phase of your application, when no other threads will yet access the database, to initialize DatabaseAcccess. After this initial call, it is thread-safe to call this function again. In a subsequent call, if the parameters are identical, nothing is done. If the parameters change, the current database will be closed. When parameters have been set or changed, the new one will be opened on-demand, i.e. when the first CoreDbAccess object is constructed.