I am using the query
functions in order to build the SQL queries for my tables. Is there a way to see the actual query that is run? For instance log it somewher
adb shell setprop log.tag.SQLiteStatements VERBOSE
Don't forget to restart your app after setting this property.
It is also possible to enable logging of execution time. More details are availabe here: http://androidxref.com/4.2.2_r1/xref/frameworks/base/core/java/android/database/sqlite/SQLiteDebug.java
adb shell setprop log.tag.SQLiteLog V adb shell setprop log.tag.SQLiteStatements V adb shell stop adb shell start
You can apply your own SQLiteDatabase.CursorFactory
to the database. (See the openDatabase parameters.) This will allow you to create your own subclass of Cursor
, which keeps the query in an easily accessible field.
edit: In fact, you may not even have to subclass Cursor
. Just have your factory's newCursor()
method return a standard SQLiteCursor
, but log the query before doing so.
Using an SQLiteQueryBuilder
it's painfully simple. buildQuery()
returns a raw sql string, which can then be logged:
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(ExampleTable.TABLE_NAME);
String sql = qb.buildQuery(projection, selection, null, null, sortOrder, null);
Log.d("Example", sql);
If it is for once off scenario, I would suggest injecting an error (e.g. type in expression like LIEK instead of LIKE!) and watch the Eclipse LogCat for any errors! HTH!
So far the best I could do was to have a look at the cursor's member mQuery using a breakpoint. This member is of course not public and does not have a getter, hence, no way to output it. Any better suggestion?