Akonadi

schematypes.cpp
1 /***************************************************************************
2  * SPDX-FileCopyrightText: 2006 Tobias Koenig <[email protected]> *
3  * SPDX-FileCopyrightText: 2013 Volker Krause <[email protected]> *
4  * *
5  * SPDX-License-Identifier: LGPL-2.0-or-later *
6  ***************************************************************************/
7 
8 #include "schematypes.h"
9 
10 #include <algorithm>
11 
12 using namespace Akonadi::Server;
13 
14 ColumnDescription::ColumnDescription()
15  : size(-1)
16  , allowNull(true)
17  , isAutoIncrement(false)
18  , isPrimaryKey(false)
19  , isUnique(false)
20  , isEnum(false)
21  , onUpdate(Cascade)
22  , onDelete(Cascade)
23  , noUpdate(false)
24 {
25 }
26 
27 IndexDescription::IndexDescription()
28  : isUnique(false)
29 {
30 }
31 
32 DataDescription::DataDescription()
33 {
34 }
35 
36 TableDescription::TableDescription()
37 {
38 }
39 
40 int TableDescription::primaryKeyColumnCount() const
41 {
42  return std::count_if(columns.constBegin(), columns.constEnd(), [](const ColumnDescription &col) {
43  return col.isPrimaryKey;
44  });
45 }
46 
47 RelationDescription::RelationDescription()
48 {
49 }
50 
51 RelationTableDescription::RelationTableDescription(const RelationDescription &relation)
53 {
54  name = relation.firstTable + relation.secondTable + QStringLiteral("Relation");
55 
56  columns.reserve(2);
57  ColumnDescription column;
58  column.type = QStringLiteral("qint64");
59  column.allowNull = false;
60  column.isPrimaryKey = true;
61  column.onUpdate = ColumnDescription::Cascade;
62  column.onDelete = ColumnDescription::Cascade;
63  column.name = relation.firstTable + QLatin1Char('_') + relation.firstColumn;
64  column.refTable = relation.firstTable;
65  column.refColumn = relation.firstColumn;
66  columns.push_back(column);
67  IndexDescription index;
68  index.name = QStringLiteral("%1Index").arg(column.name);
69  index.columns = QStringList{column.name};
70  index.isUnique = false;
71  indexes.push_back(index);
72 
73  column.name = relation.secondTable + QLatin1Char('_') + relation.secondColumn;
74  column.refTable = relation.secondTable;
75  column.refColumn = relation.secondColumn;
76  columns.push_back(column);
77  index.name = QStringLiteral("%1Index").arg(column.name);
78  index.columns = QStringList{column.name};
79  indexes.push_back(index);
80 
81  indexes += relation.indexes;
82 }
A helper class that describes a column of a table for the DbInitializer.
Definition: schematypes.h:32
A helper class that describes the relation between two tables for the DbInitializer.
Definition: schematypes.h:107
A helper class that describes indexes of a table for the DbInitializer.
Definition: schematypes.h:64
void push_back(QChar ch)
A helper class that describes a table for the DbInitializer.
Definition: schematypes.h:92
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString name(StandardShortcut id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jun 30 2022 03:51:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.