We pass so many parameters to query() method of android. Android has simplified our work by giving query method. Is there any way so that i can print the sql query which android will form from this query method arguments which android creates and sends to sqlite.
According to a previous post, I have tried and I got the following solution in order to print the query string in the log.
buildQueryString method of
SQLiteQueryBuilder. It takes almost same parameters as
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);
For what it’s worth, if you run under the debugger you can view the private member variable
mQuery, which shows you the exact SQL query executed on that cursor – it’s handy and can be used on demand without mucking with any code.
Since the query methods are of cursor type, I am not sure whether It will be printed or not.
If you want to debug any query, you can use EXPLAIN QUERY PLAN keyword along with the query or use SQLiteQueryBuilder() or simply run the SQL query by using rawQuery() method.
You can take references from: