Android sqlite show tables

Is it possible to query a list of tables in a database in Cursor? I don't know how to implement show tables method in android. One way is to store all tables in the "collector" table as records, but this is a workaround.

PS: I don't need all the tables, only those that start with "PR_" (I know how to handle this in queries, which I don't know if it matters in this case).

+3


source to share


2 answers


I found a solution. In the SQLiteOpenHelper class:

public Cursor showAllTables(){
        String mySql = " SELECT name FROM sqlite_master " + " WHERE type='table'             "
                + "   AND name LIKE 'PR_%' ";
        return ourDatabase.rawQuery(mySql, null);
    }

      



In action:

     Cursor c = info.showAllTables();
             if (c.moveToFirst())
             {
             do{
                todoItems.add(c.getString(0));

                }while (c.moveToNext());
             }
             if (todoItems.size() >= 0)
             {
                 for (int i=0; i<todoItems.size(); i++)
                 {
                     Log.d("TODOItems(" + i + ")", todoItems.get(i) + "");

                 }

             }

      

+7


source


In SQLite, you can query SQLITE_MASTER. Hasn't tested this on Android. See http://sqlite.org/faq.html#q7



+2


source







All Articles