Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: max sql return null #278

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions pkg/database/dao/subject_template_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,24 @@ func (m *subjectTemplateGroupManager) GetMaxExpiredAtBySubjectGroup(
subjectPK, groupPK int64,
excludeTemplateID int64,
) (int64, error) {
var expiredAt int64
var nullExpiredAt sql.NullInt64
zhu327 marked this conversation as resolved.
Show resolved Hide resolved
query := `SELECT
MAX(expired_at)
FROM subject_template_group
WHERE subject_pk = ?
AND group_pk = ?
AND template_id != ?`
err := database.SqlxGet(m.DB, &expiredAt, query, subjectPK, groupPK, excludeTemplateID)
return expiredAt, err
err := database.SqlxGet(m.DB, &nullExpiredAt, query, subjectPK, groupPK, excludeTemplateID)
if err != nil {
return 0, err
}

if nullExpiredAt.Valid {
return nullExpiredAt.Int64, nil
}

// Handle NULL case, for example, by returning a default value
return 0, nil
}

func (m *subjectTemplateGroupManager) ListPagingTemplateGroupMember(
Expand Down