Commit 494a2c82 authored by Julien Schröter's avatar Julien Schröter Committed by Julien Schröter

Allow title's unlock_score or unlock_win to be null

parent 31513bea
Pipeline #2020 canceled with stages
in 1 minute and 52 seconds
......@@ -53,6 +53,8 @@ func (MySQLTitleQuery) Select(userID uint32) ([]schemas.TitleSchema, error) {
for rows.Next() {
var tmpTitle schemas.TitleSchema
var tmpUnlockScore sql.NullInt32
var tmpUnlockWin sql.NullInt32
// Temporary subject
var tmpSubjectID sql.NullInt32
......@@ -69,14 +71,26 @@ func (MySQLTitleQuery) Select(userID uint32) ([]schemas.TitleSchema, error) {
&(tmpSubjectShortForm),
&(tmpSubjectDepartment),
&(tmpSubjectDescription),
&(tmpTitle.UnlockScore),
&(tmpTitle.UnlockWin),
&(tmpUnlockScore),
&(tmpUnlockWin),
)
if errFetch != nil {
return nil, fmt.Errorf("Cannot scan db values into titles list. " + errFetch.Error())
}
if tmpUnlockScore.Valid {
tmpTitle.UnlockScore = tmpUnlockScore.Int32
} else {
tmpTitle.UnlockScore = -1
}
if tmpUnlockWin.Valid {
tmpTitle.UnlockWin = tmpUnlockWin.Int32
} else {
tmpTitle.UnlockWin = -1
}
if tmpSubjectName.Valid {
tmpTitle.Subject = &schemas.Subject{
ID: uint32(tmpSubjectID.Int32),
......@@ -129,6 +143,9 @@ func (MySQLTitleQuery) SelectAll() ([]schemas.TitleSchema, error) {
for rows.Next() {
var tmpTitle schemas.TitleSchema
var tmpUnlockScore sql.NullInt32
var tmpUnlockWin sql.NullInt32
// Temporary subject
var tmpSubjectID sql.NullInt32
var tmpSubjectName sql.NullString
......@@ -144,14 +161,26 @@ func (MySQLTitleQuery) SelectAll() ([]schemas.TitleSchema, error) {
&(tmpSubjectShortForm),
&(tmpSubjectDepartment),
&(tmpSubjectDescription),
&(tmpTitle.UnlockScore),
&(tmpTitle.UnlockWin),
&(tmpUnlockScore),
&(tmpUnlockWin),
)
if errFetch != nil {
return nil, fmt.Errorf("Cannot scan db values into titles list. " + errFetch.Error())
}
if tmpUnlockScore.Valid {
tmpTitle.UnlockScore = tmpUnlockScore.Int32
} else {
tmpTitle.UnlockScore = -1
}
if tmpUnlockWin.Valid {
tmpTitle.UnlockWin = tmpUnlockWin.Int32
} else {
tmpTitle.UnlockWin = -1
}
if tmpSubjectName.Valid {
tmpTitle.Subject = &schemas.Subject{
ID: uint32(tmpSubjectID.Int32),
......@@ -196,6 +225,9 @@ func (MySQLTitleQuery) SelectByID(titleID uint32) (*schemas.TitleSchema, error)
var title schemas.TitleSchema
var tmpUnlockScore sql.NullInt32
var tmpUnlockWin sql.NullInt32
// Temporary subject
var tmpSubjectID sql.NullInt32
var tmpSubjectName sql.NullString
......@@ -211,14 +243,26 @@ func (MySQLTitleQuery) SelectByID(titleID uint32) (*schemas.TitleSchema, error)
&(tmpSubjectShortForm),
&(tmpSubjectDepartment),
&(tmpSubjectDescription),
&title.UnlockScore,
&title.UnlockWin,
&tmpUnlockScore,
&tmpUnlockWin,
)
if errScan != nil {
return nil, fmt.Errorf("Could not get title form database. %s", errScan.Error())
}
if tmpUnlockScore.Valid {
title.UnlockScore = tmpUnlockScore.Int32
} else {
title.UnlockScore = -1
}
if tmpUnlockWin.Valid {
title.UnlockWin = tmpUnlockWin.Int32
} else {
title.UnlockWin = -1
}
if tmpSubjectName.Valid {
title.Subject = &schemas.Subject{
ID: uint32(tmpSubjectID.Int32),
......@@ -257,6 +301,7 @@ func (MySQLTitleQuery) SelectAndUpdateNew(userID uint32) ([]schemas.TitleSchema,
for res.Next() {
var newTitle = schemas.TitleSchema{}
var tmpUnlockScore sql.NullInt32
var tmpSubjectID sql.NullInt32
var tmpSubjectName sql.NullString
var tmpSubjectShortForm sql.NullString
......@@ -270,12 +315,18 @@ func (MySQLTitleQuery) SelectAndUpdateNew(userID uint32) ([]schemas.TitleSchema,
&(tmpSubjectShortForm),
&(tmpSubjectDepartment),
&(tmpSubjectDescription),
&newTitle.UnlockScore)
&tmpUnlockScore)
if errScan != nil {
return nil, fmt.Errorf("Could not scan new titles query result. %s", errScan.Error())
}
if tmpUnlockScore.Valid {
newTitle.UnlockScore = tmpUnlockScore.Int32
} else {
newTitle.UnlockScore = -1
}
if tmpSubjectID.Valid {
// the title has a subject. subject is not null
var subject schemas.Subject
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment