Akonadi

dbintrospector.h
1 /*
2  SPDX-FileCopyrightText: 2006 Tobias Koenig <[email protected]>
3  SPDX-FileCopyrightText: 2012 Volker Krause <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 #ifndef DBINTROSPECTOR_H
8 #define DBINTROSPECTOR_H
9 
10 #include <QHash>
11 #include <QSharedPointer>
12 #include <QSqlDatabase>
13 #include <QStringList>
14 
15 class DbIntrospectorTest;
16 
17 namespace Akonadi
18 {
19 namespace Server
20 {
21 
27 {
28 public:
30 
32  class ForeignKey
33  {
34  public:
35  QString name;
36  QString column;
37  QString refTable;
38  QString refColumn;
39  QString onUpdate; // TODO use same enum as DbInitializer
40  QString onDelete; // dito
41  };
42 
46  static DbIntrospector::Ptr createInstance(const QSqlDatabase &database);
47 
48  virtual ~DbIntrospector();
49 
55  virtual bool hasTable(const QString &tableName);
56 
63  virtual bool hasIndex(const QString &tableName, const QString &indexName);
64 
69  virtual bool hasColumn(const QString &tableName, const QString &columnName);
70 
76  virtual bool isTableEmpty(const QString &tableName);
77 
83  virtual QVector<ForeignKey> foreignKeyConstraints(const QString &tableName);
84 
85 protected:
91  DbIntrospector(const QSqlDatabase &database);
92 
100  virtual QString hasIndexQuery(const QString &tableName, const QString &indexName);
101 
104 
105 private:
106  Q_DISABLE_COPY_MOVE(DbIntrospector)
107 
108  friend class ::DbIntrospectorTest;
109  QHash<QString, QStringList> m_columnCache; // avoids extra db roundtrips
110 };
111 
112 } // namespace Server
113 } // namespace Akonadi
114 
115 #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:31
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-2021 The KDE developers.
Generated on Sat Jan 23 2021 07:17:47 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.