Changeset View
Changeset View
Standalone View
Standalone View
kexi/plugins/reports/kexidbreportdata.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Kexi Report Plugin | 2 | * Kexi Report Plugin | ||
3 | * Copyright (C) 2007-2009 by Adam Pigg (adam@piggz.co.uk) | 3 | * Copyright (C) 2007-2009 by Adam Pigg (adam@piggz.co.uk) | ||
4 | * Copyright (C) 2015 Jarosław Staniek <staniek@kde.org> | ||||
4 | * | 5 | * | ||
5 | * This library is free software; you can redistribute it and/or | 6 | * This library is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU Lesser General Public | 7 | * modify it under the terms of the GNU Lesser General Public | ||
7 | * License as published by the Free Software Foundation; either | 8 | * License as published by the Free Software Foundation; either | ||
8 | * version 2.1 of the License, or (at your option) any later version. | 9 | * version 2.1 of the License, or (at your option) any later version. | ||
9 | * | 10 | * | ||
10 | * This library is distributed in the hope that it will be useful, | 11 | * This library is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * Lesser General Public License for more details. | 14 | * Lesser General Public License for more details. | ||
14 | * | 15 | * | ||
15 | * You should have received a copy of the GNU Lesser General Public | 16 | * You should have received a copy of the GNU Lesser General Public | ||
16 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 17 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | 18 | */ | ||
18 | 19 | | |||
19 | #include "kexidbreportdata.h" | 20 | #include "kexidbreportdata.h" | ||
20 | #include <kdebug.h> | 21 | #include "kexireportview.h" | ||
21 | #include <db/queryschema.h> | 22 | #include <db/queryschema.h> | ||
22 | #include <core/kexipart.h> | 23 | #include <core/kexipart.h> | ||
23 | #include <QDomDocument> | | |||
24 | 24 | | |||
25 | #include <kdebug.h> | ||||
26 | | ||||
27 | #include <QDomDocument> | ||||
25 | 28 | | |||
26 | class KexiDBReportData::Private | 29 | class KexiDBReportData::Private | ||
27 | { | 30 | { | ||
28 | public: | 31 | public: | ||
29 | explicit Private(KexiDB::Connection *pDb) | 32 | explicit Private(KexiDB::Connection *pDb, KexiReportView *v) | ||
30 | : cursor(0), connection(pDb), originalSchema(0), copySchema(0) | 33 | : cursor(0), connection(pDb), view(v), originalSchema(0), copySchema(0) | ||
31 | { | 34 | { | ||
32 | } | 35 | } | ||
33 | ~Private() | 36 | ~Private() | ||
34 | { | 37 | { | ||
35 | delete copySchema; | 38 | delete copySchema; | ||
36 | delete originalSchema; | 39 | delete originalSchema; | ||
37 | delete cursor; | 40 | delete cursor; | ||
38 | } | 41 | } | ||
39 | 42 | | |||
40 | | ||||
41 | QString objectName; | 43 | QString objectName; | ||
42 | | ||||
43 | KexiDB::Cursor *cursor; | 44 | KexiDB::Cursor *cursor; | ||
44 | KexiDB::Connection *connection; | 45 | KexiDB::Connection * const connection; | ||
46 | KexiReportView * const view; | ||||
45 | KexiDB::QuerySchema *originalSchema; | 47 | KexiDB::QuerySchema *originalSchema; | ||
46 | KexiDB::QuerySchema *copySchema; | 48 | KexiDB::QuerySchema *copySchema; | ||
47 | }; | 49 | }; | ||
48 | 50 | | |||
49 | KexiDBReportData::KexiDBReportData (const QString &objectName, | 51 | KexiDBReportData::KexiDBReportData (const QString &objectName, | ||
50 | KexiDB::Connection * pDb) | 52 | KexiDB::Connection * pDb, KexiReportView *view) | ||
51 | : d(new Private(pDb)) | 53 | : d(new Private(pDb, view)) | ||
52 | { | 54 | { | ||
53 | d->objectName = objectName; | 55 | d->objectName = objectName; | ||
54 | getSchema(); | 56 | getSchema(); | ||
55 | } | 57 | } | ||
56 | 58 | | |||
57 | KexiDBReportData::KexiDBReportData(const QString& objectName, | 59 | KexiDBReportData::KexiDBReportData(const QString& objectName, | ||
58 | const QString& partClass, | 60 | const QString& partClass, | ||
59 | KexiDB::Connection* pDb) | 61 | KexiDB::Connection* pDb, KexiReportView *view) | ||
60 | : d(new Private(pDb)) | 62 | : d(new Private(pDb, view)) | ||
61 | { | 63 | { | ||
62 | d->objectName = objectName; | 64 | d->objectName = objectName; | ||
63 | getSchema(partClass); | 65 | getSchema(partClass); | ||
64 | } | 66 | } | ||
65 | 67 | | |||
66 | void KexiDBReportData::setSorting(const QList<SortedField>& sorting) | 68 | void KexiDBReportData::setSorting(const QList<SortedField>& sorting) | ||
67 | { | 69 | { | ||
68 | if (d->copySchema) { | 70 | if (d->copySchema) { | ||
Show All 28 Lines | |||||
97 | } | 99 | } | ||
98 | 100 | | |||
99 | bool KexiDBReportData::open() | 101 | bool KexiDBReportData::open() | ||
100 | { | 102 | { | ||
101 | if ( d->connection && d->cursor == 0 ) | 103 | if ( d->connection && d->cursor == 0 ) | ||
102 | { | 104 | { | ||
103 | if ( d->objectName.isEmpty() ) | 105 | if ( d->objectName.isEmpty() ) | ||
104 | { | 106 | { | ||
105 | d->cursor = d->connection->executeQuery ( "SELECT '' AS expr1 FROM kexi__db WHERE kexi__db.db_property = 'kexidb_major_ver'" ); | 107 | d->cursor = d->connection->prepareQuery("SELECT '' AS expr1 FROM kexi__db WHERE kexi__db.db_property = 'kexidb_major_ver'"); | ||
106 | } | 108 | } | ||
107 | else if ( d->copySchema) | 109 | else if ( d->copySchema) | ||
108 | { | 110 | { | ||
109 | kDebug() << "Opening cursor.." << d->copySchema->debugString(); | 111 | kDebug() << "Opening cursor.." << d->copySchema->debugString(); | ||
110 | d->cursor = d->connection->executeQuery ( *d->copySchema, 1 ); | 112 | d->cursor = d->connection->prepareQuery(*d->copySchema, KexiDB::Cursor::Buffered); | ||
111 | } | 113 | } | ||
112 | 114 | | |||
113 | 115 | if (d->cursor) { | |||
114 | if ( d->cursor ) | 116 | bool ok = d->view->setData(d->cursor); | ||
115 | { | 117 | if (ok) { | ||
116 | kDebug() << "Moving to first record.."; | 118 | kDebug() << "Moving to first record.."; | ||
117 | return d->cursor->moveFirst(); | 119 | if (!d->cursor->moveFirst()) { | ||
120 | ok = !d->cursor->error(); | ||||
121 | } | ||||
122 | } | ||||
123 | return ok; | ||||
118 | } | 124 | } | ||
119 | else | | |||
120 | return false; | | |||
121 | } | 125 | } | ||
122 | return false; | 126 | return false; | ||
123 | } | 127 | } | ||
124 | 128 | | |||
125 | bool KexiDBReportData::close() | 129 | bool KexiDBReportData::close() | ||
126 | { | 130 | { | ||
127 | if ( d->cursor ) | 131 | if ( d->cursor ) | ||
128 | { | 132 | { | ||
▲ Show 20 Lines • Show All 262 Lines • ▼ Show 20 Line(s) | 380 | if (d->connection && d->connection->isConnected()) { | |||
391 | } | 395 | } | ||
392 | } | 396 | } | ||
393 | 397 | | |||
394 | return qs; | 398 | return qs; | ||
395 | } | 399 | } | ||
396 | 400 | | |||
397 | KoReportData* KexiDBReportData::create(const QString& source) | 401 | KoReportData* KexiDBReportData::create(const QString& source) | ||
398 | { | 402 | { | ||
399 | return new KexiDBReportData(source, d->connection); | 403 | return new KexiDBReportData(source, d->connection, d->view); | ||
400 | } | 404 | } |