Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/reports/KexiDBReportDataSource.cpp
Show All 13 Lines | |||||
14 | * Lesser General Public License for more details. | 14 | * Lesser General Public License for more details. | ||
15 | * | 15 | * | ||
16 | * 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 | ||
17 | * 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/>. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "KexiDBReportDataSource.h" | 20 | #include "KexiDBReportDataSource.h" | ||
21 | #include "kexireportpart.h" | 21 | #include "kexireportpart.h" | ||
22 | #include <kexiutils/utils.h> | ||||
23 | #include <kexiqueryparameters.h> | ||||
22 | 24 | | |||
23 | #include <KDbConnection> | 25 | #include <KDbConnection> | ||
24 | #include <KDbOrderByColumn> | 26 | #include <KDbOrderByColumn> | ||
25 | #include <KDbQuerySchema> | 27 | #include <KDbQuerySchema> | ||
26 | #include <KDbNativeStatementBuilder> | 28 | #include <KDbNativeStatementBuilder> | ||
27 | 29 | | |||
28 | #include <QDomDocument> | 30 | #include <QDomDocument> | ||
29 | #include <QDebug> | 31 | #include <QDebug> | ||
Show All 14 Lines | 35 | public: | |||
44 | 46 | | |||
45 | QString objectName; | 47 | QString objectName; | ||
46 | 48 | | |||
47 | KDbCursor *cursor; | 49 | KDbCursor *cursor; | ||
48 | KexiReportPartTempData *tempData; | 50 | KexiReportPartTempData *tempData; | ||
49 | KDbQuerySchema *originalSchema; | 51 | KDbQuerySchema *originalSchema; | ||
50 | KDbQuerySchema *copySchema; | 52 | KDbQuerySchema *copySchema; | ||
51 | KDbEscapedString schemaSql; | 53 | KDbEscapedString schemaSql; | ||
54 | QList<QVariant> currentParams; | ||||
52 | }; | 55 | }; | ||
53 | 56 | | |||
54 | KexiDBReportDataSource::KexiDBReportDataSource(const QString &objectName, const QString &pluginId, | 57 | KexiDBReportDataSource::KexiDBReportDataSource(const QString &objectName, const QString &pluginId, | ||
55 | KexiReportPartTempData *data) | 58 | KexiReportPartTempData *data) | ||
56 | : d(new Private(data)) | 59 | : d(new Private(data)) | ||
57 | { | 60 | { | ||
58 | d->objectName = objectName; | 61 | d->objectName = objectName; | ||
59 | getSchema(pluginId); | 62 | getSchema(pluginId); | ||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | 117 | { | |||
115 | if ( d->tempData->connection() && d->cursor == 0 ) | 118 | if ( d->tempData->connection() && d->cursor == 0 ) | ||
116 | { | 119 | { | ||
117 | if ( d->objectName.isEmpty() ) | 120 | if ( d->objectName.isEmpty() ) | ||
118 | { | 121 | { | ||
119 | return false; | 122 | return false; | ||
120 | } | 123 | } | ||
121 | else if ( d->copySchema) | 124 | else if ( d->copySchema) | ||
122 | { | 125 | { | ||
123 | qDebug() << "Opening cursor.." | 126 | //qDebug() << "Opening cursor.." | ||
124 | << KDbConnectionAndQuerySchema(d->tempData->connection(), *d->copySchema); | 127 | // << KDbConnectionAndQuerySchema(d->tempData->connection(), *d->copySchema); | ||
125 | d->cursor = d->tempData->connection()->executeQuery(d->copySchema, KDbCursor::Option::Buffered); | 128 | d->cursor = d->tempData->connection()->executeQuery(d->copySchema, d->currentParams, KDbCursor::Option::Buffered); | ||
126 | } | 129 | } | ||
127 | 130 | | |||
128 | 131 | | |||
129 | if ( d->cursor ) | 132 | if ( d->cursor ) | ||
130 | { | 133 | { | ||
131 | qDebug() << "Moving to first record.."; | 134 | qDebug() << "Moving to first record.."; | ||
132 | return d->cursor->moveFirst(); | 135 | return d->cursor->moveFirst(); | ||
133 | } | 136 | } | ||
Show All 32 Lines | 167 | { | |||
166 | d->originalSchema = new KDbQuerySchema(table); | 169 | d->originalSchema = new KDbQuerySchema(table); | ||
167 | } | 170 | } | ||
168 | else if ((pluginId.isEmpty() || pluginId == "org.kexi-project.query") | 171 | else if ((pluginId.isEmpty() || pluginId == "org.kexi-project.query") | ||
169 | && (query = d->tempData->connection()->querySchema(d->objectName))) | 172 | && (query = d->tempData->connection()->querySchema(d->objectName))) | ||
170 | { | 173 | { | ||
171 | qDebug() << d->objectName << "is a query.."; | 174 | qDebug() << d->objectName << "is a query.."; | ||
172 | qDebug() << KDbConnectionAndQuerySchema(d->tempData->connection(), *query); | 175 | qDebug() << KDbConnectionAndQuerySchema(d->tempData->connection(), *query); | ||
173 | d->originalSchema = new KDbQuerySchema(*query, d->tempData->connection()); | 176 | d->originalSchema = new KDbQuerySchema(*query, d->tempData->connection()); | ||
177 | | ||||
178 | bool ok; | ||||
179 | KexiUtils::WaitCursorRemover remover; | ||||
180 | d->currentParams = KexiQueryParameters::getParameters(0, d->tempData->connection(), d->originalSchema, &ok); | ||||
181 | if (!ok) { | ||||
182 | return false; | ||||
183 | } | ||||
174 | } | 184 | } | ||
175 | 185 | | |||
176 | if (d->originalSchema) { | 186 | if (d->originalSchema) { | ||
177 | const KDbNativeStatementBuilder builder(d->tempData->connection(), KDb::DriverEscaping); | 187 | const KDbNativeStatementBuilder builder(d->tempData->connection(), KDb::DriverEscaping); | ||
178 | KDbEscapedString sql; | 188 | KDbEscapedString sql; | ||
179 | if (builder.generateSelectStatement(&sql, d->originalSchema)) { | 189 | if (builder.generateSelectStatement(&sql, d->originalSchema, d->currentParams)) { | ||
180 | qDebug() << "Original:" << sql; | 190 | qDebug() << "Original:" << sql; | ||
181 | } else { | 191 | } else { | ||
182 | qDebug() << "Original: ERROR"; | 192 | qDebug() << "Original: ERROR"; | ||
183 | return false; | 193 | return false; | ||
184 | } | 194 | } | ||
185 | qDebug() << KDbConnectionAndQuerySchema(d->tempData->connection(), *d->originalSchema); | 195 | qDebug() << KDbConnectionAndQuerySchema(d->tempData->connection(), *d->originalSchema); | ||
186 | 196 | | |||
187 | d->copySchema = new KDbQuerySchema(*d->originalSchema, d->tempData->connection()); | 197 | d->copySchema = new KDbQuerySchema(*d->originalSchema, d->tempData->connection()); | ||
188 | qDebug() << KDbConnectionAndQuerySchema(d->tempData->connection(), *d->copySchema); | 198 | qDebug() << KDbConnectionAndQuerySchema(d->tempData->connection(), *d->copySchema); | ||
189 | if (builder.generateSelectStatement(&d->schemaSql, d->copySchema)) { | 199 | if (builder.generateSelectStatement(&d->schemaSql, d->copySchema, d->currentParams)) { | ||
190 | qDebug() << "Copy:" << d->schemaSql; | 200 | qDebug() << "Copy:" << d->schemaSql; | ||
191 | } else { | 201 | } else { | ||
192 | qDebug() << "Copy: ERROR"; | 202 | qDebug() << "Copy: ERROR"; | ||
193 | return false; | 203 | return false; | ||
194 | } | 204 | } | ||
195 | if (table) { | 205 | if (table) { | ||
196 | KDbTableSchemaChangeListener::registerForChanges(d->tempData->connection(), d->tempData, table); | 206 | KDbTableSchemaChangeListener::registerForChanges(d->tempData->connection(), d->tempData, table); | ||
197 | } else if (query) { | 207 | } else if (query) { | ||
▲ Show 20 Lines • Show All 186 Lines • Show Last 20 Lines |