Question

I am using sqlcipher database. I am tracking the lastModified time of my database. According to my understanding long value returned by lastModified() function will change only if we update or add a value to the database we refer. I am using a query to fetch (not modifying) a value from the database, for this i am using the below code

mDatabaseFileObj = mContext.getDatabasePath("xxx.db");
Log.i(""," "+mDatabaseFileObj.lastModified());
mSQLiteDatabase = net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(...)
Log.i(""," "+mDatabaseFileObj.lastModified());
mCursor = mSQLiteDatabase.rawQuery(query, null);
do{
....
}while(..)

In this i had printed two logs. First log before creation of mSQLiteDatabase obj and another log after that.According to the doc for lastModified() both the values printed by the logs should be same as i just quering not modifying the database. But the value is changing.

I couldnt sort out this problem.Give your thoughts on this.

An addtional info is, i had placed this code snippet in a function and i am calling that function 5 times and strangely for the first time alone the log is printing different values but for the rest 4 times the log printed values are same..

Thanks in Advance

Was it helpful?

Solution

Deepak,

openOrCreateDatabase is not a read only operation. In particular the wrapping library, which is based on the Android sqlite library, manipulates a table called android_metadata when the database is open. This could cause the timestamp to change, because the database is actually modified during open.

OTHER TIPS

mDatabaseFileObj this is reference to your File object from OS don't confuse this with database in SQLITE database are implemented on top of file system only, so in first line you are printing when this file was last modified,

while second line you are trying to alter the file, and third line again printing time, so as per me and going with file systemn behaviour you will get a different time stamp, this doesn't mean if content inside this file was modified or not.

Just imagine it like this, open a txt file in windows and save it again without changing it notice time before and after they will be different.

Hope this help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top