我试图将详细信息保存到数据库中。这是我创建表和列时的部分。但我在"("。
附近)收到异常错误public void onCreate(SQLiteDatabase db) {
db.execSQL(" CREATE TABLE " + TABLE_NAME + " (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT , " + TITLE + " TEXT NOT NULL ," + TIME + " TEXT NOT NULL , " + DATE + " TEXT NOT NULL , " + DETAILS + " TEXT NOT NULL, ("+TITLE+", "+DATE+" UNIQUE)); ");
}
任何人都可以帮助我吗?
答案 0 :(得分:1)
您的create table语句不正确。
错误在于此部分:
("+TITLE+", "+DATE+" UNIQUE)
根据the documentation,如果您希望您的标题和日期是唯一的(两个字段的组合),您的create语句必须
db.execSQL(" CREATE TABLE " + TABLE_NAME + " (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT , " + TITLE + " TEXT NOT NULL ," + TIME + " TEXT NOT NULL , " + DATE + " TEXT NOT NULL , " + DETAILS + " TEXT NOT NULL, CONSTRAINT uniquetitledate UNIQUE ("+TITLE+", "+DATE+")); ");
或者,如果您希望您的标题是唯一的并且您的日期是唯一的,那么您的create语句必须是
db.execSQL(" CREATE TABLE " + TABLE_NAME + " (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT , " + TITLE + " TEXT NOT NULL ," + TIME + " TEXT NOT NULL , " + DATE + " TEXT NOT NULL , " + DETAILS + " TEXT NOT NULL, CONSTRAINT uniquetitle UNIQUE ("+TITLE+"), CONSTRAINT uniquedate UNIQUE ("+DATE+")); ");