3

Is there a way to check if android SQLite DB has been changed in anyway?

too be used in this sort of format:

i.e

if (isChanged){
        POST data
      }else{
         Log.i("no changes")
      }

Thanks

Chris Mowbray
  • 295
  • 1
  • 3
  • 15
  • Do you mean schema change, like new table, column add/drop? or data inside sqlite file change? – Prakash Feb 04 '14 at 22:55
  • Seems like an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). What is a "change"? Why do you need to know? Answers will vary depending on your goal (ie: checking for schema changes, checking for an updated job queue, checking for third party data forgery). – rutter Feb 04 '14 at 22:55
  • @rutter trying to sync local android SQLite with online MySQL. – Chris Mowbray Feb 04 '14 at 22:58
  • @Prakash any changes data change as is new record, deleted record or edited record – Chris Mowbray Feb 04 '14 at 22:59

2 Answers2

1

An easy solution: you can create a windows service or just publish a .xml file containig a checksum <checksum>3203025</checksum>

http://prueba.agenciareforma.com/appiphone/android/checksumdb.xml

<?xml version="1.0" encoding="UTF-8"?>
<mobiledb>
<nombre>Stiri IASI</nombre>
<urlDB>http://jorgesys.com/appiphone/android/stiridb.db</urlDB>
<checksum>3203025</checksum>
</mobiledb>

checksum changes when changes into the db have been applied http://jorgesys.com/appiphone/android/stiridb.db has changed.

Then check if the actual checksum is different to the last, so download the db with the new changes.

an example:

    //method readUrlDatabaseChecksum(), download and parse the currently value of checksum from the .xml file
    String checksumDB = readUrlDatabaseChecksum();
    //method readDBChecksum(), get the stored value (preferences or db) of the las checksum.
    String lastDBChecksum = readDBChecksum(); //dbm.obtenerCheckSum(seccion.getId());;
    //If the values are different proceed to download the new version of the Database.
    if(!checksumFeed.equals(checksumDB)){      
       Log.i(TAG, "*** Downloading new Database!");
        //method downloadDatabase(), download the new version of the database.
       downloadDatabase();
         //method saveDBChecksum(), save the new value (preferences or db) of the las checksum.
       saveDBChecksum();
       }else{
       Log.i(TAG, "*** Database hasn´t changed!");
    }
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
0

I didn't find any API for that yet, but another option would be get MD5 value of sqlite file and compare with last MD5.

How to generate an MD5 checksum for a file in Android?

Community
  • 1
  • 1
Prakash
  • 4,479
  • 30
  • 42