Compare commits
1 Commits
v1
...
lunny/fix_
Author | SHA1 | Date |
---|---|---|
|
1c0a25c2b7 |
|
@ -9,13 +9,13 @@ jobs:
|
||||||
release:
|
release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: setup go
|
- name: setup go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: 'go.mod'
|
go-version: '>=1.20.1'
|
||||||
- name: Use Go Action
|
- name: Use Go Action
|
||||||
id: use-go-action
|
id: use-go-action
|
||||||
uses: https://gitea.com/actions/release-action@main
|
uses: https://gitea.com/actions/release-action@main
|
||||||
|
|
|
@ -2,20 +2,41 @@ name: test cockroach
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- donttrigger # disabled for now
|
- master
|
||||||
#- main
|
pull_request:
|
||||||
#- v1
|
|
||||||
#pull_request:
|
env:
|
||||||
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
GOPATH: /go_path
|
||||||
|
GOCACHE: /go_cache
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-cockroach:
|
test-cockroach:
|
||||||
name: test cockroach
|
name: test cockroach
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
# - name: cache go path
|
||||||
|
# id: cache-go-path
|
||||||
|
# uses: https://github.com/actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: /go_path
|
||||||
|
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
||||||
|
# restore-keys: |
|
||||||
|
# go_path-${{ github.repository }}-
|
||||||
|
# go_path-
|
||||||
|
# - name: cache go cache
|
||||||
|
# id: cache-go-cache
|
||||||
|
# uses: https://github.com/actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: /go_cache
|
||||||
|
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
||||||
|
# restore-keys: |
|
||||||
|
# go_cache-${{ github.repository }}-
|
||||||
|
# go_cache-
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: 'go.mod'
|
go-version: 1.20
|
||||||
|
- uses: actions/checkout@v3
|
||||||
- name: test cockroach
|
- name: test cockroach
|
||||||
env:
|
env:
|
||||||
TEST_COCKROACH_HOST: "cockroach:26257"
|
TEST_COCKROACH_HOST: "cockroach:26257"
|
||||||
|
@ -28,6 +49,8 @@ jobs:
|
||||||
services:
|
services:
|
||||||
cockroach:
|
cockroach:
|
||||||
image: cockroachdb/cockroach:v19.2.4
|
image: cockroachdb/cockroach:v19.2.4
|
||||||
|
ports:
|
||||||
|
- 26257:26257
|
||||||
cmd:
|
cmd:
|
||||||
- 'start'
|
- 'start'
|
||||||
- '--insecure'
|
- '--insecure'
|
||||||
|
|
|
@ -2,19 +2,41 @@ name: test mariadb
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- master
|
||||||
- v1
|
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
GOPATH: /go_path
|
||||||
|
GOCACHE: /go_cache
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
name: test mariadb
|
name: test mariadb
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
# - name: cache go path
|
||||||
|
# id: cache-go-path
|
||||||
|
# uses: https://github.com/actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: /go_path
|
||||||
|
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
||||||
|
# restore-keys: |
|
||||||
|
# go_path-${{ github.repository }}-
|
||||||
|
# go_path-
|
||||||
|
# - name: cache go cache
|
||||||
|
# id: cache-go-cache
|
||||||
|
# uses: https://github.com/actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: /go_cache
|
||||||
|
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
||||||
|
# restore-keys: |
|
||||||
|
# go_cache-${{ github.repository }}-
|
||||||
|
# go_cache-
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: 'go.mod'
|
go-version: 1.20
|
||||||
|
- uses: actions/checkout@v3
|
||||||
- name: test mariadb
|
- name: test mariadb
|
||||||
env:
|
env:
|
||||||
TEST_MYSQL_HOST: mariadb
|
TEST_MYSQL_HOST: mariadb
|
||||||
|
@ -30,3 +52,5 @@ jobs:
|
||||||
env:
|
env:
|
||||||
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
||||||
MYSQL_DATABASE: xorm_test
|
MYSQL_DATABASE: xorm_test
|
||||||
|
ports:
|
||||||
|
- 3306:3306
|
|
@ -2,19 +2,42 @@ name: test mssql
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- master
|
||||||
- v1
|
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
GOPATH: /go_path
|
||||||
|
GOCACHE: /go_cache
|
||||||
|
RUNNER_TOOL_CACHE: /toolcache # specify with your cache path
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-mssql-collation:
|
test-mssql-collation:
|
||||||
name: test mssql with collation
|
name: test mssql with collation
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
# - name: cache go path
|
||||||
- uses: actions/setup-go@v5
|
# id: cache-go-path
|
||||||
|
# uses: https://github.com/actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: /go_path
|
||||||
|
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
||||||
|
# restore-keys: |
|
||||||
|
# go_path-${{ github.repository }}-
|
||||||
|
# go_path-
|
||||||
|
# - name: cache go cache
|
||||||
|
# id: cache-go-cache
|
||||||
|
# uses: https://github.com/actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: /go_cache
|
||||||
|
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
||||||
|
# restore-keys: |
|
||||||
|
# go_cache-${{ github.repository }}-
|
||||||
|
# go_cache-
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version-file: 'go.mod'
|
go-version: 1.20
|
||||||
|
- uses: actions/checkout@v3
|
||||||
- name: test mssql with collation
|
- name: test mssql with collation
|
||||||
env:
|
env:
|
||||||
TEST_MSSQL_HOST: mssql2
|
TEST_MSSQL_HOST: mssql2
|
||||||
|
@ -31,3 +54,5 @@ jobs:
|
||||||
ACCEPT_EULA: Y
|
ACCEPT_EULA: Y
|
||||||
SA_PASSWORD: yourStrong(!)Password
|
SA_PASSWORD: yourStrong(!)Password
|
||||||
MSSQL_PID: Standard
|
MSSQL_PID: Standard
|
||||||
|
ports:
|
||||||
|
- 1433:1433
|
|
@ -2,19 +2,41 @@ name: test mssql
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- master
|
||||||
- v1
|
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
GOPATH: /go_path
|
||||||
|
GOCACHE: /go_cache
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-mssql:
|
test-mssql:
|
||||||
name: test mssql
|
name: test mssql
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
# - name: cache go path
|
||||||
|
# id: cache-go-path
|
||||||
|
# uses: https://github.com/actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: /go_path
|
||||||
|
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
||||||
|
# restore-keys: |
|
||||||
|
# go_path-${{ github.repository }}-
|
||||||
|
# go_path-
|
||||||
|
# - name: cache go cache
|
||||||
|
# id: cache-go-cache
|
||||||
|
# uses: https://github.com/actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: /go_cache
|
||||||
|
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
||||||
|
# restore-keys: |
|
||||||
|
# go_cache-${{ github.repository }}-
|
||||||
|
# go_cache-
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: 'go.mod'
|
go-version: 1.20
|
||||||
|
- uses: actions/checkout@v3
|
||||||
- name: test mssql
|
- name: test mssql
|
||||||
env:
|
env:
|
||||||
TEST_MSSQL_HOST: mssql
|
TEST_MSSQL_HOST: mssql
|
||||||
|
@ -30,3 +52,5 @@ jobs:
|
||||||
ACCEPT_EULA: Y
|
ACCEPT_EULA: Y
|
||||||
SA_PASSWORD: yourStrong(!)Password
|
SA_PASSWORD: yourStrong(!)Password
|
||||||
MSSQL_PID: Standard
|
MSSQL_PID: Standard
|
||||||
|
ports:
|
||||||
|
- 1433:1433
|
|
@ -2,19 +2,41 @@ name: test mysql
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- master
|
||||||
- v1
|
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
GOPATH: /go_path
|
||||||
|
GOCACHE: /go_cache
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-mysql:
|
test-mysql:
|
||||||
name: test mysql
|
name: test mysql
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
# - name: cache go path
|
||||||
|
# id: cache-go-path
|
||||||
|
# uses: https://github.com/actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: /go_path
|
||||||
|
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
||||||
|
# restore-keys: |
|
||||||
|
# go_path-${{ github.repository }}-
|
||||||
|
# go_path-
|
||||||
|
# - name: cache go cache
|
||||||
|
# id: cache-go-cache
|
||||||
|
# uses: https://github.com/actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: /go_cache
|
||||||
|
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
||||||
|
# restore-keys: |
|
||||||
|
# go_cache-${{ github.repository }}-
|
||||||
|
# go_cache-
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: 'go.mod'
|
go-version: 1.20
|
||||||
|
- uses: actions/checkout@v3
|
||||||
- name: test mysql utf8mb4
|
- name: test mysql utf8mb4
|
||||||
env:
|
env:
|
||||||
TEST_MYSQL_HOST: mysql
|
TEST_MYSQL_HOST: mysql
|
||||||
|
@ -30,3 +52,5 @@ jobs:
|
||||||
env:
|
env:
|
||||||
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
||||||
MYSQL_DATABASE: xorm_test
|
MYSQL_DATABASE: xorm_test
|
||||||
|
ports:
|
||||||
|
- 3306:3306
|
|
@ -2,19 +2,41 @@ name: test mysql8
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- master
|
||||||
- v1
|
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
GOPATH: /go_path
|
||||||
|
GOCACHE: /go_cache
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
name: test mysql8
|
name: test mysql8
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
# - name: cache go path
|
||||||
|
# id: cache-go-path
|
||||||
|
# uses: https://github.com/actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: /go_path
|
||||||
|
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
||||||
|
# restore-keys: |
|
||||||
|
# go_path-${{ github.repository }}-
|
||||||
|
# go_path-
|
||||||
|
# - name: cache go cache
|
||||||
|
# id: cache-go-cache
|
||||||
|
# uses: https://github.com/actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: /go_cache
|
||||||
|
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
||||||
|
# restore-keys: |
|
||||||
|
# go_cache-${{ github.repository }}-
|
||||||
|
# go_cache-
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: 'go.mod'
|
go-version: 1.20
|
||||||
|
- uses: actions/checkout@v3
|
||||||
- name: test mysql8
|
- name: test mysql8
|
||||||
env:
|
env:
|
||||||
TEST_MYSQL_HOST: mysql8
|
TEST_MYSQL_HOST: mysql8
|
||||||
|
@ -30,3 +52,5 @@ jobs:
|
||||||
env:
|
env:
|
||||||
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
||||||
MYSQL_DATABASE: xorm_test
|
MYSQL_DATABASE: xorm_test
|
||||||
|
ports:
|
||||||
|
- 3306:3306
|
|
@ -2,19 +2,41 @@ name: test postgres
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- master
|
||||||
- v1
|
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
GOPATH: /go_path
|
||||||
|
GOCACHE: /go_cache
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
name: test postgres
|
name: test postgres
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
# - name: cache go path
|
||||||
|
# id: cache-go-path
|
||||||
|
# uses: https://github.com/actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: /go_path
|
||||||
|
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
||||||
|
# restore-keys: |
|
||||||
|
# go_path-${{ github.repository }}-
|
||||||
|
# go_path-
|
||||||
|
# - name: cache go cache
|
||||||
|
# id: cache-go-cache
|
||||||
|
# uses: https://github.com/actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: /go_cache
|
||||||
|
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
||||||
|
# restore-keys: |
|
||||||
|
# go_cache-${{ github.repository }}-
|
||||||
|
# go_cache-
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: 'go.mod'
|
go-version: 1.20
|
||||||
|
- uses: actions/checkout@v3
|
||||||
- name: test postgres
|
- name: test postgres
|
||||||
env:
|
env:
|
||||||
TEST_PGSQL_HOST: pgsql
|
TEST_PGSQL_HOST: pgsql
|
||||||
|
@ -53,3 +75,5 @@ jobs:
|
||||||
POSTGRES_DB: xorm_test
|
POSTGRES_DB: xorm_test
|
||||||
POSTGRES_USER: postgres
|
POSTGRES_USER: postgres
|
||||||
POSTGRES_PASSWORD: postgres
|
POSTGRES_PASSWORD: postgres
|
||||||
|
ports:
|
||||||
|
- 5432:5432
|
|
@ -2,19 +2,41 @@ name: test sqlite
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- master
|
||||||
- v1
|
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
GOPATH: /go_path
|
||||||
|
GOCACHE: /go_cache
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-sqlite:
|
test-sqlite:
|
||||||
name: unit test & test sqlite
|
name: unit test & test sqlite
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
# - name: cache go path
|
||||||
|
# id: cache-go-path
|
||||||
|
# uses: https://github.com/actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: /go_path
|
||||||
|
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
||||||
|
# restore-keys: |
|
||||||
|
# go_path-${{ github.repository }}-
|
||||||
|
# go_path-
|
||||||
|
# - name: cache go cache
|
||||||
|
# id: cache-go-cache
|
||||||
|
# uses: https://github.com/actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: /go_cache
|
||||||
|
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
||||||
|
# restore-keys: |
|
||||||
|
# go_cache-${{ github.repository }}-
|
||||||
|
# go_cache-
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: 'go.mod'
|
go-version: 1.20
|
||||||
|
- uses: actions/checkout@v3
|
||||||
- name: vet
|
- name: vet
|
||||||
run: make vet
|
run: make vet
|
||||||
- name: format check
|
- name: format check
|
||||||
|
@ -25,13 +47,3 @@ jobs:
|
||||||
run: make test-sqlite3
|
run: make test-sqlite3
|
||||||
- name: test sqlite3 with cache
|
- name: test sqlite3 with cache
|
||||||
run: TEST_CACHE_ENABLE=true make test-sqlite3
|
run: TEST_CACHE_ENABLE=true make test-sqlite3
|
||||||
|
|
||||||
govulncheck_job:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Run govulncheck
|
|
||||||
steps:
|
|
||||||
- id: govulncheck
|
|
||||||
uses: golang/govulncheck-action@v1
|
|
||||||
with:
|
|
||||||
go-version-file: 'go.mod'
|
|
||||||
go-package: ./...
|
|
|
@ -2,19 +2,41 @@ name: test tidb
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- master
|
||||||
- v1
|
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
GOPROXY: https://goproxy.io,direct
|
||||||
|
GOPATH: /go_path
|
||||||
|
GOCACHE: /go_cache
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-tidb:
|
test-tidb:
|
||||||
name: test tidb
|
name: test tidb
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
# - name: cache go path
|
||||||
|
# id: cache-go-path
|
||||||
|
# uses: https://github.com/actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: /go_path
|
||||||
|
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
||||||
|
# restore-keys: |
|
||||||
|
# go_path-${{ github.repository }}-
|
||||||
|
# go_path-
|
||||||
|
# - name: cache go cache
|
||||||
|
# id: cache-go-cache
|
||||||
|
# uses: https://github.com/actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: /go_cache
|
||||||
|
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
||||||
|
# restore-keys: |
|
||||||
|
# go_cache-${{ github.repository }}-
|
||||||
|
# go_cache-
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: 'go.mod'
|
go-version: 1.20
|
||||||
|
- uses: actions/checkout@v3
|
||||||
- name: test tidb
|
- name: test tidb
|
||||||
env:
|
env:
|
||||||
TEST_TIDB_HOST: "tidb:4000"
|
TEST_TIDB_HOST: "tidb:4000"
|
||||||
|
@ -26,3 +48,5 @@ jobs:
|
||||||
services:
|
services:
|
||||||
tidb:
|
tidb:
|
||||||
image: pingcap/tidb:v3.0.3
|
image: pingcap/tidb:v3.0.3
|
||||||
|
ports:
|
||||||
|
- 4000:4000
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
Xorm is a simple and powerful ORM for Go.
|
Xorm is a simple and powerful ORM for Go.
|
||||||
|
|
||||||
[](https://gitea.com/xorm/xorm/actions) [](https://gocover.io/xorm.io/xorm) [](https://goreportcard.com/report/xorm.io/xorm) [](https://discord.gg/HuR2CF3)
|
[](https://drone.gitea.com/xorm/xorm) [](https://gocover.io/xorm.io/xorm) [](https://goreportcard.com/report/xorm.io/xorm) [](https://discord.gg/HuR2CF3)
|
||||||
|
|
||||||
## Notice
|
## Notice
|
||||||
|
|
||||||
|
@ -50,9 +50,6 @@ Drivers for Go's sql package which currently support database/sql includes:
|
||||||
* MsSql
|
* MsSql
|
||||||
- [github.com/microsoft/go-mssqldb](https://github.com/microsoft/go-mssqldb)
|
- [github.com/microsoft/go-mssqldb](https://github.com/microsoft/go-mssqldb)
|
||||||
|
|
||||||
* GBase8s
|
|
||||||
- [https://gitee.com/GBase8s/go-gci](https://gitee.com/GBase8s/go-gci)
|
|
||||||
|
|
||||||
* Oracle
|
* Oracle
|
||||||
- [github.com/godror/godror](https://github.com/godror/godror) (experiment)
|
- [github.com/godror/godror](https://github.com/godror/godror) (experiment)
|
||||||
- [github.com/mattn/go-oci8](https://github.com/mattn/go-oci8) (experiment)
|
- [github.com/mattn/go-oci8](https://github.com/mattn/go-oci8) (experiment)
|
||||||
|
@ -468,7 +465,7 @@ res, err := engine.Transaction(func(session *xorm.Session) (interface{}, error)
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
If you want to pull request, please see [CONTRIBUTING](CONTRIBUTING.md). And you can also go to [Xorm on discourse](https://xorm.discourse.group) to discuss.
|
If you want to pull request, please see [CONTRIBUTING](https://gitea.com/xorm/xorm/src/branch/master/CONTRIBUTING.md). And you can also go to [Xorm on discourse](https://xorm.discourse.group) to discuss.
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
|
|
|
@ -49,9 +49,6 @@ v1.0.0 相对于 v0.8.2 有以下不兼容的变更:
|
||||||
* MsSql
|
* MsSql
|
||||||
- [github.com/microsoft/go-mssqldb](https://github.com/microsoft/go-mssqldb)
|
- [github.com/microsoft/go-mssqldb](https://github.com/microsoft/go-mssqldb)
|
||||||
|
|
||||||
* GBase8s
|
|
||||||
- [https://gitee.com/GBase8s/go-gci](https://gitee.com/GBase8s/go-gci)
|
|
||||||
|
|
||||||
* Oracle
|
* Oracle
|
||||||
- [github.com/godror/godror](https://github.com/godror/godror) (试验性支持)
|
- [github.com/godror/godror](https://github.com/godror/godror) (试验性支持)
|
||||||
- [github.com/mattn/go-oci8](https://github.com/mattn/go-oci8) (试验性支持)
|
- [github.com/mattn/go-oci8](https://github.com/mattn/go-oci8) (试验性支持)
|
||||||
|
|
|
@ -28,19 +28,14 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t
|
||||||
dt = dt.In(convertedLocation)
|
dt = dt.In(convertedLocation)
|
||||||
return &dt, nil
|
return &dt, nil
|
||||||
} else if len(s) == 20 && s[10] == 'T' && s[19] == 'Z' {
|
} else if len(s) == 20 && s[10] == 'T' && s[19] == 'Z' {
|
||||||
if strings.HasPrefix(s, "0000-00-00T00:00:00") || strings.HasPrefix(s, "0001-01-01T00:00:00") {
|
|
||||||
return &time.Time{}, nil
|
|
||||||
}
|
|
||||||
dt, err := time.ParseInLocation("2006-01-02T15:04:05", s[:19], originalLocation)
|
dt, err := time.ParseInLocation("2006-01-02T15:04:05", s[:19], originalLocation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dt = dt.In(convertedLocation)
|
dt = dt.In(convertedLocation)
|
||||||
|
dt.IsZero()
|
||||||
return &dt, nil
|
return &dt, nil
|
||||||
} else if len(s) == 25 && s[10] == 'T' && s[19] == '+' && s[22] == ':' {
|
} else if len(s) == 25 && s[10] == 'T' && s[19] == '+' && s[22] == ':' {
|
||||||
if strings.HasPrefix(s, "0000-00-00T00:00:00") || strings.HasPrefix(s, "0001-01-01T00:00:00") {
|
|
||||||
return &time.Time{}, nil
|
|
||||||
}
|
|
||||||
dt, err := time.Parse(time.RFC3339, s)
|
dt, err := time.Parse(time.RFC3339, s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -48,10 +43,6 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t
|
||||||
dt = dt.In(convertedLocation)
|
dt = dt.In(convertedLocation)
|
||||||
return &dt, nil
|
return &dt, nil
|
||||||
} else if len(s) >= 21 && s[10] == 'T' && s[19] == '.' {
|
} else if len(s) >= 21 && s[10] == 'T' && s[19] == '.' {
|
||||||
if strings.HasPrefix(s, "0000-00-00T00:00:00."+strings.Repeat("0", len(s)-20)) ||
|
|
||||||
strings.HasPrefix(s, "0001-01-01T00:00:00."+strings.Repeat("0", len(s)-20)) {
|
|
||||||
return &time.Time{}, nil
|
|
||||||
}
|
|
||||||
dt, err := time.Parse(time.RFC3339Nano, s)
|
dt, err := time.Parse(time.RFC3339Nano, s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -59,10 +50,6 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t
|
||||||
dt = dt.In(convertedLocation)
|
dt = dt.In(convertedLocation)
|
||||||
return &dt, nil
|
return &dt, nil
|
||||||
} else if len(s) >= 21 && s[19] == '.' {
|
} else if len(s) >= 21 && s[19] == '.' {
|
||||||
if strings.HasPrefix(s, "0000-00-00T00:00:00."+strings.Repeat("0", len(s)-20)) ||
|
|
||||||
strings.HasPrefix(s, "0001-01-01T00:00:00."+strings.Repeat("0", len(s)-20)) {
|
|
||||||
return &time.Time{}, nil
|
|
||||||
}
|
|
||||||
layout := "2006-01-02 15:04:05." + strings.Repeat("0", len(s)-20)
|
layout := "2006-01-02 15:04:05." + strings.Repeat("0", len(s)-20)
|
||||||
dt, err := time.ParseInLocation(layout, s, originalLocation)
|
dt, err := time.ParseInLocation(layout, s, originalLocation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -81,20 +68,20 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t
|
||||||
dt = dt.In(convertedLocation)
|
dt = dt.In(convertedLocation)
|
||||||
return &dt, nil
|
return &dt, nil
|
||||||
} else if len(s) == 8 && s[2] == ':' && s[5] == ':' {
|
} else if len(s) == 8 && s[2] == ':' && s[5] == ':' {
|
||||||
|
currentDate := time.Now()
|
||||||
dt, err := time.ParseInLocation("15:04:05", s, originalLocation)
|
dt, err := time.ParseInLocation("15:04:05", s, originalLocation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dt = dt.AddDate(2006, 01, 02).In(convertedLocation)
|
// add current date for correct time locations
|
||||||
|
dt = dt.AddDate(currentDate.Year(), int(currentDate.Month()), currentDate.Day())
|
||||||
|
dt = dt.In(convertedLocation)
|
||||||
// back to zero year
|
// back to zero year
|
||||||
dt = dt.AddDate(-2006, -01, -02)
|
dt = dt.AddDate(-currentDate.Year(), int(-currentDate.Month()), -currentDate.Day())
|
||||||
return &dt, nil
|
return &dt, nil
|
||||||
} else {
|
} else {
|
||||||
i, err := strconv.ParseInt(s, 10, 64)
|
i, err := strconv.ParseInt(s, 10, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if i == 0 {
|
|
||||||
return &time.Time{}, nil
|
|
||||||
}
|
|
||||||
tm := time.Unix(i, 0).In(convertedLocation)
|
tm := time.Unix(i, 0).In(convertedLocation)
|
||||||
return &tm, nil
|
return &tm, nil
|
||||||
}
|
}
|
||||||
|
@ -121,9 +108,6 @@ func AsTime(src interface{}, dbLoc *time.Location, uiLoc *time.Location) (*time.
|
||||||
if !t.Valid {
|
if !t.Valid {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
if utils.IsTimeZero(t.Time) {
|
|
||||||
return &time.Time{}, nil
|
|
||||||
}
|
|
||||||
z, _ := t.Time.Zone()
|
z, _ := t.Time.Zone()
|
||||||
if len(z) == 0 || t.Time.Year() == 0 || t.Time.Location().String() != dbLoc.String() {
|
if len(z) == 0 || t.Time.Year() == 0 || t.Time.Location().String() != dbLoc.String() {
|
||||||
tm := time.Date(t.Time.Year(), t.Time.Month(), t.Time.Day(), t.Time.Hour(),
|
tm := time.Date(t.Time.Year(), t.Time.Month(), t.Time.Day(), t.Time.Hour(),
|
||||||
|
@ -133,9 +117,6 @@ func AsTime(src interface{}, dbLoc *time.Location, uiLoc *time.Location) (*time.
|
||||||
tm := t.Time.In(uiLoc)
|
tm := t.Time.In(uiLoc)
|
||||||
return &tm, nil
|
return &tm, nil
|
||||||
case *time.Time:
|
case *time.Time:
|
||||||
if utils.IsTimeZero(*t) {
|
|
||||||
return &time.Time{}, nil
|
|
||||||
}
|
|
||||||
z, _ := t.Zone()
|
z, _ := t.Zone()
|
||||||
if len(z) == 0 || t.Year() == 0 || t.Location().String() != dbLoc.String() {
|
if len(z) == 0 || t.Year() == 0 || t.Location().String() != dbLoc.String() {
|
||||||
tm := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(),
|
tm := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(),
|
||||||
|
@ -145,9 +126,6 @@ func AsTime(src interface{}, dbLoc *time.Location, uiLoc *time.Location) (*time.
|
||||||
tm := t.In(uiLoc)
|
tm := t.In(uiLoc)
|
||||||
return &tm, nil
|
return &tm, nil
|
||||||
case time.Time:
|
case time.Time:
|
||||||
if utils.IsTimeZero(t) {
|
|
||||||
return &time.Time{}, nil
|
|
||||||
}
|
|
||||||
z, _ := t.Zone()
|
z, _ := t.Zone()
|
||||||
if len(z) == 0 || t.Year() == 0 || t.Location().String() != dbLoc.String() {
|
if len(z) == 0 || t.Year() == 0 || t.Location().String() != dbLoc.String() {
|
||||||
tm := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(),
|
tm := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(),
|
||||||
|
@ -157,21 +135,12 @@ func AsTime(src interface{}, dbLoc *time.Location, uiLoc *time.Location) (*time.
|
||||||
tm := t.In(uiLoc)
|
tm := t.In(uiLoc)
|
||||||
return &tm, nil
|
return &tm, nil
|
||||||
case int:
|
case int:
|
||||||
if t == 0 {
|
|
||||||
return &time.Time{}, nil
|
|
||||||
}
|
|
||||||
tm := time.Unix(int64(t), 0).In(uiLoc)
|
tm := time.Unix(int64(t), 0).In(uiLoc)
|
||||||
return &tm, nil
|
return &tm, nil
|
||||||
case int64:
|
case int64:
|
||||||
if t == 0 {
|
|
||||||
return &time.Time{}, nil
|
|
||||||
}
|
|
||||||
tm := time.Unix(t, 0).In(uiLoc)
|
tm := time.Unix(t, 0).In(uiLoc)
|
||||||
return &tm, nil
|
return &tm, nil
|
||||||
case *sql.NullInt64:
|
case *sql.NullInt64:
|
||||||
if t.Int64 == 0 {
|
|
||||||
return &time.Time{}, nil
|
|
||||||
}
|
|
||||||
tm := time.Unix(t.Int64, 0).In(uiLoc)
|
tm := time.Unix(t.Int64, 0).In(uiLoc)
|
||||||
return &tm, nil
|
return &tm, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -618,8 +618,8 @@ func (db *dameng) SQLType(c *schemas.Column) string {
|
||||||
res = t
|
res = t
|
||||||
}
|
}
|
||||||
|
|
||||||
hasLen1 := c.Length > 0
|
hasLen1 := (c.Length > 0)
|
||||||
hasLen2 := c.Length2 > 0
|
hasLen2 := (c.Length2 > 0)
|
||||||
|
|
||||||
if hasLen2 {
|
if hasLen2 {
|
||||||
res += "(" + strconv.FormatInt(c.Length, 10) + "," + strconv.FormatInt(c.Length2, 10) + ")"
|
res += "(" + strconv.FormatInt(c.Length, 10) + "," + strconv.FormatInt(c.Length2, 10) + ")"
|
||||||
|
@ -831,13 +831,6 @@ func (d *dmClobScanner) Scan(data interface{}) error {
|
||||||
d.data = string(t)
|
d.data = string(t)
|
||||||
d.valid = true
|
d.valid = true
|
||||||
return nil
|
return nil
|
||||||
case string:
|
|
||||||
if len(t) <= 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
d.data = string(t)
|
|
||||||
d.valid = true
|
|
||||||
return nil
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("cannot convert %T as dmClobScanner", data)
|
return fmt.Errorf("cannot convert %T as dmClobScanner", data)
|
||||||
}
|
}
|
||||||
|
|
|
@ -279,7 +279,6 @@ func regDrvsNDialects() bool {
|
||||||
"pgx": {"postgres", func() Driver { return &pqDriverPgx{} }, func() Dialect { return &postgres{} }},
|
"pgx": {"postgres", func() Driver { return &pqDriverPgx{} }, func() Dialect { return &postgres{} }},
|
||||||
"sqlite3": {"sqlite3", func() Driver { return &sqlite3Driver{} }, func() Dialect { return &sqlite3{} }},
|
"sqlite3": {"sqlite3", func() Driver { return &sqlite3Driver{} }, func() Dialect { return &sqlite3{} }},
|
||||||
"sqlite": {"sqlite3", func() Driver { return &sqlite3Driver{} }, func() Dialect { return &sqlite3{} }},
|
"sqlite": {"sqlite3", func() Driver { return &sqlite3Driver{} }, func() Dialect { return &sqlite3{} }},
|
||||||
"libsql": {"sqlite3", func() Driver { return &sqlite3Driver{} }, func() Dialect { return &sqlite3{} }},
|
|
||||||
"oci8": {"oracle", func() Driver { return &oci8Driver{} }, func() Dialect { return &oracle{} }},
|
"oci8": {"oracle", func() Driver { return &oci8Driver{} }, func() Dialect { return &oracle{} }},
|
||||||
"godror": {"oracle", func() Driver { return &godrorDriver{} }, func() Dialect { return &oracle{} }},
|
"godror": {"oracle", func() Driver { return &godrorDriver{} }, func() Dialect { return &oracle{} }},
|
||||||
"oracle": {"oracle", func() Driver { return &oracleDriver{} }, func() Dialect { return &oracle{} }},
|
"oracle": {"oracle", func() Driver { return &oracleDriver{} }, func() Dialect { return &oracle{} }},
|
||||||
|
|
1089
dialects/gbase8s.go
1089
dialects/gbase8s.go
File diff suppressed because it is too large
Load Diff
|
@ -330,11 +330,15 @@ func (db *mssql) SQLType(c *schemas.Column) string {
|
||||||
res += "(MAX)"
|
res += "(MAX)"
|
||||||
}
|
}
|
||||||
case schemas.TimeStamp, schemas.DateTime:
|
case schemas.TimeStamp, schemas.DateTime:
|
||||||
return "DATETIME2"
|
if c.Length > 3 {
|
||||||
|
res = "DATETIME2"
|
||||||
|
} else {
|
||||||
|
return schemas.DateTime
|
||||||
|
}
|
||||||
case schemas.TimeStampz:
|
case schemas.TimeStampz:
|
||||||
res = "DATETIMEOFFSET"
|
res = "DATETIMEOFFSET"
|
||||||
c.Length = 7
|
c.Length = 7
|
||||||
case schemas.MediumInt, schemas.SmallInt, schemas.UnsignedMediumInt, schemas.UnsignedTinyInt, schemas.UnsignedSmallInt:
|
case schemas.MediumInt, schemas.TinyInt, schemas.SmallInt, schemas.UnsignedMediumInt, schemas.UnsignedTinyInt, schemas.UnsignedSmallInt:
|
||||||
res = schemas.Int
|
res = schemas.Int
|
||||||
case schemas.Text, schemas.MediumText, schemas.TinyText, schemas.LongText, schemas.Json:
|
case schemas.Text, schemas.MediumText, schemas.TinyText, schemas.LongText, schemas.Json:
|
||||||
res = db.defaultVarchar + "(MAX)"
|
res = db.defaultVarchar + "(MAX)"
|
||||||
|
@ -377,8 +381,8 @@ func (db *mssql) SQLType(c *schemas.Column) string {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
hasLen1 := c.Length > 0
|
hasLen1 := (c.Length > 0)
|
||||||
hasLen2 := c.Length2 > 0
|
hasLen2 := (c.Length2 > 0)
|
||||||
|
|
||||||
if hasLen2 {
|
if hasLen2 {
|
||||||
res += "(" + strconv.FormatInt(c.Length, 10) + "," + strconv.FormatInt(c.Length2, 10) + ")"
|
res += "(" + strconv.FormatInt(c.Length, 10) + "," + strconv.FormatInt(c.Length2, 10) + ")"
|
||||||
|
|
|
@ -326,8 +326,8 @@ func (db *mysql) SQLType(c *schemas.Column) string {
|
||||||
res = t
|
res = t
|
||||||
}
|
}
|
||||||
|
|
||||||
hasLen1 := c.Length > 0
|
hasLen1 := (c.Length > 0)
|
||||||
hasLen2 := c.Length2 > 0
|
hasLen2 := (c.Length2 > 0)
|
||||||
|
|
||||||
if res == schemas.BigInt && !hasLen1 && !hasLen2 {
|
if res == schemas.BigInt && !hasLen1 && !hasLen2 {
|
||||||
c.Length = 20
|
c.Length = 20
|
||||||
|
@ -402,9 +402,6 @@ func (db *mysql) AddColumnSQL(tableName string, col *schemas.Column) string {
|
||||||
// ModifyColumnSQL returns a SQL to modify SQL
|
// ModifyColumnSQL returns a SQL to modify SQL
|
||||||
func (db *mysql) ModifyColumnSQL(tableName string, col *schemas.Column) string {
|
func (db *mysql) ModifyColumnSQL(tableName string, col *schemas.Column) string {
|
||||||
s, _ := ColumnString(db.dialect, col, false, true)
|
s, _ := ColumnString(db.dialect, col, false, true)
|
||||||
if col.IsAutoIncrement {
|
|
||||||
s += " " + db.AutoIncrStr()
|
|
||||||
}
|
|
||||||
if col.Comment != "" {
|
if col.Comment != "" {
|
||||||
s += fmt.Sprintf(" COMMENT '%s'", col.Comment)
|
s += fmt.Sprintf(" COMMENT '%s'", col.Comment)
|
||||||
}
|
}
|
||||||
|
|
|
@ -585,8 +585,8 @@ func (db *oracle) SQLType(c *schemas.Column) string {
|
||||||
res = t
|
res = t
|
||||||
}
|
}
|
||||||
|
|
||||||
hasLen1 := c.Length > 0
|
hasLen1 := (c.Length > 0)
|
||||||
hasLen2 := c.Length2 > 0
|
hasLen2 := (c.Length2 > 0)
|
||||||
|
|
||||||
if hasLen2 {
|
if hasLen2 {
|
||||||
res += "(" + strconv.FormatInt(c.Length, 10) + "," + strconv.FormatInt(c.Length2, 10) + ")"
|
res += "(" + strconv.FormatInt(c.Length, 10) + "," + strconv.FormatInt(c.Length2, 10) + ")"
|
||||||
|
@ -684,17 +684,6 @@ func (db *oracle) IndexCheckSQL(tableName, idxName string) (string, []interface{
|
||||||
`WHERE TABLE_NAME = :1 AND INDEX_NAME = :2`, args
|
`WHERE TABLE_NAME = :1 AND INDEX_NAME = :2`, args
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *oracle) DropIndexSQL(tableName string, index *schemas.Index) string {
|
|
||||||
quote := db.dialect.Quoter().Quote
|
|
||||||
var name string
|
|
||||||
if index.IsRegular {
|
|
||||||
name = index.XName(tableName)
|
|
||||||
} else {
|
|
||||||
name = index.Name
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("DROP INDEX %v", quote(name))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (db *oracle) IsTableExist(queryer core.Queryer, ctx context.Context, tableName string) (bool, error) {
|
func (db *oracle) IsTableExist(queryer core.Queryer, ctx context.Context, tableName string) (bool, error) {
|
||||||
return db.HasRecords(queryer, ctx, `SELECT table_name FROM user_tables WHERE table_name = :1`, tableName)
|
return db.HasRecords(queryer, ctx, `SELECT table_name FROM user_tables WHERE table_name = :1`, tableName)
|
||||||
}
|
}
|
||||||
|
|
|
@ -957,8 +957,8 @@ func (db *postgres) SQLType(c *schemas.Column) string {
|
||||||
// for bool, we don't need length information
|
// for bool, we don't need length information
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
hasLen1 := c.Length > 0
|
hasLen1 := (c.Length > 0)
|
||||||
hasLen2 := c.Length2 > 0
|
hasLen2 := (c.Length2 > 0)
|
||||||
|
|
||||||
if hasLen2 {
|
if hasLen2 {
|
||||||
res += "(" + strconv.FormatInt(c.Length, 10) + "," + strconv.FormatInt(c.Length2, 10) + ")"
|
res += "(" + strconv.FormatInt(c.Length, 10) + "," + strconv.FormatInt(c.Length2, 10) + ")"
|
||||||
|
@ -1185,7 +1185,7 @@ WHERE n.nspname= s.table_schema AND c.relkind = 'r' AND c.relname = $1%s AND f.a
|
||||||
col.IsPrimaryKey = true
|
col.IsPrimaryKey = true
|
||||||
}
|
}
|
||||||
|
|
||||||
col.Nullable = isNullable == "YES"
|
col.Nullable = (isNullable == "YES")
|
||||||
|
|
||||||
switch strings.ToLower(dataType) {
|
switch strings.ToLower(dataType) {
|
||||||
case "character varying", "string":
|
case "character varying", "string":
|
||||||
|
|
|
@ -7,23 +7,20 @@ package dialects
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"xorm.io/xorm/internal/utils"
|
|
||||||
|
|
||||||
"xorm.io/xorm/schemas"
|
"xorm.io/xorm/schemas"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FormatColumnTime format column time
|
// FormatColumnTime format column time
|
||||||
func FormatColumnTime(dialect Dialect, dbLocation *time.Location, col *schemas.Column, t time.Time) (interface{}, error) {
|
func FormatColumnTime(dialect Dialect, dbLocation *time.Location, col *schemas.Column, t time.Time) (interface{}, error) {
|
||||||
if utils.IsTimeZero(t) {
|
if t.IsZero() {
|
||||||
if col.Nullable {
|
if col.Nullable {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if col.SQLType.IsNumeric() {
|
if col.SQLType.IsNumeric() {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
if col.SQLType.Name == schemas.TimeStamp || col.SQLType.Name == schemas.TimeStampz {
|
|
||||||
t = time.Unix(0, 0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tmZone := dbLocation
|
tmZone := dbLocation
|
||||||
|
|
18
engine.go
18
engine.go
|
@ -798,22 +798,6 @@ func (engine *Engine) dumpTables(ctx context.Context, tables []*schemas.Table, w
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if sess.engine.dialect.URI().DBType == schemas.GBASE8S {
|
|
||||||
stp.Name = strings.Replace(stp.Name, "SQLT_", "", 1)
|
|
||||||
if stp.IsTime() && len(s.String) == 20 { // "2025-06-10T07:55:31Z"
|
|
||||||
t, err := time.Parse(time.RFC3339, s.String)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to parse time %s: %v", s.String, err)
|
|
||||||
}
|
|
||||||
r := t.Format("2006-01-02 15:04:05")
|
|
||||||
if _, err = io.WriteString(w, "'"+r+"'"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if _, err = io.WriteString(w, "'"+strings.ReplaceAll(s.String, "'", "''")+"'"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if _, err = io.WriteString(w, "'"+strings.ReplaceAll(s.String, "'", "''")+"'"); err != nil {
|
if _, err = io.WriteString(w, "'"+strings.ReplaceAll(s.String, "'", "''")+"'"); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1228,7 +1212,7 @@ func (engine *Engine) Insert(beans ...interface{}) (int64, error) {
|
||||||
func (engine *Engine) InsertOne(bean interface{}) (int64, error) {
|
func (engine *Engine) InsertOne(bean interface{}) (int64, error) {
|
||||||
session := engine.NewSession()
|
session := engine.NewSession()
|
||||||
defer session.Close()
|
defer session.Close()
|
||||||
return session.Insert(bean)
|
return session.InsertOne(bean)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update records, bean's non-empty fields are updated contents,
|
// Update records, bean's non-empty fields are updated contents,
|
||||||
|
|
12
go.mod
12
go.mod
|
@ -6,7 +6,7 @@ require (
|
||||||
gitee.com/travelliu/dm v1.8.11192
|
gitee.com/travelliu/dm v1.8.11192
|
||||||
github.com/go-sql-driver/mysql v1.7.0
|
github.com/go-sql-driver/mysql v1.7.0
|
||||||
github.com/goccy/go-json v0.8.1
|
github.com/goccy/go-json v0.8.1
|
||||||
github.com/jackc/pgx/v4 v4.18.2
|
github.com/jackc/pgx/v4 v4.18.0
|
||||||
github.com/json-iterator/go v1.1.12
|
github.com/json-iterator/go v1.1.12
|
||||||
github.com/lib/pq v1.10.7
|
github.com/lib/pq v1.10.7
|
||||||
github.com/mattn/go-sqlite3 v1.14.16
|
github.com/mattn/go-sqlite3 v1.14.16
|
||||||
|
@ -27,10 +27,10 @@ require (
|
||||||
github.com/golang/snappy v0.0.4 // indirect
|
github.com/golang/snappy v0.0.4 // indirect
|
||||||
github.com/google/uuid v1.3.0 // indirect
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
|
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
|
||||||
github.com/jackc/pgconn v1.14.3 // indirect
|
github.com/jackc/pgconn v1.14.0 // indirect
|
||||||
github.com/jackc/pgio v1.0.0 // indirect
|
github.com/jackc/pgio v1.0.0 // indirect
|
||||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||||
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
|
github.com/jackc/pgproto3/v2 v2.3.2 // indirect
|
||||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
|
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
|
||||||
github.com/jackc/pgtype v1.14.0 // indirect
|
github.com/jackc/pgtype v1.14.0 // indirect
|
||||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
||||||
|
@ -39,10 +39,10 @@ require (
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
|
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
|
||||||
golang.org/x/crypto v0.20.0 // indirect
|
golang.org/x/crypto v0.12.0 // indirect
|
||||||
golang.org/x/mod v0.8.0 // indirect
|
golang.org/x/mod v0.8.0 // indirect
|
||||||
golang.org/x/sys v0.17.0 // indirect
|
golang.org/x/sys v0.11.0 // indirect
|
||||||
golang.org/x/text v0.14.0 // indirect
|
golang.org/x/text v0.12.0 // indirect
|
||||||
golang.org/x/tools v0.6.0 // indirect
|
golang.org/x/tools v0.6.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
lukechampine.com/uint128 v1.2.0 // indirect
|
lukechampine.com/uint128 v1.2.0 // indirect
|
||||||
|
|
48
go.sum
48
go.sum
|
@ -59,8 +59,8 @@ github.com/jackc/pgconn v0.0.0-20190831204454-2fabfa3c18b7/go.mod h1:ZJKsE/KZfsU
|
||||||
github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o=
|
github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o=
|
||||||
github.com/jackc/pgconn v1.9.0/go.mod h1:YctiPyvzfU11JFxoXokUOOKQXQmDMoJL9vJzHH8/2JY=
|
github.com/jackc/pgconn v1.9.0/go.mod h1:YctiPyvzfU11JFxoXokUOOKQXQmDMoJL9vJzHH8/2JY=
|
||||||
github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI=
|
github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI=
|
||||||
github.com/jackc/pgconn v1.14.3 h1:bVoTr12EGANZz66nZPkMInAV/KHD2TxH9npjXXgiB3w=
|
github.com/jackc/pgconn v1.14.0 h1:vrbA9Ud87g6JdFWkHTJXppVce58qPIdP7N8y0Ml/A7Q=
|
||||||
github.com/jackc/pgconn v1.14.3/go.mod h1:RZbme4uasqzybK2RK5c65VsHxoyaml09lx3tXOcO/VM=
|
github.com/jackc/pgconn v1.14.0/go.mod h1:9mBNlny0UvkgJdCDvdVHYSjI+8tD2rnKK69Wz8ti++E=
|
||||||
github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE=
|
github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE=
|
||||||
github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8=
|
github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8=
|
||||||
github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE=
|
github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE=
|
||||||
|
@ -76,8 +76,8 @@ github.com/jackc/pgproto3/v2 v2.0.0-rc3/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvW
|
||||||
github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM=
|
github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM=
|
||||||
github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
||||||
github.com/jackc/pgproto3/v2 v2.1.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
github.com/jackc/pgproto3/v2 v2.1.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
||||||
github.com/jackc/pgproto3/v2 v2.3.3 h1:1HLSx5H+tXR9pW3in3zaztoEwQYRC9SQaYUHjTSUOag=
|
github.com/jackc/pgproto3/v2 v2.3.2 h1:7eY55bdBeCz1F2fTzSz69QC+pG46jYq9/jtSPiJ5nn0=
|
||||||
github.com/jackc/pgproto3/v2 v2.3.3/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
github.com/jackc/pgproto3/v2 v2.3.2/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
|
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
|
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||||
|
@ -91,11 +91,12 @@ github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08
|
||||||
github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM=
|
github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM=
|
||||||
github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc=
|
github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc=
|
||||||
github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs=
|
github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs=
|
||||||
github.com/jackc/pgx/v4 v4.18.2 h1:xVpYkNR5pk5bMCZGfClbO962UIqVABcAGt7ha1s/FeU=
|
github.com/jackc/pgx/v4 v4.18.0 h1:Ltaa1ePvc7msFGALnCrqKJVEByu/qYh5jJBYcDtAno4=
|
||||||
github.com/jackc/pgx/v4 v4.18.2/go.mod h1:Ey4Oru5tH5sB6tV7hDmfWFahwF15Eb7DNXlRKx2CkVw=
|
github.com/jackc/pgx/v4 v4.18.0/go.mod h1:FydWkUyadDmdNH/mHnGob881GawxeEm7TcMCzkb+qQE=
|
||||||
github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
||||||
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
||||||
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
||||||
|
github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
||||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
|
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
|
||||||
|
@ -157,15 +158,21 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||||
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
|
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
|
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
|
||||||
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
|
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
|
||||||
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
|
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
|
||||||
github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
|
github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
|
||||||
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
|
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
|
||||||
|
@ -189,11 +196,14 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
|
||||||
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/crypto v0.20.0 h1:jmAMJJZXr5KiCw05dfYK9QnqaqKLYXijU23lsEdcQqg=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/crypto v0.20.0/go.mod h1:Xwo95rrVNIoSMx9wa1JroENMToLWn3RNVrTBpLHgZPQ=
|
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
||||||
|
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
|
||||||
|
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
|
||||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
|
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
|
||||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
@ -202,9 +212,12 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
|
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
|
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
|
||||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
||||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
@ -219,18 +232,25 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
|
||||||
|
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
|
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
|
||||||
|
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||||
|
@ -238,7 +258,9 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw
|
||||||
golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
|
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
|
||||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||||
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
|
|
@ -5,23 +5,10 @@
|
||||||
package statements
|
package statements
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql/driver"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
"xorm.io/xorm/schemas"
|
"xorm.io/xorm/schemas"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DateTimeString struct {
|
|
||||||
Layout string
|
|
||||||
Str string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Value implements the driver Valuer interface.
|
|
||||||
func (n DateTimeString) Value() (driver.Value, error) {
|
|
||||||
return n.Str, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteArg writes an arg
|
// WriteArg writes an arg
|
||||||
func (statement *Statement) WriteArg(w *builder.BytesWriter, arg interface{}) error {
|
func (statement *Statement) WriteArg(w *builder.BytesWriter, arg interface{}) error {
|
||||||
switch argv := arg.(type) {
|
switch argv := arg.(type) {
|
||||||
|
@ -35,17 +22,6 @@ func (statement *Statement) WriteArg(w *builder.BytesWriter, arg interface{}) er
|
||||||
if _, err := w.WriteString(")"); err != nil {
|
if _, err := w.WriteString(")"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case *DateTimeString:
|
|
||||||
if statement.dialect.URI().DBType == schemas.ORACLE {
|
|
||||||
if _, err := fmt.Fprintf(w, `TO_DATE(?,'%s')`, argv.Layout); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if err := w.WriteByte('?'); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
w.Append(arg)
|
|
||||||
default:
|
default:
|
||||||
if err := w.WriteByte('?'); err != nil {
|
if err := w.WriteByte('?'); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -19,9 +19,8 @@ func (statement *Statement) isUsingLegacyLimitOffset() bool {
|
||||||
func (statement *Statement) writeMssqlLegacySelect(buf *builder.BytesWriter, columnStr string) error {
|
func (statement *Statement) writeMssqlLegacySelect(buf *builder.BytesWriter, columnStr string) error {
|
||||||
return statement.writeMultiple(buf,
|
return statement.writeMultiple(buf,
|
||||||
statement.writeStrings("SELECT"),
|
statement.writeStrings("SELECT"),
|
||||||
|
statement.writeDistinct(columnStr),
|
||||||
statement.writeTop,
|
statement.writeTop,
|
||||||
statement.writeDistinct,
|
|
||||||
statement.writeStrings(" ", columnStr),
|
|
||||||
statement.writeFrom,
|
statement.writeFrom,
|
||||||
statement.writeWhereWithMssqlPagination,
|
statement.writeWhereWithMssqlPagination,
|
||||||
statement.writeGroupBy,
|
statement.writeGroupBy,
|
||||||
|
@ -33,9 +32,10 @@ func (statement *Statement) writeMssqlLegacySelect(buf *builder.BytesWriter, col
|
||||||
|
|
||||||
func (statement *Statement) writeOracleLegacySelect(buf *builder.BytesWriter, columnStr string) error {
|
func (statement *Statement) writeOracleLegacySelect(buf *builder.BytesWriter, columnStr string) error {
|
||||||
return statement.writeMultiple(buf,
|
return statement.writeMultiple(buf,
|
||||||
statement.writeSelectColumns(columnStr),
|
statement.writeStrings("SELECT"),
|
||||||
|
statement.writeDistinct(columnStr),
|
||||||
|
statement.writeStrings(" ", columnStr),
|
||||||
statement.writeFrom,
|
statement.writeFrom,
|
||||||
statement.writeWhere,
|
|
||||||
statement.writeOracleLimit(columnStr),
|
statement.writeOracleLimit(columnStr),
|
||||||
statement.writeGroupBy,
|
statement.writeGroupBy,
|
||||||
statement.writeHaving,
|
statement.writeHaving,
|
||||||
|
|
|
@ -50,7 +50,7 @@ var ErrNoColumnName = errors.New("no column name")
|
||||||
|
|
||||||
func (statement *Statement) writeOrderBy(w *builder.BytesWriter, orderBy orderBy) error {
|
func (statement *Statement) writeOrderBy(w *builder.BytesWriter, orderBy orderBy) error {
|
||||||
switch t := orderBy.orderStr.(type) {
|
switch t := orderBy.orderStr.(type) {
|
||||||
case *builder.Expression:
|
case (*builder.Expression):
|
||||||
if _, err := fmt.Fprint(w.Builder, statement.dialect.Quoter().Replace(t.Content())); err != nil {
|
if _, err := fmt.Fprint(w.Builder, statement.dialect.Quoter().Replace(t.Content())); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,29 +141,20 @@ func (statement *Statement) GenCountSQL(beans ...interface{}) (string, []interfa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
selectSQL := statement.SelectStr
|
selectBuf := builder.NewWriter()
|
||||||
if len(selectSQL) <= 0 {
|
if err := statement.writeSelectCount(selectBuf); err != nil {
|
||||||
if statement.IsDistinct {
|
return "", nil, err
|
||||||
selectSQL = fmt.Sprintf("count(DISTINCT %s)", statement.ColumnStr())
|
|
||||||
} else if statement.ColumnStr() != "" {
|
|
||||||
selectSQL = fmt.Sprintf("count(%s)", statement.ColumnStr())
|
|
||||||
} else {
|
|
||||||
selectSQL = "count(*)"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := builder.NewWriter()
|
buf := builder.NewWriter()
|
||||||
if statement.GroupByStr != "" {
|
|
||||||
if _, err := fmt.Fprintf(buf, "SELECT %s FROM (", selectSQL); err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var subQuerySelect string
|
var subQuerySelect string
|
||||||
if statement.GroupByStr != "" {
|
if statement.GroupByStr != "" {
|
||||||
|
if err := statement.writeStrings("SELECT ", selectBuf.String(), " FROM (")(buf); err != nil {
|
||||||
|
return "", nil, err
|
||||||
|
}
|
||||||
subQuerySelect = statement.GroupByStr
|
subQuerySelect = statement.GroupByStr
|
||||||
} else {
|
} else {
|
||||||
subQuerySelect = selectSQL
|
subQuerySelect = selectBuf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := statement.writeSelect(buf, subQuerySelect, true); err != nil {
|
if err := statement.writeSelect(buf, subQuerySelect, true); err != nil {
|
||||||
|
@ -198,20 +189,27 @@ func (statement *Statement) writeTop(w *builder.BytesWriter) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (statement *Statement) writeDistinct(w *builder.BytesWriter) error {
|
func (statement *Statement) writeDistinct(selectStr string) func(w *builder.BytesWriter) error {
|
||||||
if statement.IsDistinct && !strings.HasPrefix(statement.SelectStr, "count(") {
|
return func(w *builder.BytesWriter) error {
|
||||||
_, err := fmt.Fprint(w, " DISTINCT")
|
if statement.IsDistinct && !strings.HasPrefix(selectStr, "COUNT(") {
|
||||||
return err
|
_, err := fmt.Fprint(w, " DISTINCT")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (statement *Statement) writeSelectColumns(columnStr string) func(w *builder.BytesWriter) error {
|
func (statement *Statement) writeSelectCount(w *builder.BytesWriter) error {
|
||||||
return statement.groupWriteFns(
|
if statement.SelectStr != "" {
|
||||||
statement.writeStrings("SELECT"),
|
return statement.writeStrings(statement.SelectStr)(w)
|
||||||
statement.writeDistinct,
|
}
|
||||||
statement.writeStrings(" ", columnStr),
|
|
||||||
)
|
if statement.IsDistinct {
|
||||||
|
return statement.writeStrings("COUNT(DISTINCT ", statement.ColumnStr(), ")")(w)
|
||||||
|
} else if statement.ColumnStr() != "" {
|
||||||
|
return statement.writeStrings("COUNT(", statement.ColumnStr(), ")")(w)
|
||||||
|
}
|
||||||
|
return statement.writeStrings("COUNT(*)")(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (statement *Statement) writeWhereCond(w *builder.BytesWriter, cond builder.Cond) error {
|
func (statement *Statement) writeWhereCond(w *builder.BytesWriter, cond builder.Cond) error {
|
||||||
|
@ -253,7 +251,9 @@ func (statement *Statement) writeSelect(buf *builder.BytesWriter, columnStr stri
|
||||||
}
|
}
|
||||||
|
|
||||||
return statement.writeMultiple(buf,
|
return statement.writeMultiple(buf,
|
||||||
statement.writeSelectColumns(columnStr),
|
statement.writeStrings("SELECT"),
|
||||||
|
statement.writeDistinct(columnStr),
|
||||||
|
statement.writeStrings(" ", columnStr),
|
||||||
statement.writeFrom,
|
statement.writeFrom,
|
||||||
statement.writeWhere,
|
statement.writeWhere,
|
||||||
statement.writeGroupBy,
|
statement.writeGroupBy,
|
||||||
|
|
|
@ -170,7 +170,7 @@ func (statement *Statement) Reset() {
|
||||||
// SQL adds raw sql statement
|
// SQL adds raw sql statement
|
||||||
func (statement *Statement) SQL(query interface{}, args ...interface{}) *Statement {
|
func (statement *Statement) SQL(query interface{}, args ...interface{}) *Statement {
|
||||||
switch t := query.(type) {
|
switch t := query.(type) {
|
||||||
case *builder.Builder:
|
case (*builder.Builder):
|
||||||
var err error
|
var err error
|
||||||
statement.RawSQL, statement.RawParams, err = t.ToSQL()
|
statement.RawSQL, statement.RawParams, err = t.ToSQL()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -616,7 +616,7 @@ func (statement *Statement) BuildConds(table *schemas.Table, bean interface{}, i
|
||||||
// MergeConds merge conditions from bean and id
|
// MergeConds merge conditions from bean and id
|
||||||
func (statement *Statement) MergeConds(bean interface{}) error {
|
func (statement *Statement) MergeConds(bean interface{}) error {
|
||||||
if !statement.NoAutoCondition && statement.RefTable != nil {
|
if !statement.NoAutoCondition && statement.RefTable != nil {
|
||||||
addedTableName := len(statement.joins) > 0
|
addedTableName := (len(statement.joins) > 0)
|
||||||
autoCond, err := statement.BuildConds(statement.RefTable, bean, true, true, false, true, addedTableName)
|
autoCond, err := statement.BuildConds(statement.RefTable, bean, true, true, false, true, addedTableName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -713,14 +713,11 @@ func (statement *Statement) CondDeleted(col *schemas.Column) builder.Cond {
|
||||||
cond := builder.NewCond()
|
cond := builder.NewCond()
|
||||||
if col.SQLType.IsNumeric() {
|
if col.SQLType.IsNumeric() {
|
||||||
cond = builder.Eq{colName: 0}
|
cond = builder.Eq{colName: 0}
|
||||||
} else if col.SQLType.Name == schemas.TimeStamp || col.SQLType.Name == schemas.TimeStampz {
|
|
||||||
tmZone := statement.defaultTimeZone
|
|
||||||
if col.TimeZone != nil {
|
|
||||||
tmZone = col.TimeZone
|
|
||||||
}
|
|
||||||
cond = builder.Eq{colName: time.Unix(0, 0).In(tmZone).Format("2006-01-02 15:04:05.999999999")}
|
|
||||||
} else {
|
} else {
|
||||||
cond = builder.Eq{colName: utils.ZeroTime1}
|
// FIXME: mssql: The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
|
||||||
|
if statement.dialect.URI().DBType != schemas.MSSQL {
|
||||||
|
cond = builder.Eq{colName: utils.ZeroTime1}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if col.Nullable {
|
if col.Nullable {
|
||||||
|
|
|
@ -126,9 +126,6 @@ func (statement *Statement) BuildUpdates(tableValue reflect.Value,
|
||||||
|
|
||||||
if fieldValue.CanAddr() {
|
if fieldValue.CanAddr() {
|
||||||
if structConvert, ok := fieldValue.Addr().Interface().(convert.Conversion); ok {
|
if structConvert, ok := fieldValue.Addr().Interface().(convert.Conversion); ok {
|
||||||
if !includeNil && !requiredField && utils.IsZero(fieldValue.Interface()) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
data, err := structConvert.ToDB()
|
data, err := structConvert.ToDB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
|
|
@ -88,20 +88,7 @@ func (statement *Statement) Value2Interface(col *schemas.Column, fieldValue refl
|
||||||
if fieldType.ConvertibleTo(schemas.TimeType) {
|
if fieldType.ConvertibleTo(schemas.TimeType) {
|
||||||
t := fieldValue.Convert(schemas.TimeType).Interface().(time.Time)
|
t := fieldValue.Convert(schemas.TimeType).Interface().(time.Time)
|
||||||
tf, err := dialects.FormatColumnTime(statement.dialect, statement.defaultTimeZone, col, t)
|
tf, err := dialects.FormatColumnTime(statement.dialect, statement.defaultTimeZone, col, t)
|
||||||
if val, ok := tf.(string); ok {
|
return tf, err
|
||||||
var layout string
|
|
||||||
switch col.SQLType.Name {
|
|
||||||
case schemas.Date:
|
|
||||||
layout = "yyyy-MM-dd"
|
|
||||||
case schemas.Time:
|
|
||||||
layout = "HH24:mi:ss"
|
|
||||||
default:
|
|
||||||
layout = "yyyy-MM-dd HH24:mi:ss"
|
|
||||||
}
|
|
||||||
return &DateTimeString{Layout: layout, Str: val}, err
|
|
||||||
} else {
|
|
||||||
return tf, err
|
|
||||||
}
|
|
||||||
} else if fieldType.ConvertibleTo(nullFloatType) {
|
} else if fieldType.ConvertibleTo(nullFloatType) {
|
||||||
t := fieldValue.Convert(nullFloatType).Interface().(sql.NullFloat64)
|
t := fieldValue.Convert(nullFloatType).Interface().(sql.NullFloat64)
|
||||||
if !t.Valid {
|
if !t.Valid {
|
||||||
|
|
|
@ -146,6 +146,6 @@ const (
|
||||||
|
|
||||||
// IsTimeZero return true if a time is zero
|
// IsTimeZero return true if a time is zero
|
||||||
func IsTimeZero(t time.Time) bool {
|
func IsTimeZero(t time.Time) bool {
|
||||||
return t.IsZero() || t.Format("2006-01-02 15:04:05.999999999") == ZeroTime0 ||
|
return t.IsZero() || t.Format("2006-01-02 15:04:05") == ZeroTime0 ||
|
||||||
t.Format("2006-01-02 15:04:05.999999999") == ZeroTime1
|
t.Format("2006-01-02 15:04:05") == ZeroTime1
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
package migrate
|
package migrate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
"xorm.io/xorm/schemas"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// MigrateFunc is the func signature for migrating.
|
// MigrateFunc is the func signature for migrating.
|
||||||
|
@ -143,9 +140,7 @@ func (m *Migrate) RollbackMigration(mig *Migration) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
tableName := m.db.TableName(m.options.TableName, true)
|
sql := fmt.Sprintf("DELETE FROM %s WHERE %s = ?", m.options.TableName, m.options.IDColumnName)
|
||||||
|
|
||||||
sql := fmt.Sprintf("DELETE FROM %s WHERE %s = ?", tableName, m.options.IDColumnName)
|
|
||||||
if _, err := m.db.Exec(sql, mig.ID); err != nil {
|
if _, err := m.db.Exec(sql, mig.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -197,19 +192,7 @@ func (m *Migrate) createMigrationTableIfNotExists() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
idCol := schemas.NewColumn(m.options.IDColumnName, "", schemas.SQLType{
|
sql := fmt.Sprintf("CREATE TABLE %s (%s VARCHAR(255) PRIMARY KEY)", m.options.TableName, m.options.IDColumnName)
|
||||||
Name: "VARCHAR",
|
|
||||||
}, 255, 0, false)
|
|
||||||
idCol.IsPrimaryKey = true
|
|
||||||
|
|
||||||
table := schemas.NewTable(m.options.TableName, reflect.TypeOf(new(schemas.Table)))
|
|
||||||
table.AddColumn(idCol)
|
|
||||||
|
|
||||||
sql, _, err := m.db.Dialect().CreateTableSQL(context.Background(), m.db.DB(), table, m.options.TableName)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := m.db.Exec(sql); err != nil {
|
if _, err := m.db.Exec(sql); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -217,21 +200,18 @@ func (m *Migrate) createMigrationTableIfNotExists() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Migrate) migrationDidRun(mig *Migration) (bool, error) {
|
func (m *Migrate) migrationDidRun(mig *Migration) (bool, error) {
|
||||||
tableName := m.db.TableName(m.options.TableName, true)
|
count, err := m.db.SQL(fmt.Sprintf("SELECT COUNT(*) FROM %s WHERE %s = ?", m.options.TableName, m.options.IDColumnName), mig.ID).Count()
|
||||||
count, err := m.db.SQL(fmt.Sprintf("SELECT COUNT(*) FROM %s WHERE %s = ?", tableName, m.options.IDColumnName), mig.ID).Count()
|
|
||||||
return count > 0, err
|
return count > 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Migrate) isFirstRun() (bool, error) {
|
func (m *Migrate) isFirstRun() (bool, error) {
|
||||||
var count int
|
var count int
|
||||||
tableName := m.db.TableName(m.options.TableName, true)
|
_, err := m.db.SQL(fmt.Sprintf("SELECT COUNT(*) FROM %s", m.options.TableName)).Get(&count)
|
||||||
_, err := m.db.SQL(fmt.Sprintf("SELECT COUNT(*) FROM %s", tableName)).Get(&count)
|
|
||||||
return count == 0, err
|
return count == 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Migrate) insertMigration(id string) error {
|
func (m *Migrate) insertMigration(id string) error {
|
||||||
tableName := m.db.TableName(m.options.TableName, true)
|
sql := fmt.Sprintf("INSERT INTO %s (%s) VALUES (?)", m.options.TableName, m.options.IDColumnName)
|
||||||
sql := fmt.Sprintf("INSERT INTO %s (%s) VALUES (?)", tableName, m.options.IDColumnName)
|
|
||||||
_, err := m.db.Exec(sql, id)
|
_, err := m.db.Exec(sql, id)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,7 +149,7 @@ func isASCIIUpper(r rune) bool {
|
||||||
|
|
||||||
func toASCIIUpper(r rune) rune {
|
func toASCIIUpper(r rune) rune {
|
||||||
if 'a' <= r && r <= 'z' {
|
if 'a' <= r && r <= 'z' {
|
||||||
r -= 'a' - 'A'
|
r -= ('a' - 'A')
|
||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ type Column struct {
|
||||||
FieldIndex []int // Available only when parsed from a struct
|
FieldIndex []int // Available only when parsed from a struct
|
||||||
SQLType SQLType
|
SQLType SQLType
|
||||||
IsJSON bool
|
IsJSON bool
|
||||||
IsJSONB bool
|
|
||||||
Length int64
|
Length int64
|
||||||
Length2 int64
|
Length2 int64
|
||||||
Nullable bool
|
Nullable bool
|
||||||
|
|
|
@ -23,7 +23,6 @@ const (
|
||||||
MSSQL DBType = "mssql"
|
MSSQL DBType = "mssql"
|
||||||
ORACLE DBType = "oracle"
|
ORACLE DBType = "oracle"
|
||||||
DAMENG DBType = "dameng"
|
DAMENG DBType = "dameng"
|
||||||
GBASE8S DBType = "gbase8s"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SQLType represents SQL types
|
// SQLType represents SQL types
|
||||||
|
|
|
@ -471,8 +471,7 @@ func (session *Session) genInsertColumns(bean interface{}) ([]string, []interfac
|
||||||
}
|
}
|
||||||
|
|
||||||
if col.IsDeleted {
|
if col.IsDeleted {
|
||||||
zeroTime := time.Date(1, 1, 1, 0, 0, 0, 0, session.engine.DatabaseTZ)
|
arg, err := dialects.FormatColumnTime(session.engine.dialect, session.engine.DatabaseTZ, col, time.Time{})
|
||||||
arg, err := dialects.FormatColumnTime(session.engine.dialect, session.engine.DatabaseTZ, col, zeroTime)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
12
sync.go
12
sync.go
|
@ -17,8 +17,6 @@ type SyncOptions struct {
|
||||||
IgnoreConstrains bool
|
IgnoreConstrains bool
|
||||||
// IgnoreIndices will not add or delete indices
|
// IgnoreIndices will not add or delete indices
|
||||||
IgnoreIndices bool
|
IgnoreIndices bool
|
||||||
// IgnoreDropIndices will not delete indices
|
|
||||||
IgnoreDropIndices bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type SyncResult struct{}
|
type SyncResult struct{}
|
||||||
|
@ -57,7 +55,6 @@ func (session *Session) Sync(beans ...interface{}) error {
|
||||||
WarnIfDatabaseColumnMissed: false,
|
WarnIfDatabaseColumnMissed: false,
|
||||||
IgnoreConstrains: false,
|
IgnoreConstrains: false,
|
||||||
IgnoreIndices: false,
|
IgnoreIndices: false,
|
||||||
IgnoreDropIndices: false,
|
|
||||||
}, beans...)
|
}, beans...)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -171,8 +168,7 @@ func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{})
|
||||||
tbNameWithSchema, col.Name, curType, expectedType)
|
tbNameWithSchema, col.Name, curType, expectedType)
|
||||||
}
|
}
|
||||||
} else if strings.HasPrefix(curType, schemas.Varchar) && strings.HasPrefix(expectedType, schemas.Varchar) {
|
} else if strings.HasPrefix(curType, schemas.Varchar) && strings.HasPrefix(expectedType, schemas.Varchar) {
|
||||||
if engine.dialect.URI().DBType == schemas.POSTGRES ||
|
if engine.dialect.URI().DBType == schemas.MYSQL {
|
||||||
engine.dialect.URI().DBType == schemas.MYSQL {
|
|
||||||
if oriCol.Length < col.Length {
|
if oriCol.Length < col.Length {
|
||||||
engine.logger.Infof("Table %s column %s change type from varchar(%d) to varchar(%d)\n",
|
engine.logger.Infof("Table %s column %s change type from varchar(%d) to varchar(%d)\n",
|
||||||
tbNameWithSchema, col.Name, oriCol.Length, col.Length)
|
tbNameWithSchema, col.Name, oriCol.Length, col.Length)
|
||||||
|
@ -188,8 +184,7 @@ func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if expectedType == schemas.Varchar {
|
} else if expectedType == schemas.Varchar {
|
||||||
if engine.dialect.URI().DBType == schemas.POSTGRES ||
|
if engine.dialect.URI().DBType == schemas.MYSQL {
|
||||||
engine.dialect.URI().DBType == schemas.MYSQL {
|
|
||||||
if oriCol.Length < col.Length {
|
if oriCol.Length < col.Length {
|
||||||
engine.logger.Infof("Table %s column %s change type from varchar(%d) to varchar(%d)\n",
|
engine.logger.Infof("Table %s column %s change type from varchar(%d) to varchar(%d)\n",
|
||||||
tbNameWithSchema, col.Name, oriCol.Length, col.Length)
|
tbNameWithSchema, col.Name, oriCol.Length, col.Length)
|
||||||
|
@ -198,7 +193,6 @@ func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{})
|
||||||
}
|
}
|
||||||
} else if col.Comment != oriCol.Comment {
|
} else if col.Comment != oriCol.Comment {
|
||||||
if engine.dialect.URI().DBType == schemas.POSTGRES ||
|
if engine.dialect.URI().DBType == schemas.POSTGRES ||
|
||||||
engine.dialect.URI().DBType == schemas.GBASE8S ||
|
|
||||||
engine.dialect.URI().DBType == schemas.MYSQL {
|
engine.dialect.URI().DBType == schemas.MYSQL {
|
||||||
_, err = session.exec(engine.dialect.ModifyColumnSQL(tbNameWithSchema, col))
|
_, err = session.exec(engine.dialect.ModifyColumnSQL(tbNameWithSchema, col))
|
||||||
}
|
}
|
||||||
|
@ -250,7 +244,7 @@ func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{})
|
||||||
for name2, index2 := range oriTable.Indexes {
|
for name2, index2 := range oriTable.Indexes {
|
||||||
if _, ok := foundIndexNames[name2]; !ok {
|
if _, ok := foundIndexNames[name2]; !ok {
|
||||||
// ignore based on there type
|
// ignore based on there type
|
||||||
if (index2.Type == schemas.IndexType && (opts.IgnoreIndices || opts.IgnoreDropIndices)) ||
|
if (index2.Type == schemas.IndexType && opts.IgnoreIndices) ||
|
||||||
(index2.Type == schemas.UniqueType && opts.IgnoreConstrains) {
|
(index2.Type == schemas.UniqueType && opts.IgnoreConstrains) {
|
||||||
// make sure we do not add a index with same name later
|
// make sure we do not add a index with same name later
|
||||||
delete(addedNames, name2)
|
delete(addedNames, name2)
|
||||||
|
|
|
@ -250,16 +250,10 @@ func (parser *Parser) parseFieldWithTags(table *schemas.Table, fieldIndex int, f
|
||||||
}
|
}
|
||||||
|
|
||||||
if col.SQLType.Name == "" {
|
if col.SQLType.Name == "" {
|
||||||
if col.IsJSONB { // check is jsonb first because it is also json
|
var err error
|
||||||
col.SQLType = schemas.SQLType{Name: schemas.Jsonb}
|
col.SQLType, err = parser.getSQLTypeByType(field.Type)
|
||||||
} else if col.IsJSON {
|
if err != nil {
|
||||||
col.SQLType = schemas.SQLType{Name: schemas.Json}
|
return nil, err
|
||||||
} else {
|
|
||||||
var err error
|
|
||||||
col.SQLType, err = parser.getSQLTypeByType(field.Type)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ctx.isUnsigned && col.SQLType.IsNumeric() && !strings.HasPrefix(col.SQLType.Name, "UNSIGNED") {
|
if ctx.isUnsigned && col.SQLType.IsNumeric() && !strings.HasPrefix(col.SQLType.Name, "UNSIGNED") {
|
||||||
|
|
|
@ -577,7 +577,7 @@ func TestParseWithJSONB(t *testing.T) {
|
||||||
assert.EqualValues(t, "struct_with_jsonb", table.Name)
|
assert.EqualValues(t, "struct_with_jsonb", table.Name)
|
||||||
assert.EqualValues(t, 1, len(table.Columns()))
|
assert.EqualValues(t, 1, len(table.Columns()))
|
||||||
assert.EqualValues(t, "default1", table.Columns()[0].Name)
|
assert.EqualValues(t, "default1", table.Columns()[0].Name)
|
||||||
assert.True(t, table.Columns()[0].IsJSONB)
|
assert.True(t, table.Columns()[0].IsJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseWithSQLType(t *testing.T) {
|
func TestParseWithSQLType(t *testing.T) {
|
||||||
|
@ -617,53 +617,3 @@ func TestParseWithSQLType(t *testing.T) {
|
||||||
assert.EqualValues(t, "DATETIME", table.Columns()[3].SQLType.Name)
|
assert.EqualValues(t, "DATETIME", table.Columns()[3].SQLType.Name)
|
||||||
assert.EqualValues(t, "UUID", table.Columns()[4].SQLType.Name)
|
assert.EqualValues(t, "UUID", table.Columns()[4].SQLType.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseWithJSONLongText(t *testing.T) {
|
|
||||||
parser := NewParser(
|
|
||||||
"db",
|
|
||||||
dialects.QueryDialect("mysql"),
|
|
||||||
names.GonicMapper{
|
|
||||||
"JSON": true,
|
|
||||||
},
|
|
||||||
names.GonicMapper{
|
|
||||||
"JSON": true,
|
|
||||||
},
|
|
||||||
caches.NewManager(),
|
|
||||||
)
|
|
||||||
|
|
||||||
type StructWithJSONLongText struct {
|
|
||||||
Col1 string `db:"LongText json"`
|
|
||||||
}
|
|
||||||
|
|
||||||
table, err := parser.Parse(reflect.ValueOf(new(StructWithJSONLongText)))
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.EqualValues(t, "struct_with_json_long_text", table.Name)
|
|
||||||
assert.EqualValues(t, 1, len(table.Columns()))
|
|
||||||
assert.EqualValues(t, "col1", table.Columns()[0].Name)
|
|
||||||
assert.EqualValues(t, "LONGTEXT", table.Columns()[0].SQLType.Name)
|
|
||||||
assert.EqualValues(t, true, table.Columns()[0].IsJSON)
|
|
||||||
|
|
||||||
type StructWithJSONLongText2 struct {
|
|
||||||
Col1 string `db:"json"`
|
|
||||||
}
|
|
||||||
|
|
||||||
table, err = parser.Parse(reflect.ValueOf(new(StructWithJSONLongText2)))
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.EqualValues(t, "struct_with_json_long_text2", table.Name)
|
|
||||||
assert.EqualValues(t, 1, len(table.Columns()))
|
|
||||||
assert.EqualValues(t, "col1", table.Columns()[0].Name)
|
|
||||||
assert.EqualValues(t, "JSON", table.Columns()[0].SQLType.Name)
|
|
||||||
assert.EqualValues(t, true, table.Columns()[0].IsJSON)
|
|
||||||
|
|
||||||
type StructWithJSONLongText3 struct {
|
|
||||||
Col1 string `db:"jsonb"`
|
|
||||||
}
|
|
||||||
|
|
||||||
table, err = parser.Parse(reflect.ValueOf(new(StructWithJSONLongText3)))
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.EqualValues(t, "struct_with_json_long_text3", table.Name)
|
|
||||||
assert.EqualValues(t, 1, len(table.Columns()))
|
|
||||||
assert.EqualValues(t, "col1", table.Columns()[0].Name)
|
|
||||||
assert.EqualValues(t, "JSONB", table.Columns()[0].SQLType.Name)
|
|
||||||
assert.EqualValues(t, true, table.Columns()[0].IsJSONB)
|
|
||||||
}
|
|
||||||
|
|
22
tags/tag.go
22
tags/tag.go
|
@ -124,16 +124,10 @@ var defaultTagHandlers = map[string]Handler{
|
||||||
"EXTENDS": ExtendsTagHandler,
|
"EXTENDS": ExtendsTagHandler,
|
||||||
"UNSIGNED": UnsignedTagHandler,
|
"UNSIGNED": UnsignedTagHandler,
|
||||||
"COLLATE": CollateTagHandler,
|
"COLLATE": CollateTagHandler,
|
||||||
"JSON": JSONTagHandler,
|
|
||||||
"JSONB": JSONBTagHandler,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
for k := range schemas.SqlTypes {
|
for k := range schemas.SqlTypes {
|
||||||
// don't override default tag handlers
|
|
||||||
if _, ok := defaultTagHandlers[k]; ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
defaultTagHandlers[k] = SQLTypeTagHandler
|
defaultTagHandlers[k] = SQLTypeTagHandler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,7 +163,7 @@ func PKTagHandler(ctx *Context) error {
|
||||||
|
|
||||||
// NULLTagHandler describes null tag handler
|
// NULLTagHandler describes null tag handler
|
||||||
func NULLTagHandler(ctx *Context) error {
|
func NULLTagHandler(ctx *Context) error {
|
||||||
ctx.col.Nullable = strings.ToUpper(ctx.preTag) != "NOT"
|
ctx.col.Nullable = (strings.ToUpper(ctx.preTag) != "NOT")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,20 +293,12 @@ func CollateTagHandler(ctx *Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func JSONTagHandler(ctx *Context) error {
|
|
||||||
ctx.col.IsJSON = true
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func JSONBTagHandler(ctx *Context) error {
|
|
||||||
ctx.col.IsJSONB = true
|
|
||||||
ctx.col.IsJSON = true // jsonb is also json
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SQLTypeTagHandler describes SQL Type tag handler
|
// SQLTypeTagHandler describes SQL Type tag handler
|
||||||
func SQLTypeTagHandler(ctx *Context) error {
|
func SQLTypeTagHandler(ctx *Context) error {
|
||||||
ctx.col.SQLType = schemas.SQLType{Name: ctx.tagUname}
|
ctx.col.SQLType = schemas.SQLType{Name: ctx.tagUname}
|
||||||
|
if ctx.tagUname == "JSON" || ctx.tagUname == "JSONB" {
|
||||||
|
ctx.col.IsJSON = true
|
||||||
|
}
|
||||||
if len(ctx.params) == 0 {
|
if len(ctx.params) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -698,7 +698,7 @@ func TestSyncWithOptions(t *testing.T) {
|
||||||
assert.NotNil(t, result)
|
assert.NotNil(t, result)
|
||||||
assert.Len(t, getIndicesOfBeanFromDB(t, &SyncWithOpts1{}), 0)
|
assert.Len(t, getIndicesOfBeanFromDB(t, &SyncWithOpts1{}), 0)
|
||||||
|
|
||||||
// only ignore constrains
|
// only ignore indices
|
||||||
result, err = testEngine.SyncWithOptions(xorm.SyncOptions{IgnoreConstrains: true}, &SyncWithOpts2{})
|
result, err = testEngine.SyncWithOptions(xorm.SyncOptions{IgnoreConstrains: true}, &SyncWithOpts2{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, result)
|
assert.NotNil(t, result)
|
||||||
|
@ -706,7 +706,7 @@ func TestSyncWithOptions(t *testing.T) {
|
||||||
assert.Len(t, indices, 2)
|
assert.Len(t, indices, 2)
|
||||||
assert.ElementsMatch(t, []string{"ttt", "index"}, getKeysFromMap(indices))
|
assert.ElementsMatch(t, []string{"ttt", "index"}, getKeysFromMap(indices))
|
||||||
|
|
||||||
// only ignore indices
|
// only ignore constrains
|
||||||
result, err = testEngine.SyncWithOptions(xorm.SyncOptions{IgnoreIndices: true}, &SyncWithOpts3{})
|
result, err = testEngine.SyncWithOptions(xorm.SyncOptions{IgnoreIndices: true}, &SyncWithOpts3{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, result)
|
assert.NotNil(t, result)
|
||||||
|
@ -714,16 +714,9 @@ func TestSyncWithOptions(t *testing.T) {
|
||||||
assert.Len(t, indices, 4)
|
assert.Len(t, indices, 4)
|
||||||
assert.ElementsMatch(t, []string{"ttt", "index", "unique", "lll"}, getKeysFromMap(indices))
|
assert.ElementsMatch(t, []string{"ttt", "index", "unique", "lll"}, getKeysFromMap(indices))
|
||||||
|
|
||||||
// only ignore drop indices
|
|
||||||
result, err = testEngine.SyncWithOptions(xorm.SyncOptions{IgnoreDropIndices: true}, &SyncWithOpts3{})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NotNil(t, result)
|
|
||||||
indices = getIndicesOfBeanFromDB(t, &SyncWithOpts1{})
|
|
||||||
assert.Len(t, indices, 4)
|
|
||||||
assert.ElementsMatch(t, []string{"ttt", "index", "unique", "lll"}, getKeysFromMap(indices))
|
|
||||||
|
|
||||||
tableInfoFromStruct, _ := testEngine.TableInfo(&SyncWithOpts1{})
|
tableInfoFromStruct, _ := testEngine.TableInfo(&SyncWithOpts1{})
|
||||||
assert.ElementsMatch(t, getKeysFromMap(tableInfoFromStruct.Indexes), getKeysFromMap(getIndicesOfBeanFromDB(t, &SyncWithOpts1{})))
|
assert.ElementsMatch(t, getKeysFromMap(tableInfoFromStruct.Indexes), getKeysFromMap(getIndicesOfBeanFromDB(t, &SyncWithOpts1{})))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getIndicesOfBeanFromDB(t *testing.T, bean interface{}) map[string]*schemas.Index {
|
func getIndicesOfBeanFromDB(t *testing.T, bean interface{}) map[string]*schemas.Index {
|
||||||
|
@ -751,72 +744,3 @@ func getKeysFromMap(m map[string]*schemas.Index) []string {
|
||||||
}
|
}
|
||||||
return ss
|
return ss
|
||||||
}
|
}
|
||||||
|
|
||||||
type SyncTestUser struct {
|
|
||||||
Id int64 `xorm:"pk autoincr 'id' comment('primary key 1')"`
|
|
||||||
Name string `xorm:"'name' notnull comment('nickname')" json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *SyncTestUser) TableName() string {
|
|
||||||
return "sync_test_user"
|
|
||||||
}
|
|
||||||
|
|
||||||
type SyncTestUser2 struct {
|
|
||||||
Id int64 `xorm:"pk autoincr 'id' comment('primary key 2')"`
|
|
||||||
Name string `xorm:"'name' notnull comment('nickname')" json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *SyncTestUser2) TableName() string {
|
|
||||||
return "sync_test_user"
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSync2_3(t *testing.T) {
|
|
||||||
if testEngine.Dialect().URI().DBType == schemas.MYSQL {
|
|
||||||
assert.NoError(t, PrepareEngine())
|
|
||||||
assertSync(t, new(SyncTestUser))
|
|
||||||
|
|
||||||
assert.NoError(t, testEngine.Sync2(new(SyncTestUser2)))
|
|
||||||
tables, err := testEngine.DBMetas()
|
|
||||||
assert.NoError(t, err)
|
|
||||||
tableInfo, err := testEngine.TableInfo(new(SyncTestUser2))
|
|
||||||
|
|
||||||
assert.EqualValues(t, tables[0].GetColumn("id").IsAutoIncrement, tableInfo.GetColumn("id").IsAutoIncrement)
|
|
||||||
assert.EqualValues(t, tables[0].GetColumn("id").Name, tableInfo.GetColumn("id").Name)
|
|
||||||
assert.EqualValues(t, tables[0].GetColumn("id").SQLType.Name, tableInfo.GetColumn("id").SQLType.Name)
|
|
||||||
assert.EqualValues(t, tables[0].GetColumn("id").Nullable, tableInfo.GetColumn("id").Nullable)
|
|
||||||
assert.EqualValues(t, tables[0].GetColumn("id").Comment, tableInfo.GetColumn("id").Comment)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSyncJSON(t *testing.T) {
|
|
||||||
type SyncTestJSON struct {
|
|
||||||
Id int64
|
|
||||||
Value string `xorm:"LONGTEXT JSON 'value' comment('json value')"`
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.NoError(t, PrepareEngine())
|
|
||||||
assertSync(t, new(SyncTestJSON))
|
|
||||||
|
|
||||||
assert.NoError(t, testEngine.Sync(new(SyncTestJSON)))
|
|
||||||
tables, err := testEngine.DBMetas()
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
tableInfo, err := testEngine.TableInfo(new(SyncTestJSON))
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
assert.EqualValues(t, tables[0].GetColumn("id").IsAutoIncrement, tableInfo.GetColumn("id").IsAutoIncrement)
|
|
||||||
assert.EqualValues(t, tables[0].GetColumn("id").Name, tableInfo.GetColumn("id").Name)
|
|
||||||
if testEngine.Dialect().URI().DBType == schemas.MYSQL {
|
|
||||||
assert.EqualValues(t, tables[0].GetColumn("id").SQLType.Name, tableInfo.GetColumn("id").SQLType.Name)
|
|
||||||
}
|
|
||||||
assert.EqualValues(t, tables[0].GetColumn("id").Nullable, tableInfo.GetColumn("id").Nullable)
|
|
||||||
|
|
||||||
assert.EqualValues(t, tables[0].GetColumn("value").IsAutoIncrement, tableInfo.GetColumn("value").IsAutoIncrement)
|
|
||||||
assert.EqualValues(t, tables[0].GetColumn("value").Name, tableInfo.GetColumn("value").Name)
|
|
||||||
assert.EqualValues(t, tables[0].GetColumn("value").Nullable, tableInfo.GetColumn("value").Nullable)
|
|
||||||
|
|
||||||
if testEngine.Dialect().URI().DBType == schemas.MYSQL {
|
|
||||||
assert.EqualValues(t, tables[0].GetColumn("value").SQLType.Name, tableInfo.GetColumn("value").SQLType.Name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -899,58 +899,6 @@ func TestFindExtends3(t *testing.T) {
|
||||||
assert.EqualValues(t, 2, len(results))
|
assert.EqualValues(t, 2, len(results))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFindExtends4(t *testing.T) {
|
|
||||||
type FindExtends4A struct {
|
|
||||||
Id int64
|
|
||||||
Age int
|
|
||||||
Name string
|
|
||||||
}
|
|
||||||
|
|
||||||
type FindExtends4B struct {
|
|
||||||
Id int64
|
|
||||||
ExtId int64 `xorm:"index"`
|
|
||||||
Age int
|
|
||||||
Name string
|
|
||||||
Value int
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.NoError(t, PrepareEngine())
|
|
||||||
assertSync(t, new(FindExtends4A), new(FindExtends4B))
|
|
||||||
|
|
||||||
fe := FindExtends4A{
|
|
||||||
Age: 1,
|
|
||||||
Name: "1",
|
|
||||||
}
|
|
||||||
cnt, err := testEngine.Insert(&fe)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.EqualValues(t, 1, cnt)
|
|
||||||
|
|
||||||
cnt, err = testEngine.Insert(&FindExtends4B{
|
|
||||||
ExtId: fe.Id,
|
|
||||||
Age: 2,
|
|
||||||
Name: "2",
|
|
||||||
Value: 3,
|
|
||||||
})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.EqualValues(t, 1, cnt)
|
|
||||||
|
|
||||||
type FindExtends4C struct {
|
|
||||||
FindExtends4A `xorm:"extends"`
|
|
||||||
FindExtends4B `xorm:"extends"`
|
|
||||||
}
|
|
||||||
var results []FindExtends4C
|
|
||||||
err = testEngine.Table("find_extends4_a").
|
|
||||||
Join("INNER", "find_extends4_b", "`find_extends4_b`.`ext_id`=`find_extends4_a`.`id`").
|
|
||||||
Find(&results)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.EqualValues(t, 1, len(results))
|
|
||||||
assert.EqualValues(t, 1, results[0].FindExtends4A.Age)
|
|
||||||
assert.EqualValues(t, "1", results[0].FindExtends4A.Name)
|
|
||||||
assert.EqualValues(t, 2, results[0].FindExtends4B.Age)
|
|
||||||
assert.EqualValues(t, "2", results[0].FindExtends4B.Name)
|
|
||||||
assert.EqualValues(t, 3, results[0].FindExtends4B.Value)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFindCacheLimit(t *testing.T) {
|
func TestFindCacheLimit(t *testing.T) {
|
||||||
type InviteCode struct {
|
type InviteCode struct {
|
||||||
ID int64 `xorm:"pk autoincr 'id'"`
|
ID int64 `xorm:"pk autoincr 'id'"`
|
||||||
|
@ -1306,3 +1254,20 @@ func TestFindInMaxID(t *testing.T) {
|
||||||
err := testEngine.In("id", builder.Select("max(id)").From(testEngine.Quote(tableName))).Find(&res)
|
err := testEngine.In("id", builder.Select("max(id)").From(testEngine.Quote(tableName))).Find(&res)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDistinctFindAndCount(t *testing.T) {
|
||||||
|
assert.NoError(t, PrepareEngine())
|
||||||
|
|
||||||
|
type TestDistinctFindAndCount struct {
|
||||||
|
Id int64
|
||||||
|
Name string `xorm:"index"`
|
||||||
|
Age2 int
|
||||||
|
}
|
||||||
|
|
||||||
|
assertSync(t, new(TestDistinctFindAndCount))
|
||||||
|
|
||||||
|
objects := make([]*TestDistinctFindAndCount, 0, 10)
|
||||||
|
total, err := testEngine.Distinct(testEngine.TableName(new(TestDistinctFindAndCount)) + ".*").FindAndCount(&objects)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 0, total)
|
||||||
|
}
|
||||||
|
|
|
@ -943,7 +943,7 @@ func TestMultipleInsertTableName(t *testing.T) {
|
||||||
assert.NoError(t, testEngine.Table(tableName).Sync(new(NightlyRate)))
|
assert.NoError(t, testEngine.Table(tableName).Sync(new(NightlyRate)))
|
||||||
|
|
||||||
trans := testEngine.NewSession()
|
trans := testEngine.NewSession()
|
||||||
defer func(trans *xorm.Session) { _ = trans.Close() }(trans)
|
defer trans.Close()
|
||||||
err := trans.Begin()
|
err := trans.Begin()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
@ -1031,7 +1031,7 @@ func TestInsertTwice(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ssn := testEngine.NewSession()
|
ssn := testEngine.NewSession()
|
||||||
defer func(ssn *xorm.Session) { _ = ssn.Close() }(ssn)
|
defer ssn.Close()
|
||||||
|
|
||||||
err := ssn.Begin()
|
err := ssn.Begin()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -1209,166 +1209,3 @@ func TestInsertMultipleMap(t *testing.T) {
|
||||||
Name: "xiaolunwen",
|
Name: "xiaolunwen",
|
||||||
}, res[1])
|
}, res[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInsertNotDeleted(t *testing.T) {
|
|
||||||
assert.NoError(t, PrepareEngine())
|
|
||||||
zeroTime := time.Date(1, 1, 1, 0, 0, 0, 0, testEngine.GetTZDatabase())
|
|
||||||
type TestInsertNotDeletedStructNotRight struct {
|
|
||||||
ID uint64 `xorm:"'ID' pk autoincr"`
|
|
||||||
DeletedAt time.Time `xorm:"'DELETED_AT' deleted notnull"`
|
|
||||||
}
|
|
||||||
// notnull tag will be ignored
|
|
||||||
err := testEngine.Sync(new(TestInsertNotDeletedStructNotRight))
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
type TestInsertNotDeletedStruct struct {
|
|
||||||
ID uint64 `xorm:"'ID' pk autoincr"`
|
|
||||||
DeletedAt time.Time `xorm:"'DELETED_AT' deleted"`
|
|
||||||
}
|
|
||||||
|
|
||||||
err = testEngine.Sync(new(TestInsertNotDeletedStruct))
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
var v1 TestInsertNotDeletedStructNotRight
|
|
||||||
_, err = testEngine.Insert(&v1)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
var v2 TestInsertNotDeletedStructNotRight
|
|
||||||
has, err := testEngine.Get(&v2)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.True(t, has)
|
|
||||||
assert.Equal(t, v2.DeletedAt.In(testEngine.GetTZDatabase()).Format("2006-01-02 15:04:05"), zeroTime.Format("2006-01-02 15:04:05"))
|
|
||||||
|
|
||||||
var v3 TestInsertNotDeletedStruct
|
|
||||||
_, err = testEngine.Insert(&v3)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
var v4 TestInsertNotDeletedStruct
|
|
||||||
has, err = testEngine.Get(&v4)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.True(t, has)
|
|
||||||
assert.Equal(t, v4.DeletedAt.In(testEngine.GetTZDatabase()).Format("2006-01-02 15:04:05"), zeroTime.Format("2006-01-02 15:04:05"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestInsertNotDeletedNum(t *testing.T) {
|
|
||||||
assert.NoError(t, PrepareEngine())
|
|
||||||
type TestInsertNotDeletedNumStructNotRight struct {
|
|
||||||
ID uint64 `xorm:"'ID' pk autoincr"`
|
|
||||||
DeletedAt int64 `xorm:"'DELETED_AT' deleted notnull INT(11)"`
|
|
||||||
}
|
|
||||||
// notnull tag will be ignored
|
|
||||||
err := testEngine.Sync(new(TestInsertNotDeletedNumStructNotRight))
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
type TestInsertNotDeletedNumStruct struct {
|
|
||||||
ID uint64 `xorm:"'ID' pk autoincr"`
|
|
||||||
DeletedAt int64 `xorm:"'DELETED_AT' deleted INT(11)"`
|
|
||||||
}
|
|
||||||
|
|
||||||
err = testEngine.Sync(new(TestInsertNotDeletedNumStruct))
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
var v1 TestInsertNotDeletedNumStructNotRight
|
|
||||||
_, err = testEngine.Insert(&v1)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
var v2 TestInsertNotDeletedNumStructNotRight
|
|
||||||
has, err := testEngine.Get(&v2)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.True(t, has)
|
|
||||||
assert.Equal(t, v2.DeletedAt, int64(0))
|
|
||||||
|
|
||||||
var v3 TestInsertNotDeletedNumStruct
|
|
||||||
_, err = testEngine.Insert(&v3)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
var v4 TestInsertNotDeletedNumStruct
|
|
||||||
has, err = testEngine.Get(&v4)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.True(t, has)
|
|
||||||
assert.Equal(t, v4.DeletedAt, int64(0))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestInsertNotDeletedTimeStamp(t *testing.T) {
|
|
||||||
assert.NoError(t, PrepareEngine())
|
|
||||||
|
|
||||||
// IN MYSQL DB
|
|
||||||
// The time range that timestamps can store is from '1970 01 01 00:00:01.000000' to '2038 01 19 03:14:07.999999'
|
|
||||||
// PASS notnull timestamp IN MYSQL DB
|
|
||||||
if testEngine.Dialect().URI().DBType == schemas.MSSQL ||
|
|
||||||
testEngine.Dialect().URI().DBType == schemas.SQLITE ||
|
|
||||||
testEngine.Dialect().URI().DBType == schemas.POSTGRES {
|
|
||||||
|
|
||||||
type TestInsertNotDeletedTimeStampStructNotRight struct {
|
|
||||||
ID uint64 `xorm:"'ID' pk autoincr"`
|
|
||||||
DeletedAt time.Time `xorm:"'DELETED_AT' deleted notnull TIMESTAMP"`
|
|
||||||
}
|
|
||||||
err := testEngine.Sync(new(TestInsertNotDeletedTimeStampStructNotRight))
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
var v1 TestInsertNotDeletedTimeStampStructNotRight
|
|
||||||
_, err = testEngine.Insert(&v1)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
var v2 TestInsertNotDeletedTimeStampStructNotRight
|
|
||||||
has, err := testEngine.Get(&v2)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.True(t, has)
|
|
||||||
assert.Equal(t, v2.DeletedAt, time.Unix(0, 0))
|
|
||||||
}
|
|
||||||
|
|
||||||
type TestInsertNotDeletedTimeStampStruct struct {
|
|
||||||
ID uint64 `xorm:"'ID' pk autoincr"`
|
|
||||||
DeletedAt time.Time `xorm:"'DELETED_AT' deleted TIMESTAMP"`
|
|
||||||
}
|
|
||||||
err := testEngine.Sync(new(TestInsertNotDeletedTimeStampStruct))
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
var v3 TestInsertNotDeletedTimeStampStruct
|
|
||||||
_, err = testEngine.Insert(&v3)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
var v4 TestInsertNotDeletedTimeStampStruct
|
|
||||||
has, err := testEngine.Get(&v4)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.True(t, has)
|
|
||||||
assert.Equal(t, v4.DeletedAt, time.Time{})
|
|
||||||
}
|
|
||||||
|
|
||||||
type MyAutoTimeFields1 struct {
|
|
||||||
Id int64
|
|
||||||
Dt time.Time `xorm:"created DATETIME"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (MyAutoTimeFields1) TableName() string {
|
|
||||||
return "my_auto_time_fields"
|
|
||||||
}
|
|
||||||
|
|
||||||
type MyAutoTimeFields2 struct {
|
|
||||||
Id int64
|
|
||||||
Dt time.Time `xorm:"created"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (MyAutoTimeFields2) TableName() string {
|
|
||||||
return "my_auto_time_fields"
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAutoTimeFields(t *testing.T) {
|
|
||||||
assert.NoError(t, PrepareEngine())
|
|
||||||
|
|
||||||
assertSync(t, new(MyAutoTimeFields1))
|
|
||||||
|
|
||||||
_, err := testEngine.Insert(&MyAutoTimeFields1{})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
var res []MyAutoTimeFields2
|
|
||||||
assert.NoError(t, testEngine.Find(&res))
|
|
||||||
assert.EqualValues(t, 1, len(res))
|
|
||||||
|
|
||||||
_, err = testEngine.Insert(&MyAutoTimeFields2{})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
res = []MyAutoTimeFields2{}
|
|
||||||
assert.NoError(t, testEngine.Find(&res))
|
|
||||||
assert.EqualValues(t, 2, len(res))
|
|
||||||
}
|
|
||||||
|
|
|
@ -7,11 +7,11 @@ package tests
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"xorm.io/xorm/convert"
|
|
||||||
"xorm.io/xorm/internal/utils"
|
"xorm.io/xorm/internal/utils"
|
||||||
"xorm.io/xorm/names"
|
"xorm.io/xorm/names"
|
||||||
"xorm.io/xorm/schemas"
|
"xorm.io/xorm/schemas"
|
||||||
|
@ -1201,10 +1201,8 @@ func TestTagTime(t *testing.T) {
|
||||||
has, err = testEngine.Table("tag_u_t_c_struct").Cols("created").Get(&tm)
|
has, err = testEngine.Table("tag_u_t_c_struct").Cols("created").Get(&tm)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, has)
|
assert.True(t, has)
|
||||||
|
assert.EqualValues(t, s.Created.UTC().Format("2006-01-02 15:04:05"),
|
||||||
tmTime, err := convert.String2Time(tm, time.UTC, time.UTC)
|
strings.ReplaceAll(strings.ReplaceAll(tm, "T", " "), "Z", ""))
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.EqualValues(t, s.Created.UTC().Format("2006-01-02 15:04:05"), tmTime.Format("2006-01-02 15:04:05"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTagAutoIncr(t *testing.T) {
|
func TestTagAutoIncr(t *testing.T) {
|
||||||
|
|
|
@ -619,95 +619,3 @@ func TestMyArray(t *testing.T) {
|
||||||
assert.True(t, has)
|
assert.True(t, has)
|
||||||
assert.EqualValues(t, v, m.Content)
|
assert.EqualValues(t, v, m.Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ZDecimal struct {
|
|
||||||
value *big.Int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *ZDecimal) FromDB(data []byte) error {
|
|
||||||
i, _ := strconv.ParseInt(string(data), 10, 64)
|
|
||||||
*d = ZDecimal{
|
|
||||||
value: big.NewInt(i),
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d ZDecimal) ToDB() ([]byte, error) {
|
|
||||||
if d.value == nil {
|
|
||||||
return []byte("0"), nil
|
|
||||||
}
|
|
||||||
return []byte(fmt.Sprintf("%d", (d.value).Int64())), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d ZDecimal) IsZero() bool {
|
|
||||||
if d.value == nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return d.value.Sign() == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d ZDecimal) String() string {
|
|
||||||
if d.value == nil {
|
|
||||||
return "0"
|
|
||||||
}
|
|
||||||
return d.value.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestZDecimal(t *testing.T) {
|
|
||||||
type ZMyMoney struct {
|
|
||||||
Id int64
|
|
||||||
Account string
|
|
||||||
Amount ZDecimal
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.NoError(t, PrepareEngine())
|
|
||||||
assertSync(t, new(ZMyMoney))
|
|
||||||
|
|
||||||
_, err := testEngine.Insert(&ZMyMoney{
|
|
||||||
Account: "test",
|
|
||||||
Amount: ZDecimal{
|
|
||||||
value: big.NewInt(10000000000000000),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
m := ZMyMoney{
|
|
||||||
Id: 1,
|
|
||||||
}
|
|
||||||
has, err := testEngine.Get(&m)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.True(t, has)
|
|
||||||
|
|
||||||
_, err = testEngine.Update(&ZMyMoney{
|
|
||||||
Id: 1,
|
|
||||||
Account: "test2",
|
|
||||||
})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
m2 := ZMyMoney{
|
|
||||||
Id: 1,
|
|
||||||
}
|
|
||||||
has, err = testEngine.Get(&m2)
|
|
||||||
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.True(t, has)
|
|
||||||
assert.Equal(t, "test2", "test2")
|
|
||||||
assert.False(t, m2.Amount.IsZero())
|
|
||||||
assert.Equal(t, "10000000000000000", m2.Amount.String())
|
|
||||||
|
|
||||||
_, err = testEngine.AllCols().Update(&ZMyMoney{
|
|
||||||
Id: 1,
|
|
||||||
Account: "test3",
|
|
||||||
})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
var m3 = ZMyMoney{
|
|
||||||
Id: 1,
|
|
||||||
}
|
|
||||||
has, err = testEngine.Get(&m3)
|
|
||||||
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.True(t, has)
|
|
||||||
assert.Equal(t, "test3", "test3")
|
|
||||||
assert.True(t, m3.Amount.IsZero())
|
|
||||||
assert.Equal(t, "0", m3.Amount.String())
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue