RepoInfo Storage::GetRepo (int repoId) { QueryGetRepo_.bindValue (":repo_id", repoId); if (!QueryGetRepo_.exec ()) { Util::DBLock::DumpError (QueryGetRepo_); throw std::runtime_error ("Query execution failed."); } if (!QueryGetRepo_.next ()) { qWarning () << Q_FUNC_INFO << "could not position on next record"; throw std::runtime_error ("Could not position on next record"); } RepoInfo result (QUrl::fromEncoded (QueryGetRepo_.value (0).toString ().toUtf8 ())); result.SetName (QueryGetRepo_.value (1).toString ()); result.SetShortDescr (QueryGetRepo_.value (2).toString ()); result.SetLongDescr (QueryGetRepo_.value (3).toString ()); MaintainerInfo info = { QueryGetRepo_.value (4).toString (), QueryGetRepo_.value (5).toString () }; result.SetMaintainer (info); QueryGetRepo_.finish (); result.SetComponents (GetComponents (repoId)); return result; }
RepoInfo ParseRepoInfo (const QUrl& url, const QString& data) { QXmlQuery query; query.setFocus (data); RepoInfo info (url); QString out; query.setQuery ("/repo/name/text()"); if (!query.evaluateTo (&out)) throw QObject::tr ("Could not get repo name."); info.SetName (out.simplified ()); query.setQuery ("/repo/description/short/text()"); if (!query.evaluateTo (&out)) throw QObject::tr ("Could not get repo description."); info.SetShortDescr (out.simplified ()); query.setQuery ("/repo/description/long/text()"); if (!query.evaluateTo (&out)) throw QObject::tr ("Could not get long repo description."); info.SetLongDescr (out.simplified ()); MaintainerInfo maintInfo; query.setQuery ("/repo/maintainer/name/text()"); if (!query.evaluateTo (&out)) throw QObject::tr ("Could not get maintainer name."); maintInfo.Name_ = out.simplified (); query.setQuery ("/repo/maintainer/email/text()"); if (!query.evaluateTo (&out)) throw QObject::tr ("Could not get maintainer email."); maintInfo.Email_ = out.simplified (); info.SetMaintainer (maintInfo); QStringList components; query.setQuery ("/repo/components/component/text()"); if (query.evaluateTo (&components)) info.SetComponents (components); else if (query.evaluateTo (&out)) info.SetComponents (QStringList (out)); else throw QObject::tr ("Could not get components."); return info; }