Improving DbInspector library.
Table Of Contents
DbInspector is a useful library that helps us to view our database in the app. I have forked it and tried to add some small features to make this awesome library more awesome, and even more useful.
There are three main changes I have done in my fork.
1. Support For Older versions.
Db Inspector was the inspiration behind my Shared Peference Inspector library, with which my first target was to provide as much support for 2.3 as I can. As per their readme, dbInspector can give support for api v7, but they have only tested for ICS and above. I have added the code to give support for older API, and tested it in GingerBread device I had with me.
When 2.3 devices are less than 10%, neither me, nor infinum should waste their time supporting those device. And with their code base and readme, it seemed it can not be achieved as they may have used native fragment, but it was possible when I found out they are already using appcompat (v20). Replacing FragmentManager with SupportFragmentManagers and Native (OS Provided) fragments with Support versions did the trick for me. And it was way easier than I have thought, untill I found out they used PreferenceFragment for showing preference for row counts on every table. As we all know Preference Fragments are not supported in older versions, I used a code from this xda thred as a solution.
2. Database Versions
When we have to upgrade our database, it’s essential to know on which database version this app is running, esp before and after the upgrade operation. I have faced this problem sometimes when I have worked on projects which are already live and I have to modify the database. At the time of testing the upgrade logic, it’s hard to know on which version the database is unless I look at the code. So I felt it can be handy if DbInspector can show database version somewhere.
If you want to check your databse version, running "PRAGMA user_version"
query on your database will return the database version (you can see the code here). If you run my forked code, you can find current database version in the ActionBar subtitle.
3. Added Search and Copy menu
DbInspector is good to see the database in app, and in the example they have provided the database is small and compact (as every example should be). In real life the database is not always small and compact. One app I have worked with had ~40 tables in their database. In that app DbInspector is helpful to check whether such data is available or not. But finding exact table was bit harder for them as they have to scroll up or down for that table. I have added search menu so finding exact table is bit more convenient for us when database have more tables.
The other menu I have added is the copy menu. Checking data is fine for DbInspector, but we need to copy the database in our computer to test some queries (this is often the case with the apps I am working now). The copy menu copies current database in External Memory (in the directory named after the application) and from there you can run adb pull
command to get that database in your computer.
Update: as of 8th March 2015 the changes are merged with main repository and v 3.0 contains these changes. Thanks Dino for your patience and your helping.
This is it for now.