How to print a query executed by query () method for android

We pass so many parameters to the query () method for android. Android has simplified our work by providing a request method. Is there a way so that I can print the sql query that android will form from this argument of the query method that android creates and sends to sqlite.

+7
source share
3 answers

According to the previous post, I tried and I got the following solution to print the query string in the log.

Use the buildQueryString SQLiteQueryBuilder method. It takes almost the same parameters as the query() method takes .........

 String sqlQry = SQLiteQueryBuilder.buildQueryString(false,TABLE_NAME, null, COLUMN_NAME_PATIENTID +"="+ patientID, null, null, COLUMN_NAME_PATIENTFIRSTNAME, null); Log.i(TAG, sqlQry); cursor = db.query(TABLE_NAME, null, COLUMN_NAME_PATIENTID +"="+ patientID, null, null, null, COLUMN_NAME_PATIENTFIRSTNAME); 
+6
source

For what it's worth, if you run under the debugger, you can view the private member mQuery , which shows you the exact SQL query executed on this cursor - it is convenient and can be used on demand without dumping with any code.

+6
source

Since the request methods have a cursor type, I'm not sure if it will be printed or not. If you want to debug any query, you can use the EXPLAIN QUERY PLAN keyword along with the query or use SQLiteQueryBuilder () or simply run the SQL query using the rawQuery () method. You can take links from:

http://developer.android.com/reference/android/database/sqlite/SQLiteQueryBuilder.html

http://www.sqlite.org/eqp.html

0
source

All Articles