DBFileDialog::DBFileDialog(QWidget* parent, Qt::WindowFlags fl) : QDialog(parent, fl) { setupUi(this); // signals and slots connections connect(_btnOk, SIGNAL(clicked()), this, SLOT(accept())); connect(_btnCancel, SIGNAL(clicked()), this, SLOT(reject())); connect(_list, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(sSelectedReport())); connect(_name, SIGNAL(textChanged(const QString&)), this, SLOT(sNameChanged(const QString&))); connect(_list, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(accept())); connect(_grade, SIGNAL(valueChanged(int)), this, SLOT(sGradeChanged(int))); _list->setColumnCount(2); QStringList cnames; cnames << tr("Name") << tr("Grade"); QTreeWidgetItem * item = new QTreeWidgetItem(_list, cnames); item->setData(1, Qt::TextAlignmentRole, Qt::AlignLeft); item->setData(2, Qt::TextAlignmentRole, Qt::AlignRight); XSqlQuery qry(getSqlFromTag("fmt12", QSqlDatabase::database().driverName())); while(qry.next()) { QTreeWidgetItem * item = new QTreeWidgetItem(_list, QStringList() << qry.value("report_name").toString() << qry.value("report_grade").toString()); item->setData(0, Qt::UserRole, qry.value("report_id")); } }
void ImportWindow::timerEvent( QTimerEvent * e ) { if(e->timerId() == _dbTimerId) { QSqlDatabase db = QSqlDatabase::database(QSqlDatabase::defaultConnection,FALSE); if(db.isValid()) QSqlQuery qry(getSqlFromTag("fmt07", db.driverName())); // if we are not connected then we have some problems! } }
QString DBFileDialog::getSource() { int rid = getId(); if(rid != -1) { XSqlQuery src_qry; src_qry.prepare(getSqlFromTag("fmt13", QSqlDatabase::database().driverName())); // MANU src_qry.bindValue(":report_id", rid); src_qry.exec(); if(src_qry.first()) return src_qry.value("report_source").toString(); } return QString::null; }
int DBFileDialog::getGradeById() { int rid = getId(); if(rid != -1) { XSqlQuery src_qry; src_qry.prepare(getSqlFromTag("fmt15", QSqlDatabase::database().driverName())); // MANU src_qry.bindValue(":report_id", rid); src_qry.exec(); if(src_qry.first()) return src_qry.value("report_grade").toInt(); } return -1; }
// Builds the report table if its a database engine that is supported bool buildTable(QSqlDatabase &db, QTextStream &out, QString &dbServer) { bool result = false; // be pessimistic QString stCommand; QString stDriver = db.driverName(); if ( ! getSqlDriver(stDriver)) { displayNotSupportedMesg(db, out); return result; } if ( stDriver == "QODBC" ) { if ( ! odbcSanityCheck(db, dbServer) ) { out << "If -databaseURL uses the ODBC protocol then -dbengine " << endl; out << "must indicate the type of database being connected to via " << endl; out << "ODBC. Eg. mysql, db2, psql" << endl; out << "-dbengine=" << dbServer << " Do not know how to create report table for this engine" << endl; displayNotSupportedMesg(db, out); return result; } stDriver = dbServer; } if (stDriver == "QOCI") { stCommand = getSqlFromTag("crt01", stDriver); execTableBuild(stCommand, out); stCommand = getSqlFromTag("crt02", stDriver); execTableBuild(stCommand, out); stCommand = getSqlFromTag("crt03", stDriver); execTableBuild(stCommand, out); } else { stCommand = getSqlFromTag("crt01", stDriver); execTableBuild(stCommand, out); // Create the labeldef table stCommand = getSqlFromTag("crt04", stDriver); if (execTableBuild(stCommand, out)) { stCommand = getSqlFromTag("crt07", stDriver); execTableBuild(stCommand, out); } } return true; }
void orReport::constructor(const QString &pReportName) { _internal->_reportName = pReportName; XSqlQuery report(_internal->_prerenderer.database()); report.prepare(getSqlFromTag("fmt04", _internal->_prerenderer.database().driverName())); // MANU report.bindValue(":report_name", pReportName); report.exec(); if (report.first()) { _internal->_reportExists = true; QString errorMessage; int errorLine; QDomDocument docReport; if (docReport.setContent(report.value("report_source").toString(), &errorMessage, &errorLine)) setDom(docReport); } else _internal->_reportExists = false; }
void RenderWindow::fileLoad(const QString & reportname) { XSqlQuery rq; rq.prepare(getSqlFromTag("fmt04", QSqlDatabase::database().driverName())); // MANU rq.bindValue(":report_name", reportname); rq.exec(); if(!rq.first()) { QMessageBox::critical(this, tr("Error Loading Report"), tr("There was an error loading the report from the database.")); return; } QDomDocument doc; QString errMsg; int errLine, errColm; if(!doc.setContent(rq.value("report_source").toString(), &errMsg, &errLine, &errColm)) { QMessageBox::critical(this, tr("Error Loading Report"), tr("There was an error opening the report %1." "\n\n%2 on line %3 column %4.") .arg(reportname).arg(errMsg).arg(errLine).arg(errColm) ); return; } QDomElement root = doc.documentElement(); if(root.tagName() != "report") { QMessageBox::critical(this, tr("Not a Valid File"), tr("The file %1 does not appear to be a valid file." "\n\nThe root node is not 'report'.").arg(reportname) ); return; } _report->setText(reportname); setDocument(doc); }
ImportWindow::ImportWindow(QWidget* parent, Qt::WindowFlags fl) : QMainWindow(parent, fl) { setupUi(this); (void)statusBar(); // signals and slots connections connect(helpIndexAction, SIGNAL(activated()), this, SLOT(helpIndex())); connect(helpContentsAction, SIGNAL(activated()), this, SLOT(helpContents())); connect(helpAboutAction, SIGNAL(activated()), this, SLOT(helpAbout())); connect(fileExitAction, SIGNAL(activated()), this, SLOT(fileExit())); connect(fileOpenAction, SIGNAL(activated()), this, SLOT(sAdd())); connect(_add, SIGNAL(clicked()), this, SLOT(sAdd())); connect(_import, SIGNAL(clicked()), this, SLOT(sImport())); connect(_remove, SIGNAL(clicked()), this, SLOT(sRemove())); _reports->clear(); QSqlQuery qpop; QSqlError err; if(!qpop.exec(getSqlFromTag("fmt19", QSqlDatabase::database().driverName()))) { err = qpop.lastError(); _log->append(tr("<font color=red>The following error was encountered " "retrieving available schemas:\n" "\t%1\n\t%2\n</font>") .arg(err.driverText()) .arg(err.databaseText())); return; } else while (qpop.next()) _schema->addItem(qpop.value(0).toString(), qpop.value(0)); _dbTimerId = startTimer(60000); }
void ImportWindow::sImport() { _log->append(tr("Import Started...")); QListWidgetItem * item = 0; QList<QListWidgetItem *> list = _reports->selectedItems(); for(int i = 0; i < list.count(); i++) { item = list.at(i); QString xml_file = item->text(); QString report_name = QString::null; QString report_desc = QString::null; QString report_src = QString::null; int report_grade = item->data(Qt::UserRole).toInt(); if(!xml_file.isEmpty()) { QFile file(xml_file); if(file.open(QIODevice::ReadOnly)) { QDomDocument doc; QString errMsg; int errLine, errCol; if(doc.setContent(&file, &errMsg, &errLine, &errCol)) { QDomElement root = doc.documentElement(); if(root.tagName() == "report") { for(QDomNode n = root.firstChild(); !n.isNull(); n = n.nextSibling()) { if(n.nodeName() == "name") report_name = n.firstChild().nodeValue(); else if(n.nodeName() == "description") report_desc = n.firstChild().nodeValue(); } report_src = doc.toString(); if(!report_name.isEmpty()) { QSqlQuery qry; QSqlQuery query; qry.prepare(getSqlFromTag("fmt09", QSqlDatabase::database().driverName())); // MANU qry.bindValue(":report_name", report_name); // MANU qry.bindValue(":report_grade", report_grade); // MANU qry.exec(); if(qry.first()) { // update query.prepare(getSqlFromTag("fmt10", QSqlDatabase::database().driverName())); // MANU query.bindValue(":report_desc", report_desc); // MANU query.bindValue(":report_src", report_src); // MANU query.bindValue(":report_id", qry.value(0)); // MANU query.bindValue(":report_name", report_name); // MANU } else { // insert query.prepare(getSqlFromTag("fmt11", QSqlDatabase::database().driverName())); // MANU query.bindValue(":report_name", report_name); // MANU query.bindValue(":report_desc", report_desc); // MANU query.bindValue(":report_src", report_src); // MANU query.bindValue(":report_grade", report_grade); // MANU } if(!query.exec()) { QSqlError err = query.lastError(); _log->append(tr("<font color=red>The following error was encountered while trying to import %1 into the database:\n" "\t%2\n\t%3\n</font>") .arg(xml_file) .arg(err.driverText()) .arg(err.databaseText())); } else _log->append(tr("Import successful of %1").arg(xml_file)); } else _log->append(tr("<font color=orange>The document %1 does not have a report name defined\n</font>") .arg(xml_file)); } else _log->append(tr("<font color=red>XML Document %1 does not have root node of report\n</font>") .arg(xml_file)); } else _log->append(tr("<font color=red>Error parsing file %1: %2 on line %3 column %4\n</font>") .arg(xml_file).arg(errMsg).arg(errLine).arg(errCol)); } else _log->append(tr("<font color=red>Could not open the specified file: %1\n</font>") .arg(xml_file)); } else _log->append("<font color=red>Encountered and empty entry: No file name was given.\n</font>"); } _log->append(tr("Import complete!\n\n\n")); }
int main(int argc, char *argv[]) { QCoreApplication application(argc, argv); application.addLibraryPath("."); if (argc > 1) { QString databaseURL; QString username; QString passwd; QString arguments; for (int counter = 1; counter < argc; counter++) { arguments = QString(argv[counter]); if (arguments.startsWith("-databaseURL=", Qt::CaseInsensitive)) databaseURL = arguments.right(arguments.length() - 13); else if (arguments.startsWith("-username="******"-passwd=", Qt::CaseInsensitive)) passwd = arguments.right(arguments.length() - 8); } if ( (databaseURL != "") && (username != "") ) { QSqlDatabase db; QString protocol; QString hostName; QString dbName; QString port; // Open the Database Driver db = databaseFromURL(databaseURL); if (!db.isValid()) { printf("Could not load the specified database driver.\n"); exit(-1); } // Try to connect to the Database bool valport = false; int iport = port.toInt(&valport); if(!valport) iport = 5432; db.setUserName(username); if(!passwd.isEmpty()) db.setPassword(passwd); if (!db.open()) { printf( "Host=%s, Database=%s, port=%s\n", hostName.toLatin1().data(), dbName.toLatin1().data(), port.toLatin1().data() ); printf( "Could not log into database. System Error: %s\n", db.lastError().text().toLatin1().data() ); exit(-1); } QSqlQuery().exec(getSqlFromTag("fmt05", db.driverName())); // MANU // first we need to determine if there is already a report in the database of the same // name and if so then we will perform an update instead of an insert QSqlQuery qry; qry.prepare(getSqlFromTag("fmt06", db.driverName())); // MANU qry.exec(); if(!qry.exec()) { QSqlError err = qry.lastError(); printf("Error: %s\n\t%s\n", qPrintable( err.text() ), qPrintable( err.databaseText() ) ); exit(-1); } QString fname; while(qry.next()) { fname = QString("%1-%2.xml").arg(qry.value(0).toString()).arg(qry.value(1).toString()); fname.replace('/',"-"); QFile file(fname); if(file.open(QIODevice::WriteOnly)) { QTextStream stream( &file ); stream << qry.value(2).toString(); file.close(); } else printf("Error: Could not open file %s: %s\n", fname.toLatin1().data(), file.errorString().toLatin1().data()); } } else if (databaseURL == "") printf("You must specify a Database URL by using the -databaseURL= parameter.\n"); else if (username == "") printf("You must specify a Database Username by using the -username= parameter.\n"); } else printf( "Usage: exportrpt -databaseURL='$' -username='******' -passwd='$'\n"); return 0; }
int main(int argc, char *argv[]) { QCoreApplication application(argc, argv); application.addLibraryPath("."); QTextStream out(stdout, QIODevice::WriteOnly); if (application.argc() > 1) { QString databaseURL; QString username; QString passwd; QString arguments; QString xml_file = QString::null; int report_grade = 0; for (int counter = 1; counter < application.argc(); counter++) { QString arguments(application.argv()[counter]); if (arguments.startsWith("-databaseURL=", Qt::CaseInsensitive)) databaseURL = arguments.right(arguments.length() - 13); else if (arguments.startsWith("-username="******"-passwd=", Qt::CaseInsensitive)) passwd = arguments.right(arguments.length() - 8); else if (arguments.startsWith("-f=", Qt::CaseInsensitive)) xml_file = arguments.right(arguments.length() - 3); else if (arguments.startsWith("-grade=", Qt::CaseInsensitive)) report_grade = (arguments.right(arguments.length() - 7)).toInt(); else if(!arguments.startsWith("-")) xml_file = arguments; } QString report_name = QString::null; QString report_desc = QString::null; QString report_src = QString::null; if(xml_file != "") { QFile file(xml_file); if(file.open( QIODevice::ReadOnly )) { QDomDocument doc; QString errMsg; int errLine, errCol; if(doc.setContent(&file, &errMsg, &errLine, &errCol)) { QDomElement root = doc.documentElement(); if(root.tagName() == "report") { for(QDomNode n = root.firstChild(); !n.isNull(); n = n.nextSibling() ) { if(n.nodeName() == "name") { report_name = n.firstChild().nodeValue(); } else if(n.nodeName() == "description") { report_desc = n.firstChild().nodeValue(); } } report_src = doc.toString(); if(report_name == "") { out << "The document " << xml_file << " does not have a report name defined." << endl; } } else { out << "XML Document " << xml_file << " does not have root node of report." << endl; } } else { out << "Error parsing file " << xml_file << ": " << errMsg << " on line " << errLine << " column " << errCol << endl; } } else { out << "Could not open the specified file: " << xml_file << endl; } } else { out << "You must specify an XML file to load by using the -f= parameter." << endl; } if(report_name == "" || report_src == "") { // an error message already should have been displayed to the user exit(-1); } if ( (databaseURL != "") && (username != "") && (passwd != "") ) { QSqlDatabase db; // Open the Database Driver db = databaseFromURL( databaseURL ); if (!db.isValid()) { out << "Could not load the specified database driver." << endl; exit(-1); } // Try to connect to the Database db.setUserName(username); db.setPassword(passwd); if (!db.open()) { out << "Host=" << db.hostName() << ", Database=" << db.databaseName() << ", port=" << db.port() << endl; out << "Could not log into database. System Error: " << db.lastError().text() << endl; exit(-1); } QSqlQuery().exec(getSqlFromTag("fmt05", db.driverName())); // MANU // first we need to determine if there is already a report in the database of the same // name and if so then we will perform an update instead of an insert QSqlQuery qry; qry.prepare(getSqlFromTag("fmt09", db.driverName())); // MANU qry.bindValue(":report_name", report_name); qry.bindValue(":report_grade", report_grade); qry.exec(); QSqlQuery query; if(qry.first()) { // update query.prepare(getSqlFromTag("fmt10", db.driverName())); // MANU query.bindValue(":report_desc", report_desc); query.bindValue(":report_src", report_src); query.bindValue(":report_id", qry.value(0)); query.bindValue(":report_name", report_name); } else { // insert query.prepare(getSqlFromTag("fmt11", db.driverName())); // MANU query.bindValue(":report_name", report_name); query.bindValue(":report_desc", report_desc); query.bindValue(":report_src", report_src); query.bindValue(":report_grade", report_grade); } if(!query.exec()) { QSqlError err = query.lastError(); out << "Error: " << err.driverText() << endl << "\t" << err.databaseText() << endl; exit(-1); } } else if (databaseURL == "") out << "You must specify a Database URL by using the -databaseURL= parameter." << endl; else if (username == "") out << "You must specify a Database Username by using the -username= parameter." << endl; else if (passwd == "") out << "You must specify a Database Password by using the -passwd= parameter." << endl; } else out << "Usage: import -databaseURL='$' -username='******' -passwd='$' -grade=# -f='$'" << endl; return 0; }
void ImportWindow::sImport() { _log->append(tr("Import Started...")); QList<QListWidgetItem *> list = _reports->selectedItems(); if(list.empty()) { if(QMessageBox::question(this, tr("No Reports Selected"), tr("You have not selected any reports to import. Would you like to select all loaded reports now?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { _reports->selectAll(); list = _reports->selectedItems(); } } QSqlQuery qtrig; QSqlError err; if(!qtrig.exec(getSqlFromTag("fmt16", QSqlDatabase::database().driverName()))) { err = qtrig.lastError(); _log->append(tr("<font color=red>The following error was encountered disabling the trigger:\n" "\t%1\n\t%2\n</font>") .arg(err.driverText()) .arg(err.databaseText())); return; } for(int i = 0; i < list.count(); i++) { QListWidgetItem * item = list.at(i); QString xml_file = item->text(); QString metasql_name = QString::null; QString metasql_group = QString::null; QString metasql_desc = QString::null; QString metasql_src = QString::null; if(!xml_file.isEmpty()) { QFile file(xml_file); if(file.open(QIODevice::ReadOnly)) { QByteArray contents = file.readAll(); metasql_src = contents; if(!contents.isEmpty()) { MQLUtil::extractMetadata(contents, metasql_group, metasql_name, metasql_desc); if(!metasql_name.isEmpty() && !metasql_group.isEmpty()) { QSqlQuery qry; QSqlQuery query; query.prepare(getSqlFromTag("fmt17", QSqlDatabase::database().driverName())); query.bindValue(":name", metasql_name); query.bindValue(":group", metasql_group); query.bindValue(":notes", metasql_desc); query.bindValue(":query", metasql_src); query.bindValue(":system",QVariant(false)); query.bindValue(":schema",(_schema->currentText().isEmpty() ? "public" : _schema->currentText())); if(!query.exec()) { err = query.lastError(); _log->append(tr("<font color=red>The following error was encountered while trying to import %1 into the database:\n" "\t%2\n\t%3\n</font>") .arg(xml_file) .arg(err.driverText()) .arg(err.databaseText())); } else { if (query.first()) { int metasqlid = query.value(0).toInt(); if (metasqlid < 0) { _log->append(tr("The saveMetasql stored procedure failed for %1, returning %2.") .arg(xml_file).arg(metasqlid)); } else _log->append(tr("Import successful of %1").arg(xml_file)); } else _log->append(tr("No results returned from query for %1").arg(xml_file)); } } else _log->append(tr("<font color=orange>The document %1 does not have a name and/or group defined\n</font>") .arg(xml_file)); } else _log->append(tr("<font color=red>Error reading file %1 or file was empty\n</font>") .arg(xml_file)); } else _log->append(tr("<font color=red>Could not open the specified file: %1\n</font>") .arg(xml_file)); } else _log->append("<font color=red>Encountered and empty entry: No file name was given.\n</font>"); } if(!qtrig.exec(getSqlFromTag("fmt18", QSqlDatabase::database().driverName()))) { err = qtrig.lastError(); _log->append(tr("<font color=red>The following error was encountered re-enabling the trigger:\n" "\t%1\n\t%2\n</font>") .arg(err.driverText()) .arg(err.databaseText())); } _log->append(tr("Import complete!\n\n\n")); }