I use this code in onCreate method for create database manualy.But only first line (CREATE TABLE if not exists [tbl_collection]) executed.I execute all query in sqlite expert program and No problem.Please help
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE if not exists [tbl_collection] ( [id] integer PRIMARY KEY AUTOINCREMENT NOT NULL, [name_collection] nvarchar(256) NOT NULL COLLATE NOCASE);");
db.execSQL("CREATE TRIGGER if not exists [fkd_tbl_Subject_id_collection_tbl_collection_id] Before Delete ON [tbl_collection] BEGIN SELECT RAISE(ROLLBACK, 'delete on table tbl_collection violates foreign key constraint fkd_tbl_Subject_id_collection_tbl_collection_id') WHERE (SELECT id_collection FROM tbl_Subject WHERE id_collection = OLD.id) IS NOT NULL; END;");
db.execSQL("CREATE TABLE if not exists [tbl_Subject] ( [id] integer PRIMARY KEY AUTOINCREMENT NOT NULL, [id_collection] integer NOT NULL, [name_subject] nvarchar(256) NOT NULL COLLATE NOCASE, FOREIGN KEY ([id_collection]) REFERENCES [tbl_collection]([id]));");
db.execSQL("CREATE TRIGGER if not exists [fki_tbl_Subject_id_collection_tbl_collection_id] Before Insert ON [tbl_Subject] BEGIN SELECT RAISE(ROLLBACK, 'insert on table tbl_Subject violates foreign key constraint fki_tbl_Subject_id_collection_tbl_collection_id') WHERE (SELECT id FROM tbl_collection WHERE id = NEW.id_collection) IS NULL; END;");
db.execSQL("CREATE TRIGGER if not exists [fku_tbl_Subject_id_collection_tbl_collection_id] Before Update ON [tbl_Subject] BEGIN SELECT RAISE(ROLLBACK, 'update on table tbl_Subject violates foreign key constraint fku_tbl_Subject_id_collection_tbl_collection_id') WHERE (SELECT id FROM tbl_collection WHERE id = NEW.id_collection) IS NULL; END;");
db.execSQL("CREATE TRIGGER if not exists [fkd_tbl_Subject_Property_id_subject_tbl_Subject_id] Before Delete ON [tbl_Subject] BEGIN SELECT RAISE(ROLLBACK, 'delete on table tbl_Subject violates foreign key constraint fkd_tbl_Subject_Property_id_subject_tbl_Subject_id') WHERE (SELECT id_subject FROM tbl_Subject_Property WHERE id_subject = OLD.id) IS NOT NULL; END;");
db.execSQL("CREATE TABLE if not exists [tbl_Subject_Property] ( [id] integer PRIMARY KEY AUTOINCREMENT NOT NULL, [id_subject] integer NOT NULL, [text] nvarchar(512) COLLATE NOCASE, [picture] nvarchar(512) COLLATE NOCASE, [voice] nvarchar(512) COLLATE NOCASE, [video] nvarchar(512) COLLATE NOCASE, FOREIGN KEY ([id_subject]) REFERENCES [tbl_Subject]([id]));");
db.execSQL("CREATE TRIGGER if not exists [fki_tbl_Subject_Property_id_subject_tbl_Subject_id] Before Insert ON [tbl_Subject_Property] BEGIN SELECT RAISE(ROLLBACK, 'insert on table tbl_Subject_Property violates foreign key constraint fki_tbl_Subject_Property_id_subject_tbl_Subject_id') WHERE (SELECT id FROM tbl_Subject WHERE id = NEW.id_subject) IS NULL; END;");
db.execSQL("CREATE TRIGGER if not exists [fku_tbl_Subject_Property_id_subject_tbl_Subject_id] Before Update ON [tbl_Subject_Property] BEGIN SELECT RAISE(ROLLBACK, 'update on table tbl_Subject_Property violates foreign key constraint fku_tbl_Subject_Property_id_subject_tbl_Subject_id') WHERE (SELECT id FROM tbl_Subject WHERE id = NEW.id_subject) IS NULL; END;");
}
Aucun commentaire:
Enregistrer un commentaire