fic: Fix exercice deletion

This commit is contained in:
nemunaire 2021-09-02 02:25:18 +02:00
parent 17839474e1
commit 2246e00948
4 changed files with 7 additions and 1 deletions

View File

@ -261,7 +261,7 @@ CREATE TABLE IF NOT EXISTS exercice_hints_omcq_deps(
id_hint INTEGER NOT NULL,
id_mcq_dep INTEGER NOT NULL,
FOREIGN KEY(id_hint) REFERENCES exercice_hints(id_hint),
FOREIGN KEY(id_mcq_dep) REFERENCES exercice_flags(id_flag)
FOREIGN KEY(id_mcq_dep) REFERENCES exercice_mcq(id_mcq)
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_bin;
`); err != nil {
return err

View File

@ -243,6 +243,8 @@ func (e Exercice) DeleteCascade() (int64, error) {
return 0, err
} else if _, err := DBExec("DELETE FROM exercice_hints_okey_deps WHERE id_hint IN (SELECT id_hint FROM exercice_hints WHERE id_exercice = ?)", e.Id); err != nil {
return 0, err
} else if _, err := DBExec("DELETE FROM exercice_hints_omcq_deps WHERE id_hint IN (SELECT id_hint FROM exercice_hints WHERE id_exercice = ?)", e.Id); err != nil {
return 0, err
} else if _, err := DBExec("DELETE FROM exercice_hints WHERE id_exercice = ?", e.Id); err != nil {
return 0, err
} else if _, err := DBExec("DELETE FROM exercice_flags_deps WHERE id_flag IN (SELECT id_flag FROM exercice_flags WHERE id_exercice = ?)", e.Id); err != nil {

View File

@ -198,6 +198,8 @@ func (k FlagKey) Delete() (int64, error) {
return 0, err
} else if _, err := DBExec("DELETE FROM exercice_flags_deps WHERE id_flag = ? OR id_flag_dep = ?", k.Id, k.Id); err != nil {
return 0, err
} else if _, err := DBExec("DELETE FROM exercice_hints_okey_deps WHERE id_flag_dep = ?", k.Id); err != nil {
return 0, err
} else if _, err := DBExec("DELETE FROM flag_choices WHERE id_flag = ?", k.Id); err != nil {
return 0, err
} else if res, err := DBExec("DELETE FROM exercice_flags WHERE id_flag = ?", k.Id); err != nil {

View File

@ -172,6 +172,8 @@ func (m MCQ) Delete() (int64, error) {
return 0, err
} else if _, err := DBExec("DELETE FROM exercice_flags_omcq_deps WHERE id_mcq_dep = ?", m.Id); err != nil {
return 0, err
} else if _, err := DBExec("DELETE FROM exercice_hints_omcq_deps WHERE id_mcq_dep = ?", m.Id); err != nil {
return 0, err
} else if res, err := DBExec("DELETE FROM exercice_mcq WHERE id_mcq = ?", m.Id); err != nil {
return 0, err
} else if nb, err := res.RowsAffected(); err != nil {