about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2010-02-19T17·15+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2010-02-19T17·15+0000
commit1930570ad96e47de9e8557a7734c7bfd9f36f942 (patch)
treeed4eb236f6e7935a955659105821f1e9beadef65 /src
parent9c9a88e9e25bdc4456368a40691e61acf5d3b330 (diff)
* Foreign key support in SQLite is not a persistent setting, so enable
  it at startup.
* Implement negative caching.  Now `make check' passes.

Diffstat (limited to 'src')
-rw-r--r--src/libstore/local-store.cc21
-rw-r--r--src/libstore/local-store.hh2
-rw-r--r--src/libstore/schema.sql4
3 files changed, 22 insertions, 5 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index cd25ded72bce..4c1bbb708e78 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -209,6 +209,9 @@ LocalStore::LocalStore()
     if (sqlite3_busy_timeout(db, 60000) != SQLITE_OK)
         throw SQLiteError(db, "setting timeout");
 
+    if (sqlite3_exec(db, "pragma foreign_keys = 1;", 0, 0, 0) != SQLITE_OK)
+        throw SQLiteError(db, "enabling foreign keys");
+
     /* !!! check whether sqlite has been built with foreign key
        support */
     
@@ -288,6 +291,10 @@ void LocalStore::prepareStatements()
         "select path from Refs join ValidPaths on referrer = id where reference = (select id from ValidPaths where path = ?);");
     stmtInvalidatePath.create(db,
         "delete from ValidPaths where path = ?;");
+    stmtRegisterFailedPath.create(db,
+        "insert into FailedPaths (path, time) values (?, ?);");
+    stmtHasPathFailed.create(db,
+        "select time from FailedPaths where path = ?;");
 }
 
 
@@ -425,13 +432,23 @@ void LocalStore::registerValidPath(const ValidPathInfo & info)
 
 void LocalStore::registerFailedPath(const Path & path)
 {
-    throw Error("not implemented");
+    if (hasPathFailed(path)) return;
+    SQLiteStmtUse use(stmtRegisterFailedPath);
+    stmtRegisterFailedPath.bind(path);
+    stmtRegisterFailedPath.bind(time(0));
+    if (sqlite3_step(stmtRegisterFailedPath) != SQLITE_DONE)
+        throw SQLiteError(db, format("registering failed path `%1%'") % path);
 }
 
 
 bool LocalStore::hasPathFailed(const Path & path)
 {
-    throw Error("not implemented");
+    SQLiteStmtUse use(stmtHasPathFailed);
+    stmtHasPathFailed.bind(path);
+    int res = sqlite3_step(stmtHasPathFailed);
+    if (res != SQLITE_DONE && res != SQLITE_ROW)
+        throw SQLiteError(db, "querying whether path failed");
+    return res == SQLITE_ROW;
 }
 
 
diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh
index 34aa55fc8f2d..e1859e68edf2 100644
--- a/src/libstore/local-store.hh
+++ b/src/libstore/local-store.hh
@@ -196,6 +196,8 @@ private:
     SQLiteStmt stmtQueryReferences;
     SQLiteStmt stmtQueryReferrers;
     SQLiteStmt stmtInvalidatePath;
+    SQLiteStmt stmtRegisterFailedPath;
+    SQLiteStmt stmtHasPathFailed;
 
     int getSchema();
 
diff --git a/src/libstore/schema.sql b/src/libstore/schema.sql
index dc53f452c2d6..1e707ce1f41e 100644
--- a/src/libstore/schema.sql
+++ b/src/libstore/schema.sql
@@ -1,5 +1,3 @@
-pragma foreign_keys = on;
-
 create table if not exists ValidPaths (
     id               integer primary key autoincrement not null,
     path             text unique not null,
@@ -19,7 +17,7 @@ create table if not exists Refs (
 create index if not exists IndexReferrer on Refs(referrer);
 create index if not exists IndexReference on Refs(reference);
 
-create table if not exists FailedDerivations (
+create table if not exists FailedPaths (
     path text primary key not null,
     time integer not null
 );