Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SQLite database comparison

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

like image 792
Chris Mowbray Avatar asked Dec 02 '25 01:12

Chris Mowbray


1 Answers

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!");
    }
like image 120
Jorgesys Avatar answered Dec 03 '25 18:12

Jorgesys



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!