From 38ae53bac981d564d9f04c038a88d727289db5c8 Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Tue, 15 Jan 2008 10:48:30 -0800 Subject: [PATCH] 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. --- localdb.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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); } -- 2.20.1