- rename ResolvableQuery::iterateResolvablesByKindsAndStrings
authorKlaus Kaempf <kkaempf@suse.de>
Tue, 28 Aug 2007 15:38:01 +0000 (15:38 +0000)
committerKlaus Kaempf <kkaempf@suse.de>
Tue, 28 Aug 2007 15:38:01 +0000 (15:38 +0000)
  to ResolvableQuery::iterateResolvablesByKindsAndStringsAndRepos
  in order to support query-by-repo (#305384)
- fix iterateResolvablesByKindsAndStringsAndRepos to take any
  number of kinds, names, or repos (#305347)
- remove ResolvableQuery::iterateResolvablesByKind, not needed
- version 3.19.0
- rev 6935

VERSION.cmake
package/libzypp.changes
zypp/cache/ResolvableQuery.cc
zypp/cache/ResolvableQuery.h

index 43b12e6..ed960f8 100644 (file)
@@ -45,6 +45,6 @@
 #
 
 SET(LIBZYPP_MAJOR "3")
-SET(LIBZYPP_MINOR "18")
-SET(LIBZYPP_COMPATMINOR "13")
-SET(LIBZYPP_PATCH "4")
+SET(LIBZYPP_MINOR "19")
+SET(LIBZYPP_COMPATMINOR "0")
+SET(LIBZYPP_PATCH "0")
index 0208119..3ccdedd 100644 (file)
@@ -1,4 +1,16 @@
 -------------------------------------------------------------------
+Tue Aug 28 17:30:30 CEST 2007 - kkaempf@suse.de
+
+- rename ResolvableQuery::iterateResolvablesByKindsAndStrings
+  to ResolvableQuery::iterateResolvablesByKindsAndStringsAndRepos
+  in order to support query-by-repo (#305384)
+- fix iterateResolvablesByKindsAndStringsAndRepos to take any
+  number of kinds, names, or repos (#305347)
+- remove ResolvableQuery::iterateResolvablesByKind, not needed
+- version 3.19.0
+- rev 6935
+
+-------------------------------------------------------------------
 Tue Aug 28 11:27:53 CEST 2007 - duncan@suse.de
 
 - real fix for reading signature ids. (#390535).  
index 9979d0c..25471d3 100644 (file)
@@ -186,29 +186,34 @@ struct ResolvableQuery::Impl
     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
 
@@ -231,19 +236,68 @@ struct ResolvableQuery::Impl
       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())
     {
@@ -426,15 +480,10 @@ std::string ResolvableQuery::queryRepositoryAlias( const data::RecordId &repo_id
   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 );
 }
 //////////////////////////////////////////////////////////////////////////////
 
index 1904107..1e4765c 100644 (file)
@@ -243,21 +243,22 @@ namespace zypp
       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. */