Akonadi

schematypes.cpp
1 /***************************************************************************
2  * Copyright (C) 2006 by Tobias Koenig <[email protected]> *
3  * Copyright (C) 2013 by Volker Krause <[email protected]> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU Library General Public License as *
7  * published by the Free Software Foundation; either version 2 of the *
8  * License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU Library General Public *
16  * License along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 #include "schematypes.h"
22 
23 #include <algorithm>
24 
25 using namespace Akonadi::Server;
26 
27 ColumnDescription::ColumnDescription()
28  : size(-1)
29  , allowNull(true)
30  , isAutoIncrement(false)
31  , isPrimaryKey(false)
32  , isUnique(false)
33  , isEnum(false)
34  , onUpdate(Cascade)
35  , onDelete(Cascade)
36  , noUpdate(false)
37 {
38 }
39 
40 IndexDescription::IndexDescription()
41  : isUnique(false)
42 {
43 }
44 
45 DataDescription::DataDescription()
46 {
47 }
48 
49 TableDescription::TableDescription()
50 {
51 }
52 
53 int TableDescription::primaryKeyColumnCount() const
54 {
55  return std::count_if(columns.constBegin(), columns.constEnd(), [](const ColumnDescription & col) {
56  return col.isPrimaryKey;
57  }
58  );
59 }
60 
61 RelationDescription::RelationDescription()
62 {
63 }
64 
65 RelationTableDescription::RelationTableDescription(const RelationDescription &relation)
67 {
68  name = relation.firstTable + relation.secondTable + QStringLiteral("Relation");
69 
70  columns.reserve(2);
71  ColumnDescription column;
72  column.type = QStringLiteral("qint64");
73  column.allowNull = false;
74  column.isPrimaryKey = true;
75  column.onUpdate = ColumnDescription::Cascade;
76  column.onDelete = ColumnDescription::Cascade;
77  column.name = relation.firstTable + QLatin1Char('_') + relation.firstColumn;
78  column.refTable = relation.firstTable;
79  column.refColumn = relation.firstColumn;
80  columns.push_back(column);
81  IndexDescription index;
82  index.name = QStringLiteral("%1Index").arg(column.name);
83  index.columns = QStringList{column.name};
84  index.isUnique = false;
85  indexes.push_back(index);
86 
87  column.name = relation.secondTable + QLatin1Char('_') + relation.secondColumn;
88  column.refTable = relation.secondTable;
89  column.refColumn = relation.secondColumn;
90  columns.push_back(column);
91  index.name = QStringLiteral("%1Index").arg(column.name);
92  index.columns = QStringList{column.name};
93  indexes.push_back(index);
94 
95  indexes += relation.indexes;
96 }
A helper class that describes indexes of a table for the DbInitializer.
Definition: schematypes.h:69
A helper class that describes a table for the DbInitializer.
Definition: schematypes.h:97
QString name(StandardShortcut id)
void push_back(QChar ch)
A helper class that describes a column of a table for the DbInitializer.
Definition: schematypes.h:37
A helper class that describes the relation between two tables for the DbInitializer.
Definition: schematypes.h:112
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed May 27 2020 22:43:40 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.