Juri Strumpflohner
Juri Strumpflohner Juri is a full stack developer and tech lead with a special passion for the web and frontend development. He creates online videos for Egghead.io, writes articles on his blog and for tech magazines, speaks at conferences and holds training workshops. Juri is also a recognized Google Developer Expert in Web Technologies

Android: HowTo Detect Installed SQLite DB Version

1 min read

As you might already know, Android comes with a preinstalled SQLite database. This is quite handy because you can rely on it without the need to care about installing a DB along with your application (although you can, standalone, small DB's of course like HSQLDB). On the Android Developer documentation SQLite version 3.4.0 is indicated as the reference version to develop against. Usually you should be fine with that and if you don't have any valid reason you should stay with. But still in the very rare cases you may have the need to detect the installed version on the handset your application is running on (maybe simplifying/optimizing a complex query with operators introduced in some 3.4+ version).

So you have two different possibilities for doing so. If you have the device at hand and want to know the version, you can simply plug the USB cable and connect through the adb bridge typing (Alex, Stackoverflow)
$ adb shell
$ sqlite3 --version
Alternatively the following code determines the version at runtime:
Cursor cursor = SQLiteDatabase.openOrCreateDatabase(":memory:", null).rawQuery("select sqlite_version() AS sqlite_version", null);
String sqliteVersion = "";
sqliteVersion += cursor.getString(0);
Interestingly, several comments of other users on my Stackoverflow post revealed that there are substantially higher SQLite versions available on the devices as 3.4.0.
Questions? Thoughts? Hit me up on Twitter
comments powered by Disqus