How to count number of columns in a table in SQLITE?

后端 未结 4 1574
我寻月下人不归
我寻月下人不归 2021-01-13 03:59

How can I count the number of columns in a table in a sqlite database in Android?

4条回答
  •  滥情空心
    2021-01-13 04:47

    Here is the code and it runs perfectly without any error.

    public Cursor getAllTitles(){
       return db.query(DATABASE_TABLE, new String[] {
            KEY_ROWID,KEY_ISBN,KEY_TITLE,KEY_PUBLISHER},
            null,null,null,null,null);
    }
    

    Now create the following object in onCreate() method to call above getAllTitles() method.

    Cursor c = db.getAllTitles();
    c.getColumnCount(); //this line will give the number of columns in table.
    

提交回复
热议问题