diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-03-22 23:12:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-22 11:12:55 -0400 |
commit | c61b902538e8e4b2bb83136f190e044a6bbcdd9b (patch) | |
tree | bc08142f5ced69721ab14793b8dc62aa83314268 /vendor/xorm.io/builder | |
parent | dcaa5643d70cd1be72e53e82a30d2bc6e5f8de92 (diff) | |
download | gitea-c61b902538e8e4b2bb83136f190e044a6bbcdd9b.tar.gz gitea-c61b902538e8e4b2bb83136f190e044a6bbcdd9b.zip |
Upgrade xorm to v1.0.0 (#10646)
* Upgrade xorm to v1.0.0
* small nit
* Fix tests
* Update xorm
* Update xorm
* fix go.sum
* fix test
* Fix bug when dump
* Fix bug
* update xorm to latest
* Fix migration test
* update xorm to latest
* Fix import order
* Use xorm tag
Diffstat (limited to 'vendor/xorm.io/builder')
-rw-r--r-- | vendor/xorm.io/builder/.drone.yml | 71 | ||||
-rw-r--r-- | vendor/xorm.io/builder/.gitignore | 1 | ||||
-rw-r--r-- | vendor/xorm.io/builder/builder.go | 60 | ||||
-rw-r--r-- | vendor/xorm.io/builder/builder_insert.go | 2 | ||||
-rw-r--r-- | vendor/xorm.io/builder/builder_limit.go | 9 | ||||
-rw-r--r-- | vendor/xorm.io/builder/builder_select.go | 2 | ||||
-rw-r--r-- | vendor/xorm.io/builder/builder_set_operations.go (renamed from vendor/xorm.io/builder/builder_union.go) | 14 | ||||
-rw-r--r-- | vendor/xorm.io/builder/builder_update.go | 4 | ||||
-rw-r--r-- | vendor/xorm.io/builder/cond_eq.go | 4 | ||||
-rw-r--r-- | vendor/xorm.io/builder/go.mod | 2 | ||||
-rw-r--r-- | vendor/xorm.io/builder/go.sum | 4 | ||||
-rw-r--r-- | vendor/xorm.io/builder/sql.go | 9 |
12 files changed, 78 insertions, 104 deletions
diff --git a/vendor/xorm.io/builder/.drone.yml b/vendor/xorm.io/builder/.drone.yml index 557dbf66f0..61d323d5f6 100644 --- a/vendor/xorm.io/builder/.drone.yml +++ b/vendor/xorm.io/builder/.drone.yml @@ -1,31 +1,6 @@ --- kind: pipeline -name: go1.10 - -workspace: - base: /go - path: src/xorm.io/builder - -steps: -- name: test - pull: default - image: golang:1.10 - commands: - - go get -u golang.org/x/lint/golint - - go get -u github.com/stretchr/testify/assert - - go get -u github.com/go-xorm/sqlfiddle - - golint ./... - - go vet - - go test -v -race -coverprofile=coverage.txt -covermode=atomic - when: - event: - - push - - tag - - pull_request - ---- -kind: pipeline -name: go1.11 +name: testing steps: - name: test @@ -43,48 +18,4 @@ steps: event: - push - tag - - pull_request - ---- -kind: pipeline -name: go1.12 - -steps: -- name: test - pull: default - image: golang:1.12 - commands: - - go get -u golang.org/x/lint/golint - - golint ./... - - go vet - - go test -v -race -coverprofile=coverage.txt -covermode=atomic - environment: - GOPROXY: https://goproxy.cn - GO111MODULE: "on" - when: - event: - - push - - tag - - pull_request - ---- -kind: pipeline -name: go1.13 - -steps: -- name: test - pull: default - image: golang:1.13 - commands: - - go get -u golang.org/x/lint/golint - - golint ./... - - go vet - - go test -v -race -coverprofile=coverage.txt -covermode=atomic - environment: - GOPROXY: https://goproxy.cn - GO111MODULE: "on" - when: - event: - - push - - tag - pull_request
\ No newline at end of file diff --git a/vendor/xorm.io/builder/.gitignore b/vendor/xorm.io/builder/.gitignore new file mode 100644 index 0000000000..723ef36f4e --- /dev/null +++ b/vendor/xorm.io/builder/.gitignore @@ -0,0 +1 @@ +.idea
\ No newline at end of file diff --git a/vendor/xorm.io/builder/builder.go b/vendor/xorm.io/builder/builder.go index 4f14222843..cccc8a7fd9 100644 --- a/vendor/xorm.io/builder/builder.go +++ b/vendor/xorm.io/builder/builder.go @@ -17,7 +17,7 @@ const ( insertType // insert updateType // update deleteType // delete - unionType // union + setOpType // set operation ) // all databasees @@ -27,6 +27,10 @@ const ( MYSQL = "mysql" MSSQL = "mssql" ORACLE = "oracle" + + UNION = "union" + INTERSECT = "intersect" + EXCEPT = "except" ) type join struct { @@ -35,9 +39,10 @@ type join struct { joinCond Cond } -type union struct { - unionType string - builder *Builder +type setOp struct { + opType string + distinctType string + builder *Builder } type limit struct { @@ -56,7 +61,7 @@ type Builder struct { cond Cond selects []string joins []join - unions []union + setOps []setOp limitation *limit insertCols []string insertVals []interface{} @@ -144,33 +149,48 @@ func (b *Builder) Into(tableName string) *Builder { } // Union sets union conditions -func (b *Builder) Union(unionTp string, unionCond *Builder) *Builder { +func (b *Builder) Union(distinctType string, cond *Builder) *Builder { + return b.setOperation(UNION, distinctType, cond) +} + +// Intersect sets intersect conditions +func (b *Builder) Intersect(distinctType string, cond *Builder) *Builder { + return b.setOperation(INTERSECT, distinctType, cond) +} + +// Except sets except conditions +func (b *Builder) Except(distinctType string, cond *Builder) *Builder { + return b.setOperation(EXCEPT, distinctType, cond) +} + +func (b *Builder) setOperation(opType, distinctType string, cond *Builder) *Builder { + var builder *Builder - if b.optype != unionType { + if b.optype != setOpType { builder = &Builder{cond: NewCond()} - builder.optype = unionType + builder.optype = setOpType builder.dialect = b.dialect builder.selects = b.selects - currentUnions := b.unions - // erase sub unions (actually append to new Builder.unions) - b.unions = nil + currentSetOps := b.setOps + // erase sub setOps (actually append to new Builder.unions) + b.setOps = nil - for e := range currentUnions { - currentUnions[e].builder.dialect = b.dialect + for e := range currentSetOps { + currentSetOps[e].builder.dialect = b.dialect } - builder.unions = append(append(builder.unions, union{"", b}), currentUnions...) + builder.setOps = append(append(builder.setOps, setOp{opType, "", b}), currentSetOps...) } else { builder = b } - if unionCond != nil { - if unionCond.dialect == "" && builder.dialect != "" { - unionCond.dialect = builder.dialect + if cond != nil { + if cond.dialect == "" && builder.dialect != "" { + cond.dialect = builder.dialect } - builder.unions = append(builder.unions, union{unionTp, unionCond}) + builder.setOps = append(builder.setOps, setOp{opType, distinctType, cond}) } return builder @@ -240,8 +260,8 @@ func (b *Builder) WriteTo(w Writer) error { return b.updateWriteTo(w) case deleteType: return b.deleteWriteTo(w) - case unionType: - return b.unionWriteTo(w) + case setOpType: + return b.setOpWriteTo(w) } return ErrNotSupportType diff --git a/vendor/xorm.io/builder/builder_insert.go b/vendor/xorm.io/builder/builder_insert.go index 9558a8acad..8cef5c56c6 100644 --- a/vendor/xorm.io/builder/builder_insert.go +++ b/vendor/xorm.io/builder/builder_insert.go @@ -58,6 +58,8 @@ func (b *Builder) insertWriteTo(w Writer) error { if e, ok := value.(expr); ok { fmt.Fprintf(valBuffer, "(%s)", e.sql) args = append(args, e.args...) + } else if value == nil { + fmt.Fprintf(valBuffer, `null`) } else { fmt.Fprint(valBuffer, "?") args = append(args, value) diff --git a/vendor/xorm.io/builder/builder_limit.go b/vendor/xorm.io/builder/builder_limit.go index 82435dacbd..82e1179367 100644 --- a/vendor/xorm.io/builder/builder_limit.go +++ b/vendor/xorm.io/builder/builder_limit.go @@ -21,6 +21,9 @@ func (b *Builder) limitWriteTo(w Writer) error { } // erase limit condition b.limitation = nil + defer func() { + b.limitation = limit + }() ow := w.(*BytesWriter) switch strings.ToLower(strings.TrimSpace(b.dialect)) { @@ -34,7 +37,7 @@ func (b *Builder) limitWriteTo(w Writer) error { b.selects = append(selects, "ROWNUM RN") var wb *Builder - if b.optype == unionType { + if b.optype == setOpType { wb = Dialect(b.dialect).Select("at.*", "ROWNUM RN"). From(b, "at") } else { @@ -55,7 +58,7 @@ func (b *Builder) limitWriteTo(w Writer) error { return final.WriteTo(ow) case SQLITE, MYSQL, POSTGRES: // if type UNION, we need to write previous content back to current writer - if b.optype == unionType { + if b.optype == setOpType { if err := b.WriteTo(ow); err != nil { return err } @@ -77,7 +80,7 @@ func (b *Builder) limitWriteTo(w Writer) error { b.selects[1:]...), "ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS RN") var wb *Builder - if b.optype == unionType { + if b.optype == setOpType { wb = Dialect(b.dialect).Select("*", "ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS RN"). From(b, "at") } else { diff --git a/vendor/xorm.io/builder/builder_select.go b/vendor/xorm.io/builder/builder_select.go index 814d1b5afb..087a71d870 100644 --- a/vendor/xorm.io/builder/builder_select.go +++ b/vendor/xorm.io/builder/builder_select.go @@ -63,7 +63,7 @@ func (b *Builder) selectWriteTo(w Writer) error { } switch b.subQuery.optype { - case selectType, unionType: + case selectType, setOpType: fmt.Fprint(w, " FROM (") if err := b.subQuery.WriteTo(w); err != nil { return err diff --git a/vendor/xorm.io/builder/builder_union.go b/vendor/xorm.io/builder/builder_set_operations.go index 4ba9216178..b2b4a3daf9 100644 --- a/vendor/xorm.io/builder/builder_union.go +++ b/vendor/xorm.io/builder/builder_set_operations.go @@ -9,19 +9,19 @@ import ( "strings" ) -func (b *Builder) unionWriteTo(w Writer) error { +func (b *Builder) setOpWriteTo(w Writer) error { if b.limitation != nil || b.cond.IsValid() || b.orderBy != "" || b.having != "" || b.groupBy != "" { return ErrNotUnexpectedUnionConditions } - for idx, u := range b.unions { - current := u.builder + for idx, o := range b.setOps { + current := o.builder if current.optype != selectType { return ErrUnsupportedUnionMembers } - if len(b.unions) == 1 { + if len(b.setOps) == 1 { if err := current.selectWriteTo(w); err != nil { return err } @@ -31,7 +31,11 @@ func (b *Builder) unionWriteTo(w Writer) error { } if idx != 0 { - fmt.Fprint(w, fmt.Sprintf(" UNION %v ", strings.ToUpper(u.unionType))) + if o.distinctType == "" { + fmt.Fprint(w, fmt.Sprintf(" %s ", strings.ToUpper(o.opType))) + } else { + fmt.Fprint(w, fmt.Sprintf(" %s %s ", strings.ToUpper(o.opType), strings.ToUpper(o.distinctType))) + } } fmt.Fprint(w, "(") diff --git a/vendor/xorm.io/builder/builder_update.go b/vendor/xorm.io/builder/builder_update.go index 9b6e10bc95..5fffbe3497 100644 --- a/vendor/xorm.io/builder/builder_update.go +++ b/vendor/xorm.io/builder/builder_update.go @@ -45,6 +45,10 @@ func (b *Builder) updateWriteTo(w Writer) error { } } + if !b.cond.IsValid() { + return nil + } + if _, err := fmt.Fprint(w, " WHERE "); err != nil { return err } diff --git a/vendor/xorm.io/builder/cond_eq.go b/vendor/xorm.io/builder/cond_eq.go index 32f04d5d4a..9976d1804c 100644 --- a/vendor/xorm.io/builder/cond_eq.go +++ b/vendor/xorm.io/builder/cond_eq.go @@ -64,6 +64,10 @@ func (eq Eq) OpWriteTo(op string, w Writer) error { return err } w.Append(int(v.(Decr))) + case nil: + if _, err := fmt.Fprintf(w, "%s=null", k); err != nil { + return err + } default: if _, err := fmt.Fprintf(w, "%s=?", k); err != nil { return err diff --git a/vendor/xorm.io/builder/go.mod b/vendor/xorm.io/builder/go.mod index 9c730113fb..620f943bd2 100644 --- a/vendor/xorm.io/builder/go.mod +++ b/vendor/xorm.io/builder/go.mod @@ -3,6 +3,6 @@ module xorm.io/builder go 1.11 require ( - github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a + gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a github.com/stretchr/testify v1.3.0 ) diff --git a/vendor/xorm.io/builder/go.sum b/vendor/xorm.io/builder/go.sum index 468ba4a2d5..a5727cab6e 100644 --- a/vendor/xorm.io/builder/go.sum +++ b/vendor/xorm.io/builder/go.sum @@ -1,7 +1,7 @@ +gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s= +gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:9wScpmSP5A3Bk8V3XHWUcJmYTh+ZnlHVyc+A4oZYS3Y= -github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:56xuuqnHyryaerycW3BfssRdxQstACi0Epw/yC5E2xM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/vendor/xorm.io/builder/sql.go b/vendor/xorm.io/builder/sql.go index 4250fea18d..a6d1066b82 100644 --- a/vendor/xorm.io/builder/sql.go +++ b/vendor/xorm.io/builder/sql.go @@ -75,6 +75,7 @@ func noSQLQuoteNeeded(a interface{}) bool { } t := reflect.TypeOf(a) + switch t.Kind() { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: return true @@ -133,12 +134,16 @@ func ConvertToBoundSQL(sql string, args []interface{}) (string, error) { return buf.String(), nil } -// ConvertPlaceholder replaces ? to $1, $2 ... or :1, :2 ... according prefix +// ConvertPlaceholder replaces the place holder ? to $1, $2 ... or :1, :2 ... according prefix func ConvertPlaceholder(sql, prefix string) (string, error) { buf := strings.Builder{} var i, j, start int + var ready = true for ; i < len(sql); i++ { - if sql[i] == '?' { + if sql[i] == '\'' && i > 0 && sql[i-1] != '\\' { + ready = !ready + } + if ready && sql[i] == '?' { if _, err := buf.WriteString(sql[start:i]); err != nil { return "", err } |