Coder Social home page Coder Social logo

Comments (3)

pkbutler avatar pkbutler commented on June 6, 2024 1

No this requires a change in gogs to process this correctly for mssql.

I did a local recompile with the following changes, if that helps anyone fix this.
file: internal/db/actions.go


 func (db *actions) ListByUser(ctx context.Context, userID, actorID, afterID int64, isProfile bool) ([]*Action, error) {
diff --git a/internal/db/repo.go b/internal/db/repo.go
index 8f15ea2b..fff66768 100644
--- a/internal/db/repo.go
+++ b/internal/db/repo.go
@@ -2392,7 +2392,7 @@ func GetWatchers(repoID int64) ([]*Watch, error) {
 func (repo *Repository) GetWatchers(page int) ([]*User, error) {
        users := make([]*User, 0, ItemsPerPage)
        sess := x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).Where("watch.repo_id=?", repo.ID)
-       if conf.UsePostgreSQL {
+       if conf.UsePostgreSQL || conf.UseMSSQL {
                sess = sess.Join("LEFT", "watch", `"user".id=watch.user_id`)
        } else {
                sess = sess.Join("LEFT", "watch", "user.id=watch.user_id")
@@ -2492,7 +2492,7 @@ func IsStaring(userID, repoID int64) bool {
 func (repo *Repository) GetStargazers(page int) ([]*User, error) {
        users := make([]*User, 0, ItemsPerPage)
        sess := x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).Where("star.repo_id=?", repo.ID)
-       if conf.UsePostgreSQL {
+       if conf.UsePostgreSQL || conf.UseMSSQL {
                sess = sess.Join("LEFT", "star", `"user".id=star.uid`)
        } else {
                sess = sess.Join("LEFT", "star", "user.id=star.uid")
diff --git a/internal/dbutil/string.go b/internal/dbutil/string.go
index 4ee3f012..9afeb2d3 100644
--- a/internal/dbutil/string.go
+++ b/internal/dbutil/string.go
@@ -11,12 +11,16 @@ import (
 )

 // Quote adds surrounding double quotes for all given arguments before being
-// formatted if the current database is UsePostgreSQL.
+// formatted if the current database is UsePostgreSQL
+// Quote adds surrounding square brackets for all given arguments before being
+// formatted if the current database is UseMSSQL.
 func Quote(format string, args ...string) string {
        anys := make([]any, len(args))
        for i := range args {
                if conf.UsePostgreSQL {
                        anys[i] = `"` + args[i] + `"`
+               } else if conf.UseMSSQL {
+                       anys[i] = `[` + args[i] + `]`
                } else {
                        anys[i] = args[i]
                }


from gogs.

pkbutler avatar pkbutler commented on June 6, 2024

The term user is a mssql reserved word so in the FROM and WHERE parts of the query the usage of user must be quoted i.e. user.type = '0' should be "user".type or [user].type

from gogs.

ItsFullOfCode avatar ItsFullOfCode commented on June 6, 2024

Thanks. Is there something I can do about this? The query is generated by Gogs.

from gogs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.