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.
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);
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.
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.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With