+ sqlite3_finalize(stmt);
+
+ int64_t new_size = old_size;
+ if (ref.has_range()) {
+ new_size += ref.get_range_length();
+ new_size = min(new_size, block_size);
+ } else {
+ new_size = block_size;
+ }
+
+ if (new_size != old_size) {
+ stmt = Prepare("insert or replace "
+ "into snapshot_refs(segmentid, object, size) "
+ "values (?, ?, ?)");
+ sqlite3_bind_int64(stmt, 1, SegmentToId(ref.get_segment()));
+ obj = ref.get_sequence();
+ sqlite3_bind_text(stmt, 2, obj.c_str(), obj.size(), SQLITE_TRANSIENT);
+ sqlite3_bind_int64(stmt, 3, new_size);
+
+ rc = sqlite3_step(stmt);
+ if (rc != SQLITE_DONE) {
+ fprintf(stderr, "Could not execute INSERT statement!\n");
+ ReportError(rc);
+ }
+
+ sqlite3_finalize(stmt);
+ }
+}
+
+void LocalDb::UseSegment(const std::string &segment, double utilization)
+{
+ int rc;
+ sqlite3_stmt *stmt;
+
+ stmt = Prepare("insert or replace "
+ "into segments_used(snapshotid, segmentid, utilization) "
+ "values (?, ?, ?)");
+ sqlite3_bind_int64(stmt, 1, snapshotid);
+ sqlite3_bind_int64(stmt, 2, SegmentToId(segment));
+ sqlite3_bind_double(stmt, 3, utilization);
+
+ rc = sqlite3_step(stmt);
+ if (rc != SQLITE_DONE) {
+ fprintf(stderr, "Could not insert segment use record!\n");
+ ReportError(rc);
+ }
+
+ sqlite3_finalize(stmt);
+}
+
+void LocalDb::SetSegmentChecksum(const std::string &segment,
+ const std::string &path,
+ const std::string &checksum,
+ int size)
+{
+ int rc;
+ sqlite3_stmt *stmt;
+
+ stmt = Prepare("update segments set path = ?, checksum = ?, size = ?, "
+ "mtime = coalesce(mtime, julianday('now')) "
+ "where segmentid = ?");
+ sqlite3_bind_text(stmt, 1, path.c_str(), path.size(),
+ SQLITE_TRANSIENT);
+ sqlite3_bind_text(stmt, 2, checksum.c_str(), checksum.size(),
+ SQLITE_TRANSIENT);
+ sqlite3_bind_int64(stmt, 3, size);
+ sqlite3_bind_int64(stmt, 4, SegmentToId(segment));
+
+ rc = sqlite3_step(stmt);
+ if (rc != SQLITE_DONE) {
+ fprintf(stderr, "Could not update segment checksum in database!\n");
+ ReportError(rc);
+ }
+
+ sqlite3_finalize(stmt);
+}
+
+bool LocalDb::GetSegmentChecksum(const string &segment,
+ string *seg_path,
+ string *seg_checksum)
+{
+ int rc;
+ sqlite3_stmt *stmt;
+ ObjectReference ref;
+ int found = false;