From cfe742cfc50e40b590e75200179013dd62b07bde Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 24 Feb 2010 15:07:23 +0000 Subject: [PATCH] * A function to query just the database id of a valid path. --- src/libstore/local-store.cc | 36 ++++++++++++++++++++---------------- src/libstore/local-store.hh | 2 ++ 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 6963ba5a15..bfb253bc10 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 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 ec0b482eae..1e4080becd 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);