- fix ResolvableQuery::query(), add ResolvableQuery::queryByName()
authorKlaus Kaempf <kkaempf@suse.de>
Thu, 16 Aug 2007 21:45:52 +0000 (21:45 +0000)
committerKlaus Kaempf <kkaempf@suse.de>
Thu, 16 Aug 2007 21:45:52 +0000 (21:45 +0000)
- install zypp/cache header files.

package/libzypp.changes
zypp/CMakeLists.txt
zypp/cache/ResolvableQuery.cc
zypp/cache/ResolvableQuery.h

index 399da71..acaf381 100644 (file)
@@ -1,4 +1,11 @@
 -------------------------------------------------------------------
+Thu Aug 16 23:43:50 CEST 2007 - kkaempf@suse.de
+
+- fix ResolvableQuery::query(), add ResolvableQuery::queryByName()
+  install zypp/cache header files.
+- rev 6719
+
+-------------------------------------------------------------------
 Thu Aug 16 17:21:52 CEST 2007 - kkaempf@suse.de
 
 - discard pattern files with incompatbile architecture, both
index 4ffd1c6..536e584 100644 (file)
@@ -900,10 +900,10 @@ SET( zypp_cache_HEADERS
   cache/Utils.h
 )
 
-#INSTALL(  FILES
-#  ${zypp_cache_HEADERS}
-#  DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/cache
-#)
+INSTALL(  FILES
+  ${zypp_cache_HEADERS}
+  DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/cache
+)
 
 SET( zypp_cache_sqlite3x_SRCS
   cache/sqlite3x/sqlite3x_command.cpp
index dbf509e..75da55f 100644 (file)
@@ -68,17 +68,13 @@ struct ResolvableQuery::Impl
   void query( const data::RecordId &id,
                   ProcessResolvable fnc )
   {
-    sqlite3_connection con((_dbdir + "zypp.db").asString().c_str());
-    //con.executenonquery("PRAGMA cache_size=8000;");
-    con.executenonquery("BEGIN;");
-    sqlite3_command cmd( con, "select " + _fields + " from resolvables where id=:id;");
+    sqlite3_command cmd( _con, "select " + _fields + " from resolvables where id=:id;");
     cmd.bind(":id", id);
     sqlite3_reader reader = cmd.executereader();
     while(reader.read())
     {
       fnc( id, fromRow(reader) );
     }
-    con.executenonquery("COMMIT;");
   }
 
 
@@ -86,17 +82,38 @@ struct ResolvableQuery::Impl
               ProcessResolvable fnc  )
   {  
     
-    sqlite3_connection con((_dbdir + "zypp.db").asString().c_str());
-    //con.executenonquery("PRAGMA cache_size=8000;");
-    con.executenonquery("BEGIN;");
-    sqlite3_command cmd( con, "select " + _fields + " from resolvables where name like :name;");
+    sqlite3_command cmd( _con, "select " + _fields + " from resolvables where name like :name;");
     cmd.bind(":name", string("%") + s + "%");
     sqlite3_reader reader = cmd.executereader();
     while(reader.read())
     {
       fnc( reader.getint64(0), fromRow(reader) );
     }
-    con.executenonquery("COMMIT;");
+  }
+
+  void queryByName( const std::string &name, int wild, ProcessResolvable fnc  )
+  {
+    std::string sqlcmd = "select " + _fields + " from resolvables where name ";
+    std::string s( name );
+    if (wild == 0)
+    {
+      sqlcmd += "=";
+    }
+    else
+    {
+      sqlcmd += "like";
+    }
+    sqlite3_command cmd( _con, sqlcmd + " :name;");
+    if (wild & 1)
+      s += "%";
+    if (wild & 2)
+      s = string("%") + s;
+    cmd.bind( ":name", s );
+    sqlite3_reader reader = cmd.executereader();
+    while(reader.read())
+    {
+      fnc( reader.getint64(0), fromRow(reader) );
+    }
   }
 
 
@@ -158,6 +175,20 @@ struct ResolvableQuery::Impl
       du.add(entry);
     }
   }
+
+  std::string queryRepositoryAlias( const data::RecordId &repo_id )
+  {
+    std::string alias;
+    sqlite3_command cmd( _con, "select alias from repositories where id=:id;" );
+    cmd.bind( ":id", repo_id );
+    sqlite3_reader reader = cmd.executereader();
+    while( reader.read() )
+    {
+      alias = reader.getstring( 0 );
+      break;
+    }
+    return alias;
+  }
   
 private:
 
@@ -329,6 +360,16 @@ void ResolvableQuery::queryDiskUsage( const data::RecordId &record_id, DiskUsage
   _pimpl->queryDiskUsage(record_id, du);
 }
 
+std::string ResolvableQuery::queryRepositoryAlias( const data::RecordId &repo_id )
+{
+  return _pimpl->queryRepositoryAlias( repo_id );
+}
+
+void ResolvableQuery::queryByName( const std::string &name, int wild, ProcessResolvable fnc  )
+{
+  _pimpl->queryByName( name, wild, fnc );
+}
+
 //////////////////////////////////////////////////////////////////////////////
 
 } } // namespace zypp::cache
index 3963e8f..eaf92db 100644 (file)
@@ -220,6 +220,21 @@ namespace zypp
        */
       void queryDiskUsage( const data::RecordId &record_id,
                            DiskUsage &du );
+
+      /**
+       * \short Query repo alias by id
+       */
+      std::string queryRepositoryAlias( const data::RecordId &repo_id );
+
+      /**
+      * Query by matching name
+      * \param name name to match
+      * \param wild 0 = no wild, 1 = trailing wild, 2 = leading wild, 3 = trailing & leading wild
+      * \param fnc callback to send the data to. (Will be called once per result)
+      */
+      void queryByName( const std::string &name, int wild,
+                  ProcessResolvable fnc  );
+
     private:
       /** Implementation. */
       class Impl;