Skip to content

Commit bcb78e7

Browse files
authored
Quote table release in sql queries (#27205)
Fixes #27174 `release` is a reserved keyword in MySql. I can't reproduce the issue on my setup and we have a test for that code but it seems there can be setups where it fails. https://github.com/go-gitea/gitea/blob/a101dbaa7952e359843c6d8303ca24a0e63c865c/tests/integration/repo_activity_test.go#L45-L46
1 parent 0ee7cbf commit bcb78e7

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

models/activities/repo_activity.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,15 @@ func (stats *ActivityStats) FillReleases(ctx context.Context, repoID int64, from
342342

343343
// Published releases list
344344
sess := releasesForActivityStatement(ctx, repoID, fromTime)
345-
sess.OrderBy("release.created_unix DESC")
345+
sess.OrderBy("`release`.created_unix DESC")
346346
stats.PublishedReleases = make([]*repo_model.Release, 0)
347347
if err = sess.Find(&stats.PublishedReleases); err != nil {
348348
return err
349349
}
350350

351351
// Published releases authors
352352
sess = releasesForActivityStatement(ctx, repoID, fromTime)
353-
if _, err = sess.Select("count(distinct release.publisher_id) as `count`").Table("release").Get(&count); err != nil {
353+
if _, err = sess.Select("count(distinct `release`.publisher_id) as `count`").Table("release").Get(&count); err != nil {
354354
return err
355355
}
356356
stats.PublishedReleaseAuthorCount = count
@@ -359,7 +359,7 @@ func (stats *ActivityStats) FillReleases(ctx context.Context, repoID int64, from
359359
}
360360

361361
func releasesForActivityStatement(ctx context.Context, repoID int64, fromTime time.Time) *xorm.Session {
362-
return db.GetEngine(ctx).Where("release.repo_id = ?", repoID).
363-
And("release.is_draft = ?", false).
364-
And("release.created_unix >= ?", fromTime.Unix())
362+
return db.GetEngine(ctx).Where("`release`.repo_id = ?", repoID).
363+
And("`release`.is_draft = ?", false).
364+
And("`release`.created_unix >= ?", fromTime.Unix())
365365
}

modules/doctor/dbconsistency.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func checkDBConsistency(ctx context.Context, logger log.Logger, autofix bool) er
101101
},
102102
// find releases without existing repository
103103
genericOrphanCheck("Orphaned Releases without existing repository",
104-
"release", "repository", "release.repo_id=repository.id"),
104+
"release", "repository", "`release`.repo_id=repository.id"),
105105
// find pulls without existing issues
106106
genericOrphanCheck("Orphaned PullRequests without existing issue",
107107
"pull_request", "issue", "pull_request.issue_id=issue.id"),

0 commit comments

Comments
 (0)