Esempio n. 1
0
bool FLManager::checkMetaData(const QString &n)
{
#ifndef FL_QUICK_CLIENT
  QDomDocument doc(n);
  QDomElement docElem;

  QString mtd1 = db_->managerModules()->contentCached(n + ".mtd");
  if (!db_->dbAux())
    return true;

  QString mtd2;
  QSqlCursor c("flmetadata", true, db_->dbAux());
  c.setForwardOnly(true);
  c.setFilter(QString::fromLatin1("tabla='") + n + QString::fromLatin1("'"));
  c.select();
  if (c.next())
    mtd2 = c.value("xml").toString();
  else
    return true;

  return !!checkMetaData(mtd1, mtd2);
#else
  return true;
#endif
}
Preference PhononItem::preference() const {
    checkMetaData();
    return MetaDataObject::preference();
}
QString PhononItem::comment() const {
    checkMetaData();
    return MetaDataObject::comment();
}
QTime PhononItem::trackTime() const {
    checkMetaData();
    return MetaDataObject::trackTime();
}
QString PhononItem::trackNumber() const {
    checkMetaData();
    return MetaDataObject::trackNumber();
}
QString PhononItem::albumTitle() const {
    checkMetaData();
    return MetaDataObject::albumTitle();
}
QString PhononItem::artist() const {
    checkMetaData();
    return MetaDataObject::artist();
}
QString PhononItem::genre() const {
    checkMetaData();
    return MetaDataObject::genre();
}
Esempio n. 9
0
FLTableMetaData *FLManager::metadata(const QString &n, bool quick)
{
  if (n.isEmpty() || !db_->dbAux())
    return 0;

  FLTableMetaData *ret = 0;
  QDomDocument doc(n);
  QDomElement docElem;

  QString key;
  QString *dictKey = 0;
  QString stream = db_->managerModules()->contentCached(n + QString::fromLatin1(".mtd"), &key);
  bool newTable = false;
  bool notSysTable = n.left(3) != "sys" && !isSystemTable(n);

  if (!notSysTable)
    dictKey = new QString(n);

#ifndef FL_QUICK_CLIENT
  if (!quick) {
    if (db_->canRegenTables() && notSysTable) {
      QSqlRecord *buffer = 0;
      QString key2;
      delete dictKey;
      dictKey = dictKeyMetaData_->find(n);
      if (dictKey)
        key2 = *dictKey;
      if (key2.isEmpty()) {
        QSqlCursor c("flmetadata", true, db_->dbAux());
        c.setForwardOnly(true);
        c.setFilter(QString::fromLatin1("tabla='") + n + QString::fromLatin1("'"));
        c.select();
        if (c.next()) {
          c.primeDelete();
          c.del();
        }
        buffer = c.primeInsert();
        buffer->setValue("tabla", n);
        if (key.isEmpty()) {
          buffer->setValue("xml", stream);
          dictKey = new QString(stream);
          dictKeyMetaData_->replace(n, dictKey);
        } else {
          buffer->setValue("xml", key);
          dictKey = new QString(key);
          dictKeyMetaData_->replace(n, dictKey);
        }
        newTable = true;
        c.insert();
      } else {
        if (key != key2) {
          QString s;
          if (key2.left(255).find("<!DOCTYPE TMD>", 0, true) == -1)
            AQ_DISKCACHE_FIND(key2, s);
          else
            s = key2;
          bool mustAlter;
          if (key.isEmpty())
            mustAlter = !checkMetaData(s, stream);
          else
            mustAlter = (key != key2);
          if (mustAlter) {
            if (alterTable(s, stream, key2)) {
              QSqlCursor c("flmetadata", true, db_->dbAux());
              c.setForwardOnly(true);
              c.setFilter(QString::fromLatin1("tabla='") + n + QString::fromLatin1("'"));
              c.select();
              c.next();
              buffer = c.primeUpdate();
              if (key.isEmpty()) {
                buffer->setValue("xml", stream);
                dictKey = new QString(stream);
                dictKeyMetaData_->replace(n, dictKey);
              } else {
                buffer->setValue("xml", key);
                dictKey = new QString(key);
                dictKeyMetaData_->replace(n, dictKey);
              }
              c.update();
            }
          }
        }
      }
    }
  } else {
    if (key.isEmpty())
      dictKey = new QString(n);
    else
      dictKey = new QString(key);
  }
#else
  if (key.isEmpty())
    dictKey = new QString(n);
  else
    dictKey = new QString(key);
#endif //FL_QUICK_CLIENT
  if (dictKey) {
    if (cacheMetaData_ && notSysTable) {
      ret = cacheMetaData_->find(*dictKey);
    } else if (cacheMetaDataSys_ && !notSysTable) {
      ret = cacheMetaDataSys_->find(*dictKey);
    }
    if (ret) {
      FLAccessControlLists *acl = aqApp ->acl();
      if (acl)
        acl->process(ret);
      if (quick)
        delete dictKey;
      return ret;
    }
  }

  if (!FLUtil::domDocumentSetContent(doc, stream)) {
#ifdef FL_DEBUG
    qWarning("FLManager : " + QApplication::tr("Error al cargar los metadatos para la tabla %1").arg(n));
#endif
    if (quick)
      delete dictKey;
#ifdef FL_QUICK_CLIENT
    else
      delete dictKey;
#endif
    return 0;
  }

  docElem = doc.documentElement();
  ret = metadata(&docElem, quick);
  if (dictKey &&
      (!notSysTable || (!ret->isQuery() && ret->fieldsNamesUnlock().isEmpty()))) {
    if (cacheMetaData_ && notSysTable) {
      cacheMetaData_->insert(*dictKey, ret);
    } else if (cacheMetaDataSys_ && !notSysTable) {
      cacheMetaDataSys_->insert(*dictKey, ret);
    }
    if (quick)
      delete dictKey;
#ifdef FL_QUICK_CLIENT
    else
      delete dictKey;
#endif
  }
  return ret;
}