Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print query executed by query() method of android

Tags:

android

sqlite

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.

like image 335
Bagesh Sharma Avatar asked Feb 07 '13 06:02

Bagesh Sharma


People also ask

How do I print a query in CI 4?

Use the below query to display the query string: print_r($this->db->last_query()); To display the query result follow this: print_r($query);

Which method is used for running SQL queries in android?

The rawQuery() method allows an app to have great flexibility and construct more complex queries using joins, sub-queries, unions, or any other SQL construct supported by SQLite.

Which method is used to execute the SQLite raw queries?

RawQuery methods must return a non-void type. If you want to execute a raw query that does not return any value, use RoomDatabase#query methods. RawQuery methods can only be used for read queries. For write queries, use RoomDatabase.

What is query Language android?

android.arch.persistence.room.Query. Marks a method in a Dao annotated class as a query method. The value of the annotation includes the query that will be run when this method is called. This query is verified at compile time by Room to ensure that it compiles fine against the database.


1 Answers

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);
like image 143
Bagesh Sharma Avatar answered Sep 20 '22 09:09

Bagesh Sharma