Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Sqlite database schema

Tags:

android

sqlite

I think I have created an sqllite database with android but every time I go to do an insert it claims a column does not exist. How can I view the schema and is the onCreate method called on object creation?

like image 762
Paul Avatar asked Jan 17 '13 23:01

Paul


1 Answers

You can do it with code. Sqlite has a table called "sqlite_master " which holds the schema information.

    /**
     * Get all table Details from the sqlite_master table in Db.
     * 
     * @return An ArrayList of table details.
     */
    public ArrayList<String[]> getDbTableDetails() {
        Cursor c = db.rawQuery(
                "SELECT name FROM sqlite_master WHERE type='table'", null);
        ArrayList<String[]> result = new ArrayList<String[]>();
        int i = 0;
        result.add(c.getColumnNames());
        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
            String[] temp = new String[c.getColumnCount()];
            for (i = 0; i < temp.length; i++) {
                temp[i] = c.getString(i);
            }
            result.add(temp);
        }

        return result;
    }

A more simple way is to run it on the emulator .

  1. open ddms perspective
  2. Find data/data/PACKAGENAME/database/YOURFILE
  3. Click the pull from db button on top right shown in picture.

Open enter image description here

like image 147
wtsang02 Avatar answered Oct 04 '22 15:10

wtsang02