From: Michael Vrable Date: Tue, 15 Jan 2008 18:48:30 +0000 (-0800) Subject: Fix to segment age calculation in local database. X-Git-Url: http://git.vrable.net/?p=cumulus.git;a=commitdiff_plain;h=38ae53bac981d564d9f04c038a88d727289db5c8 Fix to segment age calculation in local database. It seems that in SQLite, max(x, NULL) yields NULL, not x. This was being used to set the mtime of a segment to the maximum mtime of any object in it, starting with an mtime of NULL. Fix the computation so it does the right thing. --- diff --git a/localdb.cc b/localdb.cc index 1c44fa4..077c927 100644 --- a/localdb.cc +++ b/localdb.cc @@ -248,10 +248,12 @@ void LocalDb::StoreObject(const ObjectReference& ref, sqlite3_finalize(stmt); if (age != 0.0) { - stmt = Prepare("update segments set mtime = max(mtime, ?) " + stmt = Prepare("update segments " + "set mtime = coalesce(max(mtime, ?), ?) " "where segmentid = ?"); sqlite3_bind_double(stmt, 1, age); - sqlite3_bind_int64(stmt, 2, SegmentToId(ref.get_segment())); + sqlite3_bind_double(stmt, 2, age); + sqlite3_bind_int64(stmt, 3, SegmentToId(ref.get_segment())); rc = sqlite3_step(stmt); sqlite3_finalize(stmt); }