How to get all table names in android sqlite database?

后端 未结 5 1594
逝去的感伤
逝去的感伤 2020-12-05 06:37

I have tried this code

Cursor c=db.rawQuery("SELECT name FROM sqlite_master WHERE type = \'table\'",null);
c.moveToFirst();
while(!c.isAfterLast()){         


        
5条回答
  •  粉色の甜心
    2020-12-05 07:02

    Try adding the schema before the table

    schema.sqlite_master

    From SQL FAQ

    If you are running the sqlite3 command-line access program you can type ".tables" to get a list of all tables. Or you can type ".schema" to see the complete database schema including all tables and indices. Either of these commands can be followed by a LIKE pattern that will restrict the tables that are displayed.

    From within a C/C++ program (or a script using Tcl/Ruby/Perl/Python bindings) you can get access to table and index names by doing a SELECT on a special table named "SQLITE_MASTER". Every SQLite database has an SQLITE_MASTER table that defines the schema for the database. The SQLITE_MASTER table looks like this:

    CREATE TABLE sqlite_master ( type TEXT, name TEXT, tbl_name TEXT, rootpage INTEGER, sql TEXT );

提交回复
热议问题