Search code examples
javaandroidsqlitelogcat

How to find out the query being sent into SQLite in Android?


My question is concerned with SQLite database in Android.

When I use a statement like

cursor c = databaseHelper.rawQuery("SELECT " +user_id+" from "+DATABASE_TABLE,new String [] {});

How can I find out the query being sent to the database ?
Is there any way to print the query in Logcat ?


Solution

  • While others have mentioned manually logging the query before calling databaseHelper.rawQuery the big problem with that approach is that modifications are required at call-site, adding the logging statements everywhere the method is called.

    I have not worked on Android but for the exact same issue of logging queries I have used AspectJ with great success. A quick search and glance at android-aspectj suggests the combination works.

    Overall, this seems to be prime cross-cutting usecase and AspectJ would be the best approach.