简体   繁体   English

无法编辑 SQLite 数据库名称

[英]Can't edit SQLite database name

I can't edit my database name and I can't find the list of information I put into the database.我无法编辑我的数据库名称,也找不到我放入数据库的信息列表。

If I try to change the database name from "diet" to something else, I'm still able to run but there's the green underline typo.如果我尝试将数据库名称从“饮食”更改为其他名称,我仍然可以运行,但出现绿色下划线错误。 I'm following this tutorial.我正在关注本教程。

public class DietDbHelper extends SQLiteOpenHelper {
    public static final String TABLE_NAME = "entry";
    public static final String COLUMN_NAME_ID = "_id";
    public static final String COLUMN_NAME_TIMESTAMP = "timestamp";
    public static final String COLUMN_NAME_WEIGHT = "weight";

    private static final String SQL_CREATE_ENTRIES =
            "CREATE TABLE " + TABLE_NAME + " (" +
                    COLUMN_NAME_ID + " INTEGER PRIMARY KEY," +
                    COLUMN_NAME_TIMESTAMP + " INTEGER," +
                    COLUMN_NAME_WEIGHT + " INTEGER )";

    private static final String SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS " + TABLE_NAME;

    // If you change the database schema, you must increment the database version.
    public static final int DATABASE_VERSION = 2;
    public static final String DATABASE_NAME = "diet";

    public DietDbHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(SQL_CREATE_ENTRIES);
    }
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // This database is only a cache for online data, so its upgrade policy is
        // to simply to discard the data and start over
        db.execSQL(SQL_DELETE_ENTRIES);
        onCreate(db);
    }
    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        onUpgrade(db, oldVersion, newVersion);
    }
}

I would change your database name code from public static final String DATABASE_NAME = "diet";我会从 public static final String DATABASE_NAME = "diet"; 更改您的数据库名称代码。

to public static final String DATABASE_NAME = "diet.db";到 public static final String DATABASE_NAME = "diet.db"; All of my sqlite column names, table and database names are highlighted in green.我所有的 sqlite 列名、表名和数据库名都以绿色突出显示。

you have to change database version for each change that you make in your database structure.您必须为您在数据库结构中所做的每个更改更改数据库版本。 for example change :例如改变:

public static final int DATABASE_VERSION = 2;

to

public static final int DATABASE_VERSION = 3;

and so on for every change.等等每次更改。 I hope it will help我希望它会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM