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 | ||
Context not available. | |||||
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() | ||
Context not available. | |||||
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(); | ||
Context not available. | |||||
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); | ||
Context not available. | |||||
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 | } | ||
Context not available. | |||||
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 | } | ||
Context not available. |