Debug failing SQLite in your mobile (MonoTouch or MonoDroid) project

You’ve added SQLite into your mobile (MonoTouch or MonoDroid) project and created a file on the mobile filesystem. You app starts up and you expect it to pump data into the SQLite database and save it without hassle. But then you notice that the next time you start the app the information was not saved correctly and it seems that the data has not been saved or a rollback has occurred?!

Sounds familiar? In order to stop yourself from becoming mad you need to check out the following debug tips that get me around and help debugging my SQLite related code.

Here are some debugging tips for working with SQLite:

  1. Check the counter result for any SQLite command that you execute
    It doesn’t matter if you use the .Execute, .Insert, .Update or the .Delete other command; they all give back an integer value indicating the number of affected records. For instance, if your query updates records and it does so for 4 records that number will be the result. If you expect this to happen but you get 0, there’s something going wrong with your database CRUD interactions
  2. There’s always the Result object
    If there are no (InvalidOperation/NotSupported/…)exceptions thrown by the SQLite code and something’s off you can always check the SQLite object’s Result property. This stores any errors that may have occurred (but not thrown an exception) and will give you quick insight on what might be going wrong.

Using the tips mentioned above  you will be debugging any SQLite issue in a higher gear.

If YOU have any tips regarding SQLite, drop a comment. I’m (always) curious 🙂