Android的SQLite数据库模式模式、数据库、Android、SQLite

2023-09-07 23:42:28 作者:最繁华时最悲凉

我想我已经创建了一个数据库sqllite与Android,但我每次去做到这一点声称列不存在插入。我怎样才能查看架构并呼吁创建对象onCreate方法?

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?

推荐答案

您可以用code做到这一点。 sqlite的有一个叫SQLITE_MASTER表,该表holdes此信息。

You can do it with code. Sqlite has a table called "sqlite_master " which holdes this information.

/**
     * Get all table Details from teh 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 .

开启DDMS透视图找到数据/数据​​/ PACKAGENAME /数据库/ YOURFILE 单击从数据库按钮,在显示画面右上角的拉动。

打开

Open