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

4
  • Do you mean schema change, like new table, column add/drop? or data inside sqlite file change? Commented Feb 4, 2014 at 22:55
  • Seems like an 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). Commented Feb 4, 2014 at 22:55
  • @rutter trying to sync local android SQLite with online MySQL. Commented Feb 4, 2014 at 22:58
  • @Prakash any changes data change as is new record, deleted record or edited record Commented Feb 4, 2014 at 22:59

2 Answers 2

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!");
    }
Sign up to request clarification or add additional context in comments.

Comments

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.