+
+bool LocalDb::IsOldObject(const string &checksum, int64_t size, double *age)
+{
+ int rc;
+ sqlite3_stmt *stmt;
+ bool found = false;
+
+ stmt = Prepare("select segmentid, object, timestamp from block_index "
+ "where checksum = ? and size = ?");
+ 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;
+ *age = sqlite3_column_double(stmt, 2);
+ } else {
+ fprintf(stderr, "Could not execute SELECT statement!\n");
+ }
+
+ sqlite3_finalize(stmt);
+
+ return found;
+}
+
+void LocalDb::UseObject(const ObjectReference& ref)
+{
+ int rc;
+ sqlite3_stmt *stmt;
+
+ stmt = Prepare("insert or ignore into snapshot_contents "
+ "select blockid, ? as snapshotid from block_index "
+ "where segmentid = ? and object = ?");
+ sqlite3_bind_int64(stmt, 1, snapshotid);
+ sqlite3_bind_int64(stmt, 2, SegmentToId(ref.get_segment()));
+ string obj = ref.get_sequence();
+ sqlite3_bind_text(stmt, 3, obj.c_str(), obj.size(), SQLITE_TRANSIENT);
+
+ rc = sqlite3_step(stmt);
+ if (rc != SQLITE_DONE) {
+ fprintf(stderr, "Could not execute INSERT statement!\n");
+ }
+
+ sqlite3_finalize(stmt);
+}