在级联删除android Sqlite 3.7.11无法正常工作

时间:2013-04-19 17:56:22

标签: android sqlite

我帮助了3个表

1)用于用户信息存储的Login_Table表 2)Service_Table用于存储具有一列引用Login_Table表的服务 3)SubService_Table用于存储具有一列引用service_table和另一个Login_Table表的子服务

我想删除特定服务表中的行然后从引用服务表id表的子服务行中自动删除记录但是当我从服务表中删除特定行时它强制关闭

db.execSQL( " CREATE TABLE "+ LoginTable +" ( " +login_ID + " INTEGER PRIMARY KEY AUTOINCREMENT , " + NAME + " TEXT, " + USERNAME + " TEXT, " +PASSWORD + " TEXT," + GENDER + " TEXT, " + CONTACT + " TEXT, " + SQUE + " TEXT, " + ANSWER + " TEXT, " + EmailId + " TEXT, " + UType+" TEXT)");

db.execSQL("CREATE TABLE "+Services+"("+Ser_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+Ser_Name+" TEXT, "+Ser_UID+" Integer not null, FOREIGN KEY ("+Ser_UID+") REFERENCES "+LoginTable+" ("+login_ID+"));");

db.execSQL("CREATE TABLE "+Sub_Services+"("+Sub_Ser_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+Sub_Ser_Name+" TEXT, "+Ref_Ser_ID+" Integer not null, "+Sub_Ser_UID+" Integer not null, FOREIGN KEY ("+Ref_Ser_ID+") REFERENCES "+Services+" ("+Ser_ID+") ON DELETE CASCADE , FOREIGN KEY ("+Sub_Ser_UID+") REFERENCES "+LoginTable+" ("+login_ID+")) ;");

我也通过以下代码

使用了启用外键

public void onOpen(SQLiteDatabase db) {
        super.onOpen(db);
        if (!db.isReadOnly()) {
        db.execSQL("PRAGMA foreign_keys=ON;");
        }
    }

public void onOpen(SQLiteDatabase db) { super.onOpen(db); if (!db.isReadOnly()) { db.execSQL("PRAGMA foreign_keys=ON;"); } }

cascade删除如何在android SQLite中使用?我用的是android 4.2和sqlite 3.7.11的版本......

0 个答案:

没有答案