From 40f1aa27fcc3850134bca7a50283f70382261db2 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 24 Sep 2019 09:26:25 +0800 Subject: [PATCH] fix label count --- go.mod | 4 +- go.sum | 12 +- models/issue.go | 5 - models/issue_label.go | 24 +-- vendor/github.com/go-xorm/xorm/.drone.yml | 140 ++++++++++++++++-- .../go-xorm/xorm/dialect_postgres.go | 8 +- vendor/github.com/go-xorm/xorm/engine.go | 4 +- vendor/github.com/go-xorm/xorm/go.mod | 4 +- vendor/github.com/go-xorm/xorm/go.sum | 4 +- vendor/github.com/go-xorm/xorm/statement.go | 10 +- vendor/modules.txt | 4 +- vendor/xorm.io/builder/.drone.yml | 22 +-- vendor/xorm.io/builder/README.md | 26 ++-- vendor/xorm.io/builder/builder.go | 106 +------------ vendor/xorm.io/builder/builder_insert.go | 58 ++++++++ vendor/xorm.io/builder/builder_join.go | 42 ++++++ vendor/xorm.io/builder/builder_select.go | 17 ++- vendor/xorm.io/builder/builder_update.go | 11 +- vendor/xorm.io/builder/cond.go | 5 +- vendor/xorm.io/builder/cond_eq.go | 7 +- vendor/xorm.io/builder/cond_expr.go | 4 + vendor/xorm.io/builder/cond_neq.go | 2 +- vendor/xorm.io/builder/doc.go | 22 +-- vendor/xorm.io/builder/go.mod | 2 + vendor/xorm.io/builder/sql.go | 10 +- vendor/xorm.io/builder/string_builder.go | 119 --------------- 26 files changed, 358 insertions(+), 314 deletions(-) create mode 100644 vendor/xorm.io/builder/builder_join.go delete mode 100644 vendor/xorm.io/builder/string_builder.go diff --git a/go.mod b/go.mod index 0b5dd381de92..2c6212d79018 100644 --- a/go.mod +++ b/go.mod @@ -48,7 +48,7 @@ require ( github.com/go-redis/redis v6.15.2+incompatible github.com/go-sql-driver/mysql v1.4.1 github.com/go-swagger/go-swagger v0.20.1 - github.com/go-xorm/xorm v0.7.7-0.20190822154023-17592d96b35b + github.com/go-xorm/xorm v0.7.8-0.20190923153426-6d1191376545 github.com/gobwas/glob v0.2.3 github.com/gogits/chardet v0.0.0-20150115103509-2404f7772561 github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14 @@ -124,6 +124,6 @@ require ( gopkg.in/testfixtures.v2 v2.5.0 mvdan.cc/xurls/v2 v2.0.0 strk.kbt.io/projects/go/libravatar v0.0.0-20160628055650-5eed7bff870a - xorm.io/builder v0.3.5 + xorm.io/builder v0.3.6 xorm.io/core v0.7.0 ) diff --git a/go.sum b/go.sum index a0eff427da2f..3e49a0d046b0 100644 --- a/go.sum +++ b/go.sum @@ -250,10 +250,13 @@ github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013/go.m 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/go-xorm/xorm v0.7.6/go.mod h1:nqz2TAsuOHWH2yk4FYWtacCGgdbrcdZ5mF1XadqEHls= -github.com/go-xorm/xorm v0.7.7-0.20190822154023-17592d96b35b h1:Y0hWUheXDHpIs7BWtJcykO4d1VOsVDKg1PsP5YJwxxM= -github.com/go-xorm/xorm v0.7.7-0.20190822154023-17592d96b35b/go.mod h1:nqz2TAsuOHWH2yk4FYWtacCGgdbrcdZ5mF1XadqEHls= +github.com/go-xorm/xorm v0.7.7-0.20190906141504-57a7e4421e87 h1:vWBG8ItvL5knPwn2Y9WHHreK/YOWfIvhOvVZL7rYwtc= +github.com/go-xorm/xorm v0.7.7-0.20190906141504-57a7e4421e87/go.mod h1:naX9gqm6RkYnlRkV+dY8Ysjiknn2DofS930iRgBLaCE= +github.com/go-xorm/xorm v0.7.8-0.20190923153426-6d1191376545 h1:b3qn2nZKxoG2hsi6cJpSV0ylNJSQfB+nQ9vYL9uxYBU= +github.com/go-xorm/xorm v0.7.8-0.20190923153426-6d1191376545/go.mod h1:RSsmsVARCy4sayuKWFPaVNQMPYGLNRIK71YIVvgImL0= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= +github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogits/chardet v0.0.0-20150115103509-2404f7772561 h1:deE7ritpK04PgtpyVOS2TYcQEld9qLCD5b5EbVNOuLA= github.com/gogits/chardet v0.0.0-20150115103509-2404f7772561/go.mod h1:YgYOrVn3Nj9Tq0EvjmFbphRytDj7JNRoWSStJZWDJTQ= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -340,6 +343,7 @@ github.com/jackc/pgx v3.3.0+incompatible h1:Wa90/+qsITBAPkAZjiByeIGHFcj3Ztu+Vzrr github.com/jackc/pgx v3.3.0+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I= github.com/jackc/pgx v3.5.0+incompatible h1:BRJ4G3UPtvml5R1ey0biqqGuYUGayMYekm3woO75orY= github.com/jackc/pgx v3.5.0+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I= +github.com/jackc/pgx v3.6.0+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I= github.com/jarcoal/httpmock v0.0.0-20180424175123-9c70cfe4a1da/go.mod h1:ks+b9deReOc7jgqp+e7LuFiCBH6Rm5hL32cLcEAArb4= github.com/jaytaylor/html2text v0.0.0-20160923191438-8fb95d837f7d h1:ig/iUfDDg06RVW8OMby+GrmW6K2nPO3AFHlEIdvJSd4= github.com/jaytaylor/html2text v0.0.0-20160923191438-8fb95d837f7d/go.mod h1:CVKlgaMiht+LXvHG173ujK6JUhZXKb2u/BQtjPDIvyk= @@ -818,5 +822,9 @@ strk.kbt.io/projects/go/libravatar v0.0.0-20160628055650-5eed7bff870a h1:8q33Shx strk.kbt.io/projects/go/libravatar v0.0.0-20160628055650-5eed7bff870a/go.mod h1:FJGmPh3vz9jSos1L/F91iAgnC/aejc0wIIrF2ZwJxdY= xorm.io/builder v0.3.5 h1:EilU39fvWDxjb1cDaELpYhsF+zziRBhew8xk4pngO+A= xorm.io/builder v0.3.5/go.mod h1:ZFbByS/KxZI1FKRjL05PyJ4YrK2bcxlUaAxdum5aTR8= +xorm.io/builder v0.3.6-0.20190906062455-b937eb46ecfb h1:2idZcp79ldX5qLeQ6WKCdS7aEFNOMvQc9wrtt5hSRwM= +xorm.io/builder v0.3.6-0.20190906062455-b937eb46ecfb/go.mod h1:LEFAPISnRzG+zxaxj2vPicRwz67BdhFreKg8yv8/TgU= +xorm.io/builder v0.3.6 h1:ha28mQ2M+TFx96Hxo+iq6tQgnkC9IZkM6D8w9sKHHF8= +xorm.io/builder v0.3.6/go.mod h1:LEFAPISnRzG+zxaxj2vPicRwz67BdhFreKg8yv8/TgU= xorm.io/core v0.7.0 h1:hKxuOKWZNeiFQsSuGet/KV8HZ788hclvAl+7azx3tkM= xorm.io/core v0.7.0/go.mod h1:TuOJjIVa7e3w/rN8tDcAvuLBMtwzdHPbyOzE6Gk1EUI= diff --git a/models/issue.go b/models/issue.go index c4b15e9ddfd3..77712c0fec72 100644 --- a/models/issue.go +++ b/models/issue.go @@ -760,11 +760,6 @@ func (issue *Issue) changeStatus(e *xorm.Session, doer *User, isClosed bool) (er return err } for idx := range issue.Labels { - if issue.IsClosed { - issue.Labels[idx].NumClosedIssues++ - } else { - issue.Labels[idx].NumClosedIssues-- - } if err = updateLabel(e, issue.Labels[idx]); err != nil { return err } diff --git a/models/issue_label.go b/models/issue_label.go index f378f62e654e..7498c8f346d6 100644 --- a/models/issue_label.go +++ b/models/issue_label.go @@ -12,6 +12,7 @@ import ( "strings" api "code.gitea.io/gitea/modules/structs" + "xorm.io/builder" "github.com/go-xorm/xorm" ) @@ -294,7 +295,20 @@ func GetLabelsByIssueID(issueID int64) ([]*Label, error) { } func updateLabel(e Engine, l *Label) error { - _, err := e.ID(l.ID).AllCols().Update(l) + _, err := e.ID(l.ID). + SetExpr("num_issues", + builder.Select("count(*)").From("issue_label"). + Where(builder.Eq{"label_id": l.ID}), + ). + SetExpr("num_closed_issues", + builder.Select("count(*)").From("issue_label"). + InnerJoin("issue", "issue_label.issue_id = issue.id"). + Where(builder.Eq{ + "issue_label.label_id": l.ID, + "issue.is_closed": true, + }), + ). + AllCols().Update(l) return err } @@ -375,10 +389,6 @@ func newIssueLabel(e *xorm.Session, issue *Issue, label *Label, doer *User) (err return err } - label.NumIssues++ - if issue.IsClosed { - label.NumClosedIssues++ - } return updateLabel(e, label) } @@ -448,10 +458,6 @@ func deleteIssueLabel(e *xorm.Session, issue *Issue, label *Label, doer *User) ( return err } - label.NumIssues-- - if issue.IsClosed { - label.NumClosedIssues-- - } return updateLabel(e, label) } diff --git a/vendor/github.com/go-xorm/xorm/.drone.yml b/vendor/github.com/go-xorm/xorm/.drone.yml index 94ba92e6088f..6001ec595a81 100644 --- a/vendor/github.com/go-xorm/xorm/.drone.yml +++ b/vendor/github.com/go-xorm/xorm/.drone.yml @@ -103,7 +103,18 @@ steps: commands: - "go test -v -race -db=\"postgres\" -conn_str=\"postgres://postgres:@pgsql/xorm_test?sslmode=disable\" -schema=xorm -coverprofile=coverage5-1.txt -covermode=atomic" - "go test -v -race -db=\"postgres\" -conn_str=\"postgres://postgres:@pgsql/xorm_test?sslmode=disable\" -schema=xorm -cache=true -coverprofile=coverage5-2.txt -covermode=atomic" - - gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage2.1-1.txt coverage2.1-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt > coverage.txt + when: + event: + - push + - pull_request + +- name: test-mssql + pull: default + image: golang:1.10 + commands: + - "go test -v -race -db=\"mssql\" -conn_str=\"server=mssql;user id=sa;password=yourStrong(!)Password;database=xorm_test\" -coverprofile=coverage6-1.txt -covermode=atomic" + - "go test -v -race -db=\"mssql\" -conn_str=\"server=mssql;user id=sa;password=yourStrong(!)Password;database=xorm_test\" -cache=true -coverprofile=coverage6-2.txt -covermode=atomic" + - gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage2.1-1.txt coverage2.1-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt coverage6-1.txt coverage6-2.txt > coverage.txt when: event: - push @@ -134,6 +145,19 @@ services: - tag - pull_request +- name: mssql + pull: default + image: microsoft/mssql-server-linux:latest + environment: + ACCEPT_EULA: Y + SA_PASSWORD: yourStrong(!)Password + MSSQL_PID: Developer + when: + event: + - push + - tag + - pull_request + --- kind: pipeline name: matrix-2 @@ -167,11 +191,13 @@ steps: - name: build pull: default image: golang:1.11 + environment: + GO111MODULE: "off" commands: - go get -t -d -v ./... - go get -u xorm.io/core - go get -u xorm.io/builder - - GO111MODULE=off go build -v + - go build -v when: event: - push @@ -181,9 +207,10 @@ steps: pull: default image: golang:1.11 environment: + GO111MODULE: "on" GOPROXY: "https://goproxy.cn" commands: - - GO111MODULE=on go build -v + - go build -v when: event: - push @@ -192,8 +219,10 @@ steps: - name: test-sqlite pull: default image: golang:1.11 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" commands: - - go get -u github.com/wadey/gocovmerge - "go test -v -race -db=\"sqlite3\" -conn_str=\"./test.db\" -coverprofile=coverage1-1.txt -covermode=atomic" - "go test -v -race -db=\"sqlite3\" -conn_str=\"./test.db\" -cache=true -coverprofile=coverage1-2.txt -covermode=atomic" when: @@ -204,6 +233,9 @@ steps: - name: test-mysql pull: default image: golang:1.11 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" commands: - "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(mysql)/xorm_test\" -coverprofile=coverage2-1.txt -covermode=atomic" - "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(mysql)/xorm_test\" -cache=true -coverprofile=coverage2-2.txt -covermode=atomic" @@ -215,6 +247,9 @@ steps: - name: test-mysql-utf8mb4 pull: default image: golang:1.11 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" commands: - "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(mysql)/xorm_test?charset=utf8mb4\" -coverprofile=coverage2.1-1.txt -covermode=atomic" - "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(mysql)/xorm_test?charset=utf8mb4\" -cache=true -coverprofile=coverage2.1-2.txt -covermode=atomic" @@ -226,6 +261,9 @@ steps: - name: test-mymysql pull: default image: golang:1.11 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" commands: - "go test -v -race -db=\"mymysql\" -conn_str=\"tcp:mysql:3306*xorm_test/root/\" -coverprofile=coverage3-1.txt -covermode=atomic" - "go test -v -race -db=\"mymysql\" -conn_str=\"tcp:mysql:3306*xorm_test/root/\" -cache=true -coverprofile=coverage3-2.txt -covermode=atomic" @@ -237,6 +275,9 @@ steps: - name: test-postgres pull: default image: golang:1.11 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" commands: - "go test -v -race -db=\"postgres\" -conn_str=\"postgres://postgres:@pgsql/xorm_test?sslmode=disable\" -coverprofile=coverage4-1.txt -covermode=atomic" - "go test -v -race -db=\"postgres\" -conn_str=\"postgres://postgres:@pgsql/xorm_test?sslmode=disable\" -cache=true -coverprofile=coverage4-2.txt -covermode=atomic" @@ -248,10 +289,28 @@ steps: - name: test-postgres-schema pull: default image: golang:1.11 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" commands: - "go test -v -race -db=\"postgres\" -conn_str=\"postgres://postgres:@pgsql/xorm_test?sslmode=disable\" -schema=xorm -coverprofile=coverage5-1.txt -covermode=atomic" - "go test -v -race -db=\"postgres\" -conn_str=\"postgres://postgres:@pgsql/xorm_test?sslmode=disable\" -schema=xorm -cache=true -coverprofile=coverage5-2.txt -covermode=atomic" - - gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage2.1-1.txt coverage2.1-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt > coverage.txt + when: + event: + - push + - pull_request + +- name: test-mssql + pull: default + image: golang:1.11 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" + commands: + - "go test -v -race -db=\"mssql\" -conn_str=\"server=mssql;user id=sa;password=yourStrong(!)Password;database=xorm_test\" -coverprofile=coverage6-1.txt -covermode=atomic" + - "go test -v -race -db=\"mssql\" -conn_str=\"server=mssql;user id=sa;password=yourStrong(!)Password;database=xorm_test\" -cache=true -coverprofile=coverage6-2.txt -covermode=atomic" + - go get github.com/wadey/gocovmerge + - gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage2.1-1.txt coverage2.1-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt coverage6-1.txt coverage6-2.txt > coverage.txt when: event: - push @@ -282,6 +341,19 @@ services: - tag - pull_request +- name: mssql + pull: default + image: microsoft/mssql-server-linux:latest + environment: + ACCEPT_EULA: Y + SA_PASSWORD: yourStrong(!)Password + MSSQL_PID: Developer + when: + event: + - push + - tag + - pull_request + --- kind: pipeline name: matrix-3 @@ -315,11 +387,13 @@ steps: - name: build pull: default image: golang:1.12 + environment: + GO111MODULE: "off" commands: - go get -t -d -v ./... - go get -u xorm.io/core - go get -u xorm.io/builder - - GO111MODULE=off go build -v + - go build -v when: event: - push @@ -329,9 +403,10 @@ steps: pull: default image: golang:1.12 environment: - GOPROXY: "https://goproxy.cn" + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" commands: - - GO111MODULE=on go build -v + - go build -v when: event: - push @@ -340,8 +415,10 @@ steps: - name: test-sqlite pull: default image: golang:1.12 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" commands: - - go get -u github.com/wadey/gocovmerge - "go test -v -race -db=\"sqlite3\" -conn_str=\"./test.db\" -coverprofile=coverage1-1.txt -covermode=atomic" - "go test -v -race -db=\"sqlite3\" -conn_str=\"./test.db\" -cache=true -coverprofile=coverage1-2.txt -covermode=atomic" when: @@ -352,6 +429,9 @@ steps: - name: test-mysql pull: default image: golang:1.12 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" commands: - "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(mysql)/xorm_test\" -coverprofile=coverage2-1.txt -covermode=atomic" - "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(mysql)/xorm_test\" -cache=true -coverprofile=coverage2-2.txt -covermode=atomic" @@ -363,6 +443,9 @@ steps: - name: test-mysql-utf8mb4 pull: default image: golang:1.12 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" commands: - "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(mysql)/xorm_test?charset=utf8mb4\" -coverprofile=coverage2.1-1.txt -covermode=atomic" - "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(mysql)/xorm_test?charset=utf8mb4\" -cache=true -coverprofile=coverage2.1-2.txt -covermode=atomic" @@ -374,6 +457,9 @@ steps: - name: test-mymysql pull: default image: golang:1.12 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" commands: - "go test -v -race -db=\"mymysql\" -conn_str=\"tcp:mysql:3306*xorm_test/root/\" -coverprofile=coverage3-1.txt -covermode=atomic" - "go test -v -race -db=\"mymysql\" -conn_str=\"tcp:mysql:3306*xorm_test/root/\" -cache=true -coverprofile=coverage3-2.txt -covermode=atomic" @@ -385,6 +471,9 @@ steps: - name: test-postgres pull: default image: golang:1.12 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" commands: - "go test -v -race -db=\"postgres\" -conn_str=\"postgres://postgres:@pgsql/xorm_test?sslmode=disable\" -coverprofile=coverage4-1.txt -covermode=atomic" - "go test -v -race -db=\"postgres\" -conn_str=\"postgres://postgres:@pgsql/xorm_test?sslmode=disable\" -cache=true -coverprofile=coverage4-2.txt -covermode=atomic" @@ -396,10 +485,28 @@ steps: - name: test-postgres-schema pull: default image: golang:1.12 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" commands: - "go test -v -race -db=\"postgres\" -conn_str=\"postgres://postgres:@pgsql/xorm_test?sslmode=disable\" -schema=xorm -coverprofile=coverage5-1.txt -covermode=atomic" - "go test -v -race -db=\"postgres\" -conn_str=\"postgres://postgres:@pgsql/xorm_test?sslmode=disable\" -schema=xorm -cache=true -coverprofile=coverage5-2.txt -covermode=atomic" - - gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage2.1-1.txt coverage2.1-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt > coverage.txt + when: + event: + - push + - pull_request + +- name: test-mssql + pull: default + image: golang:1.12 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" + commands: + - "go test -v -race -db=\"mssql\" -conn_str=\"server=mssql;user id=sa;password=yourStrong(!)Password;database=xorm_test\" -coverprofile=coverage6-1.txt -covermode=atomic" + - "go test -v -race -db=\"mssql\" -conn_str=\"server=mssql;user id=sa;password=yourStrong(!)Password;database=xorm_test\" -cache=true -coverprofile=coverage6-2.txt -covermode=atomic" + - go get -u github.com/wadey/gocovmerge + - gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage2.1-1.txt coverage2.1-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt coverage6-1.txt coverage6-2.txt > coverage.txt when: event: - push @@ -424,6 +531,19 @@ services: environment: POSTGRES_DB: xorm_test POSTGRES_USER: postgres + when: + event: + - push + - tag + - pull_request + +- name: mssql + pull: default + image: microsoft/mssql-server-linux:latest + environment: + ACCEPT_EULA: Y + SA_PASSWORD: yourStrong(!)Password + MSSQL_PID: Developer when: event: - push diff --git a/vendor/github.com/go-xorm/xorm/dialect_postgres.go b/vendor/github.com/go-xorm/xorm/dialect_postgres.go index e1c377a063c5..3df682e81ac4 100644 --- a/vendor/github.com/go-xorm/xorm/dialect_postgres.go +++ b/vendor/github.com/go-xorm/xorm/dialect_postgres.go @@ -952,7 +952,7 @@ func (db *postgres) IsColumnExist(tableName, colName string) (bool, error) { func (db *postgres) GetColumns(tableName string) ([]string, map[string]*core.Column, error) { args := []interface{}{tableName} - s := `SELECT column_name, column_default, is_nullable, data_type, character_maximum_length, numeric_precision, numeric_precision_radix , + s := `SELECT column_name, column_default, is_nullable, data_type, character_maximum_length, CASE WHEN p.contype = 'p' THEN true ELSE false END AS primarykey, CASE WHEN p.contype = 'u' THEN true ELSE false END AS uniquekey FROM pg_attribute f @@ -987,14 +987,14 @@ WHERE c.relkind = 'r'::char AND c.relname = $1%s AND f.attnum > 0 ORDER BY f.att col.Indexes = make(map[string]int) var colName, isNullable, dataType string - var maxLenStr, colDefault, numPrecision, numRadix *string + var maxLenStr, colDefault *string var isPK, isUnique bool - err = rows.Scan(&colName, &colDefault, &isNullable, &dataType, &maxLenStr, &numPrecision, &numRadix, &isPK, &isUnique) + err = rows.Scan(&colName, &colDefault, &isNullable, &dataType, &maxLenStr, &isPK, &isUnique) if err != nil { return nil, nil, err } - // fmt.Println(args, colName, isNullable, dataType, maxLenStr, colDefault, numPrecision, numRadix, isPK, isUnique) + // fmt.Println(args, colName, isNullable, dataType, maxLenStr, colDefault, isPK, isUnique) var maxLen int if maxLenStr != nil { maxLen, err = strconv.Atoi(*maxLenStr) diff --git a/vendor/github.com/go-xorm/xorm/engine.go b/vendor/github.com/go-xorm/xorm/engine.go index ebcab91bc7c7..f04c702e5820 100644 --- a/vendor/github.com/go-xorm/xorm/engine.go +++ b/vendor/github.com/go-xorm/xorm/engine.go @@ -190,14 +190,14 @@ func (engine *Engine) Quote(value string) string { return value } - buf := builder.StringBuilder{} + buf := strings.Builder{} engine.QuoteTo(&buf, value) return buf.String() } // QuoteTo quotes string and writes into the buffer -func (engine *Engine) QuoteTo(buf *builder.StringBuilder, value string) { +func (engine *Engine) QuoteTo(buf *strings.Builder, value string) { if buf == nil { return } diff --git a/vendor/github.com/go-xorm/xorm/go.mod b/vendor/github.com/go-xorm/xorm/go.mod index 9a30e7978f3c..a3e78cae45b1 100644 --- a/vendor/github.com/go-xorm/xorm/go.mod +++ b/vendor/github.com/go-xorm/xorm/go.mod @@ -1,5 +1,7 @@ module github.com/go-xorm/xorm +go 1.11 + require ( github.com/cockroachdb/apd v1.1.0 // indirect github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4 @@ -14,6 +16,6 @@ require ( github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 // indirect github.com/stretchr/testify v1.3.0 github.com/ziutek/mymysql v1.5.4 - xorm.io/builder v0.3.5 + xorm.io/builder v0.3.6-0.20190906062455-b937eb46ecfb xorm.io/core v0.7.0 ) diff --git a/vendor/github.com/go-xorm/xorm/go.sum b/vendor/github.com/go-xorm/xorm/go.sum index 370dcd0b6083..0f2baf174ccc 100644 --- a/vendor/github.com/go-xorm/xorm/go.sum +++ b/vendor/github.com/go-xorm/xorm/go.sum @@ -162,7 +162,7 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -xorm.io/builder v0.3.5 h1:EilU39fvWDxjb1cDaELpYhsF+zziRBhew8xk4pngO+A= -xorm.io/builder v0.3.5/go.mod h1:ZFbByS/KxZI1FKRjL05PyJ4YrK2bcxlUaAxdum5aTR8= +xorm.io/builder v0.3.6-0.20190906062455-b937eb46ecfb h1:2idZcp79ldX5qLeQ6WKCdS7aEFNOMvQc9wrtt5hSRwM= +xorm.io/builder v0.3.6-0.20190906062455-b937eb46ecfb/go.mod h1:LEFAPISnRzG+zxaxj2vPicRwz67BdhFreKg8yv8/TgU= xorm.io/core v0.7.0 h1:hKxuOKWZNeiFQsSuGet/KV8HZ788hclvAl+7azx3tkM= xorm.io/core v0.7.0/go.mod h1:TuOJjIVa7e3w/rN8tDcAvuLBMtwzdHPbyOzE6Gk1EUI= diff --git a/vendor/github.com/go-xorm/xorm/statement.go b/vendor/github.com/go-xorm/xorm/statement.go index 585378a8b1bb..6cdbad7d4257 100644 --- a/vendor/github.com/go-xorm/xorm/statement.go +++ b/vendor/github.com/go-xorm/xorm/statement.go @@ -695,7 +695,7 @@ func (statement *Statement) OrderBy(order string) *Statement { // Desc generate `ORDER BY xx DESC` func (statement *Statement) Desc(colNames ...string) *Statement { - var buf builder.StringBuilder + var buf strings.Builder if len(statement.OrderStr) > 0 { fmt.Fprint(&buf, statement.OrderStr, ", ") } @@ -707,7 +707,7 @@ func (statement *Statement) Desc(colNames ...string) *Statement { // Asc provide asc order by query condition, the input parameters are columns. func (statement *Statement) Asc(colNames ...string) *Statement { - var buf builder.StringBuilder + var buf strings.Builder if len(statement.OrderStr) > 0 { fmt.Fprint(&buf, statement.OrderStr, ", ") } @@ -736,7 +736,7 @@ func (statement *Statement) Table(tableNameOrBean interface{}) *Statement { // Join The joinOP should be one of INNER, LEFT OUTER, CROSS etc - this will be prepended to JOIN func (statement *Statement) Join(joinOP string, tablename interface{}, condition string, args ...interface{}) *Statement { - var buf builder.StringBuilder + var buf strings.Builder if len(statement.JoinStr) > 0 { fmt.Fprintf(&buf, "%v %v JOIN ", statement.JoinStr, joinOP) } else { @@ -801,7 +801,7 @@ func (statement *Statement) genColumnStr() string { return "" } - var buf builder.StringBuilder + var buf strings.Builder columns := statement.RefTable.Columns() for _, col := range columns { @@ -1118,7 +1118,7 @@ func (statement *Statement) genSelectSQL(columnStr, condSQL string, needLimit, n } } - var buf builder.StringBuilder + var buf strings.Builder fmt.Fprintf(&buf, "SELECT %v%v%v%v%v", distinct, top, columnStr, fromStr, whereStr) if len(mssqlCondi) > 0 { if len(whereStr) > 0 { diff --git a/vendor/modules.txt b/vendor/modules.txt index e300a9bbe40e..92ce73f0c28d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -198,7 +198,7 @@ github.com/go-swagger/go-swagger/cmd/swagger/commands/initcmd github.com/go-swagger/go-swagger/codescan github.com/go-swagger/go-swagger/generator github.com/go-swagger/go-swagger/scan -# github.com/go-xorm/xorm v0.7.7-0.20190822154023-17592d96b35b +# github.com/go-xorm/xorm v0.7.7-0.20190906141504-57a7e4421e87 github.com/go-xorm/xorm # github.com/gobwas/glob v0.2.3 github.com/gobwas/glob @@ -612,7 +612,7 @@ gopkg.in/yaml.v2 mvdan.cc/xurls/v2 # strk.kbt.io/projects/go/libravatar v0.0.0-20160628055650-5eed7bff870a strk.kbt.io/projects/go/libravatar -# xorm.io/builder v0.3.5 +# xorm.io/builder v0.3.6-0.20190906062455-b937eb46ecfb xorm.io/builder # xorm.io/core v0.7.0 xorm.io/core diff --git a/vendor/xorm.io/builder/.drone.yml b/vendor/xorm.io/builder/.drone.yml index ca40377721eb..208d8683d24a 100644 --- a/vendor/xorm.io/builder/.drone.yml +++ b/vendor/xorm.io/builder/.drone.yml @@ -1,6 +1,6 @@ workspace: base: /go - path: src/github.com/go-xorm/builder + path: src/xorm.io/builder clone: git: @@ -10,28 +10,22 @@ clone: matrix: GO_VERSION: - - 1.8 - - 1.9 - 1.10 - 1.11 + - 1.12 + - 1.13 pipeline: test: image: golang:${GO_VERSION} + environment: + GOPROXY: https://goproxy.cn commands: - - go get -u github.com/golang/lint/golint + - 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 ] - -codecov: - image: robertstettner/drone-codecov - group: build - secrets: [ codecov_token ] - files: - - coverage.txt - when: - event: [ push, pull_request ] \ No newline at end of file + event: [ push, tag, pull_request ] \ No newline at end of file diff --git a/vendor/xorm.io/builder/README.md b/vendor/xorm.io/builder/README.md index cf516d1fd58b..53e5403203ad 100644 --- a/vendor/xorm.io/builder/README.md +++ b/vendor/xorm.io/builder/README.md @@ -1,13 +1,13 @@ # SQL builder -[![GitCI.cn](https://gitci.cn/api/badges/go-xorm/builder/status.svg)](https://gitci.cn/go-xorm/builder) [![codecov](https://codecov.io/gh/go-xorm/builder/branch/master/graph/badge.svg)](https://codecov.io/gh/go-xorm/builder) -[![](https://goreportcard.com/badge/github.com/go-xorm/builder)](https://goreportcard.com/report/github.com/go-xorm/builder) +[![Build Status](https://drone.gitea.com/api/badges/xorm/builder/status.svg)](https://drone.gitea.com/xorm/builder) [![](http://gocover.io/_badge/xorm.io/builder)](http://gocover.io/xorm.io/builder) +[![](https://goreportcard.com/badge/xorm.io/builder)](https://goreportcard.com/report/xorm.io/builder) Package builder is a lightweight and fast SQL builder for Go and XORM. Make sure you have installed Go 1.8+ and then: - go get github.com/go-xorm/builder + go get xorm.io/builder # Insert @@ -71,7 +71,7 @@ sql, args, err := Select("*").From("a").Where(Eq{"status": "1"}). * `Eq` is a redefine of a map, you can give one or more conditions to `Eq` ```Go -import . "github.com/go-xorm/builder" +import . "xorm.io/builder" sql, args, _ := ToSQL(Eq{"a":1}) // a=? [1] @@ -90,7 +90,7 @@ sql, args, _ := ToSQL(Eq{"b": 1, "c":[]int{2, 3}}) * `Neq` is the same to `Eq` ```Go -import . "github.com/go-xorm/builder" +import . "xorm.io/builder" sql, args, _ := ToSQL(Neq{"a":1}) // a<>? [1] @@ -109,7 +109,7 @@ sql, args, _ := ToSQL(Neq{"b": 1, "c":[]int{2, 3}}) * `Gt`, `Gte`, `Lt`, `Lte` ```Go -import . "github.com/go-xorm/builder" +import . "xorm.io/builder" sql, args, _ := ToSQL(Gt{"a", 1}.And(Gte{"b", 2})) // a>? AND b>=? [1, 2] @@ -120,7 +120,7 @@ sql, args, _ := ToSQL(Lt{"a", 1}.Or(Lte{"b", 2})) * `Like` ```Go -import . "github.com/go-xorm/builder" +import . "xorm.io/builder" sql, args, _ := ToSQL(Like{"a", "c"}) // a LIKE ? [%c%] @@ -129,7 +129,7 @@ sql, args, _ := ToSQL(Like{"a", "c"}) * `Expr` you can customerize your sql with `Expr` ```Go -import . "github.com/go-xorm/builder" +import . "xorm.io/builder" sql, args, _ := ToSQL(Expr("a = ? ", 1)) // a = ? [1] @@ -140,7 +140,7 @@ sql, args, _ := ToSQL(Eq{"a": Expr("select id from table where c = ?", 1)}) * `In` and `NotIn` ```Go -import . "github.com/go-xorm/builder" +import . "xorm.io/builder" sql, args, _ := ToSQL(In("a", 1, 2, 3)) // a IN (?,?,?) [1,2,3] @@ -153,7 +153,7 @@ sql, args, _ := ToSQL(In("a", Expr("select id from b where c = ?", 1)))) * `IsNull` and `NotNull` ```Go -import . "github.com/go-xorm/builder" +import . "xorm.io/builder" sql, args, _ := ToSQL(IsNull{"a"}) // a IS NULL [] @@ -164,7 +164,7 @@ sql, args, _ := ToSQL(NotNull{"b"}) * `And(conds ...Cond)`, And can connect one or more condtions via And ```Go -import . "github.com/go-xorm/builder" +import . "xorm.io/builder" sql, args, _ := ToSQL(And(Eq{"a":1}, Like{"b", "c"}, Neq{"d", 2})) // a=? AND b LIKE ? AND d<>? [1, %c%, 2] @@ -173,7 +173,7 @@ sql, args, _ := ToSQL(And(Eq{"a":1}, Like{"b", "c"}, Neq{"d", 2})) * `Or(conds ...Cond)`, Or can connect one or more conditions via Or ```Go -import . "github.com/go-xorm/builder" +import . "xorm.io/builder" sql, args, _ := ToSQL(Or(Eq{"a":1}, Like{"b", "c"}, Neq{"d", 2})) // a=? OR b LIKE ? OR d<>? [1, %c%, 2] @@ -184,7 +184,7 @@ sql, args, _ := ToSQL(Or(Eq{"a":1}, And(Like{"b", "c"}, Neq{"d", 2}))) * `Between` ```Go -import . "github.com/go-xorm/builder" +import . "xorm.io/builder" sql, args, _ := ToSQL(Between{"a", 1, 2}) // a BETWEEN 1 AND 2 diff --git a/vendor/xorm.io/builder/builder.go b/vendor/xorm.io/builder/builder.go index ffe86d4dcb56..bcf2ac5b42ce 100644 --- a/vendor/xorm.io/builder/builder.go +++ b/vendor/xorm.io/builder/builder.go @@ -7,7 +7,6 @@ package builder import ( sql2 "database/sql" "fmt" - "sort" ) type optype byte @@ -31,7 +30,7 @@ const ( type join struct { joinType string - joinTable string + joinTable interface{} joinCond Cond } @@ -60,7 +59,7 @@ type Builder struct { limitation *limit insertCols []string insertVals []interface{} - updates []Eq + updates []UpdateCond orderBy string groupBy string having string @@ -143,18 +142,6 @@ func (b *Builder) Into(tableName string) *Builder { return b } -// Join sets join table and conditions -func (b *Builder) Join(joinType, joinTable string, joinCond interface{}) *Builder { - switch joinCond.(type) { - case Cond: - b.joins = append(b.joins, join{joinType, joinTable, joinCond.(Cond)}) - case string: - b.joins = append(b.joins, join{joinType, joinTable, Expr(joinCond.(string))}) - } - - return b -} - // Union sets union conditions func (b *Builder) Union(unionTp string, unionCond *Builder) *Builder { var builder *Builder @@ -199,31 +186,6 @@ func (b *Builder) Limit(limitN int, offset ...int) *Builder { return b } -// InnerJoin sets inner join -func (b *Builder) InnerJoin(joinTable string, joinCond interface{}) *Builder { - return b.Join("INNER", joinTable, joinCond) -} - -// LeftJoin sets left join SQL -func (b *Builder) LeftJoin(joinTable string, joinCond interface{}) *Builder { - return b.Join("LEFT", joinTable, joinCond) -} - -// RightJoin sets right join SQL -func (b *Builder) RightJoin(joinTable string, joinCond interface{}) *Builder { - return b.Join("RIGHT", joinTable, joinCond) -} - -// CrossJoin sets cross join SQL -func (b *Builder) CrossJoin(joinTable string, joinCond interface{}) *Builder { - return b.Join("CROSS", joinTable, joinCond) -} - -// FullJoin sets full join SQL -func (b *Builder) FullJoin(joinTable string, joinCond interface{}) *Builder { - return b.Join("FULL", joinTable, joinCond) -} - // Select sets select SQL func (b *Builder) Select(cols ...string) *Builder { b.selects = cols @@ -245,68 +207,12 @@ func (b *Builder) Or(cond Cond) *Builder { return b } -type insertColsSorter struct { - cols []string - vals []interface{} -} - -func (s insertColsSorter) Len() int { - return len(s.cols) -} -func (s insertColsSorter) Swap(i, j int) { - s.cols[i], s.cols[j] = s.cols[j], s.cols[i] - s.vals[i], s.vals[j] = s.vals[j], s.vals[i] -} - -func (s insertColsSorter) Less(i, j int) bool { - return s.cols[i] < s.cols[j] -} - -// Insert sets insert SQL -func (b *Builder) Insert(eq ...interface{}) *Builder { - if len(eq) > 0 { - var paramType = -1 - for _, e := range eq { - switch t := e.(type) { - case Eq: - if paramType == -1 { - paramType = 0 - } - if paramType != 0 { - break - } - for k, v := range t { - b.insertCols = append(b.insertCols, k) - b.insertVals = append(b.insertVals, v) - } - case string: - if paramType == -1 { - paramType = 1 - } - if paramType != 1 { - break - } - b.insertCols = append(b.insertCols, t) - } - } - } - - if len(b.insertCols) == len(b.insertVals) { - sort.Sort(insertColsSorter{ - cols: b.insertCols, - vals: b.insertVals, - }) - } - b.optype = insertType - return b -} - // Update sets update SQL -func (b *Builder) Update(updates ...Eq) *Builder { - b.updates = make([]Eq, 0, len(updates)) +func (b *Builder) Update(updates ...Cond) *Builder { + b.updates = make([]UpdateCond, 0, len(updates)) for _, update := range updates { - if update.IsValid() { - b.updates = append(b.updates, update) + if u, ok := update.(UpdateCond); ok && u.IsValid() { + b.updates = append(b.updates, u) } } b.optype = updateType diff --git a/vendor/xorm.io/builder/builder_insert.go b/vendor/xorm.io/builder/builder_insert.go index 202cad51d846..9558a8acad57 100644 --- a/vendor/xorm.io/builder/builder_insert.go +++ b/vendor/xorm.io/builder/builder_insert.go @@ -7,6 +7,7 @@ package builder import ( "bytes" "fmt" + "sort" ) // Insert creates an insert Builder @@ -87,3 +88,60 @@ func (b *Builder) insertWriteTo(w Writer) error { return nil } + +type insertColsSorter struct { + cols []string + vals []interface{} +} + +func (s insertColsSorter) Len() int { + return len(s.cols) +} + +func (s insertColsSorter) Swap(i, j int) { + s.cols[i], s.cols[j] = s.cols[j], s.cols[i] + s.vals[i], s.vals[j] = s.vals[j], s.vals[i] +} + +func (s insertColsSorter) Less(i, j int) bool { + return s.cols[i] < s.cols[j] +} + +// Insert sets insert SQL +func (b *Builder) Insert(eq ...interface{}) *Builder { + if len(eq) > 0 { + var paramType = -1 + for _, e := range eq { + switch t := e.(type) { + case Eq: + if paramType == -1 { + paramType = 0 + } + if paramType != 0 { + break + } + for k, v := range t { + b.insertCols = append(b.insertCols, k) + b.insertVals = append(b.insertVals, v) + } + case string: + if paramType == -1 { + paramType = 1 + } + if paramType != 1 { + break + } + b.insertCols = append(b.insertCols, t) + } + } + } + + if len(b.insertCols) == len(b.insertVals) { + sort.Sort(insertColsSorter{ + cols: b.insertCols, + vals: b.insertVals, + }) + } + b.optype = insertType + return b +} diff --git a/vendor/xorm.io/builder/builder_join.go b/vendor/xorm.io/builder/builder_join.go new file mode 100644 index 000000000000..a6604c5f6e32 --- /dev/null +++ b/vendor/xorm.io/builder/builder_join.go @@ -0,0 +1,42 @@ +// Copyright 2019 The Xorm Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package builder + +// InnerJoin sets inner join +func (b *Builder) InnerJoin(joinTable, joinCond interface{}) *Builder { + return b.Join("INNER", joinTable, joinCond) +} + +// LeftJoin sets left join SQL +func (b *Builder) LeftJoin(joinTable, joinCond interface{}) *Builder { + return b.Join("LEFT", joinTable, joinCond) +} + +// RightJoin sets right join SQL +func (b *Builder) RightJoin(joinTable, joinCond interface{}) *Builder { + return b.Join("RIGHT", joinTable, joinCond) +} + +// CrossJoin sets cross join SQL +func (b *Builder) CrossJoin(joinTable, joinCond interface{}) *Builder { + return b.Join("CROSS", joinTable, joinCond) +} + +// FullJoin sets full join SQL +func (b *Builder) FullJoin(joinTable, joinCond interface{}) *Builder { + return b.Join("FULL", joinTable, joinCond) +} + +// Join sets join table and conditions +func (b *Builder) Join(joinType string, joinTable, joinCond interface{}) *Builder { + switch joinCond.(type) { + case Cond: + b.joins = append(b.joins, join{joinType, joinTable, joinCond.(Cond)}) + case string: + b.joins = append(b.joins, join{joinType, joinTable, Expr(joinCond.(string))}) + } + + return b +} diff --git a/vendor/xorm.io/builder/builder_select.go b/vendor/xorm.io/builder/builder_select.go index c33b38698be3..814d1b5afb3f 100644 --- a/vendor/xorm.io/builder/builder_select.go +++ b/vendor/xorm.io/builder/builder_select.go @@ -80,8 +80,21 @@ func (b *Builder) selectWriteTo(w Writer) error { } for _, v := range b.joins { - if _, err := fmt.Fprintf(w, " %s JOIN %s ON ", v.joinType, v.joinTable); err != nil { - return err + b, ok := v.joinTable.(*Builder) + if ok { + if _, err := fmt.Fprintf(w, " %s JOIN (", v.joinType); err != nil { + return err + } + if err := b.WriteTo(w); err != nil { + return err + } + if _, err := fmt.Fprintf(w, ") ON "); err != nil { + return err + } + } else { + if _, err := fmt.Fprintf(w, " %s JOIN %s ON ", v.joinType, v.joinTable); err != nil { + return err + } } if err := v.joinCond.WriteTo(w); err != nil { diff --git a/vendor/xorm.io/builder/builder_update.go b/vendor/xorm.io/builder/builder_update.go index 37b455152688..9b6e10bc959f 100644 --- a/vendor/xorm.io/builder/builder_update.go +++ b/vendor/xorm.io/builder/builder_update.go @@ -8,8 +8,14 @@ import ( "fmt" ) +// UpdateCond defines an interface that cond could be used with update +type UpdateCond interface { + IsValid() bool + OpWriteTo(op string, w Writer) error +} + // Update creates an update Builder -func Update(updates ...Eq) *Builder { +func Update(updates ...Cond) *Builder { builder := &Builder{cond: NewCond()} return builder.Update(updates...) } @@ -27,7 +33,8 @@ func (b *Builder) updateWriteTo(w Writer) error { } for i, s := range b.updates { - if err := s.opWriteTo(",", w); err != nil { + + if err := s.OpWriteTo(",", w); err != nil { return err } diff --git a/vendor/xorm.io/builder/cond.go b/vendor/xorm.io/builder/cond.go index e44173bbd5a8..eb8cc92a2e30 100644 --- a/vendor/xorm.io/builder/cond.go +++ b/vendor/xorm.io/builder/cond.go @@ -6,6 +6,7 @@ package builder import ( "io" + "strings" ) // Writer defines the interface @@ -18,14 +19,14 @@ var _ Writer = NewWriter() // BytesWriter implments Writer and save SQL in bytes.Buffer type BytesWriter struct { - writer *StringBuilder + writer *strings.Builder args []interface{} } // NewWriter creates a new string writer func NewWriter() *BytesWriter { w := &BytesWriter{ - writer: &StringBuilder{}, + writer: &strings.Builder{}, } return w } diff --git a/vendor/xorm.io/builder/cond_eq.go b/vendor/xorm.io/builder/cond_eq.go index 79d795e6dd2f..32f04d5d4a96 100644 --- a/vendor/xorm.io/builder/cond_eq.go +++ b/vendor/xorm.io/builder/cond_eq.go @@ -20,7 +20,8 @@ type Eq map[string]interface{} var _ Cond = Eq{} -func (eq Eq) opWriteTo(op string, w Writer) error { +// OpWriteTo writes conditions with special operator +func (eq Eq) OpWriteTo(op string, w Writer) error { var i = 0 for _, k := range eq.sortedKeys() { v := eq[k] @@ -81,7 +82,7 @@ func (eq Eq) opWriteTo(op string, w Writer) error { // WriteTo writes SQL to Writer func (eq Eq) WriteTo(w Writer) error { - return eq.opWriteTo(" AND ", w) + return eq.OpWriteTo(" AND ", w) } // And implements And with other conditions @@ -101,7 +102,7 @@ func (eq Eq) IsValid() bool { // sortedKeys returns all keys of this Eq sorted with sort.Strings. // It is used internally for consistent ordering when generating -// SQL, see https://github.com/go-xorm/builder/issues/10 +// SQL, see https://gitea.com/xorm/builder/issues/10 func (eq Eq) sortedKeys() []string { keys := make([]string, 0, len(eq)) for key := range eq { diff --git a/vendor/xorm.io/builder/cond_expr.go b/vendor/xorm.io/builder/cond_expr.go index e5ed572b1503..8288aa044095 100644 --- a/vendor/xorm.io/builder/cond_expr.go +++ b/vendor/xorm.io/builder/cond_expr.go @@ -18,6 +18,10 @@ func Expr(sql string, args ...interface{}) Cond { return expr{sql, args} } +func (expr expr) OpWriteTo(op string, w Writer) error { + return expr.WriteTo(w) +} + func (expr expr) WriteTo(w Writer) error { if _, err := fmt.Fprint(w, expr.sql); err != nil { return err diff --git a/vendor/xorm.io/builder/cond_neq.go b/vendor/xorm.io/builder/cond_neq.go index 3a8f3136d9d6..687c59fc2e9a 100644 --- a/vendor/xorm.io/builder/cond_neq.go +++ b/vendor/xorm.io/builder/cond_neq.go @@ -83,7 +83,7 @@ func (neq Neq) IsValid() bool { // sortedKeys returns all keys of this Neq sorted with sort.Strings. // It is used internally for consistent ordering when generating -// SQL, see https://github.com/go-xorm/builder/issues/10 +// SQL, see https://gitea.com/xorm/builder/issues/10 func (neq Neq) sortedKeys() []string { keys := make([]string, 0, len(neq)) for key := range neq { diff --git a/vendor/xorm.io/builder/doc.go b/vendor/xorm.io/builder/doc.go index 162b150f101b..6e7dd452b86c 100644 --- a/vendor/xorm.io/builder/doc.go +++ b/vendor/xorm.io/builder/doc.go @@ -8,13 +8,13 @@ Package builder is a simple and powerful sql builder for Go. Make sure you have installed Go 1.1+ and then: - go get github.com/go-xorm/builder + go get xorm.io/builder WARNNING: Currently, only query conditions are supported. Below is the supported conditions. 1. Eq is a redefine of a map, you can give one or more conditions to Eq - import . "github.com/go-xorm/builder" + import . "xorm.io/builder" sql, args, _ := ToSQL(Eq{"a":1}) // a=? [1] @@ -31,7 +31,7 @@ WARNNING: Currently, only query conditions are supported. Below is the supported 2. Neq is the same to Eq - import . "github.com/go-xorm/builder" + import . "xorm.io/builder" sql, args, _ := ToSQL(Neq{"a":1}) // a<>? [1] @@ -48,7 +48,7 @@ WARNNING: Currently, only query conditions are supported. Below is the supported 3. Gt, Gte, Lt, Lte - import . "github.com/go-xorm/builder" + import . "xorm.io/builder" sql, args, _ := ToSQL(Gt{"a", 1}.And(Gte{"b", 2})) // a>? AND b>=? [1, 2] @@ -57,14 +57,14 @@ WARNNING: Currently, only query conditions are supported. Below is the supported 4. Like - import . "github.com/go-xorm/builder" + import . "xorm.io/builder" sql, args, _ := ToSQL(Like{"a", "c"}) // a LIKE ? [%c%] 5. Expr you can customerize your sql with Expr - import . "github.com/go-xorm/builder" + import . "xorm.io/builder" sql, args, _ := ToSQL(Expr("a = ? ", 1)) // a = ? [1] @@ -73,7 +73,7 @@ WARNNING: Currently, only query conditions are supported. Below is the supported 6. In and NotIn - import . "github.com/go-xorm/builder" + import . "xorm.io/builder" sql, args, _ := ToSQL(In("a", 1, 2, 3)) // a IN (?,?,?) [1,2,3] @@ -84,7 +84,7 @@ WARNNING: Currently, only query conditions are supported. Below is the supported 7. IsNull and NotNull - import . "github.com/go-xorm/builder" + import . "xorm.io/builder" sql, args, _ := ToSQL(IsNull{"a"}) // a IS NULL [] @@ -93,14 +93,14 @@ WARNNING: Currently, only query conditions are supported. Below is the supported 8. And(conds ...Cond), And can connect one or more condtions via AND - import . "github.com/go-xorm/builder" + import . "xorm.io/builder" sql, args, _ := ToSQL(And(Eq{"a":1}, Like{"b", "c"}, Neq{"d", 2})) // a=? AND b LIKE ? AND d<>? [1, %c%, 2] 9. Or(conds ...Cond), Or can connect one or more conditions via Or - import . "github.com/go-xorm/builder" + import . "xorm.io/builder" sql, args, _ := ToSQL(Or(Eq{"a":1}, Like{"b", "c"}, Neq{"d", 2})) // a=? OR b LIKE ? OR d<>? [1, %c%, 2] @@ -109,7 +109,7 @@ WARNNING: Currently, only query conditions are supported. Below is the supported 10. Between - import . "github.com/go-xorm/builder" + import . "xorm.io/builder" sql, args, _ := ToSQL(Between("a", 1, 2)) // a BETWEEN 1 AND 2 diff --git a/vendor/xorm.io/builder/go.mod b/vendor/xorm.io/builder/go.mod index 35e43b329ff2..9c730113fb52 100644 --- a/vendor/xorm.io/builder/go.mod +++ b/vendor/xorm.io/builder/go.mod @@ -1,5 +1,7 @@ module xorm.io/builder +go 1.11 + require ( github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a github.com/stretchr/testify v1.3.0 diff --git a/vendor/xorm.io/builder/sql.go b/vendor/xorm.io/builder/sql.go index 083424276862..217672580143 100644 --- a/vendor/xorm.io/builder/sql.go +++ b/vendor/xorm.io/builder/sql.go @@ -8,6 +8,7 @@ import ( sql2 "database/sql" "fmt" "reflect" + "strings" "time" ) @@ -92,7 +93,7 @@ func noSQLQuoteNeeded(a interface{}) bool { // ConvertToBoundSQL will convert SQL and args to a bound SQL func ConvertToBoundSQL(sql string, args []interface{}) (string, error) { - buf := StringBuilder{} + buf := strings.Builder{} var i, j, start int for ; i < len(sql); i++ { if sql[i] == '?' { @@ -114,7 +115,10 @@ func ConvertToBoundSQL(sql string, args []interface{}) (string, error) { if noSQLQuoteNeeded(arg) { _, err = fmt.Fprint(&buf, arg) } else { - _, err = fmt.Fprintf(&buf, "'%v'", arg) + // replace ' -> '' (standard replacement) to avoid critical SQL injection, + // NOTICE: may allow some injection like % (or _) in LIKE query + _, err = fmt.Fprintf(&buf, "'%v'", strings.Replace(fmt.Sprintf("%v", arg), "'", + "''", -1)) } if err != nil { return "", err @@ -131,7 +135,7 @@ func ConvertToBoundSQL(sql string, args []interface{}) (string, error) { // ConvertPlaceholder replaces ? to $1, $2 ... or :1, :2 ... according prefix func ConvertPlaceholder(sql, prefix string) (string, error) { - buf := StringBuilder{} + buf := strings.Builder{} var i, j, start int for ; i < len(sql); i++ { if sql[i] == '?' { diff --git a/vendor/xorm.io/builder/string_builder.go b/vendor/xorm.io/builder/string_builder.go deleted file mode 100644 index d4de8717e77a..000000000000 --- a/vendor/xorm.io/builder/string_builder.go +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright 2017 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package builder - -import ( - "unicode/utf8" - "unsafe" -) - -// A StringBuilder is used to efficiently build a string using Write methods. -// It minimizes memory copying. The zero value is ready to use. -// Do not copy a non-zero Builder. -type StringBuilder struct { - addr *StringBuilder // of receiver, to detect copies by value - buf []byte -} - -// noescape hides a pointer from escape analysis. noescape is -// the identity function but escape analysis doesn't think the -// output depends on the input. noescape is inlined and currently -// compiles down to zero instructions. -// USE CAREFULLY! -// This was copied from the runtime; see issues 23382 and 7921. -//go:nosplit -func noescape(p unsafe.Pointer) unsafe.Pointer { - x := uintptr(p) - return unsafe.Pointer(x ^ 0) -} - -func (b *StringBuilder) copyCheck() { - if b.addr == nil { - // This hack works around a failing of Go's escape analysis - // that was causing b to escape and be heap allocated. - // See issue 23382. - // TODO: once issue 7921 is fixed, this should be reverted to - // just "b.addr = b". - b.addr = (*StringBuilder)(noescape(unsafe.Pointer(b))) - } else if b.addr != b { - panic("strings: illegal use of non-zero Builder copied by value") - } -} - -// String returns the accumulated string. -func (b *StringBuilder) String() string { - return *(*string)(unsafe.Pointer(&b.buf)) -} - -// Len returns the number of accumulated bytes; b.Len() == len(b.String()). -func (b *StringBuilder) Len() int { return len(b.buf) } - -// Reset resets the Builder to be empty. -func (b *StringBuilder) Reset() { - b.addr = nil - b.buf = nil -} - -// grow copies the buffer to a new, larger buffer so that there are at least n -// bytes of capacity beyond len(b.buf). -func (b *StringBuilder) grow(n int) { - buf := make([]byte, len(b.buf), 2*cap(b.buf)+n) - copy(buf, b.buf) - b.buf = buf -} - -// Grow grows b's capacity, if necessary, to guarantee space for -// another n bytes. After Grow(n), at least n bytes can be written to b -// without another allocation. If n is negative, Grow panics. -func (b *StringBuilder) Grow(n int) { - b.copyCheck() - if n < 0 { - panic("strings.Builder.Grow: negative count") - } - if cap(b.buf)-len(b.buf) < n { - b.grow(n) - } -} - -// Write appends the contents of p to b's buffer. -// Write always returns len(p), nil. -func (b *StringBuilder) Write(p []byte) (int, error) { - b.copyCheck() - b.buf = append(b.buf, p...) - return len(p), nil -} - -// WriteByte appends the byte c to b's buffer. -// The returned error is always nil. -func (b *StringBuilder) WriteByte(c byte) error { - b.copyCheck() - b.buf = append(b.buf, c) - return nil -} - -// WriteRune appends the UTF-8 encoding of Unicode code point r to b's buffer. -// It returns the length of r and a nil error. -func (b *StringBuilder) WriteRune(r rune) (int, error) { - b.copyCheck() - if r < utf8.RuneSelf { - b.buf = append(b.buf, byte(r)) - return 1, nil - } - l := len(b.buf) - if cap(b.buf)-l < utf8.UTFMax { - b.grow(utf8.UTFMax) - } - n := utf8.EncodeRune(b.buf[l:l+utf8.UTFMax], r) - b.buf = b.buf[:l+n] - return n, nil -} - -// WriteString appends the contents of s to b's buffer. -// It returns the length of s and a nil error. -func (b *StringBuilder) WriteString(s string) (int, error) { - b.copyCheck() - b.buf = append(b.buf, s...) - return len(s), nil -}