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) { ...@@ -53,6 +53,8 @@ func (MySQLTitleQuery) Select(userID uint32) ([]schemas.TitleSchema, error) {
for rows.Next() { for rows.Next() {
var tmpTitle schemas.TitleSchema var tmpTitle schemas.TitleSchema
var tmpUnlockScore sql.NullInt32
var tmpUnlockWin sql.NullInt32
// Temporary subject // Temporary subject
var tmpSubjectID sql.NullInt32 var tmpSubjectID sql.NullInt32
...@@ -69,14 +71,26 @@ func (MySQLTitleQuery) Select(userID uint32) ([]schemas.TitleSchema, error) { ...@@ -69,14 +71,26 @@ func (MySQLTitleQuery) Select(userID uint32) ([]schemas.TitleSchema, error) {
&(tmpSubjectShortForm), &(tmpSubjectShortForm),
&(tmpSubjectDepartment), &(tmpSubjectDepartment),
&(tmpSubjectDescription), &(tmpSubjectDescription),
&(tmpTitle.UnlockScore), &(tmpUnlockScore),
&(tmpTitle.UnlockWin), &(tmpUnlockWin),
) )
if errFetch != nil { if errFetch != nil {
return nil, fmt.Errorf("Cannot scan db values into titles list. " + errFetch.Error()) 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 { if tmpSubjectName.Valid {
tmpTitle.Subject = &schemas.Subject{ tmpTitle.Subject = &schemas.Subject{
ID: uint32(tmpSubjectID.Int32), ID: uint32(tmpSubjectID.Int32),
...@@ -129,6 +143,9 @@ func (MySQLTitleQuery) SelectAll() ([]schemas.TitleSchema, error) { ...@@ -129,6 +143,9 @@ func (MySQLTitleQuery) SelectAll() ([]schemas.TitleSchema, error) {
for rows.Next() { for rows.Next() {
var tmpTitle schemas.TitleSchema var tmpTitle schemas.TitleSchema
var tmpUnlockScore sql.NullInt32
var tmpUnlockWin sql.NullInt32
// Temporary subject // Temporary subject
var tmpSubjectID sql.NullInt32 var tmpSubjectID sql.NullInt32
var tmpSubjectName sql.NullString var tmpSubjectName sql.NullString
...@@ -144,14 +161,26 @@ func (MySQLTitleQuery) SelectAll() ([]schemas.TitleSchema, error) { ...@@ -144,14 +161,26 @@ func (MySQLTitleQuery) SelectAll() ([]schemas.TitleSchema, error) {
&(tmpSubjectShortForm), &(tmpSubjectShortForm),
&(tmpSubjectDepartment), &(tmpSubjectDepartment),
&(tmpSubjectDescription), &(tmpSubjectDescription),
&(tmpTitle.UnlockScore), &(tmpUnlockScore),
&(tmpTitle.UnlockWin), &(tmpUnlockWin),
) )
if errFetch != nil { if errFetch != nil {
return nil, fmt.Errorf("Cannot scan db values into titles list. " + errFetch.Error()) 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 { if tmpSubjectName.Valid {
tmpTitle.Subject = &schemas.Subject{ tmpTitle.Subject = &schemas.Subject{
ID: uint32(tmpSubjectID.Int32), ID: uint32(tmpSubjectID.Int32),
...@@ -196,6 +225,9 @@ func (MySQLTitleQuery) SelectByID(titleID uint32) (*schemas.TitleSchema, error) ...@@ -196,6 +225,9 @@ func (MySQLTitleQuery) SelectByID(titleID uint32) (*schemas.TitleSchema, error)
var title schemas.TitleSchema var title schemas.TitleSchema
var tmpUnlockScore sql.NullInt32
var tmpUnlockWin sql.NullInt32
// Temporary subject // Temporary subject
var tmpSubjectID sql.NullInt32 var tmpSubjectID sql.NullInt32
var tmpSubjectName sql.NullString var tmpSubjectName sql.NullString
...@@ -211,14 +243,26 @@ func (MySQLTitleQuery) SelectByID(titleID uint32) (*schemas.TitleSchema, error) ...@@ -211,14 +243,26 @@ func (MySQLTitleQuery) SelectByID(titleID uint32) (*schemas.TitleSchema, error)
&(tmpSubjectShortForm), &(tmpSubjectShortForm),
&(tmpSubjectDepartment), &(tmpSubjectDepartment),
&(tmpSubjectDescription), &(tmpSubjectDescription),
&title.UnlockScore, &tmpUnlockScore,
&title.UnlockWin, &tmpUnlockWin,
) )
if errScan != nil { if errScan != nil {
return nil, fmt.Errorf("Could not get title form database. %s", errScan.Error()) 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 { if tmpSubjectName.Valid {
title.Subject = &schemas.Subject{ title.Subject = &schemas.Subject{
ID: uint32(tmpSubjectID.Int32), ID: uint32(tmpSubjectID.Int32),
...@@ -257,6 +301,7 @@ func (MySQLTitleQuery) SelectAndUpdateNew(userID uint32) ([]schemas.TitleSchema, ...@@ -257,6 +301,7 @@ func (MySQLTitleQuery) SelectAndUpdateNew(userID uint32) ([]schemas.TitleSchema,
for res.Next() { for res.Next() {
var newTitle = schemas.TitleSchema{} var newTitle = schemas.TitleSchema{}
var tmpUnlockScore sql.NullInt32
var tmpSubjectID sql.NullInt32 var tmpSubjectID sql.NullInt32
var tmpSubjectName sql.NullString var tmpSubjectName sql.NullString
var tmpSubjectShortForm sql.NullString var tmpSubjectShortForm sql.NullString
...@@ -270,12 +315,18 @@ func (MySQLTitleQuery) SelectAndUpdateNew(userID uint32) ([]schemas.TitleSchema, ...@@ -270,12 +315,18 @@ func (MySQLTitleQuery) SelectAndUpdateNew(userID uint32) ([]schemas.TitleSchema,
&(tmpSubjectShortForm), &(tmpSubjectShortForm),
&(tmpSubjectDepartment), &(tmpSubjectDepartment),
&(tmpSubjectDescription), &(tmpSubjectDescription),
&newTitle.UnlockScore) &tmpUnlockScore)
if errScan != nil { if errScan != nil {
return nil, fmt.Errorf("Could not scan new titles query result. %s", errScan.Error()) 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 { if tmpSubjectID.Valid {
// the title has a subject. subject is not null // the title has a subject. subject is not null
var subject schemas.Subject 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