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.

Constructor & Destructor Documentation

◆ ~DbInitializer()

DbInitializer::~DbInitializer ( )

Destroys the database initializer.

Definition at line 55 of file dbinitializer.cpp.

◆ DbInitializer()

DbInitializer::DbInitializer ( const QSqlDatabase database)

Creates a new database initializer.

databaseThe reference to the database.

Definition at line 47 of file dbinitializer.cpp.

Member Function Documentation

◆ buildAddForeignKeyConstraintStatements()

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

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 332 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)

Use for multi-column primary keys during table creation.

Definition at line 366 of file dbinitializer.cpp.

◆ buildRemoveForeignKeyConstraintStatements()

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

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

◆ createInstance()

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

Returns an initializer instance for a given backend.

Definition at line 26 of file dbinitializer.cpp.

◆ errorMsg()

QString DbInitializer::errorMsg ( ) const

Returns the textual description of an occurred error.

Definition at line 212 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 59 of file dbinitializer.cpp.

◆ sqlType()

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

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

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

Definition at line 267 of file dbinitializer.cpp.

◆ sqlValue()

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

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

Definition at line 297 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 217 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-2023 The KDE developers.
Generated on Sat Dec 9 2023 04:03:59 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.