libfic: add new functions to retrieve the Id of some contents from Title, Label, ...

This commit is contained in:
nemunaire 2019-11-25 14:19:29 +01:00
commit 698c2f1a47
4 changed files with 30 additions and 0 deletions

View file

@ -102,6 +102,15 @@ func (m MCQ) GetId() int64 {
return m.Id
}
// RecoverId returns the MCQ identifier as register in DB.
func (m MCQ) RecoverId() (Flag, error) {
if err := DBQueryRow("SELECT id_mcq FROM exercice_mcq WHERE title LIKE ? AND id_exercice = ?", m.Title, m.IdExercice).Scan(&m.Id); err != nil {
return MCQ{}, err
} else {
return m, err
}
}
// Create registers a MCQ into the database and recursively add its entries.
func (m MCQ) Create(e Exercice) (Flag, error) {
if res, err := DBExec("INSERT INTO exercice_mcq (id_exercice, title) VALUES (?, ?)", e.Id, m.Title); err != nil {