0

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

Sudarshan
  • 1,291
  • 3
  • 26
  • 35

2 Answers2

1

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.

Stephen Lombardo
  • 1,503
  • 8
  • 7
  • Thanks for your response. I could understand your comment and relate it to my scenario. But one hickup is like, the pbm occurs only in 4.1.2 version Android Tablets and in other devices the mentioned problem is not happening. I know that android_metadata table is created automatically, is there any way to restrict that to happen when i create my DB. – Sudarshan Dec 11 '13 at 06:18
  • I have another question, After your reply i had changed the openOrCreateDatabase to openDatabase with ReadOnly flag. But still the problem occurs. Your views on this – Sudarshan Dec 11 '13 at 07:31
  • Actually i had solved my problem in two steps and the first step is to use the Opendatabase instead of openOrCreateDatabase. So i am checking your reply as the answer to my problem .. Thanks Stephen for your reply – Sudarshan Dec 12 '13 at 09:39
0

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.

Techfist
  • 4,314
  • 6
  • 22
  • 32
  • Till we edit something in the file it wont change the modified time. An extra 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.. – Sudarshan Dec 09 '13 at 13:07