8

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.

1
  • you mean return database.rawQuery("SELECT * FROM content where pc=" + pc + " and sc=" + sc + "", null);...and display this in log if right then use sysout for print on logcat Commented Feb 7, 2013 at 6:56

3 Answers 3

8

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

Use 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);
Sign up to request clarification or add additional context in comments.

1 Comment

Can't format arguments to where query. Not the same
8

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.

Comments

0

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:

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.