return alias;
}
- void iterateResolvablesByKind( zypp::Resolvable::Kind kind, ProcessResolvable fnc )
+ data::RecordId queryRepositoryId( const std::string &repo_alias )
{
- sqlite3_command cmd( _con, "select " + _fields + " from resolvables where kind=:kind;");
- data::RecordId kind_id = _type_cache.idForKind( kind );
- cmd.bind(":kind", kind_id);
+ long long id = 0;
+ sqlite3_command cmd( _con, "select id from repositories where alias=:alias;" );
+ cmd.bind( ":alias", repo_alias );
sqlite3_reader reader = cmd.executereader();
- while(reader.read())
+ while( reader.read() )
{
- fnc( reader.getint64(0), fromRow(reader) );
+ id = reader.getint64(0);
+ break;
}
+ return id;
}
- void iterateResolvablesByKindsAndStrings( const std::vector<zypp::Resolvable::Kind> & kinds,
- const std::vector<std::string> &strings, int flags, ProcessResolvable fnc )
+ void iterateResolvablesByKindsAndStringsAndRepos( const std::vector<zypp::Resolvable::Kind> & kinds,
+ const std::vector<std::string> &strings, int flags, const std::vector<std::string> repos, ProcessResolvable fnc )
{
- std::string sqlcmd( "SELECT " + _fields + " FROM resolvables WHERE (" );
+ std::string sqlcmd( "SELECT " + _fields + " FROM resolvables" );
+
std::vector<std::string>::const_iterator it_s;
for (it_s = strings.begin(); it_s != strings.end(); ++it_s)
{
std::string s( *it_s );
- if (it_s != strings.begin())
- sqlcmd += "AND";
+ if (it_s == strings.begin())
+ sqlcmd += " WHERE (";
+ else
+ sqlcmd += " AND ";
//FIXME: Implement MATCH_RESSUMM and MATCH_RESDESC
sqlcmd += s;
sqlcmd += "'";
}
- sqlcmd += ") AND kind IN (";
+
+ if (it_s != strings.begin())
+ {
+ sqlcmd += ")";
+ }
std::vector<zypp::Resolvable::Kind>::const_iterator it_k;
- for (it_k = kinds.begin(); it_k != kinds.end(); ++it_k)
+ if (!kinds.empty())
{
+ if (it_s == strings.begin())
+ sqlcmd += " WHERE";
+ else
+ sqlcmd += " AND";
+
+ for (it_k = kinds.begin(); it_k != kinds.end(); ++it_k)
+ {
+ if (it_k == kinds.begin())
+ sqlcmd += " kind IN (";
+ else
+ sqlcmd += ", ";
+
+ char idbuf[16];
+ snprintf( idbuf, 15, "%d", (int)(_type_cache.idForKind( *it_k )) );
+ sqlcmd += idbuf;
+ }
+
if (it_k != kinds.begin())
- sqlcmd += ", ";
- char idbuf[16];
- snprintf( idbuf, 15, "%d", (int)(_type_cache.idForKind( *it_k )) );
- sqlcmd += idbuf;
+ {
+ sqlcmd += ")";
+ }
+ }
+
+ std::vector<std::string>::const_iterator it_r;
+ if (!repos.empty())
+ {
+ if (it_s == strings.begin()
+ && it_k == kinds.begin())
+ sqlcmd += " WHERE";
+ else
+ sqlcmd += " AND";
+
+ for (it_r = repos.begin(); it_r != repos.end(); ++it_r)
+ {
+ if (it_r == repos.begin())
+ sqlcmd += " (";
+ else
+ sqlcmd += " OR ";
+
+ sqlcmd += "repository_id = ";
+ char idbuf[16];
+ snprintf( idbuf, 15, "%ld", (long)(queryRepositoryId( *it_r )) );
+ sqlcmd += idbuf;
+ }
+
+ if (it_r != repos.begin())
+ {
+ sqlcmd += ")";
+ }
}
- sqlite3_command cmd( _con, sqlcmd + ")");
+MIL << "sqlcmd " << sqlcmd << endl;
+ sqlite3_command cmd( _con, sqlcmd );
sqlite3_reader reader = cmd.executereader();
while(reader.read())
{
return _pimpl->queryRepositoryAlias( repo_id );
}
-void ResolvableQuery::iterateResolvablesByKind( zypp::Resolvable::Kind kind, ProcessResolvable fnc )
-{
- return _pimpl->iterateResolvablesByKind( kind, fnc );
-}
-
-void ResolvableQuery::iterateResolvablesByKindsAndStrings( const std::vector<zypp::Resolvable::Kind> & kinds,
- const std::vector<std::string> &strings, int flags, ProcessResolvable fnc )
+void ResolvableQuery::iterateResolvablesByKindsAndStringsAndRepos( const std::vector<zypp::Resolvable::Kind> & kinds,
+ const std::vector<std::string> &strings, int flags, const std::vector<std::string> &repos, ProcessResolvable fnc )
{
- _pimpl->iterateResolvablesByKindsAndStrings( kinds, strings, flags, fnc );
+ _pimpl->iterateResolvablesByKindsAndStringsAndRepos( kinds, strings, flags, repos, fnc );
}
//////////////////////////////////////////////////////////////////////////////
std::string queryRepositoryAlias( const data::RecordId &repo_id );
/**
- * \short Iterate resolvables by Kind
+ * \short Query repo id by alias
*/
- void iterateResolvablesByKind( zypp::Resolvable::Kind kind, ProcessResolvable fnc );
+ data::RecordId queryRepositoryId( const std::string &repo_alias );
/**
* \short Iterate resolvables by Kinds and Strings
* \param kinds kinds to match, will be ORed
* \param names names to match, will be ANDed
- * \param flags MATCH_xxx, see above
+ * \param repos repository aliases to match, will be ORed
+ * \param flags MATCH_xxx, see above; applied to 'names'
* \param fnc callback to send the data to. (Will be called once per result)
*
* Beware: Searching for multiple strings with MATCH_EXACT will _not_ find anything, except if all strings are identical ...
*/
- void iterateResolvablesByKindsAndStrings( const std::vector<zypp::Resolvable::Kind> & kinds,
- const std::vector<std::string> &strings, int flags, ProcessResolvable fnc );
+ void iterateResolvablesByKindsAndStringsAndRepos( const std::vector<zypp::Resolvable::Kind> & kinds,
+ const std::vector<std::string> &names, int flags, const std::vector<std::string> &repos, ProcessResolvable fnc );
private:
/** Implementation. */