Xslt_Convert::~Xslt_Convert() { EndingJob = true; qDebug() << "### Destructor .......................... ->" << UmanTimeFromUnix(QTime_Null()); qDebug() << "### EndingJob .......................... ->" << EndingJob; qt_unlink(XMLERROR_FILE); /* remove debug or error message from last */ }
Browser::Browser(QWidget *parent) { setupUi(this); connect(bsincro, SIGNAL(clicked()), this , SLOT(ConfigSincroWizard())); connect(this, SIGNAL(registerQuerySuccess(QString,QString)), this , SLOT(Export_Xml(QString,QString))); openwsin = new Sincro(this); connect(openwsin, SIGNAL(MakeParentQuery(QString)), this , SLOT(GoSetQuery(QString))); connect(this, SIGNAL(displaystatus(int,int)), this , SLOT(SendDialog(int,int))); table->addAction(insertRowAction); table->addAction(deleteRowAction); QSettings setter; //////Make_Arianna(); setter.setValue("TimeToday", UmanTimeFromUnix(QTime_Null())); QString lastq = setter.value("LastQuery").toString(); if (lastq.size() > 1) { sqlEdit->clear(); sqlEdit->append(lastq); sqlEdit->toPlainText(); } if (QSqlDatabase::drivers().isEmpty()) QMessageBox::information(this, tr("No database drivers found"), tr("This App requires at least one Qt database driver. " "Please check the documentation.")); emit statusMessage(tr("Ready.")); }
void Xslt_Convert::CheckError() { qDebug() << "### CheckError .......................... ->" << UmanTimeFromUnix(QTime_Null()); qDebug() << "### EndingJob .......................... ->" << EndingJob; }
void Browser::ExportXmlPrimary( QString qx ) { bool ok; QString userd = QInputDialog::getText(this, tr("Tell me Your name?... to signed the xml file"),tr("Autor:"), QLineEdit::Normal,"", &ok); QString userorg = QInputDialog::getText(this, tr("Tell me Your ORG name?... to signed the xml file"),tr("ORG:"), QLineEdit::Normal,"", &ok); QString xfileName = QFileDialog::getSaveFileName(this, "Export XML",QString(setter.value("lastdirDir").toString()), "*.xml"); if (!xfileName.endsWith(".xml")) { xfileName = xfileName+".xml"; } if (!ok and userd.size() < 2) { userd = "From unknow Autor"; } if (userorg.size() < 2) { userorg = "UNKNOW"; } if (xfileName.size() < 2) { return; } QString dirsave = xfileName.left(xfileName.lastIndexOf("/"))+"/"; setter.setValue("lastdirDir",dirsave); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QSqlQuery query(qx,connectionWidget->currentDatabase()); QSqlRecord rec = query.record(); int sumcol = rec.count(); int sumrow = query.numRowsAffected(); int recnum = 0 - 1; /* xml ##################################### StructureTable( QSqlRecord now ) */ QDomDocument em; QDomProcessingInstruction header = em.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"utf-8\" " ); em.appendChild( header ); QDomElement root = em.createElement("odbc_root"); root.setAttribute ("org",userorg.toUpper()); root.setAttribute ("build",UmanTimeFromUnix(QTime_Null())); root.setAttribute ("appsname",_PROGRAM_TITLE_); root.setAttribute ("export_from",QString(setter.value("ODBBC_Name").toString())); root.setAttribute ("createtable",StructureTable(rec)); em.appendChild( root ); QDomElement queril = em.createElement( "query" ); queril.setAttribute ("name",qx); queril.setAttribute ("org",userorg.toUpper()); if (sumrow > 0) { queril.setAttribute ("sumrow",QString::number(sumrow)); } else { queril.setAttribute ("sumrow","Driver_Not_Support_RowsAffected"); } queril.setAttribute ("sumcool",QString::number(sumcol)); queril.setAttribute ("user",userd); root.appendChild(queril); while (query.next()) { recnum++; QDomElement lines = em.createElement( "line" ); lines.setAttribute ("id",recnum); queril.appendChild(lines); for(int i=0;i<sumcol;i++){ QDomElement line = em.createElement( "row" ); QString value = Strtrimmed(query.value(i).toString()); QString fname = rec.fieldName(i); ///////qDebug() << "### fieldname " << fname; line.setAttribute ("fieldname",fname); line.setAttribute ("value",value); if (is_numeric(value)) { line.setAttribute ("digit","1"); } else { line.setAttribute ("digit","0"); } line.setAttribute ("id",i); //////qDebug() << "### recnum " << recnum; lines.appendChild(line); } } QTextCodec *setcurrentcodec; setcurrentcodec = QTextCodec::codecForMib(106); /* utf8 */ QFile f( xfileName ); if ( f.open( QFile::WriteOnly | QFile::Text ) ) { QTextStream sw( &f ); sw.setCodec(setcurrentcodec); sw << em.toString(); f.close(); } else { QApplication::restoreOverrideCursor(); QMessageBox::information(this, tr("Error!"),tr("Unable to save to file %1").arg(xfileName)); } QApplication::restoreOverrideCursor(); }
void Browser::ExportMysql( QString qx ) { QString tta; QString cfileName = QFileDialog::getSaveFileName(this, "Export MYSQL locale format text",QString(setter.value("lastdirDir").toString()), "*.sql"); bool ok; QString newtablename = QInputDialog::getText(this, tr("You like mysql insert on new table name?"),tr("TableName:"), QLineEdit::Normal,runningtable, &ok); QString msgDB =tr("<p>Append create table command? mysql</p>"); int removeyes = QMessageBox::question(this, tr("Please confirm!"),msgDB, tr("&Yes"), tr("&No"), QString(),8888,9999); QString responder = QString::number(removeyes); if (cfileName.size() > 0) { QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); if (!cfileName.endsWith(".sql")) { cfileName = cfileName+".sql"; } QString dirsave = cfileName.left(cfileName.lastIndexOf("/"))+"/"; setter.setValue("lastdirDir",dirsave); dlg = new QProgressDialog(this,Qt::Popup); dlg->setLabelText (tr("Export table \"%1\"").arg( runningtable )); dlg->setCancelButton(0); QStringList cvslines; QStringList Fname; QStringList Fvalue; cvslines.append(QString("### Created on %1 ###").arg(_PROGRAM_TITLE_)); cvslines.append(QString("### Export from %1 ###").arg(UmanTimeFromUnix(QTime_Null()))); cvslines.append(QString("### Remove comment line if other application not support! ###")); QSqlQuery query(qx,connectionWidget->currentDatabase()); QSqlRecord rec = query.record(); bool window = false; if (responder =="0") { if (runningdriver == "qmysql") { window = OSWinServer(); QString dtabi = SqlCreateTable(runningtable); if (newtablename.size() > 0 ) { if (window) { dtabi.replace("`"+runningtable.toUpper()+"`","`"+newtablename.toUpper()+"`"); } else { dtabi.replace("`"+runningtable+"`","`"+newtablename+"`"); } } cvslines.append(dtabi); } else { cvslines.append(StructureMYSQLTable(rec)); cvslines.append(QString("### Manual rewrite if is from odbc export! ###")); } } if (newtablename.size() > 0 ) { runningtable = newtablename; } bool suppoaffect; int sumcol = rec.count(); int sumrow = query.numRowsAffected(); int recnum = 0; /* QProgressDialog *dlg; */ int pasero = 0; if (sumrow < 1) { suppoaffect = false; sumrow = 1000; } else { suppoaffect = true; } while (query.next()) { recnum++; /* count fake lines */ emit displaystatus(recnum,sumrow); Fvalue.clear(); Fname.clear(); for(int i=0;i<sumcol;i++){ bool oknr; QSqlField fld = rec.field(i); QString value =""; QString typeoffield = QString(QVariant::typeToName(fld.type())); if (typeoffield != "QByteArray") { value = Strsqltrimmed(query.value(i).toString()); } else { value = Strsqltrimmed(query.value(i).toString()); } int vnummer = value.toInt(&oknr); QString fname = Strcsvtrimmed(rec.fieldName(i)); if (oknr) { Fvalue.append(value); } else if (value.isEmpty()) { Fvalue.append("NULL"); } else { Fvalue.append(QString("'%1'").arg(value)); } } QString Dvalue = Fvalue.join(","); if (window) { cvslines.append(QString("REPLACE INTO `%1` VALUES (%2);").arg(runningtable.toUpper()).arg(Dvalue)); } else { cvslines.append(QString("REPLACE INTO `%1` VALUES (%2);").arg(runningtable).arg(Dvalue)); } if (!suppoaffect) { if (recnum == 1001) { recnum = 0; pasero++; dlg->setLabelText (tr("Export table \"%1\" %2x1000 !numRowsAffected").arg( runningtable ).arg(pasero)); } } } QString contentxt = cvslines.join("\n"); ///////////QTextCodec *setcurrentcodec; //////////setcurrentcodec = QTextCodec::codecForMib(106); /* utf8 */ QFile f( cfileName ); if ( f.open( QFile::WriteOnly | QFile::Text ) ) { QTextStream sw( &f ); /////////sw.setCodec(setcurrentcodec); sw << contentxt; f.close(); if (dlg->isVisible ()) { dlg->close(); } } else { if (dlg->isVisible ()) { dlg->close(); } QApplication::restoreOverrideCursor(); QMessageBox::information(this, tr("Error!"),tr("Unable to save to file %1").arg(cfileName)); } QApplication::restoreOverrideCursor(); } }
void Browser::ExportSqlite3( QString qx ) { QString cfileName = QFileDialog::getSaveFileName(this, "Export SQLITE3 UTF-8 text",QString(setter.value("lastdirDir").toString()), "*.sql"); bool ok; QString newtablename = QInputDialog::getText(this, tr("You like sqlite insert on new table name?"),tr("TableName:"), QLineEdit::Normal,runningtable, &ok); if (newtablename.size() > 0 ) { runningtable = newtablename; } if (cfileName.size() > 0) { QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); if (!cfileName.endsWith(".sql")) { cfileName = cfileName+".sql"; } QString dirsave = cfileName.left(cfileName.lastIndexOf("/"))+"/"; setter.setValue("lastdirDir",dirsave); QStringList cvslines; QStringList Fname; QStringList Fvalue; cvslines.append(QString("### Created on %1 ###").arg(_PROGRAM_TITLE_)); cvslines.append(QString("### Export from %1 ###").arg(UmanTimeFromUnix(QTime_Null()))); cvslines.append("### original saved on utf-8 format use vim or so to convert on other format ###"); cvslines.append(QString("### Remove comment line if other application not support! ###")); cvslines.append("BEGIN TRANSACTION;"); QSqlQuery query(qx,connectionWidget->currentDatabase()); QSqlRecord rec = query.record(); ////////cvslines.append(StructureMYSQLTable(rec)); cvslines.append(StructureTable(rec)); int sumcol = rec.count(); int sumrow = query.numRowsAffected(); int recnum = 0 - 1; while (query.next()) { recnum++; /* count fake lines */ Fvalue.clear(); Fname.clear(); for(int i=0;i<sumcol;i++){ bool oknr; QString value = Strsqltrimmed(query.value(i).toString()); int vnummer = value.toInt(&oknr); QString fname = Strcsvtrimmed(rec.fieldName(i)); if (oknr) { Fvalue.append(value); } else if (value.isEmpty()) { Fvalue.append("NULL"); } else { Fvalue.append(QString("'%1'").arg(value)); } } QString Dvalue = Fvalue.join(","); cvslines.append(QString("INSERT INTO %1 VALUES (%2);").arg(runningtable).arg(Dvalue)); } cvslines.append("COMMIT;"); QString contentxt = cvslines.join("\n"); QTextCodec *setcurrentcodec; setcurrentcodec = QTextCodec::codecForMib(106); /* utf8 */ QFile f( cfileName ); if ( f.open( QFile::WriteOnly | QFile::Text ) ) { QTextStream sw( &f ); sw.setCodec(setcurrentcodec); sw << contentxt; f.close(); } else { QApplication::restoreOverrideCursor(); QMessageBox::information(this, tr("Error!"),tr("Unable to save to file %1").arg(cfileName)); } QApplication::restoreOverrideCursor(); } }
Xslt_Convert::Xslt_Convert( const QString xmlfile , const QString xsltfile , QString resulterxml ) :EndingJob(false),xmlcodec(0),xsltcodec(0) { ////////qDebug() << "### Start Xslt_Convert ................... ->" << UmanTimeFromUnix(QTime_Null()); qt_unlink(XMLERROR_FILE); /* remove debug or error message from last */ qt_unlink(resulterxml); /* if exist */ ///////QTimer::singleShot(1000, this, SLOT(CheckError())); QFile *xfile = new QFile( xmlfile ); if (!xfile->exists()) { emit ErrorMsg(QString("File %1 not exist!").arg(xmlfile)); return; } QFile *sfile = new QFile( xsltfile ); if (!sfile->exists()) { emit ErrorMsg(QString("File %1 not exist!").arg(xsltfile)); return; } xmlcodec = GetcodecfromXml(xmlfile); xsltcodec = GetcodecfromXml(xsltfile); ///////////qDebug() << "### xmlfile .......................... " << xmlfile; ////////qDebug() << "### xsltfile .......................... " << xsltfile; ////////qDebug() << "### codec .......................... " << xmlcodec->mibEnum(); ////////qDebug() << "### codec .......................... " << xmlcodec->name(); //////qDebug() << "### codec .......................... " << xsltcodec->mibEnum(); ////////qDebug() << "### codec .......................... " << xsltcodec->name(); const QString maildate = QString("\"%1\"").arg(UmanTimeFromUnix(QTime_Null())); const QString unixtime = QString("\"%1\"").arg(QTime_Null()); const char* params[2]; params[0] = NULL; params[1] = NULL; /* ######################################### */ xsltStylesheetPtr cur = NULL; xmlDocPtr doc, outputDoc; xmlSubstituteEntitiesDefault(1); xmlLoadExtDtdDefaultValue = 1; /* ######################################### */ char* xslt_errors; xsltSetGenericErrorFunc(&xslt_errors, qt_libxml_error_handler); xmlSetGenericErrorFunc(&xslt_errors, qt_libxml_error_handler); xsltSetGenericDebugFunc(&xslt_errors, qt_libxml_error_handler); QByteArray gocharxslt = QFile::encodeName(xsltfile); cur = xsltParseStylesheetFile( (const xmlChar*)gocharxslt.data() ); doc = xmlParseFile( QFile::encodeName(xmlfile) ); outputDoc = xsltApplyStylesheet(cur, doc, params); xmlFreeDoc( doc ); /* free ram from xml! */ doc = outputDoc; /* swap input and output */ FILE* outfile = fopen( QFile::encodeName( resulterxml ), "w" ); xsltSaveResultToFile( outfile, doc, cur ); fclose( outfile ); xsltFreeStylesheet(cur); xmlFreeDoc( outputDoc ); xsltCleanupGlobals(); xmlCleanupParser(); //////// qDebug() << "### resulterxml .......................... " << resulterxml; //////// qDebug() << "### XMLERROR_FILE .......................... " << XMLERROR_FILE; Rstream = StreamFromFile(resulterxml); debug_msg = ReadFileUtf8Xml(XMLERROR_FILE); /////////qDebug() << "### resulterxml .......................... " << debug_msg; qt_unlink(XMLERROR_FILE); EndingJob = true; emit DebugMsg(debug_msg); }