1 /*
2 * Kexi Report Plugin
3 * Copyright (C) 2007-2017 by Adam Pigg <adam@piggz.co.uk>
4 * Copyright (C) 2017-2018 Jarosław Staniek <staniek@kde.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
set_permissions(path: impl AsRef<Path>, perm: Permissions) -> io::Result<()>12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef __KEXIDBREPORTDATA_H__
21 #define __KEXIDBREPORTDATA_H__
22 
23 #include <QString>
24 #include <QStringList>
25 
26 #include <KReportDataSource>
27 
28 class KexiReportPartTempData;
29 
30 //! @brief Implementation of database report data source
31 class KexiDBReportDataSource : public KReportDataSource
32 {
33 public:
34     /*!
35      * @a pluginId specifies type of @a objectName, a table or query.
36      * Types accepted:
37      * -"org.kexi-project.table"
38      * -"org.kexi-project.query"
39      * -empty QString() - attempt to resolve @a objectName
40      */
41     KexiDBReportDataSource(const QString &objectName, const QString &pluginId,
42                            KexiReportPartTempData *data);
43     virtual ~KexiDBReportDataSource();
44 
45     virtual QStringList fieldNames() const;
46     virtual void setSorting(const QList<SortedField>& sorting);
47 
48     //! Adds a condition <field> <relation> <value> to the data source.
49     //! @note Only single-character relation operators such as "=" or ">" are supported now.
50     //! @todo Use KDb parser to support all relation operators such as ">=".
51     virtual void addCondition(const QString &field, const QVariant &value,
52                               const QString &relation = QLatin1String("="));
53 
54     virtual QString sourceName() const;
55     virtual int fieldNumber(const QString &field) const;
56     virtual QVariant value(int) const;
57     virtual QVariant value(const QString &field) const;
58 
59     virtual bool open();
60     virtual bool close();
61     virtual bool moveNext();
62     virtual bool movePrevious();
63     virtual bool moveFirst();
64     virtual bool moveLast();
65 
66     virtual qint64 at() const;
67     virtual qint64 recordCount() const;
68 
69     /**
70      * Runs aggregate function @a function on the data source
71      *
72      * @param function name such as max, min, avg
73      * @param field name of field for which the aggregation should be executed
74      * @param conditions optional conditions that limit the record set
75      * @return value of the function, 0.0 on failure
76      *
77      * @warning SQL injection warning: validity of @a function name is not checked, this should not
78      *          be part of a public API.
79      * @todo Move SQL aggregate functions to KDb. Current code depends on support for subqueries.
80      */
81     double runAggregateFunction(const QString &function, const QString &field,
82                                 const QMap<QString, QVariant> &conditions);
83 
84     //Utility Functions
85     virtual QStringList dataSourceNames() const;
86     virtual KReportDataSource* create(const QString& source) const Q_REQUIRED_RESULT;
87 
88 private:
89     class Private;
90     Private * const d;
91 
92     bool getSchema(const QString& pluginId);
93 };
94 
95 #endif
96 
97