[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/work/kde4/playground/libs/archivereader/src
From:       Jos van den Oever <jos () vandenoever ! info>
Date:       2006-05-28 14:11:50
Message-ID: 1148825510.214237.13125.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 545851 by vandenoever:

Behave better when reindexing.

 M  +5 -4      daemon/indexscheduler.cpp  
 M  +31 -18    sqliteindexer/sqliteindexwriter.cpp  


--- branches/work/kde4/playground/libs/archivereader/src/daemon/indexscheduler.cpp \
#545850:545851 @@ -116,15 +116,16 @@
 }
 void
 IndexScheduler::index() {
+    IndexReader* reader = indexmanager->getIndexReader();
     IndexWriter* writer = indexmanager->getIndexWriter();
     StreamIndexer* streamindexer = new StreamIndexer(writer);
 
-    IndexReader* reader = indexmanager->getIndexReader();
 
-    dbfiles = reader->getFiles(0);
-    printf("%i real files in the database\n", dbfiles.size()); 
+    if (dbfiles.size() == 0 && toindex.size() == 0) {
+        // retrieve the list of real files currently in the database
+        dbfiles = reader->getFiles(0);
+        printf("%i real files in the database\n", dbfiles.size()); 
 
-    if (dbfiles.size() == 0 && toindex.size() == 0) {
         // first loop through all files
         FileLister lister;
         lister.setCallbackFunction(&addFileCallback);
--- branches/work/kde4/playground/libs/archivereader/src/sqliteindexer/sqliteindexwriter.cpp \
#545850:545851 @@ -218,30 +218,43 @@
     printf("end commit of %i rows\n", temprows);
     temprows = 0;
 }
+/**
+ * Delete all files that start with the specified path.
+ **/
 void
 SqliteIndexWriter::deleteEntry(const string& path) {
     int64_t id = -1;
     manager->ref();
-    int r = sqlite3_bind_text(getfilestmt, 1, path.c_str(), path.length(),
+    // turn on case sensitivity
+    sqlite3_exec(db, "PRAGMA case_sensitive_like = 1", 0, 0, 0);
+
+    sqlite3_stmt* getstmt;
+    string pathplus = path+"%";
+    const char* getsql = "select fileid from files where path like ?;";
+    prepareStmt(getstmt, getsql, strlen(getsql));
+    sqlite3_bind_text(getstmt, 1, pathplus.c_str(), pathplus.length(),
         SQLITE_STATIC);
-    r = sqlite3_step(getfilestmt);
-    if (r != SQLITE_ROW) {
-        printf("could not find file %s:\n", path.c_str());
-        sqlite3_reset(getfilestmt);
-        manager->deref();
-        return;
+    int r = sqlite3_step(getstmt);
+    while (r == SQLITE_ROW) {
+        id = sqlite3_column_int64(getstmt, 0);
+        ostringstream sql;
+        // todo adapt the word counts
+        sql << "delete from idx where fileid = " << id
+            << "; delete from filewords where fileid = " << id
+            << "; delete from files where fileid = " << id;
+        int sr = sqlite3_exec(db, sql.str().c_str(), 0, 0, 0);
+        if (sr != SQLITE_OK) {
+            printf("could not delete file %s: %s\n", path.c_str(),
+                sqlite3_errmsg(db));
+        }
+        r = sqlite3_step(getstmt);
     }
-    id = sqlite3_column_int64(getfilestmt, 0);
-    sqlite3_reset(getfilestmt);
+    sqlite3_finalize(getstmt);
+    if (r != SQLITE_DONE) {
+        printf("error in deleting file %s:\n", path.c_str());
+    }
 
-    ostringstream sql;
-    sql << "delete from idx where fileid = " << id
-        << "; delete from filewords where fileid = " << id
-        << "; delete from files where fileid = " << id;
-    r = sqlite3_exec(db, sql.str().c_str(), 0, 0, 0);
-    if (r != SQLITE_OK) {
-        printf("could not delete file %s: %s\n", path.c_str(),
-            sqlite3_errmsg(db));
-    }
+    // turn off case sensitivity
+    sqlite3_exec(db, "PRAGMA case_sensitive_like = 0", 0, 0, 0);
     manager->deref();
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic