void vleSmDT::xCreateDom() { if (not mDocSm) { mDocSm = new QDomDocument("vle_project_metadata"); QDomProcessingInstruction pi; pi = mDocSm->createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\" "); mDocSm->appendChild(pi); QDomElement vpmRoot = mDocSm->createElement("vle_project_metadata"); // Save VPZ file revision vpmRoot.setAttribute("version", "1.x"); // Save the author name (if known) vpmRoot.setAttribute("author", "meto"); QDomElement xCondPlug = mDocSm->createElement("variables"); vpmRoot.appendChild(xCondPlug); xCondPlug = mDocSm->createElement("compute"); vpmRoot.appendChild(xCondPlug); xCondPlug = mDocSm->createElement("srcPlugin"); xCondPlug.setAttribute("name", mpluginName); vpmRoot.appendChild(xCondPlug); QDomElement elem = createDynamic(); vpmRoot.appendChild(elem); elem = createObservable(); vpmRoot.appendChild(elem); elem = createCondition(); vpmRoot.appendChild(elem); elem = createIn(); vpmRoot.appendChild(elem); elem = createOut(); vpmRoot.appendChild(elem); mDocSm->appendChild(vpmRoot); } }
int main(int argc, char *argv[]) { QString title; title = title + "****************************************************************** \n"; title = title + " * MySQLtoFile 1.0 * \n"; title = title + " * This tool exports a table in a MySQL schema to various file * \n"; title = title + " * formats like STATA, SPSS, CSV (tab delimited), JSON and XML * \n"; title = title + " * This tool is part of CSPro Tools (c) ILRI, 2013 * \n"; title = title + " ****************************************************************** \n"; TCLAP::CmdLine cmd(title.toAscii().data(), ' ', "1.0 (Beta 1)"); //Required arguments TCLAP::ValueArg<std::string> hostArg("H","host","MySQL host. Default localhost",false,"localhost","string"); TCLAP::ValueArg<std::string> portArg("P","port","MySQL port. Default 3306.",false,"3306","string"); TCLAP::ValueArg<std::string> userArg("u","user","User to connect to MySQL",true,"","string"); TCLAP::ValueArg<std::string> passArg("p","password","Password to connect to MySQL",true,"","string"); TCLAP::ValueArg<std::string> schemaArg("s","schema","Schema in MySQL",true,"","string"); TCLAP::ValueArg<std::string> auditArg("a","audit","Target directory for the audit files. Default ./audit (created if not exists)",false,"./audit","string"); TCLAP::SwitchArg createSwitch("c","create","Create META dictionary tables", cmd, false); TCLAP::SwitchArg loadSwitch("l","load","Load META dictionary tables", cmd, false); TCLAP::SwitchArg deleteSwitch("d","delete","Delete previous data before load", cmd, false); TCLAP::SwitchArg viewSwitch("v","views","Include views in dictionary tables", cmd, false); cmd.add(hostArg); cmd.add(portArg); cmd.add(userArg); cmd.add(passArg); cmd.add(schemaArg); cmd.add(auditArg); cmd.parse( argc, argv ); //Getting the variables from the command bool createMETA; bool loadMETA; bool deldata; bool includeViews; createMETA = createSwitch.getValue(); loadMETA = loadSwitch.getValue(); deldata = deleteSwitch.getValue(); includeViews = viewSwitch.getValue(); QString host = QString::fromUtf8(hostArg.getValue().c_str()); QString port = QString::fromUtf8(portArg.getValue().c_str()); QString user = QString::fromUtf8(userArg.getValue().c_str()); QString pass = QString::fromUtf8(passArg.getValue().c_str()); QString schema = QString::fromUtf8(schemaArg.getValue().c_str()); QString auditPath = QString::fromUtf8(auditArg.getValue().c_str()); //Dictionary tables ignoreTables << "dict_grpinfo"; ignoreTables << "dict_tblinfo"; ignoreTables << "dict_clminfo"; ignoreTables << "dict_relinfo"; ignoreTables << "dict_childinfo"; ignoreTables << "audit_log"; //Authorisation tables Not used since 2015-03-19. Backward compatibility ignoreTables << "auth_group"; ignoreTables << "auth_group_permissions"; ignoreTables << "auth_permission"; ignoreTables << "auth_user"; ignoreTables << "auth_user_groups"; ignoreTables << "auth_user_user_permissions"; ignoreTables << "user_log"; //Django tables Not used since 2014. Backward compatibility ignoreTables << "auth_message"; ignoreTables << "django_admin_log"; ignoreTables << "django_content_type"; ignoreTables << "django_session"; ignoreTables << "django_site"; //I18N tables ignoreTables << "dict_iso639"; ignoreTables << "dict_lkpiso639"; ignoreTables << "dict_dctiso639"; { QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName(host); db.setPort(port.toInt()); db.setDatabaseName(schema); db.setUserName(user); db.setPassword(pass); bool METACreated; METACreated = false; bool METALoaded; METALoaded = false; bool deletePrevious; deletePrevious = false; QString data; if (db.open()) { getTableOrder(db); if (createMETA) { log("Are you sure that you want to create META's tables? This will delete any previous META information INCLUDING the audit. (Y/N): ",false); QTextStream createIn(stdin); data = createIn.readLine(); if (data.toUpper().simplified() == "Y") { if (createMETATables(db) == 0) METACreated = true; else return 1; } } if (loadMETA) { if (deldata && !createMETA) { log("Are you sure that you want to delete any previous META's data? This WILL NOT delete the audit. (Y/N): ",false); QTextStream deleteIn(stdin); data = deleteIn.readLine(); if (data.toUpper().simplified() == "Y") { deletePrevious = true; } } if (loadMETATables(db,deletePrevious,includeViews) == 0) METALoaded = true; else return 1; } createMETAAudit(db,auditPath); if (METACreated && !METALoaded) { log("META was created but not information was loaded. Use initmeta -l to load METAS's information"); } } else { log("Cannot connect to database"); log(db.lastError().databaseText()); return 1; } } return 0; }