Android SQLite Database Comparison

Is there a way to check if the SQLite SQL database has been altered at all?

can also be used in this format:

ie

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

thank

+3
source share
2 answers

Simple solution: you can create a Windows service or just publish a .xml file containing 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>

the checksum changes with changes to db http://jorgesys.com/appiphone/android/stiridb.db.

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

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!");
    }
+1
source

I have not found an API for this yet, but another option is to get the MD5 value of the sqlite file and compare it with the latest MD5.

MD5 Android?

0

All Articles