about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2010-02-24T15·07+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2010-02-24T15·07+0000
commitcfe742cfc50e40b590e75200179013dd62b07bde (patch)
tree1492982e624b32d8e044c58c4eb27419c85e5756 /src/libstore
parent6baa2a2f5ef5b11859b95f453338efaf7c5b2724 (diff)
* A function to query just the database id of a valid path.
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/local-store.cc36
-rw-r--r--src/libstore/local-store.hh2
2 files changed, 22 insertions, 16 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 6963ba5a15d8..bfb253bc10cc 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -461,10 +461,8 @@ void LocalStore::registerValidPath(const ValidPathInfo & info)
     
     unsigned long long id = addValidPath(info2);
 
-    foreach (PathSet::const_iterator, i, info2.references) {
-        ValidPathInfo ref = queryPathInfo(*i);
-        addReference(id, ref.id);
-    }
+    foreach (PathSet::const_iterator, i, info2.references)
+        addReference(id, queryValidPathId(*i));
         
     txn.commit();
 }
@@ -551,6 +549,17 @@ ValidPathInfo LocalStore::queryPathInfo(const Path & path)
 }
 
 
+unsigned long long LocalStore::queryValidPathId(const Path & path)
+{
+    SQLiteStmtUse use(stmtQueryPathInfo);
+    stmtQueryPathInfo.bind(path);
+    int res = sqlite3_step(stmtQueryPathInfo);
+    if (res == SQLITE_ROW) return sqlite3_column_int(stmtQueryPathInfo, 0);
+    if (res == SQLITE_DONE) throw Error(format("path `%1%' is not valid") % path);
+    throw SQLiteError(db, "querying path in database");
+}
+
+
 bool LocalStore::isValidPath(const Path & path)
 {
     SQLiteStmtUse use(stmtQueryPathInfo);
@@ -644,7 +653,7 @@ PathSet LocalStore::queryDerivationOutputs(const Path & path)
     SQLiteTxn txn(db);
     
     SQLiteStmtUse use(stmtQueryDerivationOutputs);
-    stmtQueryDerivationOutputs.bind(queryPathInfo(path).id);
+    stmtQueryDerivationOutputs.bind(queryValidPathId(path));
     
     PathSet outputs;
     int r;
@@ -778,9 +787,9 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos)
     foreach (ValidPathInfos::const_iterator, i, infos) addValidPath(*i);
 
     foreach (ValidPathInfos::const_iterator, i, infos) {
-        unsigned long long referrer = queryPathInfo(i->path).id;
+        unsigned long long referrer = queryValidPathId(i->path);
         foreach (PathSet::iterator, j, i->references)
-            addReference(referrer, queryPathInfo(*j).id);
+            addReference(referrer, queryValidPathId(*j));
     }
 
     txn.commit();
@@ -1229,11 +1238,8 @@ void LocalStore::upgradeStore6()
 
     SQLiteTxn txn(db);
     
-    std::map<Path, sqlite3_int64> pathToId;
-    
     foreach (PathSet::iterator, i, validPaths) {
-        ValidPathInfo info = queryPathInfoOld(*i);
-        pathToId[*i] = addValidPath(info);
+        addValidPath(queryPathInfoOld(*i));
         std::cerr << ".";
     }
 
@@ -1241,11 +1247,9 @@ void LocalStore::upgradeStore6()
     
     foreach (PathSet::iterator, i, validPaths) {
         ValidPathInfo info = queryPathInfoOld(*i);
-        foreach (PathSet::iterator, j, info.references) {
-            if (pathToId.find(*j) == pathToId.end())
-                throw Error(format("path `%1%' referenced by `%2%' is invalid") % *j % *i);
-            addReference(pathToId[*i], pathToId[*j]);
-        }
+        unsigned long long referrer = queryValidPathId(*i);
+        foreach (PathSet::iterator, j, info.references)
+            addReference(referrer, queryValidPathId(*j));
         std::cerr << ".";
     }
 
diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh
index ec0b482eae3e..1e4080becd8c 100644
--- a/src/libstore/local-store.hh
+++ b/src/libstore/local-store.hh
@@ -213,6 +213,8 @@ private:
 
     void prepareStatements();
 
+    unsigned long long queryValidPathId(const Path & path);
+
     unsigned long long addValidPath(const ValidPathInfo & info);
         
     void addReference(unsigned long long referrer, unsigned long long reference);