Akonadi

dbintrospector.h
1 /*
2  Copyright (C) 2006 by Tobias Koenig <[email protected]>
3  Copyright (c) 2012 Volker Krause <[email protected]>
4 
5  This library is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or (at your
8  option) any later version.
9 
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 #ifndef DBINTROSPECTOR_H
21 #define DBINTROSPECTOR_H
22 
23 #include <QHash>
24 #include <QSharedPointer>
25 #include <QSqlDatabase>
26 #include <QStringList>
27 
28 class DbIntrospectorTest;
29 
30 namespace Akonadi
31 {
32 namespace Server
33 {
34 
40 {
41 public:
43 
45  class ForeignKey
46  {
47  public:
48  QString name;
49  QString column;
50  QString refTable;
51  QString refColumn;
52  QString onUpdate; // TODO use same enum as DbInitializer
53  QString onDelete; // dito
54  };
55 
59  static DbIntrospector::Ptr createInstance(const QSqlDatabase &database);
60 
61  virtual ~DbIntrospector();
62 
68  virtual bool hasTable(const QString &tableName);
69 
76  virtual bool hasIndex(const QString &tableName, const QString &indexName);
77 
82  virtual bool hasColumn(const QString &tableName, const QString &columnName);
83 
89  virtual bool isTableEmpty(const QString &tableName);
90 
96  virtual QVector<ForeignKey> foreignKeyConstraints(const QString &tableName);
97 
98 protected:
104  DbIntrospector(const QSqlDatabase &database);
105 
113  virtual QString hasIndexQuery(const QString &tableName, const QString &indexName);
114 
117 
118 private:
119  Q_DISABLE_COPY_MOVE(DbIntrospector)
120 
121  friend class ::DbIntrospectorTest;
122  QHash<QString, QStringList> m_columnCache; // avoids extra db roundtrips
123 };
124 
125 } // namespace Server
126 } // namespace Akonadi
127 
128 #endif // DBINTROSPECTOR_H
virtual bool hasIndex(const QString &tableName, const QString &indexName)
Returns true of the given table has an index with the given name.
virtual bool hasTable(const QString &tableName)
Returns true if table tableName exists.
A structure describing an existing foreign key.
virtual bool isTableEmpty(const QString &tableName)
Check whether table tableName is empty, ie.
static DbIntrospector::Ptr createInstance(const QSqlDatabase &database)
Returns an introspector instance for a given database.
virtual QString hasIndexQuery(const QString &tableName, const QString &indexName)
Returns a query string to determine if tableName has an index indexName.
virtual QVector< ForeignKey > foreignKeyConstraints(const QString &tableName)
Returns the foreign key constraints on table tableName.
DbIntrospector(const QSqlDatabase &database)
Creates a new database introspector, call from subclass.
QSqlDatabase m_database
The database connection we are introspecting.
virtual bool hasColumn(const QString &tableName, const QString &columnName)
Check whether table tableName has a column named columnName.
Definition: item.h:44
Helper integration between Akonadi and Qt.
Methods for introspecting the current state of a database schema.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Jun 2 2020 23:09:07 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.