- sqlite wrapper objects for a slightly nicer interface for our purposes,
authorPanu Matilainen <pmatilai@laiskiainen.org>
Fri, 16 Feb 2007 21:11:49 +0000 (23:11 +0200)
committerPanu Matilainen <pmatilai@laiskiainen.org>
Fri, 16 Feb 2007 21:11:49 +0000 (23:11 +0200)
  use it everywhere
- almost working now :)

apt-pkg/Makefile.am
apt-pkg/Makefile.in
apt-pkg/contrib/sqlite.cc [new file with mode: 0644]
apt-pkg/contrib/sqlite.h [new file with mode: 0644]
apt-pkg/rpm/rpmhandler.cc
apt-pkg/rpm/rpmhandler.h
apt-pkg/rpm/rpmindexfile.cc
test/Makefile.am
test/Makefile.in

index a634054..b7a1ef9 100644 (file)
@@ -37,6 +37,8 @@ libapt_pkg_la_SOURCES = \
        contrib/sha1.cc \
        contrib/sha1.h \
        contrib/sptr.h \
+       contrib/sqlite.h \
+       contrib/sqlite.cc \
        contrib/strutl.cc \
        contrib/strutl.h \
        contrib/system.h \
index f3cb43c..831710b 100644 (file)
@@ -70,16 +70,16 @@ am_libapt_pkg_la_OBJECTS = contrib/cdromutl.lo contrib/cmndline.lo \
        contrib/configuration.lo contrib/crc-16.lo contrib/error.lo \
        contrib/fileutl.lo contrib/hashes.lo contrib/md5.lo \
        contrib/mmap.lo contrib/progress.lo contrib/sha1.lo \
-       contrib/strutl.lo rpm/repomd.lo rpm/rpmhandler.lo \
-       rpm/rpmindexfile.lo rpm/rpmlistparser.lo rpm/rpmpackagedata.lo \
-       rpm/rpmpm.lo rpm/rpmshowprogress.lo rpm/rpmrecords.lo \
-       rpm/rpmsrcrecords.lo rpm/rpmsystem.lo rpm/rpmversion.lo \
-       acquire.lo acquire-item.lo acquire-method.lo acquire-worker.lo \
-       algorithms.lo cachefile.lo clean.lo depcache.lo indexfile.lo \
-       init.lo luaiface.lo orderlist.lo packagemanager.lo pkgcache.lo \
-       pkgcachegen.lo pkgrecords.lo pkgsystem.lo policy.lo \
-       repository.lo sourcelist.lo srcrecords.lo tagfile.lo \
-       version.lo versionmatch.lo
+       contrib/sqlite.lo contrib/strutl.lo rpm/repomd.lo \
+       rpm/rpmhandler.lo rpm/rpmindexfile.lo rpm/rpmlistparser.lo \
+       rpm/rpmpackagedata.lo rpm/rpmpm.lo rpm/rpmshowprogress.lo \
+       rpm/rpmrecords.lo rpm/rpmsrcrecords.lo rpm/rpmsystem.lo \
+       rpm/rpmversion.lo acquire.lo acquire-item.lo acquire-method.lo \
+       acquire-worker.lo algorithms.lo cachefile.lo clean.lo \
+       depcache.lo indexfile.lo init.lo luaiface.lo orderlist.lo \
+       packagemanager.lo pkgcache.lo pkgcachegen.lo pkgrecords.lo \
+       pkgsystem.lo policy.lo repository.lo sourcelist.lo \
+       srcrecords.lo tagfile.lo version.lo versionmatch.lo
 libapt_pkg_la_OBJECTS = $(am_libapt_pkg_la_OBJECTS)
 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_builddir)/include/apt-pkg
 depcomp = $(SHELL) $(top_srcdir)/buildlib/depcomp
@@ -274,6 +274,8 @@ libapt_pkg_la_SOURCES = \
        contrib/sha1.cc \
        contrib/sha1.h \
        contrib/sptr.h \
+       contrib/sqlite.h \
+       contrib/sqlite.cc \
        contrib/strutl.cc \
        contrib/strutl.h \
        contrib/system.h \
@@ -462,6 +464,8 @@ contrib/progress.lo: contrib/$(am__dirstamp) \
        contrib/$(DEPDIR)/$(am__dirstamp)
 contrib/sha1.lo: contrib/$(am__dirstamp) \
        contrib/$(DEPDIR)/$(am__dirstamp)
+contrib/sqlite.lo: contrib/$(am__dirstamp) \
+       contrib/$(DEPDIR)/$(am__dirstamp)
 contrib/strutl.lo: contrib/$(am__dirstamp) \
        contrib/$(DEPDIR)/$(am__dirstamp)
 rpm/$(am__dirstamp):
@@ -512,6 +516,8 @@ mostlyclean-compile:
        -rm -f contrib/progress.lo
        -rm -f contrib/sha1.$(OBJEXT)
        -rm -f contrib/sha1.lo
+       -rm -f contrib/sqlite.$(OBJEXT)
+       -rm -f contrib/sqlite.lo
        -rm -f contrib/strutl.$(OBJEXT)
        -rm -f contrib/strutl.lo
        -rm -f rpm/repomd.$(OBJEXT)
@@ -575,6 +581,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@contrib/$(DEPDIR)/mmap.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@contrib/$(DEPDIR)/progress.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@contrib/$(DEPDIR)/sha1.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@contrib/$(DEPDIR)/sqlite.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@contrib/$(DEPDIR)/strutl.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@rpm/$(DEPDIR)/repomd.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@rpm/$(DEPDIR)/rpmhandler.Plo@am__quote@
diff --git a/apt-pkg/contrib/sqlite.cc b/apt-pkg/contrib/sqlite.cc
new file mode 100644 (file)
index 0000000..5ead954
--- /dev/null
@@ -0,0 +1,108 @@
+#ifdef __GNUG__
+#pragma implementation "apt-pkg/sqlite.h"
+#endif
+
+#include <apt-pkg/sqlite.h>
+#include <apt-pkg/error.h>
+
+// debug stuff..
+#include <iostream>
+using namespace std;
+
+SqliteDB::SqliteDB(string DBPath): DBPath(DBPath), DB(NULL)
+{
+   int rc;
+   //cout << __PRETTY_FUNCTION__ << " " << DBPath << endl;
+   rc = sqlite3_open(DBPath.c_str(), &DB);
+   if (rc != SQLITE_OK) {
+      _error->Error("opening %s db failed", DBPath.c_str());
+   }
+}
+
+SqliteDB::~SqliteDB()
+{
+   //cout << __PRETTY_FUNCTION__ << endl;
+   if (DB) {
+      sqlite3_close(DB);
+   }
+}
+
+SqliteQuery *SqliteDB::Query()
+{
+   return new SqliteQuery(DB);
+}
+
+bool SqliteQuery::Exec(string SQL)
+{
+   int rc;
+   rc = sqlite3_get_table(DB, SQL.c_str(), &res, &nrow, &ncol, NULL);
+   if (rc != SQLITE_OK) {
+      sqlite3_free_table(res);
+      nrow = 0;
+      ncol = 0;
+      res = NULL;
+   }
+   ColNames.clear();
+   for (int col = 0; col < ncol; col++) {
+      ColNames[res[col]] = col;
+   }
+      
+   return (rc == SQLITE_OK);
+}
+
+bool SqliteQuery::Step()
+{
+   if (cur >= nrow) {
+      return false;
+   }
+   cur ++;
+   return true;
+}
+
+bool SqliteQuery::Rewind()
+{
+   cur = 0;
+   return true;
+}
+
+bool SqliteQuery::Jump(unsigned long Pos)
+{
+   if (Pos >= nrow) {
+      return false;
+   }
+   cur = Pos;
+   return true;
+}
+
+string SqliteQuery::GetCol(string ColName)
+{
+   string val = "";
+   char *item = res[cur*ncol+ColNames[ColName]];
+   if (item != NULL)
+      val = item;
+   return val;
+} 
+
+unsigned long SqliteQuery::GetColI(string ColName)
+{
+   unsigned long val = 0;
+   char *item = res[cur*ncol+ColNames[ColName]];
+   if (item != NULL)
+      val = atol(item);
+   return val;
+} 
+SqliteQuery::SqliteQuery(sqlite3 *DB) : 
+   DB(DB), res(NULL), nrow(0), ncol(0), cur(0)
+{
+   //cout << __PRETTY_FUNCTION__ << endl;
+}
+
+SqliteQuery::~SqliteQuery()
+{
+   //cout << __PRETTY_FUNCTION__ << endl;
+   if (res) {
+      sqlite3_free_table(res);
+   }
+}
+
+// vim:sts=3:sw=3
diff --git a/apt-pkg/contrib/sqlite.h b/apt-pkg/contrib/sqlite.h
new file mode 100644 (file)
index 0000000..4fc8608
--- /dev/null
@@ -0,0 +1,59 @@
+#ifndef APTPKG_SQLITE_H
+#define APTPKG_SQLITE_H
+
+#ifdef __GNUG__
+#pragma interface "apt-pkg/sqlite.h"
+#endif
+
+#include <sqlite3.h>
+#include <string>
+#include <map>
+
+using std::string;
+using std::map;
+
+typedef map<string,string> SqliteRow; 
+
+class SqliteQuery
+{
+   protected:
+   sqlite3 *DB;
+   char **res;
+   int nrow, ncol;
+   int cur;
+
+   map<string,int> ColNames;
+
+   public:
+   bool Exec(string SQL);
+   int Size() { return nrow; };
+   //bool FetchOne(map<string,string> &Row);
+
+   // XXX size_t'ize these..
+   bool Jump(unsigned long Pos);
+   bool Rewind();
+   bool Step();
+   unsigned long inline Offset() {return cur-1;};
+
+   string GetCol(string ColName);
+   unsigned long GetColI(string ColName);
+
+   SqliteQuery(sqlite3 *DB);
+   ~SqliteQuery();
+};
+
+class SqliteDB
+{
+   protected:
+   sqlite3 *DB;
+   string DBPath;
+
+   public:
+   SqliteQuery *Query();
+
+   SqliteDB(string DBPath);
+   ~SqliteDB();
+};
+
+#endif
+// vim:sts=3:sw=3
index e168a4d..2fbea00 100644 (file)
@@ -32,6 +32,7 @@
 #include <libxml/tree.h>
 #include <libxml/xmlreader.h>
 #include <sstream>
+#include <apt-pkg/sqlite.h>
 #endif
 
 #include <apti18n.h>
@@ -1334,188 +1335,138 @@ RPMRepomdFLHandler::~RPMRepomdFLHandler()
    xmlFreeTextReader(Filelist);
 }
 
-RPMSqliteHandler::RPMSqliteHandler(string File)
+RPMSqliteHandler::RPMSqliteHandler(string File) : 
+   Primary(NULL), Filelists(NULL)
 {
    //cout << __PRETTY_FUNCTION__ << endl;
    int rc = 0;
    char **res = NULL;
    int nrow, ncol = 0;
    string sql;
+   
 
    DBPath = File; 
    // ugh, pass this in to the constructor or something..
    FilesDBPath = File.substr(0, File.size() - 14) + "filelists.sqlite";
-   //cout << "db " << DBPath << " filelists " << FilesDBPath << endl;
-   rc = sqlite3_open(DBPath.c_str(), &db);
-   if (rc != SQLITE_OK) {
-      cout << "failed to open " << DBPath << endl;
-   }
-   if (! FilesDBPath.empty()) {
-      rc = sqlite3_open(FilesDBPath.c_str(), &filedb);
-      if (rc != SQLITE_OK) {
-        cout << "failed to open " << FilesDBPath << endl;
-      }
-   }
 
-   sql = "SELECT pkgKey FROM packages";
-   rc = sqlite3_get_table(db, sql.c_str(), &res, &nrow, &ncol, NULL);
-   if (rc != SQLITE_OK) {
-      cout << "failed to read package index size" << endl;
-   }
+   Primary = new SqliteDB(DBPath);
+   Filelists = new SqliteDB(FilesDBPath);
 
-   for (int c=1; c <= nrow; c++) {
-      Pkgs.push_back(atoi(res[c]));
-   }
+   Packages = Primary->Query();
 
-   // XXX Things are dead slow without these indexes the way this
-   // is implemented now. Just ignore any failures creating them,
-   // most likely it's because the index already exists.
-   sql = "CREATE INDEX providesIdx on provides (pkgKey)";
-   rc = sqlite3_exec (db, sql.c_str(), NULL, NULL, NULL);
-   sql = "CREATE INDEX requiresIdx on requires (pkgKey)";
-   rc = sqlite3_exec (db, sql.c_str(), NULL, NULL, NULL);
-   sql = "CREATE INDEX conflictsIdx on conflicts (pkgKey)";
-   rc = sqlite3_exec (db, sql.c_str(), NULL, NULL, NULL);
-   sql = "CREATE INDEX obsoletesIdx on obsoletes (pkgKey)";
-   rc = sqlite3_exec (db, sql.c_str(), NULL, NULL, NULL);
+   // XXX without these indexes cache generation will take minutes.. ick
+   Packages->Exec("create index requireIdx on requires (pkgKey)");
+   Packages->Exec("create index provideIdx on provides (pkgKey)");
+   Packages->Exec("create index obsoleteIdx on obsoletes (pkgKey)");
+   Packages->Exec("create index conflictIdx on conflicts (pkgKey)");
 
-   iSize = Pkgs.size();
-   PkgIter = Pkgs.begin();
-   //cout << iSize << " packages in " << File << endl;
+   Packages->Exec("select * from packages");
+   iSize = Packages->Size();
+   cout << "sqlite handler initialized, isize " << iSize << endl;
 }
 
 RPMSqliteHandler::~RPMSqliteHandler()
 {
-   //cout << __PRETTY_FUNCTION__ << endl;
-   sqlite3_close(db);
-   sqlite3_close(filedb);
+   if (Primary) delete Primary;
+   if (Filelists) delete Filelists;
 }
 
-string RPMSqliteHandler::FindTag(string Tag)
-{
-   int rc = 0;
-   char **res = NULL;
-   int nrow, ncol = 0;
-   ostringstream sql;
-   string tag;
-
-   sql << "SELECT " << Tag << " FROM packages where pkgKey=" << *(PkgIter-1) << endl;
-   rc = sqlite3_get_table(db, sql.str().c_str(), &res, &nrow, &ncol, NULL);
-   if (rc != SQLITE_OK || nrow != 1) {
-      cout << "failed getting tag " << Tag << endl;
-      sqlite3_free_table(res);
-      return "";
-   }
-   tag = res[1];
-   sqlite3_free_table(res);
-   return tag;
-}
 
 bool RPMSqliteHandler::Skip()
 {
-   //cout << __PRETTY_FUNCTION__ << endl;
-   if (PkgIter == Pkgs.end()) {
-      return false;
-   }
-   iOffset = PkgIter - Pkgs.begin();
-   PkgIter++;
-   return true;
+   bool res = Packages->Step();
+   if (res)
+      iOffset++;
+   return res;
 }
 
 bool RPMSqliteHandler::Jump(off_t Offset)
 {
-   //cout << __PRETTY_FUNCTION__ << endl;
-   if (Offset >= iSize) {
+   bool res = Packages->Jump(Offset);
+   if (!res)
       return false;
-   }
-   iOffset = Offset;
-   PkgIter = Pkgs.begin() + Offset + 1;
+   iOffset = Packages->Offset();
    return true;
 }
 
 void RPMSqliteHandler::Rewind()
 {
-   //cout << __PRETTY_FUNCTION__ << endl;
+   Packages->Rewind();
    iOffset = 0;
-   PkgIter = Pkgs.begin();
 }
 
 string RPMSqliteHandler::Name()
 {
-   return FindTag("name");
+   return Packages->GetCol("name");
 }
 
 string RPMSqliteHandler::Version()
 {
-   return FindTag("version");
+   return Packages->GetCol("version");
 }
 
 string RPMSqliteHandler::Release()
 {
-   return FindTag("release");
+   return Packages->GetCol("release");
 }
 
 string RPMSqliteHandler::Epoch()
 {
-   return FindTag("epoch");
+   return Packages->GetCol("epoch");
 }
 
 string RPMSqliteHandler::Arch()
 {
-   return FindTag("arch");
+   return Packages->GetCol("arch");
 }
 
 string RPMSqliteHandler::Group()
 {
-   return FindTag("rpm_group");
+   return Packages->GetCol("rpm_group");
 }
 
 string RPMSqliteHandler::Packager()
 {
-   return FindTag("rpm_packager");
+   return Packages->GetCol("rpm_packager");
 }
 string RPMSqliteHandler::Vendor()
 {
-   return FindTag("rpm_vendor");
+   return Packages->GetCol("rpm_vendor");
 }
+
 string RPMSqliteHandler::Summary()
 {
-   return FindTag("summary");
+   return Packages->GetCol("summary");
 }
+
 string RPMSqliteHandler::Description()
 {
-   return FindTag("description");
+   return Packages->GetCol("description");
 }
+
 string RPMSqliteHandler::SourceRpm()
 {
-   return FindTag("rpm_sourcerpm");
+   return Packages->GetCol("rpm_sourcerpm");
 }
 
 string RPMSqliteHandler::FileName()
 {
-   string str = FindTag("location_href");
-   str = basename((char *)str.c_str()); 
-   //cout << "basename " << str << endl;
-   return str;
+   return flNotDir(Packages->GetCol("location_href"));
 }
 
 string RPMSqliteHandler::Directory()
 {
-   //cout << __PRETTY_FUNCTION__ << endl;
-   string str = FindTag("location_href");
-   str = dirname((char *)str.c_str()); 
-   //cout << "dir " << str << endl;
-   return str;
+   return flNotFile(Packages->GetCol("location_href"));
 }
 
 unsigned long RPMSqliteHandler::FileSize()
 {
-   return atoi(FindTag("size_package").c_str());
+   return Packages->GetColI("size_package");
 }
 
 unsigned long RPMSqliteHandler::InstalledSize()
 {
-   return atoi(FindTag("size_installed").c_str());
+   return Packages->GetColI("size_installed");
 }
 
 string RPMSqliteHandler::MD5Sum()
@@ -1525,17 +1476,12 @@ string RPMSqliteHandler::MD5Sum()
 
 string RPMSqliteHandler::SHA1Sum()
 {
-   // assuming sha sums for now..
-   return FindTag("checksum_value");
+   return Packages->GetCol("checksum_value");
 }
 
 bool RPMSqliteHandler::PRCO(unsigned int Type, vector<Dependency*> &Deps)
 {
    string what = "";
-   ostringstream sql;
-   int rc, nrow, ncol = 0;
-   char **res = NULL;
-
    switch (Type) {
       case pkgCache::Dep::Depends:
         what = "requires";
@@ -1550,25 +1496,24 @@ bool RPMSqliteHandler::PRCO(unsigned int Type, vector<Dependency*> &Deps)
         what = "provides";
          break;
    }
-   //cout << __PRETTY_FUNCTION__ << " " << *(PkgIter-1) << " " << what << endl;
 
-   sql << "SELECT name, flags, epoch, version, release FROM " << what << " where pkgKey=" << *(PkgIter-1) << endl;
-   rc = sqlite3_get_table(db, sql.str().c_str(), &res, &nrow, &ncol, NULL);
-   if (rc != SQLITE_OK) {
-      cout << what << " crap with pkgkey " << *(PkgIter-1) << endl;
-      sqlite3_free_table(res);
+   ostringstream sql;
+   unsigned long pkgKey = Packages->GetColI("pkgKey");
+   sql  << "select * from " << what << " where pkgKey=" << pkgKey << endl;
+   SqliteQuery *prco = Primary->Query();
+   if (!prco->Exec(sql.str())) {
       return false;
    }
-   for (int c=0; c < nrow*ncol; c += ncol) {
-      int i = c+ncol;
+
+   while (prco->Step()) {
       int_32 RpmOp = 0;
       string deptype, depver = "";
 
       //cout << *(PkgIter-1) << " prco " << res[i+0] << endl;
-      if (res[i+1] == NULL) {
+      if (prco->GetCol("flags").empty()) {
         RpmOp == RPMSENSE_ANY;
       } else {
-        deptype = res[i+1];
+        deptype = prco->GetCol("flags");
         if (deptype == "EQ") {
            RpmOp = RPMSENSE_EQUAL;
         } else if (deptype == "GE") {
@@ -1582,51 +1527,53 @@ bool RPMSqliteHandler::PRCO(unsigned int Type, vector<Dependency*> &Deps)
         } else {
            // erm, unknown dependency type?
            cout << "unknown dep!? " << deptype << endl;
+           delete prco;
            return false;
         }
-        if (res[i+2] != NULL) {
-           depver += string(res[i+2]) + ":";
+        if (! prco->GetCol("epoch").empty()) {
+           depver += prco->GetCol("epoch") + ":";
         }
-        if (res[i+3] != NULL) {
-           depver += res[i+3];
+        if (! prco->GetCol("version").empty()) {
+           depver += prco->GetCol("version");
         }
-        if (res[i+4] != NULL) {
-           depver += "-" + string(res[i+4]);
+        if (! prco->GetCol("release").empty()) {
+           depver += "-" + prco->GetCol("release");
         }
       }
-      char *depname = res[i+0];
-      //cout << what << " put dep " << depname << " " << RpmOp << " " << depver << endl;
-      bool res = PutDep(depname, depver.c_str(), RpmOp, Type, Deps);
+      string depname = prco->GetCol("name");
+      //cout << Name() << " (" << pkgKey << ") " << ": put dep " << depname << " " << RpmOp << " " << depver << endl;
+      bool res = PutDep(depname.c_str(), depver.c_str(), RpmOp, Type, Deps);
    }
-   sqlite3_free_table(res);
+   delete prco;
    return true;
 }
 
 bool RPMSqliteHandler::FileList(vector<string> &FileList)
 {
-   //cout << __PRETTY_FUNCTION__ << endl;
    ostringstream sql;
-   int rc, nrow, ncol = 0;
-   char **res = NULL;
-
-   sql << "SELECT dirname, filenames, filetypes FROM filelist where pkgKey=" << *(PkgIter-1) << endl;
-   rc = sqlite3_get_table(filedb, sql.str().c_str(), &res, &nrow, &ncol, NULL);
-   if (rc != SQLITE_OK) {
-      cout << "filelists crap with pkgkey " << *(PkgIter-1) << endl;
-      sqlite3_free_table(res);
+   unsigned long pkgKey = Packages->GetColI("pkgKey");
+   sql  << "select * from filelist where pkgKey=" << pkgKey << endl;
+   SqliteQuery *Files = Filelists->Query();
+   if (!Files->Exec(sql.str())) {
       return false;
    }
-   for (int c=0; c < nrow*ncol; c += ncol) {
-      int i = c+ncol;
-      string dir = res[i];
-      char *pch = strtok(res[i+1], "/");
-      while (pch != NULL) {
-        FileList.push_back(dir + "/" + pch);
-        pch = strtok(NULL, "/");
-      }
+
+   string delimiters = "/";
+   while (Files->Step()) {
+      string dir = Files->GetCol("dirname");
+      string filenames = Files->GetCol("filenames");
+
+      string::size_type lastPos = filenames.find_first_not_of(delimiters, 0);
+      string::size_type pos     = filenames.find_first_of(delimiters, lastPos);
+
+      while (string::npos != pos || string::npos != lastPos)
+      {
+        FileList.push_back(dir + "/" + filenames.substr(lastPos, pos - lastPos));
+        lastPos = filenames.find_first_not_of(delimiters, pos);
+        pos = filenames.find_first_of(delimiters, lastPos);
+      } 
    }
-   sqlite3_free_table(res);
-   
+   delete Files;
    return true;
 }
 
index 40ab9a8..41553b4 100644 (file)
@@ -17,7 +17,7 @@
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 #include <libxml/xmlreader.h>
-#include <sqlite3.h>
+#include <apt-pkg/sqlite.h>
 #endif
 
 #include <rpm/rpmlib.h>
@@ -315,18 +315,15 @@ class RPMSqliteHandler : public RPMHandler
 {
    protected:
 
-   sqlite3 *db;
-   sqlite3 *filedb;
-   sqlite3 *otherdb;
+   SqliteDB *Primary;
+   SqliteDB *Filelists;
+   
+   SqliteQuery *Packages;
+  
    string DBPath;
    string FilesDBPath;
    string OtherDBPath;
 
-   vector<off_t> Pkgs;
-   vector<off_t>::iterator PkgIter;
-
-   string FindTag(string Tag);
-
    public:
 
    virtual bool Skip();
@@ -363,3 +360,4 @@ class RPMSqliteHandler : public RPMHandler
 #endif /* APT_WITH_REPOMD */
 
 #endif
+// vim:sts=3:sw=3
index 63d346d..264cddd 100644 (file)
@@ -833,10 +833,19 @@ bool rpmRepomdDBIndex::GetIndexes(pkgAcquire *Owner) const
 
 unsigned long rpmRepomdDBIndex::Size() const
 {
+   unsigned long Res;
+   SqliteDB DB(IndexPath());
+   SqliteQuery *Q = DB.Query();
+   Q->Exec("select pkgKey from packages");
+   Res = Q->Size();
+   delete Q;
+   return Res;
+#if 0
    RPMHandler *Handler = CreateHandler();
    unsigned long Res = Handler->Size();
    delete Handler;
    return Res;
+#endif
 }
 bool rpmRepomdDBIndex::MergeFileProvides(pkgCacheGenerator &Gen,
                                        OpProgress &Prog) const
index 7195c0c..70763a9 100644 (file)
@@ -30,4 +30,9 @@ noinst_PROGRAMS += hash
 hash_SOURCES = hash.cc
 hash_LDADD = ../apt-pkg/libapt-pkg.la
 
+# Sqlite tester
+noinst_PROGRAMS += sqlite
+sqlite_SOURCES = sqlite.cc
+sqlite_LDADD = ../apt-pkg/libapt-pkg.la
+
 EXTRA_DIST = versions.lst
index fd421c1..ee82fef 100644 (file)
@@ -38,7 +38,7 @@ build_triplet = @build@
 host_triplet = @host@
 noinst_PROGRAMS = mthdcat$(EXEEXT) uritest$(EXEEXT) \
        scratch-test$(EXEEXT) versiontest$(EXEEXT) conftest$(EXEEXT) \
-       hash$(EXEEXT)
+       hash$(EXEEXT) sqlite$(EXEEXT)
 EXTRA_PROGRAMS =
 subdir = test
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
@@ -68,6 +68,9 @@ mthdcat_LDADD = $(LDADD)
 am_scratch_test_OBJECTS = scratch.$(OBJEXT)
 scratch_test_OBJECTS = $(am_scratch_test_OBJECTS)
 scratch_test_DEPENDENCIES = ../apt-pkg/libapt-pkg.la
+am_sqlite_OBJECTS = sqlite.$(OBJEXT)
+sqlite_OBJECTS = $(am_sqlite_OBJECTS)
+sqlite_DEPENDENCIES = ../apt-pkg/libapt-pkg.la
 am_uritest_OBJECTS = uri.$(OBJEXT)
 uritest_OBJECTS = $(am_uritest_OBJECTS)
 uritest_DEPENDENCIES = ../apt-pkg/libapt-pkg.la
@@ -86,10 +89,10 @@ CXXLD = $(CXX)
 CXXLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXXLD) $(AM_CXXFLAGS) \
        $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
 SOURCES = $(conftest_SOURCES) $(hash_SOURCES) $(mthdcat_SOURCES) \
-       $(scratch_test_SOURCES) $(uritest_SOURCES) \
+       $(scratch_test_SOURCES) $(sqlite_SOURCES) $(uritest_SOURCES) \
        $(versiontest_SOURCES)
 DIST_SOURCES = $(conftest_SOURCES) $(hash_SOURCES) $(mthdcat_SOURCES) \
-       $(scratch_test_SOURCES) $(uritest_SOURCES) \
+       $(scratch_test_SOURCES) $(sqlite_SOURCES) $(uritest_SOURCES) \
        $(versiontest_SOURCES)
 ETAGS = etags
 CTAGS = ctags
@@ -241,6 +244,8 @@ conftest_SOURCES = conf.cc
 conftest_LDADD = ../apt-pkg/libapt-pkg.la
 hash_SOURCES = hash.cc
 hash_LDADD = ../apt-pkg/libapt-pkg.la
+sqlite_SOURCES = sqlite.cc
+sqlite_LDADD = ../apt-pkg/libapt-pkg.la
 EXTRA_DIST = versions.lst
 all: all-am
 
@@ -294,6 +299,9 @@ mthdcat$(EXEEXT): $(mthdcat_OBJECTS) $(mthdcat_DEPENDENCIES)
 scratch-test$(EXEEXT): $(scratch_test_OBJECTS) $(scratch_test_DEPENDENCIES) 
        @rm -f scratch-test$(EXEEXT)
        $(CXXLINK) $(scratch_test_LDFLAGS) $(scratch_test_OBJECTS) $(scratch_test_LDADD) $(LIBS)
+sqlite$(EXEEXT): $(sqlite_OBJECTS) $(sqlite_DEPENDENCIES) 
+       @rm -f sqlite$(EXEEXT)
+       $(CXXLINK) $(sqlite_LDFLAGS) $(sqlite_OBJECTS) $(sqlite_LDADD) $(LIBS)
 uritest$(EXEEXT): $(uritest_OBJECTS) $(uritest_DEPENDENCIES) 
        @rm -f uritest$(EXEEXT)
        $(CXXLINK) $(uritest_LDFLAGS) $(uritest_OBJECTS) $(uritest_LDADD) $(LIBS)
@@ -311,6 +319,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hash.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mthdcat.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scratch.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sqlite.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uri.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/versiontest.Po@am__quote@