I want to add a field indicating the last modified or last accessed time for my objects. Is there an easy, auto refreshed method for doing so?
I'm not sure about how to use SQLite to support a last-modified timestamp. However, one of the features of ORMLite is a version field. You can mark a Date
field with version = true
and ever time it is updated it will update the Date
to the latest value. See the documentation for more information:
http://ormlite.com/docs/version-field
So you would add something like the following to your class:
@DatabaseField(version = true)
Date modificationDate;
I've verified this works well both for the creation and modification dates. Also, this means that when you do any upgrades, it will add something like the following to the end of the update statement automagically:
UPDATE yourclass SET ... >>> WHERE modificationDate = existing-date; <<<
See the docs for more information. Oh, and if you'd like to store it as a long, instead you could do something like:
@DatabaseField(version = true, dataType = DataType.DATE_LONG)
Date modificationDate;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With