Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/reports/KexiDBReportDataSource.cpp
Show First 20 Lines • Show All 294 Lines • ▼ Show 20 Line(s) | 294 | { | |||
---|---|---|---|---|---|
295 | if ( d->copySchema ) | 295 | if ( d->copySchema ) | ||
296 | { | 296 | { | ||
297 | return KDb::recordCount ( d->copySchema ); | 297 | return KDb::recordCount ( d->copySchema ); | ||
298 | } | 298 | } | ||
299 | 299 | | |||
300 | return 1; | 300 | return 1; | ||
301 | } | 301 | } | ||
302 | 302 | | |||
303 | static bool isInterpreterSupported(const QString &interpreterName) | | |||
304 | { | | |||
305 | return 0 == interpreterName.compare(QLatin1String("javascript"), Qt::CaseInsensitive) | | |||
306 | || 0 == interpreterName.compare(QLatin1String("qtscript"), Qt::CaseInsensitive); | | |||
307 | } | | |||
308 | | ||||
309 | QStringList KexiDBReportDataSource::scriptList() const | | |||
310 | { | | |||
311 | QStringList scripts; | | |||
312 | | ||||
313 | if( d->connection) { | | |||
314 | QList<int> scriptids = d->connection->objectIds(KexiPart::ScriptObjectType); | | |||
315 | QStringList scriptnames = d->connection->objectNames(KexiPart::ScriptObjectType); | | |||
316 | | ||||
317 | qDebug() << scriptids << scriptnames; | | |||
318 | | ||||
319 | //A blank entry | | |||
320 | scripts << ""; | | |||
321 | int i = 0; | | |||
322 | foreach(int id, scriptids) { | | |||
323 | qDebug() << "ID:" << id; | | |||
324 | tristate res; | | |||
325 | QString script; | | |||
326 | res = d->connection->loadDataBlock(id, &script, QString()); | | |||
327 | if (res == true) { | | |||
328 | QDomDocument domdoc; | | |||
329 | bool parsed = domdoc.setContent(script, false); | | |||
330 | | ||||
331 | QDomElement scriptelem = domdoc.namedItem("script").toElement(); | | |||
332 | if (parsed && !scriptelem.isNull()) { | | |||
333 | if (scriptelem.attribute("scripttype") == "object" | | |||
334 | && isInterpreterSupported(scriptelem.attribute("language"))) | | |||
335 | { | | |||
336 | scripts << scriptnames[i]; | | |||
337 | } | | |||
338 | } else { | | |||
339 | qDebug() << "Unable to parse script"; | | |||
340 | } | | |||
341 | } else { | | |||
342 | qDebug() << "Unable to loadDataBlock"; | | |||
343 | } | | |||
344 | ++i; | | |||
345 | } | | |||
346 | | ||||
347 | qDebug() << scripts; | | |||
348 | } | | |||
349 | return scripts; | | |||
350 | } | | |||
351 | | ||||
352 | QString KexiDBReportDataSource::scriptCode(const QString& scriptname) const | | |||
353 | { | | |||
354 | QString scripts; | | |||
355 | | ||||
356 | if (d->connection) { | | |||
357 | QList<int> scriptids = d->connection->objectIds(KexiPart::ScriptObjectType); | | |||
358 | QStringList scriptnames = d->connection->objectNames(KexiPart::ScriptObjectType); | | |||
359 | | ||||
360 | int i = 0; | | |||
361 | foreach(int id, scriptids) { | | |||
362 | qDebug() << "ID:" << id; | | |||
363 | tristate res; | | |||
364 | QString script; | | |||
365 | res = d->connection->loadDataBlock(id, &script, QString()); | | |||
366 | if (res == true) { | | |||
367 | QDomDocument domdoc; | | |||
368 | bool parsed = domdoc.setContent(script, false); | | |||
369 | | ||||
370 | if (! parsed) { | | |||
371 | qDebug() << "XML parsing error"; | | |||
372 | return QString(); | | |||
373 | } | | |||
374 | | ||||
375 | QDomElement scriptelem = domdoc.namedItem("script").toElement(); | | |||
376 | if (scriptelem.isNull()) { | | |||
377 | qDebug() << "script domelement is null"; | | |||
378 | return QString(); | | |||
379 | } | | |||
380 | | ||||
381 | QString interpretername = scriptelem.attribute("language"); | | |||
382 | qDebug() << scriptelem.attribute("scripttype"); | | |||
383 | qDebug() << scriptname << scriptnames[i]; | | |||
384 | | ||||
385 | if ((isInterpreterSupported(interpretername) && scriptelem.attribute("scripttype") == "module") | | |||
386 | || scriptname == scriptnames[i]) | | |||
387 | { | | |||
388 | scripts += '\n' + scriptelem.text().toUtf8(); | | |||
389 | } | | |||
390 | ++i; | | |||
391 | } else { | | |||
392 | qDebug() << "Unable to loadDataBlock"; | | |||
393 | } | | |||
394 | } | | |||
395 | } | | |||
396 | return scripts; | | |||
397 | } | | |||
398 | | ||||
399 | QStringList KexiDBReportDataSource::dataSourceNames() const | 303 | QStringList KexiDBReportDataSource::dataSourceNames() const | ||
400 | { | 304 | { | ||
401 | //Get the list of queries in the database | 305 | //Get the list of queries in the database | ||
402 | QStringList qs; | 306 | QStringList qs; | ||
403 | if (d->connection && d->connection->isConnected()) { | 307 | if (d->connection && d->connection->isConnected()) { | ||
404 | QList<int> tids = d->connection->tableIds(); | 308 | QList<int> tids = d->connection->tableIds(); | ||
405 | qs << ""; | 309 | qs << ""; | ||
406 | for (int i = 0; i < tids.size(); ++i) { | 310 | for (int i = 0; i < tids.size(); ++i) { | ||
Show All 21 Lines |