X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=localdb.cc;h=4683f4d83c567dca863fe42886a0a5f2ceac348b;hb=a7c068d940ab32b75dc2dfaf11146b363f95ca88;hp=cc88401693e83db8a5c98a302c00a2c49c6367af;hpb=6a181a1eb21ac5f9f4f742281b6de841dac9a3c8;p=cumulus.git diff --git a/localdb.cc b/localdb.cc index cc88401..4683f4d 100644 --- a/localdb.cc +++ b/localdb.cc @@ -163,8 +163,8 @@ void LocalDb::StoreObject(const ObjectReference& ref, sqlite3_stmt *stmt; static const char s[] = "insert into " - "block_index(segmentid, object, checksum, size, timestamp, expired) " - "values (?, ?, ?, ?, julianday('now'), 0)"; + "block_index(segmentid, object, checksum, size, timestamp) " + "values (?, ?, ?, ?, julianday('now'))"; const char *tail; rc = sqlite3_prepare_v2(db, s, strlen(s), &stmt, &tail); @@ -193,7 +193,7 @@ ObjectReference LocalDb::FindObject(const string &checksum, int64_t size) sqlite3_stmt *stmt; static const char s[] = "select segmentid, object from block_index " - "where checksum = ? and size = ? and expired = 0"; + "where checksum = ? and size = ? and expired is null"; const char *tail; ObjectReference ref; @@ -221,6 +221,40 @@ ObjectReference LocalDb::FindObject(const string &checksum, int64_t size) return ref; } +bool LocalDb::IsOldObject(const string &checksum, int64_t size) +{ + int rc; + sqlite3_stmt *stmt; + static const char s[] = + "select segmentid, object from block_index " + "where checksum = ? and size = ?"; + const char *tail; + + bool found = false; + + rc = sqlite3_prepare_v2(db, s, strlen(s), &stmt, &tail); + if (rc != SQLITE_OK) { + return false; + } + + sqlite3_bind_text(stmt, 1, checksum.c_str(), checksum.size(), + SQLITE_TRANSIENT); + sqlite3_bind_int64(stmt, 2, size); + + rc = sqlite3_step(stmt); + if (rc == SQLITE_DONE) { + found = false; + } else if (rc == SQLITE_ROW) { + found = true; + } else { + fprintf(stderr, "Could not execute SELECT statement!\n"); + } + + sqlite3_finalize(stmt); + + return found; +} + void LocalDb::UseObject(const ObjectReference& ref) { int rc;