Search code examples
javaandroidsqlitecursor

Get SQL command from a Cursor in JAVA (android)


How can i retrieve the sql statement from a cursor, something like the code below:

Cursor cursor = AppController.getDBO().rawQuery("SELECT * FROM tbl_name", null);
System.out.println(cursor.getSQL()?

Solution

  • There is no way, as a Cursor may be a non-SQL Cursor like MatrixCursor.

    A way to do it would be to follow those steps :

    1. Add a custom class which implements Cursor, and with a member called sqlStatement
    2. Add a custom method to performs a rawQuery in a class dedicated to SQL management (maybe a one extending SQLiteOpenHelper), that will return your custom class implementing cursor, and in which you will set the SQL statement.

    Yes, it's a bit complicated, but it's the only way I know.