Use MySQL instead of SQLite
This commit is contained in:
parent
32e8f931b9
commit
8788eea4f0
4 changed files with 72 additions and 49 deletions
|
|
@ -119,18 +119,19 @@ func (t Team) HasAccess(e Exercice) bool {
|
|||
}
|
||||
|
||||
func (t Team) HasSolved(e Exercice) (bool, time.Time, int64) {
|
||||
var nb int64
|
||||
var tm int64
|
||||
var mt *time.Time
|
||||
if DBQueryRow("SELECT MIN(time) FROM exercice_solved WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&mt); mt == nil {
|
||||
if err := DBQueryRow("SELECT COUNT(id_exercice), MAX(time) FROM exercice_tries WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&nb, &mt); err != nil {
|
||||
var nb *int64
|
||||
var tm *time.Time
|
||||
if DBQueryRow("SELECT MIN(time) FROM exercice_solved WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&tm); tm == nil {
|
||||
if DBQueryRow("SELECT COUNT(id_exercice), MAX(time) FROM exercice_tries WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&nb, &tm); tm == nil {
|
||||
return false, time.Unix(0, 0), 0
|
||||
} else if nb == nil {
|
||||
return false, *tm, 0
|
||||
} else {
|
||||
return false, *mt, nb
|
||||
return false, *tm, *nb
|
||||
}
|
||||
} else if err := DBQueryRow("SELECT COUNT(id_exercice) FROM exercice_solved WHERE id_exercice = ? AND time < ?", e.Id, tm).Scan(&nb); err != nil {
|
||||
return true, time.Unix(tm, 0), 0
|
||||
} else if DBQueryRow("SELECT COUNT(id_exercice) FROM exercice_solved WHERE id_exercice = ? AND time < ?", e.Id, tm).Scan(&nb); nb == nil {
|
||||
return true, *tm, 0
|
||||
} else {
|
||||
return true, time.Unix(tm, 0), nb + 1
|
||||
return true, *tm, *nb + 1
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue