Search code examples
androidsqlitefts3

How to debug SQLite database from SQLite Openhelper?


Usually when I want to see the contents of a SQLite database, I use the sqlite3 executable and give it commands like:

.open MYDATABASE.db
SELECT * FROM myUserTable;

It then outputs my table via command line and it is very easy to see the contents of anything in my database.

Unfortunately, the SQLite database I am working with does not even have an associated .db file. It extends from a class called SQLiteOpenHelper. The class resides in a file called DBHandler.java, but obviously attempting to execute command line statements (i.e. as I am used to) fails in this instance.

Does anyone know how to debug a SQLite database that extends from SQLiteOpenHelper?


Solution

  • You can use the cursor to see the content of your sqliteDb :

    public Cursor selectRecords() {
       String[] cols = new String[] {USER_ID, USER_NAME};  
       Cursor mCursor = database.query(true, USER_TABLE,cols,null  
                , null, null, null, null, null);  
       if (mCursor != null) {  
         mCursor.moveToFirst();  
       }  
       return mCursor; // iterate to get each value.
    }