Akonadi::Server::DbInitializer

#include <dbinitializer.h>

Public Types

typedef QSharedPointer< DbInitializerPtr
 

Public Member Functions

virtual ~DbInitializer ()
 
virtual QString buildCreateTableStatement (const TableDescription &tableDescription) const =0
 
QString errorMsg () const
 
virtual bool hasForeignKeyConstraints () const =0
 
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 49 of file dbinitializer.h.

Constructor & Destructor Documentation

DbInitializer::~DbInitializer ( )
virtual

Destroys the database initializer.

Definition at line 55 of file dbinitializer.cpp.

DbInitializer::DbInitializer ( const QSqlDatabase database)
protected

Creates a new database initializer.

Parameters
databaseThe reference to the database.

Definition at line 47 of file dbinitializer.cpp.

Member Function Documentation

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 327 of file dbinitializer.cpp.

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

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

QString DbInitializer::buildPrimaryKeyStatement ( const TableDescription table)
staticprotected

Use for multi-column primary keys during table creation.

Definition at line 362 of file dbinitializer.cpp.

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 334 of file dbinitializer.cpp.

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

Returns an initializer instance for a given backend.

Definition at line 26 of file dbinitializer.cpp.

QString DbInitializer::errorMsg ( ) const

Returns the textual description of an occurred error.

Definition at line 210 of file dbinitializer.cpp.

virtual bool Akonadi::Server::DbInitializer::hasForeignKeyConstraints ( ) const
pure virtual

Returns whether the database has working and complete foreign keys.

This information can be used for query optimizations.

Note
Result is invalid before run() has been called.
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 59 of file dbinitializer.cpp.

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 263 of file dbinitializer.cpp.

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 293 of file dbinitializer.cpp.

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 215 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-2020 The KDE developers.
Generated on Mon Jul 6 2020 23:15:40 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.