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