- create resolvables (basically bring back old api so we
[platform/upstream/libzypp.git] / zypp / cache / ResolvableQuery.cc
index 25471d3..2aefa90 100644 (file)
@@ -25,6 +25,7 @@ struct ResolvableQuery::Impl
   sqlite3_command_ptr _cmd_attr_tstr;
   sqlite3_command_ptr _cmd_attr_num;
   sqlite3_command_ptr _cmd_disk_usage;
+  sqlite3_command_ptr _cmd_shared_id;
 
   Impl( const Pathname &dbdir)
   : _dbdir(dbdir)
@@ -33,6 +34,8 @@ struct ResolvableQuery::Impl
     _con.open((dbdir + "zypp.db").asString().c_str());
     _con.executenonquery("PRAGMA cache_size=8000;");
 
+    _cmd_shared_id.reset( new sqlite3_command( _con, "select shared_id from resolvables where id=:rid;") );
+
     _cmd_attr_tstr.reset( new sqlite3_command( _con, "select a.text, l.name from text_attributes a,types l,types t where a.weak_resolvable_id=:rid and a.lang_id=l.id and a.attr_id=t.id and l.class=:lclass and t.class=:tclass and t.name=:tname;") );
 
 
@@ -41,7 +44,7 @@ struct ResolvableQuery::Impl
     _cmd_attr_num.reset( new sqlite3_command( _con, "select a.value from numeric_attributes a,types t where a.weak_resolvable_id=:rid and a.attr_id=t.id and t.class=:tclass and t.name=:tname;"));
 
     _cmd_disk_usage.reset( new sqlite3_command( _con, "select d.name,du.size,du.files from resolvable_disk_usage du,dir_names d where du.resolvable_id=:rid and du.dir_name_id=d.id;"));
-    
+
     MIL << "Creating Resolvable query impl" << endl;
     //         0   1     2        3        4      5     6     7               8             9             10          11            12
     _fields = "id, name, version, release, epoch, arch, kind, installed_size, archive_size, install_only, build_time, install_time, repository_id";
@@ -75,7 +78,7 @@ struct ResolvableQuery::Impl
     // see _fields definition above for the getXXX() numbers
 
     ptr->name = reader.getstring(1);
-    ptr->edition = Edition( reader.getstring(2), reader.getstring(3), reader.getint(4));
+    ptr->edition = Edition( reader.getstring(2), reader.getstring(3), reader.getint(4) );
     ptr->arch = _type_cache.archFor(reader.getint(5));
     ptr->kind = _type_cache.kindFor( reader.getint(6) );
     ptr->repository = reader.getint( 12 );
@@ -85,7 +88,7 @@ struct ResolvableQuery::Impl
     return ptr;
   }
 
-  
+
   void query( const data::RecordId &id,
                   ProcessResolvable fnc )
   {
@@ -101,8 +104,8 @@ struct ResolvableQuery::Impl
 
   void query( const std::string &s,
               ProcessResolvable fnc  )
-  {  
-    
+  {
+
     sqlite3_command cmd( _con, "select " + _fields + " from resolvables where name like :name;");
     cmd.bind( ":name", regex2sql( s ) );
     sqlite3_reader reader = cmd.executereader();
@@ -149,7 +152,7 @@ struct ResolvableQuery::Impl
   {
     return ( queryNumericAttributeInternal( _con, record_id, klass, name, default_value) > 0 );
   }
-      
+
   int queryNumericAttribute( const data::RecordId &record_id,
                              const std::string &klass,
                              const std::string &name,
@@ -185,7 +188,7 @@ struct ResolvableQuery::Impl
     }
     return alias;
   }
-  
+
   data::RecordId queryRepositoryId( const std::string &repo_alias )
   {
     long long id = 0;
@@ -199,7 +202,7 @@ struct ResolvableQuery::Impl
     }
     return id;
   }
-  
+
   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 )
   {
@@ -218,7 +221,7 @@ struct ResolvableQuery::Impl
 //FIXME: Implement MATCH_RESSUMM and MATCH_RESDESC
 
       sqlcmd += " name ";
-      if (flags & MATCH_WILDCARDS == 0)
+      if ((flags & MATCH_WILDCARDS) == 0)
       {
         sqlcmd += "=";
       }
@@ -322,10 +325,22 @@ private:
     sqlite3_reader reader = _cmd_attr_num->executereader();
     if ( reader.read() )
       return reader.getint(0);
+    else
+    {
+      reader.close();
+      sqlite3_reader idreader = _cmd_shared_id->executereader();
+      if ( idreader.read() )
+      {
+        _cmd_shared_id->bind(":rid", record_id);
+        data::RecordId sid = idreader.getint(0);
+        idreader.close();
+        return queryNumericAttributeInternal(con, sid, klass, name, default_value);
+      }
+    }
 
     return default_value;
   }
-  
+
   TranslatedText queryTranslatedStringAttributeInternal( sqlite3_connection &con,
                                                          const data::RecordId &record_id,
                                                          const std::string &klass,
@@ -343,7 +358,7 @@ private:
 
     TranslatedText result;
     sqlite3_reader reader = _cmd_attr_tstr->executereader();
-    
+
     int c = 0;
     while(reader.read())
     {
@@ -353,7 +368,19 @@ private:
 
     if ( c>0 )
       return result;
-    
+    else
+    {
+      reader.close();
+      _cmd_shared_id->bind(":rid", record_id);
+      sqlite3_reader idreader = _cmd_shared_id->executereader();
+      if ( idreader.read() )
+      {
+        data::RecordId sid = idreader.getint(0);
+        idreader.close();
+        return queryTranslatedStringAttributeInternal(con, sid, klass, name, default_value);
+      }
+    }
+
     return default_value;
   }
 
@@ -385,10 +412,22 @@ private:
     _cmd_attr_str->bind(":tname", name);
 
     sqlite3_reader reader = _cmd_attr_str->executereader();
-    
+
     if ( reader.read() )
       return reader.getstring(0);
-    
+    else
+    {
+      reader.close();
+      _cmd_shared_id->bind(":rid", record_id);
+      sqlite3_reader idreader = _cmd_shared_id->executereader();
+      if ( idreader.read() )
+      {
+        data::RecordId sid = idreader.getint(0);
+        idreader.close();
+        return queryStringAttributeTranslationInternal( con, sid, locale, klass, name, default_value );
+      }
+    }
+
     return default_value;
   }
 };
@@ -398,7 +437,7 @@ private:
 //////////////////////////////////////////////////////////////////////////////
 
 ResolvableQuery::ResolvableQuery( const Pathname &dbdir)
-  : _pimpl(new Impl(dbdir))
+  : _pimpl(/*new Impl(dbdir)*/)
 {
   //MIL << "Creating Resolvable query" << endl;
 }