QString FLManager::formatAssignValue(FLFieldMetaData *fMD, const QVariant &v, const bool upper) { if (!fMD) return "1 = 1"; FLTableMetaData *mtd = fMD->metadata(); QString fieldName(fMD->name()); if (mtd && mtd->isQuery()) { QString prefixTable(mtd->name()); FLSqlQuery *qry = query(mtd->query()); if (qry) { QStringList fL(qry->fieldList()); for (QStringList::Iterator it = fL.begin(); it != fL.end(); ++it) { prefixTable = (*it).section('.', 0, 0); if ((*it).section('.', 1, 1) == fieldName) break; } qry->deleteLater(); } fieldName.prepend(prefixTable + "."); } return formatAssignValue(fieldName, fMD->type(), v, upper); }
bool FLVar::set(const QString &n, const QVariant &v) { QString idSesion(aqApp->timeUser().toString(Qt::ISODate)); QString where(QString::fromLatin1("idvar='") + n + QString::fromLatin1("' AND idsesion='") + idSesion + QString::fromLatin1("'")); FLSqlQuery q; q.setTablesList("flvar"); q.setSelect("id"); q.setFrom("flvar"); q.setWhere(where); q.setForwardOnly(true); if (!q.exec()) return false; if (q.next()) return FLUtil::sqlUpdate("flvar", "valor", v.toString(), QString::fromLatin1("id='") + q.value(0).toString() + QString::fromLatin1("'")); QString values(n + QString::fromLatin1(",") + idSesion + QString::fromLatin1(",") + v.toString()); return FLUtil::sqlInsert("flvar", "idvar,idsesion,valor", values); }
void FLAccessControlLists::makeRuleGroup(FLSqlQuery *q, QDomDocument *d, const QString &idgroup) { if (idgroup.isEmpty() || !q || !d) return; FLSqlQuery qU; qU.setTablesList("flusers"); qU.setSelect("iduser"); qU.setFrom("flusers"); qU.setWhere(QString::fromLatin1("idgroup='") + idgroup + QString::fromLatin1("'")); qU.setForwardOnly(true); if (qU.exec()) while (qU.next()) makeRuleUser(q, d, qU.value(0).toString()); }
void FLAccessControlLists::installACL(const QString &idacl) { QDomDocument doc("ACL"); QDomElement root = doc.createElement("ACL"); doc.appendChild(root); QDomElement name = doc.createElement("name"); root.appendChild(name); QDomText n = doc.createTextNode(idacl); name.appendChild(n); FLSqlQuery q; q.setTablesList("flacs"); q.setSelect("idac,tipo,nombre,iduser,idgroup,degrupo,permiso"); q.setFrom("flacs"); q.setWhere(QString::fromLatin1("idacl='") + idacl + QString::fromLatin1("'")); q.setOrderBy("prioridad DESC,tipo"); q.setForwardOnly(true); if (q.exec()) { uint step = 0; QProgressDialog progress(QApplication::tr("Instalando control de acceso..."), 0, q.size(), 0, 0, true); progress.setCaption(QApplication::tr("Instalando ACL")); progress.setMinimumDuration(0); progress.setProgress(++step); while (q.next()) { makeRule(&q, &doc); progress.setProgress(++step); } FLSqlConnections::database()->managerModules()->setContent("acl.xml", "sys", doc.toString()); } }
void FLAccessControlLists::makeRuleUser(FLSqlQuery *q, QDomDocument *d, const QString &iduser) { if (iduser.isEmpty() || !q || !d) return; FLAccessControl *ac = FLAccessControlFactory::create(q->value(1).toString()); if (ac) { ac->setName(q->value(2).toString()); ac->setUser(iduser); ac->setPerm(q->value(6).toString()); FLSqlQuery qAcos; qAcos.setTablesList("flacos"); qAcos.setSelect("nombre,permiso"); qAcos.setFrom("flacos"); qAcos.setWhere(QString::fromLatin1("idac='") + q->value(0).toString() + QString::fromLatin1("'")); qAcos.setForwardOnly(true); QStringList acos; if (qAcos.exec()) { while (qAcos.next()) { acos << qAcos.value(0).toString(); acos << qAcos.value(1).toString(); } } ac->setAcos(acos); ac->get(d); delete ac; } }
FLSqlQuery *FLManager::query(const QString &n, QObject *parent) { FLSqlQuery *q; QDomDocument doc(n); if (!FLUtil::domDocumentSetContent( doc, db_->managerModules()->contentCached(n + QString::fromLatin1(".qry")) )) { #ifdef FL_DEBUG qWarning("FLManager : " + QApplication::tr("Error al cargar la consulta %1").arg(n)); #endif return 0; } q = new FLSqlQuery(parent, db_->connectionName()); QDomElement docElem = doc.documentElement(); QDomNode no = docElem.firstChild(); while (!no.isNull()) { QDomElement e = no.toElement(); if (!e.isNull()) { if (e.tagName() == "name") { q->setName(e.text()); no = no.nextSibling(); continue; } if (e.tagName() == "tables") { q->setTablesList(e.text()); no = no.nextSibling(); continue; } if (e.tagName() == "select") { q->setSelect(e.text()); no = no.nextSibling(); continue; } if (e.tagName() == "from") { q->setFrom(e.text()); no = no.nextSibling(); continue; } if (e.tagName() == "where") { q->setWhere(e.text()); no = no.nextSibling(); continue; } if (e.tagName() == "param") { q->addParameter(queryParameter(&e)); no = no.nextSibling(); continue; } if (e.tagName() == "group") { q->addGroup(queryGroup(&e)); no = no.nextSibling(); continue; } if (e.tagName() == "order") { q->setOrderBy(e.text()); no = no.nextSibling(); continue; } } no = no.nextSibling(); } return q; }
FLTableMetaData *FLManager::metadata(QDomElement *mtd, bool quick) { if (!mtd) return 0; QString name, a, q; bool v = true, ed = true, cw = true, dl = false; QDomNode no = mtd->firstChild(); while (!no.isNull()) { QDomElement e = no.toElement(); if (!e.isNull()) { if (e.tagName() == "field") { no = no.nextSibling(); continue; } if (e.tagName() == "name") { name = e.text(); no = no.nextSibling(); continue; } if (e.tagName() == "query") { q = e.text(); no = no.nextSibling(); continue; } if (e.tagName() == "alias") { a = e.text().mid(30, e.text().length() - 32); a = FLUtil::translate("MetaData", a); no = no.nextSibling(); continue; } if (e.tagName() == "visible") { v = (e.text() == "true"); no = no.nextSibling(); continue; } if (e.tagName() == "editable") { ed = (e.text() == "true"); no = no.nextSibling(); continue; } if (e.tagName() == "concurWarn") { cw = (e.text() == "true"); no = no.nextSibling(); continue; } if (e.tagName() == "detectLocks") { dl = (e.text() == "true"); no = no.nextSibling(); continue; } } no = no.nextSibling(); } FLTableMetaData *tmd = new FLTableMetaData(name, a, q); FLCompoundKey *cK = 0; QStringList assocs; tmd->setConcurWarn(cw); tmd->setDetectLocks(dl); no = mtd->firstChild(); while (!no.isNull()) { QDomElement e = no.toElement(); if (!e.isNull()) { if (e.tagName() == "field") { FLFieldMetaData *f = metadataField(&e, v, ed); if (!tmd) tmd = new FLTableMetaData(name, a, q); tmd->addFieldMD(f); if (f->isCompoundKey()) { if (!cK) cK = new FLCompoundKey(); cK->addFieldMD(f); } if (!f->associatedFieldName().isEmpty()) { assocs.append(f->associatedFieldName()); assocs.append(f->associatedFieldFilterTo()); assocs.append(f->name()); } no = no.nextSibling(); continue; } } no = no.nextSibling(); } tmd->setCompoundKey(cK); QString aWith, aBy; for (QStringList::Iterator it = assocs.begin(); it != assocs.end(); ++it) { aWith = (*it); ++it; aBy = (*it); ++it; tmd->field((*it))->setAssociatedField(tmd->field(aWith), aBy); } if (!q.isEmpty() && !quick) { FLSqlQuery *qry = query(q, tmd); if (qry) { QStringList fL = qry->fieldList(); QString table, field; QString fields = tmd->fieldsNames(); for (QStringList::Iterator it = fL.begin(); it != fL.end(); ++it) { table = (*it).section('.', 0, 0); field = (*it).section('.', 1, 1); if (table == name || fields.contains(field.lower())) continue; FLTableMetaData *mtdAux = metadata(table, true); if (mtdAux) { FLFieldMetaData *fmtdAux = mtdAux->field(field); if (fmtdAux) { int typeAux = fmtdAux->type(); if (typeAux == FLFieldMetaData::Serial) typeAux = QVariant::UInt; tmd->addFieldMD(new FLFieldMetaData(field, fmtdAux->alias(), true, false, typeAux, fmtdAux->length(), false, fmtdAux->visible(), fmtdAux->editable(), fmtdAux->partInteger(), fmtdAux->partDecimal(), false, false, false, QVariant(), false, QString::null, fmtdAux->visibleGrid(), true, false)); } } } qry->deleteLater(); } } FLAccessControlLists *acl = aqApp ->acl(); if (acl) acl->process(tmd); return tmd; }