Skip to content

Commit

Permalink
Fix DBConsistency checks on MSSQL (go-gitea#23132)
Browse files Browse the repository at this point in the history
Unfortunately xorm's `builder.Select(...).From(...)` does not escape the
table names. This is mostly not a problem but is a problem with the
`user` table.

This PR simply escapes the user table. No other uses of `From("user")`
where found in the codebase so I think this should be all that is
needed.

Fix go-gitea#23064

Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath authored and yardenshoham committed Feb 24, 2023
1 parent 8adc6a1 commit f7b5a40
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions models/issues/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ func CountOrphanedLabels() (int64, error) {
norepo, err := db.GetEngine(db.DefaultContext).Table("label").
Where(builder.And(
builder.Gt{"repo_id": 0},
builder.NotIn("repo_id", builder.Select("id").From("repository")),
builder.NotIn("repo_id", builder.Select("id").From("`repository`")),
)).
Count()
if err != nil {
Expand All @@ -765,7 +765,7 @@ func CountOrphanedLabels() (int64, error) {
noorg, err := db.GetEngine(db.DefaultContext).Table("label").
Where(builder.And(
builder.Gt{"org_id": 0},
builder.NotIn("org_id", builder.Select("id").From("user")),
builder.NotIn("org_id", builder.Select("id").From("`user`")),
)).
Count()
if err != nil {
Expand All @@ -786,7 +786,7 @@ func DeleteOrphanedLabels() error {
if _, err := db.GetEngine(db.DefaultContext).
Where(builder.And(
builder.Gt{"repo_id": 0},
builder.NotIn("repo_id", builder.Select("id").From("repository")),
builder.NotIn("repo_id", builder.Select("id").From("`repository`")),
)).
Delete(Label{}); err != nil {
return err
Expand All @@ -796,7 +796,7 @@ func DeleteOrphanedLabels() error {
if _, err := db.GetEngine(db.DefaultContext).
Where(builder.And(
builder.Gt{"org_id": 0},
builder.NotIn("org_id", builder.Select("id").From("user")),
builder.NotIn("org_id", builder.Select("id").From("`user`")),
)).
Delete(Label{}); err != nil {
return err
Expand Down

0 comments on commit f7b5a40

Please sign in to comment.