SQLite: Reset expiration time on overwrite

This commit is contained in:
Tim Wojtulewicz 2025-06-30 14:41:10 -07:00
parent 5daa83bfa4
commit fd7259f436
3 changed files with 31 additions and 1 deletions

View file

@ -186,7 +186,7 @@ OperationResult SQLite::DoOpen(OpenResultCallback* cb, RecordValPtr options) {
db),
std::make_pair(util::
fmt("insert into %s (key_str, value_str, expire_time) values(?, ?, ?) ON CONFLICT(key_str) "
"DO UPDATE SET value_str=?",
"DO UPDATE SET value_str=?, expire_time=?",
table_name.c_str()),
db),
std::make_pair(util::fmt("select value_str from %s where key_str=?", table_name.c_str()), db),
@ -318,6 +318,12 @@ OperationResult SQLite::DoPut(ResultCallback* cb, ValPtr key, ValPtr value, bool
res.code != ReturnCode::SUCCESS ) {
return res;
}
// This duplicates the above binding, but it's to overwrite the expiration time on the entry.
if ( auto res = CheckError(sqlite3_bind_double(stmt.get(), 5, expiration_time));
res.code != ReturnCode::SUCCESS ) {
return res;
}
}
return Step(stmt.get(), false);