Akonadi::Server::DbInitializer

Search for usage in LXR

#include <dbinitializer.h>

Public Types

using Ptr = QSharedPointer<DbInitializer>
 

Public Member Functions

virtual ~DbInitializer ()
 
virtual QString buildCreateTableStatement (const TableDescription &tableDescription) const =0
 
QString errorMsg () const
 
bool run ()
 
bool updateIndexesAndConstraints ()
 

Static Public Member Functions

static DbInitializer::Ptr createInstance (const QSqlDatabase &database, Schema *schema=nullptr)
 

Protected Member Functions

 DbInitializer (const QSqlDatabase &database)
 
virtual QString buildAddColumnStatement (const TableDescription &tableDescription, const ColumnDescription &columnDescription) const
 
virtual QStringList buildAddForeignKeyConstraintStatements (const TableDescription &table, const ColumnDescription &column) const
 
virtual QString buildColumnStatement (const ColumnDescription &columnDescription, const TableDescription &tableDescription) const =0
 
virtual QString buildCreateIndexStatement (const TableDescription &tableDescription, const IndexDescription &indexDescription) const
 
virtual QString buildInsertValuesStatement (const TableDescription &tableDescription, const DataDescription &dataDescription) const =0
 
virtual QStringList buildRemoveForeignKeyConstraintStatements (const DbIntrospector::ForeignKey &fk, const TableDescription &table) const
 
virtual QString sqlType (const ColumnDescription &col, int size) const
 
virtual QString sqlValue (const ColumnDescription &col, const QString &value) const
 

Static Protected Member Functions

static QString buildPrimaryKeyStatement (const TableDescription &table)
 
static QString buildReferentialAction (ColumnDescription::ReferentialAction onUpdate, ColumnDescription::ReferentialAction onDelete)
 

Detailed Description

A helper class which takes a reference to a database object and the file name of a template file and initializes the database according to the rules in the template file.

TODO: Refactor this to be easily reusable for updater too

Definition at line 47 of file dbinitializer.h.

Member Typedef Documentation

◆ Ptr

Constructor & Destructor Documentation

◆ ~DbInitializer()

DbInitializer::~DbInitializer ( )
virtual

Destroys the database initializer.

Definition at line 56 of file dbinitializer.cpp.

◆ DbInitializer()

DbInitializer::DbInitializer ( const QSqlDatabase & database)
protected

Creates a new database initializer.

Parameters
databaseThe reference to the database.

Definition at line 48 of file dbinitializer.cpp.

Member Function Documentation

◆ buildAddColumnStatement()

QString DbInitializer::buildAddColumnStatement ( const TableDescription & tableDescription,
const ColumnDescription & columnDescription ) const
protectedvirtual

Definition at line 309 of file dbinitializer.cpp.

◆ buildAddForeignKeyConstraintStatements()

QStringList DbInitializer::buildAddForeignKeyConstraintStatements ( const TableDescription & table,
const ColumnDescription & column ) const
protectedvirtual

Returns an SQL statements to add a foreign key constraint to an existing column column.

The default implementation returns an empty string, so any backend supporting foreign key constraints must reimplement this.

Definition at line 334 of file dbinitializer.cpp.

◆ buildCreateIndexStatement()

QString DbInitializer::buildCreateIndexStatement ( const TableDescription & tableDescription,
const IndexDescription & indexDescription ) const
protectedvirtual

Definition at line 314 of file dbinitializer.cpp.

◆ buildCreateTableStatement()

virtual QString Akonadi::Server::DbInitializer::buildCreateTableStatement ( const TableDescription & tableDescription) const
pure virtual

Returns a backend-specific CREATE TABLE SQL query describing given table.

◆ buildPrimaryKeyStatement()

QString DbInitializer::buildPrimaryKeyStatement ( const TableDescription & table)
staticprotected

Use for multi-column primary keys during table creation.

Definition at line 368 of file dbinitializer.cpp.

◆ buildReferentialAction()

QString DbInitializer::buildReferentialAction ( ColumnDescription::ReferentialAction onUpdate,
ColumnDescription::ReferentialAction onDelete )
staticprotected

Definition at line 348 of file dbinitializer.cpp.

◆ buildRemoveForeignKeyConstraintStatements()

QStringList DbInitializer::buildRemoveForeignKeyConstraintStatements ( const DbIntrospector::ForeignKey & fk,
const TableDescription & table ) const
protectedvirtual

Returns an SQL statements to remove the foreign key constraint fk from table table.

The default implementation returns an empty string, so any backend supporting foreign key constraints must reimplement this.

Definition at line 341 of file dbinitializer.cpp.

◆ createInstance()

DbInitializer::Ptr DbInitializer::createInstance ( const QSqlDatabase & database,
Schema * schema = nullptr )
static

Returns an initializer instance for a given backend.

Definition at line 27 of file dbinitializer.cpp.

◆ errorMsg()

QString DbInitializer::errorMsg ( ) const

Returns the textual description of an occurred error.

Definition at line 214 of file dbinitializer.cpp.

◆ run()

bool DbInitializer::run ( )

Starts the initialization process.

On success true is returned, false otherwise.

If something went wrong

See also
errorMsg() can be used to retrieve more information.

Definition at line 60 of file dbinitializer.cpp.

◆ sqlType()

QString DbInitializer::sqlType ( const ColumnDescription & col,
int size ) const
protectedvirtual

Overwrite in backend-specific sub-classes to return the SQL type for a given C++ type.

Parameters
typeName of the C++ type.
sizeOptional size hint for the column, if -1 use the default SQL type for type.

Definition at line 269 of file dbinitializer.cpp.

◆ sqlValue()

QString DbInitializer::sqlValue ( const ColumnDescription & col,
const QString & value ) const
protectedvirtual

Overwrite in backend-specific sub-classes to return the SQL value for a given C++ value.

Definition at line 299 of file dbinitializer.cpp.

◆ updateIndexesAndConstraints()

bool DbInitializer::updateIndexesAndConstraints ( )

Checks and creates missing indexes.

This method is run after DbUpdater to ensure that data in new columns are populated and creation of indexes and foreign keys does not fail.

Definition at line 219 of file dbinitializer.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:31:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.